From e7dc340dd587b232330d388abd17fb04fc6e4608 Mon Sep 17 00:00:00 2001 From: zunda <47569369+zunda-pixel@users.noreply.github.com> Date: Tue, 17 Sep 2024 00:23:34 +0900 Subject: [PATCH] fix string -> data function unwrap --- .../Authentication/AuthenticatorAssertionResponse.swift | 4 +--- .../WebAuthn/Ceremonies/Registration/AttestationObject.swift | 2 +- Sources/WebAuthn/WebAuthnError.swift | 2 -- Tests/WebAuthnTests/Utils/TestModels/TestAuthData.swift | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Sources/WebAuthn/Ceremonies/Authentication/AuthenticatorAssertionResponse.swift b/Sources/WebAuthn/Ceremonies/Authentication/AuthenticatorAssertionResponse.swift index 12474e8c..e99f5ba8 100644 --- a/Sources/WebAuthn/Ceremonies/Authentication/AuthenticatorAssertionResponse.swift +++ b/Sources/WebAuthn/Ceremonies/Authentication/AuthenticatorAssertionResponse.swift @@ -102,9 +102,7 @@ struct ParsedAuthenticatorAssertionResponse: Sendable { relyingPartyOrigin: relyingPartyOrigin ) - guard let expectedRelyingPartyIDData = relyingPartyID.data(using: .utf8) else { - throw WebAuthnError.invalidRelyingPartyID - } + let expectedRelyingPartyIDData = Data(relyingPartyID.utf8) let expectedRelyingPartyIDHash = SHA256.hash(data: expectedRelyingPartyIDData) guard expectedRelyingPartyIDHash == authenticatorData.relyingPartyIDHash else { throw WebAuthnError.relyingPartyIDHashDoesNotMatch diff --git a/Sources/WebAuthn/Ceremonies/Registration/AttestationObject.swift b/Sources/WebAuthn/Ceremonies/Registration/AttestationObject.swift index b696e966..2f70129f 100644 --- a/Sources/WebAuthn/Ceremonies/Registration/AttestationObject.swift +++ b/Sources/WebAuthn/Ceremonies/Registration/AttestationObject.swift @@ -30,7 +30,7 @@ public struct AttestationObject: Sendable { supportedPublicKeyAlgorithms: [PublicKeyCredentialParameters], pemRootCertificatesByFormat: [AttestationFormat: [Data]] = [:] ) async throws -> AttestedCredentialData { - let relyingPartyIDHash = SHA256.hash(data: relyingPartyID.data(using: .utf8)!) + let relyingPartyIDHash = SHA256.hash(data: Data(relyingPartyID.utf8)) guard relyingPartyIDHash == authenticatorData.relyingPartyIDHash else { throw WebAuthnError.relyingPartyIDHashDoesNotMatch diff --git a/Sources/WebAuthn/WebAuthnError.swift b/Sources/WebAuthn/WebAuthnError.swift index 64a9749d..7e2a36a8 100644 --- a/Sources/WebAuthn/WebAuthnError.swift +++ b/Sources/WebAuthn/WebAuthnError.swift @@ -30,7 +30,6 @@ public struct WebAuthnError: Error, Hashable, Sendable { case invalidUserID case unsupportedCredentialPublicKeyAlgorithm case credentialIDAlreadyExists - case invalidRelyingPartyID case userVerifiedFlagNotSet case potentialReplayAttack case invalidAssertionCredentialType @@ -90,7 +89,6 @@ public struct WebAuthnError: Error, Hashable, Sendable { public static let invalidUserID = Self(reason: .invalidUserID) public static let unsupportedCredentialPublicKeyAlgorithm = Self(reason: .unsupportedCredentialPublicKeyAlgorithm) public static let credentialIDAlreadyExists = Self(reason: .credentialIDAlreadyExists) - public static let invalidRelyingPartyID = Self(reason: .invalidRelyingPartyID) public static let userVerifiedFlagNotSet = Self(reason: .userVerifiedFlagNotSet) public static let potentialReplayAttack = Self(reason: .potentialReplayAttack) public static let invalidAssertionCredentialType = Self(reason: .invalidAssertionCredentialType) diff --git a/Tests/WebAuthnTests/Utils/TestModels/TestAuthData.swift b/Tests/WebAuthnTests/Utils/TestModels/TestAuthData.swift index 856ff330..923401a3 100644 --- a/Tests/WebAuthnTests/Utils/TestModels/TestAuthData.swift +++ b/Tests/WebAuthnTests/Utils/TestModels/TestAuthData.swift @@ -87,7 +87,7 @@ struct TestAuthDataBuilder { } func relyingPartyIDHash(fromRelyingPartyID relyingPartyID: String) -> Self { - let relyingPartyIDData = relyingPartyID.data(using: .utf8)! + let relyingPartyIDData = Data(relyingPartyID.utf8) let relyingPartyIDHash = SHA256.hash(data: relyingPartyIDData) var temp = self temp.wrapped.relyingPartyIDHash = [UInt8](relyingPartyIDHash)