Add host lookup xpc service (#826)

* Add host lookup xpc service

* Remove restriction that snuck in

* Test fixes
This commit is contained in:
Max Goedjen
2026-09-06 21:32:51 -07:00
committed by GitHub
parent e9a0ff31d3
commit 70e32dcf99
21 changed files with 1126 additions and 42 deletions

View File

@@ -5548,6 +5548,378 @@
}
}
},
"auth_context_request_signature_for_connection_description" : {
"comment" : "When the user performs a signature action using a secret, they are shown a prompt to approve the action. This is the description, showing which secret will be used, and where the request is coming from. The first placeholder is the name of the app requesting the operation. The second placeholder is the name of the secret.",
"extractionState" : "manual",
"localizations" : {
"af" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"ar" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"ca" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "signa una petición de “%1$(appName)@” usant el secret “%2$(targetName)@”"
}
},
"cs" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"da" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"de" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "eine Anfrage von “%1$(appName)@” mit dem Secret “%2$(targetName)@” signieren"
}
},
"el" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "sign a request from “%1$(appName)@” to connect to “%2$(targetName)@” using secret “%3$(secretName)@”"
}
},
"es" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"fi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "allekirjoita pyyntö lähteestä “%1$(appName)@” käyttäen salaisuutta “%2$(targetName)@”"
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "signer une requête de “%1$(appName)@” en utilisant le secret “%2$(targetName)@”"
}
},
"he" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"hu" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"it" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "firma la richiesta di “%1$(appName)@” usando il Segreto “%2$(targetName)@”"
}
},
"ja" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "シークレット“%2$(targetName)@”を使って“%1$(appName)@”の要求に署名します"
}
},
"ko" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "비밀 “%2$(targetName)@”를 사용해서 “%1$(appName)@”의 요청에 서명"
}
},
"nb" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"nl" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"pl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "podpisz zapytanie od “%1$(appName)@” za pomocą sekretu “%2$(targetName)@”"
}
},
"pt" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "assinar requisição a partir do “%1$(appName)@” utilizando o segredo “%2$(targetName)@”"
}
},
"ro" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"ru" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "подписать запрос от “%1$(appName)@” используя секрет “%2$(targetName)@”"
}
},
"sr" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"sv" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"tr" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"uk" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"vi" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(appName)@” using secret “%2$(targetName)@”"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "用密钥串“%2$(targetName)@”认证来自“%1$(appName)@”的请求"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "用Secret「%2$(targetName)@」認證来自「%1$(appName)@」的请求"
}
}
}
},
"auth_context_request_signature_for_signature_description" : {
"comment" : "When the user performs a signature action using a secret, they are shown a prompt to approve the action. This is the description, showing which secret will be used, and where the request is coming from. The first placeholder is the name of the app requesting the operation. The second placeholder is the name of the secret.",
"extractionState" : "manual",
"localizations" : {
"af" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"ar" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"ca" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "signa una petición de “%1$(namespace)@” usant el secret “%2$(appName)@”"
}
},
"cs" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"da" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"de" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "eine Anfrage von “%1$(namespace)@” mit dem Secret “%2$(appName)@” signieren"
}
},
"el" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "sign a %1$(namespace)@“ request from “%2$(appName)@” using secret “%3$(secretName)@”"
}
},
"es" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"fi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "allekirjoita pyyntö lähteestä “%1$(namespace)@” käyttäen salaisuutta “%2$(appName)@”"
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "signer une requête de “%1$(namespace)@” en utilisant le secret “%2$(appName)@”"
}
},
"he" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"hu" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"it" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "firma la richiesta di “%1$(namespace)@” usando il Segreto “%2$(appName)@”"
}
},
"ja" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "シークレット“%2$(appName)@”を使って“%1$(namespace)@”の要求に署名します"
}
},
"ko" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "비밀 “%2$(appName)@”를 사용해서 “%1$(namespace)@”의 요청에 서명"
}
},
"nb" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"nl" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"pl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "podpisz zapytanie od “%1$(namespace)@” za pomocą sekretu “%2$(appName)@”"
}
},
"pt" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "assinar requisição a partir do “%1$(namespace)@” utilizando o segredo “%2$(appName)@”"
}
},
"ro" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"ru" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "подписать запрос от “%1$(namespace)@” используя секрет “%2$(appName)@”"
}
},
"sr" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"sv" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"tr" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"uk" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"vi" : {
"stringUnit" : {
"state" : "new",
"value" : "sign a request from “%1$(namespace)@” using secret “%2$(appName)@”"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "用密钥串“%2$(appName)@”认证来自“%1$(namespace)@”的请求"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "用Secret「%2$(appName)@」認證来自「%1$(namespace)@」的请求"
}
}
}
},
"certificate_detail_critical_options_label" : {
"extractionState" : "manual",
"localizations" : {
@@ -23775,6 +24147,192 @@
}
}
},
"signed_connection_notification_description" : {
"comment" : "When the user performs an action using a secret, they're shown a notification describing what happened. This is the description, showing which secret was used. The placeholder is the name of the secret.",
"extractionState" : "manual",
"localizations" : {
"af" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"ar" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"ca" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Usant secret %1$(secretName)@"
}
},
"cs" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"da" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"de" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Benutze Secret %1$(secretName)@"
}
},
"el" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Using secret %1$(secretName)@ connecting to %2$(username)@@%3$(host)@"
}
},
"es" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"fi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Käytetään salaisuutta %1$(secretName)@"
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Utilisation du secret %1$(secretName)@"
}
},
"he" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"hu" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"it" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Usato il Segreto %1$(secretName)@"
}
},
"ja" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%1$(secretName)@を使用中"
}
},
"ko" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "비밀 %1$(secretName)@ 사용됨"
}
},
"nb" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"nl" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"pl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Użyto sekretu %1$(secretName)@"
}
},
"pt" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Utilizando o segredo %1$(secretName)@"
}
},
"ro" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"ru" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Используя секрет %1$(secretName)@"
}
},
"sr" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"sv" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"tr" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"uk" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"vi" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "使用密钥串 %1$(secretName)@"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "使用Secret「%1$(secretName)@」"
}
}
}
},
"signed_notification_description" : {
"comment" : "When the user performs an action using a secret, they're shown a notification describing what happened. This is the description, showing which secret was used. The placeholder is the name of the secret.",
"extractionState" : "manual",
@@ -24147,6 +24705,192 @@
}
}
},
"signed_signature_notification_description" : {
"comment" : "When the user performs an action using a secret, they're shown a notification describing what happened. This is the description, showing which secret was used. The placeholder is the name of the secret.",
"extractionState" : "manual",
"localizations" : {
"af" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"ar" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"ca" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Usant secret %1$(secretName)@"
}
},
"cs" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"da" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"de" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Benutze Secret %1$(secretName)@"
}
},
"el" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Using secret %1$(secretName)@ for %2$(namespace)@"
}
},
"es" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"fi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Käytetään salaisuutta %1$(secretName)@"
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Utilisation du secret %1$(secretName)@"
}
},
"he" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"hu" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"it" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Usato il Segreto %1$(secretName)@"
}
},
"ja" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "%1$(secretName)@を使用中"
}
},
"ko" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "비밀 %1$(secretName)@ 사용됨"
}
},
"nb" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"nl" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"pl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Użyto sekretu %1$(secretName)@"
}
},
"pt" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Utilizando o segredo %1$(secretName)@"
}
},
"ro" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"ru" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Используя секрет %1$(secretName)@"
}
},
"sr" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"sv" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"tr" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"uk" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"vi" : {
"stringUnit" : {
"state" : "new",
"value" : "Using secret %1$(secretName)@"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "使用密钥串 %1$(secretName)@"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "使用Secret「%1$(secretName)@」"
}
}
}
},
"smart_card" : {
"extractionState" : "manual",
"localizations" : {
@@ -26928,5 +27672,5 @@
}
}
},
"version" : "1.0"
"version" : "1.2"
}

View File

@@ -35,7 +35,8 @@ extension Agent {
public func handle(
request: SSHAgent.Request,
provenance: SigningRequestProvenance
provenance: SigningRequestProvenance,
hosts: [Data: String]?
) async -> Data {
logger.debug("Agent received request of type \(request.debugDescription)")
// Depending on the launch context (such as after macOS update), the agent may need to reload secrets before acting
@@ -57,7 +58,8 @@ extension Agent {
hasSignature: payload.hasSignature,
publicKeyAlgorithm: payload.publicKeyAlgorithm,
publicKey: payload.publicKey,
hostKey: payload.hostKey
hostKey: payload.hostKey,
host: hosts?[payload.hostKey]
)
)
if let boundSession = await sessionID {
@@ -79,7 +81,7 @@ extension Agent {
}
_ = target
response.append(SSHAgent.Response.agentSignResponse.data)
response.append(try await sign(data: context.dataToSign.raw, keyBlob: context.keyBlob, provenance: provenance))
response.append(try await sign(data: context.dataToSign.raw, keyBlob: context.keyBlob, provenance: provenance, target: target))
logger.debug("Agent returned \(SSHAgent.Response.agentSignResponse.debugDescription)")
case .protocolExtension(.openSSH(.sessionBind(let bind))):
// This is disabled until forward enforcement is handled.
@@ -143,19 +145,20 @@ extension Agent {
/// - data: The data to sign.
/// - provenance: A ``SecretKit.SigningRequestProvenance`` object describing the origin of the request.
/// - Returns: An OpenSSH formatted Data payload containing the signed data response.
func sign(data: Data, keyBlob: Data, provenance: SigningRequestProvenance) async throws -> Data {
func sign(data: Data, keyBlob: Data, provenance: SigningRequestProvenance, target: SigningRequestTarget?) async throws -> Data {
guard let (secret, store) = await secret(matching: keyBlob) else {
let keyBlobHex = keyBlob.formatted(.hex())
logger.debug("Agent did not have a key matching \(keyBlobHex)")
throw NoMatchingKeyError()
}
try await witness?.speakNowOrForeverHoldYourPeace(forAccessTo: secret, from: store, by: provenance)
let rawRepresentation = try await store.sign(data: data, with: secret, for: provenance)
try await witness?.speakNowOrForeverHoldYourPeace(forAccessTo: secret, from: store, by: provenance, target: target)
let rawRepresentation = try await store.sign(data: data, with: secret, for: provenance, target: target)
let signedData = signatureWriter.data(secret: secret, signature: rawRepresentation)
try await witness?.witness(accessTo: secret, from: store, by: provenance)
try await witness?.witness(accessTo: secret, from: store, by: provenance, target: target)
logger.debug("Agent signed request")

View File

@@ -1,5 +1,6 @@
import Foundation
import SecretKit
import SSHProtocolKit
/// A protocol that allows conformers to be notified of access to secrets, and optionally prevent access.
public protocol SigningWitness: Sendable {
@@ -10,13 +11,13 @@ public protocol SigningWitness: Sendable {
/// - store: The `Store` being asked to sign the request..
/// - provenance: A `SigningRequestProvenance` object describing the origin of the request.
/// - Note: This method being called does not imply that the requst has been authorized. If a secret requires authentication, authentication will still need to be performed by the user before the request will be performed. If the user declines or fails to authenticate, the request will fail.
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance) async throws
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance, target: SigningRequestTarget?) async throws
/// Notifies the callee that a signing operation has been performed for a given secret.
/// - Parameters:
/// - secret: The `Secret` that will was used to sign the request.
/// - store: The `Store` that signed the request..
/// - provenance: A `SigningRequestProvenance` object describing the origin of the request.
func witness(accessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance) async throws
func witness(accessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance, target: SigningRequestTarget?) async throws
}

View File

@@ -8,7 +8,7 @@ open class AnySecretStore: SecretStore, @unchecked Sendable {
private let _id: @Sendable () -> UUID
private let _name: @MainActor @Sendable () -> String
private let _secrets: @MainActor @Sendable () -> [AnySecret]
private let _sign: @Sendable (Data, AnySecret, SigningRequestProvenance) async throws -> Data
private let _sign: @Sendable (Data, AnySecret, SigningRequestProvenance, SigningRequestTarget?) async throws -> Data
private let _existingPersistedAuthenticationContext: @Sendable (AnySecret) async -> PersistedAuthenticationContext?
private let _persistAuthentication: @Sendable (AnySecret, TimeInterval) async throws -> Void
private let _reloadSecrets: @Sendable () async -> Void
@@ -19,7 +19,7 @@ open class AnySecretStore: SecretStore, @unchecked Sendable {
_name = { secretStore.name }
_id = { secretStore.id }
_secrets = { secretStore.secrets.map { AnySecret($0) } }
_sign = { try await secretStore.sign(data: $0, with: $1.base as! SecretStoreType.SecretType, for: $2) }
_sign = { try await secretStore.sign(data: $0, with: $1.base as! SecretStoreType.SecretType, for: $2, target: $3) }
_existingPersistedAuthenticationContext = { await secretStore.existingPersistedAuthenticationContext(secret: $0.base as! SecretStoreType.SecretType) }
_persistAuthentication = { try await secretStore.persistAuthentication(secret: $0.base as! SecretStoreType.SecretType, forDuration: $1) }
_reloadSecrets = { await secretStore.reloadSecrets() }
@@ -41,8 +41,8 @@ open class AnySecretStore: SecretStore, @unchecked Sendable {
return _secrets()
}
public func sign(data: Data, with secret: AnySecret, for provenance: SigningRequestProvenance) async throws -> Data {
try await _sign(data, secret, provenance)
public func sign(data: Data, with secret: AnySecret, for provenance: SigningRequestProvenance, target: SigningRequestTarget?) async throws -> Data {
try await _sign(data, secret, provenance, target)
}
public func existingPersistedAuthenticationContext(secret: AnySecret) async -> PersistedAuthenticationContext? {

View File

@@ -20,7 +20,7 @@ public protocol SecretStore<SecretType>: Identifiable, Sendable {
/// - secret: The ``Secret`` to sign with.
/// - provenance: A ``SigningRequestProvenance`` describing where the request came from.
/// - Returns: The signed data.
func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance) async throws -> Data
func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance, target: SigningRequestTarget?) async throws -> Data
/// Checks to see if there is currently a valid persisted authentication for a given secret.
/// - Parameters:

View File

@@ -14,6 +14,7 @@ public enum SigningRequestTarget: Sendable {
public let publicKeyAlgorithm: String
public let publicKey: Data
public let hostKey: Data
public let host: String?
public init(
username: String,
@@ -21,12 +22,14 @@ public enum SigningRequestTarget: Sendable {
publicKeyAlgorithm: String,
publicKey: Data,
hostKey: Data,
host: String?
) {
self.username = username
self.hasSignature = hasSignature
self.publicKeyAlgorithm = publicKeyAlgorithm
self.publicKey = publicKey
self.hostKey = hostKey
self.host = host
}
}

View File

@@ -37,13 +37,20 @@ extension SecureEnclave {
// MARK: SecretStore
public func sign(data: Data, with secret: Secret, for provenance: SigningRequestProvenance) async throws -> Data {
public func sign(data: Data, with secret: Secret, for provenance: SigningRequestProvenance, target: SigningRequestTarget?) async throws -> Data {
var context: LAContext
if let existing = await persistentAuthenticationHandler.existingPersistedAuthenticationContext(secret: secret) {
context = unsafe existing.context
} else {
let newContext = LAContext()
newContext.localizedReason = String(localized: .authContextRequestSignatureDescription(appName: provenance.origin.displayName, secretName: secret.name))
switch target {
case .connection(let payload) where payload.host != nil:
newContext.localizedReason = String(localized: .authContextRequestSignatureForConnectionDescription(appName: provenance.origin.displayName, targetName: payload.host!, secretName: secret.name))
case .signature(let payload):
newContext.localizedReason = String(localized: .authContextRequestSignatureForSignatureDescription(namespace: payload.namespace, appName: provenance.origin.displayName, secretName: secret.name))
default:
newContext.localizedReason = String(localized: .authContextRequestSignatureDescription(appName: provenance.origin.displayName, secretName: secret.name))
}
newContext.localizedCancelTitle = String(localized: .authContextRequestDenyButton)
context = newContext
}

View File

@@ -57,7 +57,7 @@ extension SmartCard {
// MARK: Public API
public func sign(data: Data, with secret: Secret, for provenance: SigningRequestProvenance) async throws -> Data {
public func sign(data: Data, with secret: Secret, for provenance: SigningRequestProvenance, target: SigningRequestTarget?) async throws -> Data {
guard let tokenID = await state.tokenID else { fatalError() }
var context: LAContext
if let existing = await persistentAuthenticationHandler.existingPersistedAuthenticationContext(secret: secret) {

View File

@@ -13,7 +13,7 @@ import CertificateKit
@Test func emptyStores() async throws {
let agent = Agent(storeList: SecretStoreList(), certificateStore: CertificateStore())
let request = try SSHAgentInputParser().parse(data: Constants.Requests.requestIdentities)
let response = await agent.handle(request: request, provenance: .test)
let response = await agent.handle(request: request, provenance: .test, hosts: nil)
#expect(response == Constants.Responses.requestIdentitiesEmpty)
}
@@ -21,7 +21,7 @@ import CertificateKit
let list = await storeList(with: [Constants.Secrets.ecdsa256Secret, Constants.Secrets.ecdsa384Secret])
let agent = Agent(storeList: list, certificateStore: CertificateStore())
let request = try SSHAgentInputParser().parse(data: Constants.Requests.requestIdentities)
let response = await agent.handle(request: request, provenance: .test)
let response = await agent.handle(request: request, provenance: .test, hosts: nil)
let actual = OpenSSHReader(data: response)
let expected = OpenSSHReader(data: Constants.Responses.requestIdentitiesMultiple)
@@ -35,7 +35,7 @@ import CertificateKit
let list = await storeList(with: [Constants.Secrets.ecdsa256Secret, Constants.Secrets.ecdsa384Secret])
let agent = Agent(storeList: list, certificateStore: CertificateStore())
let request = try SSHAgentInputParser().parse(data: Constants.Requests.requestSignatureWithNoneMatching)
let response = await agent.handle(request: request, provenance: .test)
let response = await agent.handle(request: request, provenance: .test, hosts: nil)
#expect(response == Constants.Responses.requestFailure)
}
@@ -44,7 +44,7 @@ import CertificateKit
guard case SSHAgent.Request.signRequest(let context) = request else { return }
let list = await storeList(with: [Constants.Secrets.ecdsa256Secret, Constants.Secrets.ecdsa384Secret])
let agent = Agent(storeList: list, certificateStore: CertificateStore())
let response = await agent.handle(request: request, provenance: .test)
let response = await agent.handle(request: request, provenance: .test, hosts: nil)
let responseReader = OpenSSHReader(data: response)
let length = try responseReader.readNextBytes(as: UInt32.self)
let type = try responseReader.readNextBytes(as: UInt8.self)
@@ -79,7 +79,7 @@ import CertificateKit
return true
}, witness: { _, _ in })
let agent = Agent(storeList: list, certificateStore: CertificateStore(), witness: witness)
let response = await agent.handle(request: .signRequest(.empty), provenance: .test)
let response = await agent.handle(request: .signRequest(.empty), provenance: .test, hosts: nil)
#expect(response == Constants.Responses.requestFailure)
}
@@ -93,7 +93,7 @@ import CertificateKit
})
let agent = Agent(storeList: list, certificateStore: CertificateStore(), witness: witness)
let request = try SSHAgentInputParser().parse(data: Constants.Requests.requestSignature)
_ = await agent.handle(request: request, provenance: .test)
_ = await agent.handle(request: request, provenance: .test, hosts: nil)
#expect(witnessed)
}
@@ -109,7 +109,7 @@ import CertificateKit
})
let agent = Agent(storeList: list, certificateStore: CertificateStore(), witness: witness)
let request = try SSHAgentInputParser().parse(data: Constants.Requests.requestSignature)
_ = await agent.handle(request: request, provenance: .test)
_ = await agent.handle(request: request, provenance: .test, hosts: nil)
#expect(witnessTrace == speakNowTrace)
#expect(witnessTrace == .test)
}
@@ -122,7 +122,7 @@ import CertificateKit
store.shouldThrow = true
let agent = Agent(storeList: list, certificateStore: CertificateStore())
let request = try SSHAgentInputParser().parse(data: Constants.Requests.requestSignature)
let response = await agent.handle(request: request, provenance: .test)
let response = await agent.handle(request: request, provenance: .test, hosts: nil)
#expect(response == Constants.Responses.requestFailure)
}
@@ -130,7 +130,7 @@ import CertificateKit
@Test func unhandledAdd() async throws {
let agent = Agent(storeList: SecretStoreList(), certificateStore: CertificateStore())
let response = await agent.handle(request: .addIdentity, provenance: .test)
let response = await agent.handle(request: .addIdentity, provenance: .test, hosts: nil)
#expect(response == Constants.Responses.requestFailure)
}

View File

@@ -49,7 +49,7 @@ extension Stub {
print("Public Key OpenSSH: \(OpenSSHPublicKeyWriter().openSSHString(secret: secret))")
}
public func sign(data: Data, with secret: Secret, for provenance: SigningRequestProvenance) throws -> Data {
public func sign(data: Data, with secret: Secret, for provenance: SigningRequestProvenance, target: SigningRequestTarget?) throws -> Data {
guard !shouldThrow else {
throw NSError(domain: "test", code: 0, userInfo: nil)
}

View File

@@ -10,14 +10,14 @@ struct StubWitness {
extension StubWitness: SigningWitness {
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance) throws {
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance, target: SigningRequestTarget?) throws {
let objection = speakNow(secret, provenance)
if objection {
throw TheresMyChance()
}
}
func witness(accessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance) throws {
func witness(accessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance, target: SigningRequestTarget?) throws {
witness(secret, provenance)
}