diff --git a/src/App/Constants.cs b/src/App/Constants.cs index 3d06223e4..2f243f01d 100644 --- a/src/App/Constants.cs +++ b/src/App/Constants.cs @@ -3,6 +3,7 @@ public static class Constants { public const string AndroidAppProtocol = "androidapp://"; + public const string iOSAppProtocol = "iosapp://"; public const string SettingFingerprintUnlockOn = "setting:fingerprintUnlockOn"; public const string SettingPinUnlockOn = "setting:pinUnlockOn"; diff --git a/src/App/Services/LoginService.cs b/src/App/Services/LoginService.cs index 42d1a6c7c..e8ce289ca 100644 --- a/src/App/Services/LoginService.cs +++ b/src/App/Services/LoginService.cs @@ -80,27 +80,30 @@ namespace Bit.App.Services Uri uri = null; string domainName = null; var androidApp = UriIsAndroidApp(uriString); + var iosApp = UriIsiOSApp(uriString); + var mobileApp = androidApp || iosApp; - if(!androidApp && - (!Uri.TryCreate(uriString, UriKind.Absolute, out uri) || + if(!mobileApp && + (!Uri.TryCreate(uriString, UriKind.Absolute, out uri) || !DomainName.TryParseBaseDomain(uri.Host, out domainName))) { return null; } - var androidAppWebUriString = WebUriFromAndroidAppUri(uriString); + var mobileAppWebUriString = androidApp ? WebUriFromAndroidAppUri(uriString) : + iosApp ? WebUriFromiOSAppUri(uriString) : null; var eqDomains = (await _settingsService.GetEquivalentDomainsAsync()).Select(d => d.ToArray()); var matchingDomains = new List(); var matchingFuzzyDomains = new List(); foreach(var eqDomain in eqDomains) { - if(androidApp) + if(mobileApp) { if(Array.IndexOf(eqDomain, uriString) >= 0) { matchingDomains.AddRange(eqDomain.Select(d => d).ToList()); } - else if(androidAppWebUriString != null && Array.IndexOf(eqDomain, androidAppWebUriString) >= 0) + else if(mobileAppWebUriString != null && Array.IndexOf(eqDomain, mobileAppWebUriString) >= 0) { matchingFuzzyDomains.AddRange(eqDomain.Select(d => d).ToList()); } @@ -113,13 +116,13 @@ namespace Bit.App.Services if(!matchingDomains.Any()) { - matchingDomains.Add(androidApp ? uriString : domainName); + matchingDomains.Add(mobileApp ? uriString : domainName); } - if(androidApp && androidAppWebUriString != null && - !matchingFuzzyDomains.Any() && !matchingDomains.Contains(androidAppWebUriString)) + if(mobileApp && mobileAppWebUriString != null && + !matchingFuzzyDomains.Any() && !matchingDomains.Contains(mobileAppWebUriString)) { - matchingFuzzyDomains.Add(androidAppWebUriString); + matchingFuzzyDomains.Add(mobileAppWebUriString); } var matchingDomainsArray = matchingDomains.ToArray(); @@ -145,12 +148,12 @@ namespace Bit.App.Services matchingLogins.Add(new Login(login)); continue; } - else if(androidApp && Array.IndexOf(matchingFuzzyDomainsArray, loginUriString) >= 0) + else if(mobileApp && Array.IndexOf(matchingFuzzyDomainsArray, loginUriString) >= 0) { matchingFuzzyLogins.Add(new Login(login)); continue; } - else if(!androidApp && Array.IndexOf(matchingDomainsArray, WebUriFromAndroidAppUri(loginUriString)) >= 0) + else if(!mobileApp && Array.IndexOf(matchingDomainsArray, WebUriFromAndroidAppUri(loginUriString)) >= 0) { matchingFuzzyLogins.Add(new Login(login)); continue; @@ -168,7 +171,7 @@ namespace Bit.App.Services { matchingLogins.Add(new Login(login)); } - else if(androidApp && Array.IndexOf(matchingFuzzyDomainsArray, loginDomainName) >= 0) + else if(mobileApp && Array.IndexOf(matchingFuzzyDomainsArray, loginDomainName) >= 0) { matchingFuzzyLogins.Add(new Login(login)); } @@ -320,9 +323,24 @@ namespace Bit.App.Services return null; } + private string WebUriFromiOSAppUri(string iosAppUriString) + { + if(!UriIsiOSApp(iosAppUriString)) + { + return null; + } + + return iosAppUriString.Replace(Constants.iOSAppProtocol, string.Empty); + } + private bool UriIsAndroidApp(string uriString) { return uriString.StartsWith(Constants.AndroidAppProtocol); } + + private bool UriIsiOSApp(string uriString) + { + return uriString.StartsWith(Constants.iOSAppProtocol); + } } } diff --git a/src/iOS.Extension/LoginListViewController.cs b/src/iOS.Extension/LoginListViewController.cs index 45f6091e3..4b201563f 100644 --- a/src/iOS.Extension/LoginListViewController.cs +++ b/src/iOS.Extension/LoginListViewController.cs @@ -14,6 +14,7 @@ using Bit.iOS.Core; using MobileCoreServices; using Bit.iOS.Core.Controllers; using Bit.App.Resources; +using Bit.App.Models; namespace Bit.iOS.Extension { @@ -119,8 +120,19 @@ namespace Bit.iOS.Extension public async Task LoadItemsAsync() { + var combinedLogins = new List(); + var logins = await _loginService.GetAllAsync(_context.UrlString); - _tableItems = logins?.Item1?.Select(s => new LoginViewModel(s)) + if(logins?.Item1 != null) + { + combinedLogins.AddRange(logins.Item1); + } + if(logins?.Item2 != null) + { + combinedLogins.AddRange(logins.Item2); + } + + _tableItems = combinedLogins.Select(s => new LoginViewModel(s)) .OrderBy(s => s.Name) .ThenBy(s => s.Username) .ToList() ?? new List(); diff --git a/src/iOS.Extension/Models/Context.cs b/src/iOS.Extension/Models/Context.cs index fe6c6fa81..992388630 100644 --- a/src/iOS.Extension/Models/Context.cs +++ b/src/iOS.Extension/Models/Context.cs @@ -1,5 +1,6 @@ using System; using Foundation; +using Bit.App; namespace Bit.iOS.Extension.Models { @@ -31,13 +32,18 @@ namespace Bit.iOS.Extension.Models set { _uriString = value; - if(_uriString != null && _uriString.Contains(".")) + if(_uriString != null && !_uriString.StartsWith(Constants.iOSAppProtocol) && _uriString.Contains(".")) { if(!_uriString.Contains("://") && !_uriString.Contains(" ")) { _uriString = string.Concat("http://", _uriString); } } + + if(!_uriString.StartsWith("http") && !_uriString.StartsWith(Constants.iOSAppProtocol)) + { + _uriString = string.Concat(Constants.iOSAppProtocol, _uriString); + } } } public string LoginTitle { get; set; }