mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
build identity store for quick type bar
This commit is contained in:
parent
197683b722
commit
f153c7509c
7 changed files with 118 additions and 13 deletions
|
@ -147,6 +147,8 @@ namespace Bit.iOS.Autofill
|
|||
public override void PrepareInterfaceForExtensionConfiguration()
|
||||
{
|
||||
base.PrepareInterfaceForExtensionConfiguration();
|
||||
var task = ASHelpers.ReplaceAllIdentities(Resolver.Resolve<ICipherService>());
|
||||
ExtensionContext.CompleteExtensionConfigurationRequest();
|
||||
}
|
||||
|
||||
public void CompleteRequest(string username = null, string password = null, string totp = null)
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
<string>MainInterface</string>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.authentication-services-credential-provider-ui</string>
|
||||
<key>ASCredentialProviderExtensionShowsConfigurationUI</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace Bit.iOS.Core.Controllers
|
|||
private IConnectivity _connectivity;
|
||||
private IEnumerable<Folder> _folders;
|
||||
protected IGoogleAnalyticsService _googleAnalyticsService;
|
||||
private bool _isAutofill;
|
||||
|
||||
public LoginAddViewController(IntPtr handle) : base(handle)
|
||||
{
|
||||
|
|
72
src/iOS.Core/Utilities/ASHelpers.cs
Normal file
72
src/iOS.Core/Utilities/ASHelpers.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AuthenticationServices;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models;
|
||||
|
||||
namespace Bit.iOS.Core.Utilities
|
||||
{
|
||||
public static class ASHelpers
|
||||
{
|
||||
public static async Task ReplaceAllIdentities(ICipherService cipherService)
|
||||
{
|
||||
if (await AutofillEnabled())
|
||||
{
|
||||
var identities = new List<ASPasswordCredentialIdentity>();
|
||||
var ciphers = await cipherService.GetAllAsync();
|
||||
foreach (var cipher in ciphers)
|
||||
{
|
||||
var identity = ToCredentialIdentity(cipher);
|
||||
if (identity != null)
|
||||
{
|
||||
identities.Add(identity);
|
||||
}
|
||||
}
|
||||
if (identities.Any())
|
||||
{
|
||||
await ASCredentialIdentityStore.SharedStore.ReplaceCredentialIdentitiesAsync(identities.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> IdentitiesCanIncremental()
|
||||
{
|
||||
var state = await ASCredentialIdentityStore.SharedStore.GetCredentialIdentityStoreStateAsync();
|
||||
return state.Enabled && state.SupportsIncrementalUpdates;
|
||||
}
|
||||
|
||||
public static async Task<bool> AutofillEnabled()
|
||||
{
|
||||
var state = await ASCredentialIdentityStore.SharedStore.GetCredentialIdentityStoreStateAsync();
|
||||
return state.Enabled;
|
||||
}
|
||||
|
||||
public static async Task<ASPasswordCredentialIdentity> GetCipherIdentityAsync(string cipherId, ICipherService cipherService)
|
||||
{
|
||||
var cipher = await cipherService.GetByIdAsync(cipherId);
|
||||
return ToCredentialIdentity(cipher);
|
||||
}
|
||||
|
||||
public static ASPasswordCredentialIdentity ToCredentialIdentity(Cipher cipher)
|
||||
{
|
||||
if (!cipher?.Login?.Uris?.Any() ?? true)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var uri = cipher.Login.Uris.FirstOrDefault()?.Uri?.Decrypt(cipher.OrganizationId);
|
||||
if (string.IsNullOrWhiteSpace(uri))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var username = cipher.Login.Username?.Decrypt(cipher.OrganizationId);
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var serviceId = new ASCredentialServiceIdentifier(uri, ASCredentialServiceIdentifierType.Url);
|
||||
return new ASPasswordCredentialIdentity(serviceId, username, cipher.Id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -73,6 +73,7 @@
|
|||
<Compile Include="Views\FormEntryTableViewCell.cs" />
|
||||
<Compile Include="Views\Toast.cs" />
|
||||
<Compile Include="Models\CipherViewModel.cs" />
|
||||
<Compile Include="Utilities\ASHelpers.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\App\App.csproj">
|
||||
|
|
|
@ -21,6 +21,12 @@ using SimpleInjector;
|
|||
using XLabs.Ioc.SimpleInjectorContainer;
|
||||
using CoreNFC;
|
||||
using Bit.App.Resources;
|
||||
using AuthenticationServices;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Models;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Bit.iOS.Core.Utilities;
|
||||
|
||||
namespace Bit.iOS
|
||||
{
|
||||
|
@ -31,6 +37,7 @@ namespace Bit.iOS
|
|||
private NFCNdefReaderSession _nfcSession = null;
|
||||
private ILockService _lockService;
|
||||
private IDeviceInfoService _deviceInfoService;
|
||||
private ICipherService _cipherService;
|
||||
private iOSPushNotificationHandler _pushHandler = null;
|
||||
private NFCReaderDelegate _nfcDelegate = null;
|
||||
|
||||
|
@ -47,6 +54,7 @@ namespace Bit.iOS
|
|||
|
||||
_lockService = Resolver.Resolve<ILockService>();
|
||||
_deviceInfoService = Resolver.Resolve<IDeviceInfoService>();
|
||||
_cipherService = Resolver.Resolve<ICipherService>();
|
||||
_pushHandler = new iOSPushNotificationHandler(Resolver.Resolve<IPushNotificationListener>());
|
||||
_nfcDelegate = new NFCReaderDelegate((success, message) => ProcessYubikey(success, message));
|
||||
var appIdService = Resolver.Resolve<IAppIdService>();
|
||||
|
@ -139,30 +147,51 @@ namespace Bit.iOS
|
|||
});
|
||||
|
||||
MessagingCenter.Subscribe<Xamarin.Forms.Application, bool>(
|
||||
Xamarin.Forms.Application.Current, "FullSyncCompleted", (sender, successfully) =>
|
||||
Xamarin.Forms.Application.Current, "FullSyncCompleted", async (sender, successfully) =>
|
||||
{
|
||||
if(successfully)
|
||||
{
|
||||
|
||||
await ASHelpers.ReplaceAllIdentities(_cipherService);
|
||||
}
|
||||
});
|
||||
|
||||
MessagingCenter.Subscribe<Xamarin.Forms.Application, string>(
|
||||
Xamarin.Forms.Application.Current, "UpsertedCipher", (sender, id) =>
|
||||
Xamarin.Forms.Application.Current, "UpsertedCipher", async (sender, id) =>
|
||||
{
|
||||
|
||||
if (await ASHelpers.IdentitiesCanIncremental())
|
||||
{
|
||||
var identity = await ASHelpers.GetCipherIdentityAsync(id, _cipherService);
|
||||
if(identity == null) {
|
||||
return;
|
||||
}
|
||||
await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
|
||||
new ASPasswordCredentialIdentity[] { identity });
|
||||
}
|
||||
else
|
||||
{
|
||||
await ASHelpers.ReplaceAllIdentities(_cipherService);
|
||||
}
|
||||
});
|
||||
|
||||
MessagingCenter.Subscribe<Xamarin.Forms.Application, string>(
|
||||
Xamarin.Forms.Application.Current, "DeletedCipher", (sender, id) =>
|
||||
Xamarin.Forms.Application.Current, "DeletedCipher", async (sender, id) =>
|
||||
{
|
||||
|
||||
if(await ASHelpers.IdentitiesCanIncremental())
|
||||
{
|
||||
var identity = new ASPasswordCredentialIdentity(null, null, id);
|
||||
await ASCredentialIdentityStore.SharedStore.RemoveCredentialIdentitiesAsync(
|
||||
new ASPasswordCredentialIdentity[] { identity });
|
||||
}
|
||||
else
|
||||
{
|
||||
await ASHelpers.ReplaceAllIdentities(_cipherService);
|
||||
}
|
||||
});
|
||||
|
||||
MessagingCenter.Subscribe<Xamarin.Forms.Application>(
|
||||
Xamarin.Forms.Application.Current, "LoggedOut", (sender) =>
|
||||
Xamarin.Forms.Application.Current, "LoggedOut", async (sender) =>
|
||||
{
|
||||
|
||||
await ASCredentialIdentityStore.SharedStore.RemoveAllCredentialIdentitiesAsync();
|
||||
});
|
||||
|
||||
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
<array>
|
||||
<string>$(AppIdentifierPrefix)com.8bit.bitwarden</string>
|
||||
</array>
|
||||
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.$(CFBundleIdentifier)</string>
|
||||
</array>
|
||||
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.$(CFBundleIdentifier)</string>
|
||||
</array>
|
||||
<key>com.apple.developer.nfc.readersession.formats</key>
|
||||
<array>
|
||||
<string>NDEF</string>
|
||||
|
|
Loading…
Reference in a new issue