From d7292988f6da537f2f4d41180d54f54b2d19bb97 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 24 Aug 2025 15:32:29 -0700 Subject: [PATCH] Fixes. --- Sources/Packages/Localizable.xcstrings | 3 --- .../Tests/SecretAgentKitTests/AgentTests.swift | 2 +- .../Tests/SecretAgentKitTests/StubStore.swift | 17 +++++------------ Sources/SecretAgent/Notifier.swift | 2 +- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Sources/Packages/Localizable.xcstrings b/Sources/Packages/Localizable.xcstrings index 357949a..b8fc719 100644 --- a/Sources/Packages/Localizable.xcstrings +++ b/Sources/Packages/Localizable.xcstrings @@ -5356,9 +5356,6 @@ } } } - }, - "Test" : { - }, "test@example.com" : { diff --git a/Sources/Packages/Tests/SecretAgentKitTests/AgentTests.swift b/Sources/Packages/Tests/SecretAgentKitTests/AgentTests.swift index 7cd519e..4112820 100644 --- a/Sources/Packages/Tests/SecretAgentKitTests/AgentTests.swift +++ b/Sources/Packages/Tests/SecretAgentKitTests/AgentTests.swift @@ -35,7 +35,7 @@ import CryptoKit #expect(stubWriter.data == Constants.Responses.requestFailure) } - @Test func signature() async throws { + @Test func ecdsaSignature() async throws { let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature) let requestReader = OpenSSHReader(data: Constants.Requests.requestSignature[5...]) _ = requestReader.readNextChunk() diff --git a/Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift b/Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift index b78cda9..6f37469 100644 --- a/Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift +++ b/Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift @@ -52,13 +52,8 @@ extension Stub { guard !shouldThrow else { throw NSError(domain: "test", code: 0, userInfo: nil) } - let privateKey = SecKeyCreateWithData(secret.privateKey as CFData, KeychainDictionary([ - kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom, - kSecAttrKeySizeInBits: secret.keySize, - kSecAttrKeyClass: kSecAttrKeyClassPrivate - ]) - , nil)! - return SecKeyCreateSignature(privateKey, signatureAlgorithm(for: secret), data as CFData, nil)! as Data + let privateKey = try CryptoKit.P256.Signing.PrivateKey(x963Representation: secret.privateKey) + return try privateKey.signature(for: data).rawRepresentation } public func existingPersistedAuthenticationContext(secret: Stub.Secret) -> PersistedAuthenticationContext? { @@ -81,22 +76,20 @@ extension Stub { let id = Data(UUID().uuidString.utf8) let name = UUID().uuidString - let algorithm = Algorithm.ecdsa - - let keySize: Int + let attributes: Attributes let publicKey: Data let requiresAuthentication = false let privateKey: Data init(keySize: Int, publicKey: Data, privateKey: Data) { - self.keySize = keySize + self.attributes = Attributes(keyType: .init(algorithm: .ecdsa, size: keySize), authentication: .notRequired) self.publicKey = publicKey self.privateKey = privateKey } var debugDescription: String { """ - Key Size \(keySize) + Key Size \(keyType.size) Private: \(privateKey.base64EncodedString()) Public: \(publicKey.base64EncodedString()) """ diff --git a/Sources/SecretAgent/Notifier.swift b/Sources/SecretAgent/Notifier.swift index 62540b8..fa48cdd 100644 --- a/Sources/SecretAgent/Notifier.swift +++ b/Sources/SecretAgent/Notifier.swift @@ -69,7 +69,7 @@ final class Notifier: Sendable { notificationContent.userInfo[Constants.persistSecretIDKey] = secret.id.description notificationContent.userInfo[Constants.persistStoreIDKey] = store.id.description notificationContent.interruptionLevel = .timeSensitive - if await store.existingPersistedAuthenticationContext(secret: secret) == nil && secret.requiresAuthentication { + if await store.existingPersistedAuthenticationContext(secret: secret) == nil && secret.authenticationRequirement.required { notificationContent.categoryIdentifier = Constants.persistAuthenticationCategoryIdentitifier } if let iconURL = provenance.origin.iconURL, let attachment = try? UNNotificationAttachment(identifier: "icon", url: iconURL, options: nil) {