From 38d3a7ed41faaaa300b52c2e7750b84dfc961811 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Thu, 29 Feb 2024 11:08:13 -0300 Subject: [PATCH] [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 --- src/iOS.Core/Utilities/ASHelpers.cs | 40 +++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/iOS.Core/Utilities/ASHelpers.cs b/src/iOS.Core/Utilities/ASHelpers.cs index 22fcf7e7a..d04c8bdd1 100644 --- a/src/iOS.Core/Utilities/ASHelpers.cs +++ b/src/iOS.Core/Utilities/ASHelpers.cs @@ -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); } } }