mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-27 12:26:31 +01:00
handle iOS apps that don't specify a url properly
This commit is contained in:
parent
3a5378d201
commit
30407f5b4e
@ -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";
|
||||
|
@ -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 &&
|
||||
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<string>();
|
||||
var matchingFuzzyDomains = new List<string>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Login>();
|
||||
|
||||
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<LoginViewModel>();
|
||||
|
@ -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; }
|
||||
|
Loading…
Reference in New Issue
Block a user