1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-17 16:03:46 +00:00

[PM-6513] Omit creating CredentialIdentity if it throws an exception (#3040)

* PM-6513 Omit creating CredentialIdentity if that throws, so it doesn't affect other ciphers. E.g. if a Passkey doesn't have a UserName it will throw here and it shouldn't break replacing all the other identities.

* PM-6513 Added fallback values to passkey username not being set
This commit is contained in:
Federico Maccaroni
2024-02-29 11:08:13 -03:00
committed by GitHub
parent 18fae7ddd8
commit 38d3a7ed41

View File

@@ -2,6 +2,7 @@
using Bit.Core.Abstractions;
using Bit.Core.Enums;
using Bit.Core.Models.View;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Foundation;
using UIKit;
@@ -135,21 +136,40 @@ namespace Bit.iOS.Core.Utilities
public static IASCredentialIdentity? ToCredentialIdentity(CipherView cipher)
{
if (!cipher.HasFido2Credential)
try
{
return ToPasswordCredentialIdentity(cipher);
}
if (!cipher.HasFido2Credential)
{
return ToPasswordCredentialIdentity(cipher);
}
if (!cipher.Login.MainFido2Credential.DiscoverableValue)
if (!cipher.Login.MainFido2Credential.DiscoverableValue)
{
return null;
}
var userName = cipher.Login.MainFido2Credential.UserName;
if (string.IsNullOrWhiteSpace(userName))
{
userName = cipher.Login.MainFido2Credential.UserDisplayName;
if (string.IsNullOrWhiteSpace(userName))
{
userName = cipher.Login.Username;
}
}
return new ASPasskeyCredentialIdentity(cipher.Login.MainFido2Credential.RpId,
userName,
NSData.FromArray(cipher.Login.MainFido2Credential.CredentialId.GuidToRawFormat()),
cipher.Login.MainFido2Credential.UserHandle,
cipher.Id);
}
catch (Exception ex)
{
LoggerHelper.LogEvenIfCantBeResolved(ex);
return null;
}
return new ASPasskeyCredentialIdentity(cipher.Login.MainFido2Credential.RpId,
cipher.Login.MainFido2Credential.UserName,
NSData.FromArray(cipher.Login.MainFido2Credential.CredentialId.GuidToRawFormat()),
cipher.Login.MainFido2Credential.UserHandle,
cipher.Id);
}
}
}