mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 10:28:28 +03:00
handle iOS apps that don't specify a url properly
This commit is contained in:
parent
3a5378d201
commit
30407f5b4e
4 changed files with 51 additions and 14 deletions
|
@ -3,6 +3,7 @@
|
||||||
public static class Constants
|
public static class Constants
|
||||||
{
|
{
|
||||||
public const string AndroidAppProtocol = "androidapp://";
|
public const string AndroidAppProtocol = "androidapp://";
|
||||||
|
public const string iOSAppProtocol = "iosapp://";
|
||||||
|
|
||||||
public const string SettingFingerprintUnlockOn = "setting:fingerprintUnlockOn";
|
public const string SettingFingerprintUnlockOn = "setting:fingerprintUnlockOn";
|
||||||
public const string SettingPinUnlockOn = "setting:pinUnlockOn";
|
public const string SettingPinUnlockOn = "setting:pinUnlockOn";
|
||||||
|
|
|
@ -80,27 +80,30 @@ namespace Bit.App.Services
|
||||||
Uri uri = null;
|
Uri uri = null;
|
||||||
string domainName = null;
|
string domainName = null;
|
||||||
var androidApp = UriIsAndroidApp(uriString);
|
var androidApp = UriIsAndroidApp(uriString);
|
||||||
|
var iosApp = UriIsiOSApp(uriString);
|
||||||
|
var mobileApp = androidApp || iosApp;
|
||||||
|
|
||||||
if(!androidApp &&
|
if(!mobileApp &&
|
||||||
(!Uri.TryCreate(uriString, UriKind.Absolute, out uri) ||
|
(!Uri.TryCreate(uriString, UriKind.Absolute, out uri) ||
|
||||||
!DomainName.TryParseBaseDomain(uri.Host, out domainName)))
|
!DomainName.TryParseBaseDomain(uri.Host, out domainName)))
|
||||||
{
|
{
|
||||||
return null;
|
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 eqDomains = (await _settingsService.GetEquivalentDomainsAsync()).Select(d => d.ToArray());
|
||||||
var matchingDomains = new List<string>();
|
var matchingDomains = new List<string>();
|
||||||
var matchingFuzzyDomains = new List<string>();
|
var matchingFuzzyDomains = new List<string>();
|
||||||
foreach(var eqDomain in eqDomains)
|
foreach(var eqDomain in eqDomains)
|
||||||
{
|
{
|
||||||
if(androidApp)
|
if(mobileApp)
|
||||||
{
|
{
|
||||||
if(Array.IndexOf(eqDomain, uriString) >= 0)
|
if(Array.IndexOf(eqDomain, uriString) >= 0)
|
||||||
{
|
{
|
||||||
matchingDomains.AddRange(eqDomain.Select(d => d).ToList());
|
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());
|
matchingFuzzyDomains.AddRange(eqDomain.Select(d => d).ToList());
|
||||||
}
|
}
|
||||||
|
@ -113,13 +116,13 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
if(!matchingDomains.Any())
|
if(!matchingDomains.Any())
|
||||||
{
|
{
|
||||||
matchingDomains.Add(androidApp ? uriString : domainName);
|
matchingDomains.Add(mobileApp ? uriString : domainName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(androidApp && androidAppWebUriString != null &&
|
if(mobileApp && mobileAppWebUriString != null &&
|
||||||
!matchingFuzzyDomains.Any() && !matchingDomains.Contains(androidAppWebUriString))
|
!matchingFuzzyDomains.Any() && !matchingDomains.Contains(mobileAppWebUriString))
|
||||||
{
|
{
|
||||||
matchingFuzzyDomains.Add(androidAppWebUriString);
|
matchingFuzzyDomains.Add(mobileAppWebUriString);
|
||||||
}
|
}
|
||||||
|
|
||||||
var matchingDomainsArray = matchingDomains.ToArray();
|
var matchingDomainsArray = matchingDomains.ToArray();
|
||||||
|
@ -145,12 +148,12 @@ namespace Bit.App.Services
|
||||||
matchingLogins.Add(new Login(login));
|
matchingLogins.Add(new Login(login));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(androidApp && Array.IndexOf(matchingFuzzyDomainsArray, loginUriString) >= 0)
|
else if(mobileApp && Array.IndexOf(matchingFuzzyDomainsArray, loginUriString) >= 0)
|
||||||
{
|
{
|
||||||
matchingFuzzyLogins.Add(new Login(login));
|
matchingFuzzyLogins.Add(new Login(login));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(!androidApp && Array.IndexOf(matchingDomainsArray, WebUriFromAndroidAppUri(loginUriString)) >= 0)
|
else if(!mobileApp && Array.IndexOf(matchingDomainsArray, WebUriFromAndroidAppUri(loginUriString)) >= 0)
|
||||||
{
|
{
|
||||||
matchingFuzzyLogins.Add(new Login(login));
|
matchingFuzzyLogins.Add(new Login(login));
|
||||||
continue;
|
continue;
|
||||||
|
@ -168,7 +171,7 @@ namespace Bit.App.Services
|
||||||
{
|
{
|
||||||
matchingLogins.Add(new Login(login));
|
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));
|
matchingFuzzyLogins.Add(new Login(login));
|
||||||
}
|
}
|
||||||
|
@ -320,9 +323,24 @@ namespace Bit.App.Services
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string WebUriFromiOSAppUri(string iosAppUriString)
|
||||||
|
{
|
||||||
|
if(!UriIsiOSApp(iosAppUriString))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return iosAppUriString.Replace(Constants.iOSAppProtocol, string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
private bool UriIsAndroidApp(string uriString)
|
private bool UriIsAndroidApp(string uriString)
|
||||||
{
|
{
|
||||||
return uriString.StartsWith(Constants.AndroidAppProtocol);
|
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 MobileCoreServices;
|
||||||
using Bit.iOS.Core.Controllers;
|
using Bit.iOS.Core.Controllers;
|
||||||
using Bit.App.Resources;
|
using Bit.App.Resources;
|
||||||
|
using Bit.App.Models;
|
||||||
|
|
||||||
namespace Bit.iOS.Extension
|
namespace Bit.iOS.Extension
|
||||||
{
|
{
|
||||||
|
@ -119,8 +120,19 @@ namespace Bit.iOS.Extension
|
||||||
|
|
||||||
public async Task LoadItemsAsync()
|
public async Task LoadItemsAsync()
|
||||||
{
|
{
|
||||||
|
var combinedLogins = new List<Login>();
|
||||||
|
|
||||||
var logins = await _loginService.GetAllAsync(_context.UrlString);
|
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)
|
.OrderBy(s => s.Name)
|
||||||
.ThenBy(s => s.Username)
|
.ThenBy(s => s.Username)
|
||||||
.ToList() ?? new List<LoginViewModel>();
|
.ToList() ?? new List<LoginViewModel>();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using Foundation;
|
using Foundation;
|
||||||
|
using Bit.App;
|
||||||
|
|
||||||
namespace Bit.iOS.Extension.Models
|
namespace Bit.iOS.Extension.Models
|
||||||
{
|
{
|
||||||
|
@ -31,13 +32,18 @@ namespace Bit.iOS.Extension.Models
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_uriString = value;
|
_uriString = value;
|
||||||
if(_uriString != null && _uriString.Contains("."))
|
if(_uriString != null && !_uriString.StartsWith(Constants.iOSAppProtocol) && _uriString.Contains("."))
|
||||||
{
|
{
|
||||||
if(!_uriString.Contains("://") && !_uriString.Contains(" "))
|
if(!_uriString.Contains("://") && !_uriString.Contains(" "))
|
||||||
{
|
{
|
||||||
_uriString = string.Concat("http://", _uriString);
|
_uriString = string.Concat("http://", _uriString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!_uriString.StartsWith("http") && !_uriString.StartsWith(Constants.iOSAppProtocol))
|
||||||
|
{
|
||||||
|
_uriString = string.Concat(Constants.iOSAppProtocol, _uriString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string LoginTitle { get; set; }
|
public string LoginTitle { get; set; }
|
||||||
|
|
Loading…
Reference in a new issue