From 747279f8374fdcaf21b5bcea10488fe601d40b93 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 20 Mar 2022 15:02:29 -0700 Subject: [PATCH] Setup --- Sources/Packages/Package.swift | 7 +++ .../ProxyAgentSecretKit/ProxyAgent.swift | 2 + .../ProxyAgentSecret.swift | 19 +++++++ .../ProxyAgentSecretKit/ProxyAgentStore.swift | 57 +++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgent.swift create mode 100644 Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgentSecret.swift create mode 100644 Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgentStore.swift diff --git a/Sources/Packages/Package.swift b/Sources/Packages/Package.swift index c5bc4c0..0a050ab 100644 --- a/Sources/Packages/Package.swift +++ b/Sources/Packages/Package.swift @@ -18,6 +18,9 @@ let package = Package( .library( name: "SmartCardSecretKit", targets: ["SmartCardSecretKit"]), + .library( + name: "ProxyAgentSecretKit", + targets: ["ProxyAgentSecretKit"]), .library( name: "SecretAgentKit", targets: ["SecretAgentKit"]), @@ -47,6 +50,10 @@ let package = Package( name: "SmartCardSecretKit", dependencies: ["SecretKit"] ), + .target( + name: "ProxyAgentSecretKit", + dependencies: ["SecretKit", "SecretAgentKit"] + ), .target( name: "SecretAgentKit", dependencies: ["SecretKit", "SecretAgentKitHeaders"] diff --git a/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgent.swift b/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgent.swift new file mode 100644 index 0000000..8cb60be --- /dev/null +++ b/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgent.swift @@ -0,0 +1,2 @@ +/// Namespace for the Proxy Agent implementations. +public enum ProxyAgent {} diff --git a/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgentSecret.swift b/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgentSecret.swift new file mode 100644 index 0000000..655214f --- /dev/null +++ b/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgentSecret.swift @@ -0,0 +1,19 @@ +import Foundation +import Combine +import SecretKit + +extension SmartCard { + + /// An implementation of Secret backed by a Smart Card. + public struct Secret: SecretKit.Secret { + + public let id: Data + public let name: String + public let algorithm: Algorithm + public let keySize: Int + public let requiresAuthentication: Bool = false + public let publicKey: Data + + } + +} diff --git a/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgentStore.swift b/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgentStore.swift new file mode 100644 index 0000000..bb9f82e --- /dev/null +++ b/Sources/Packages/Sources/ProxyAgentSecretKit/ProxyAgentStore.swift @@ -0,0 +1,57 @@ +import Foundation +import Security +import CryptoTokenKit +import LocalAuthentication +import SecretKit + +extension ProxyAgent { + + /// An implementation of Store backed by a Proxy Agent. + public class Store: SecretStore { + + @Published public var isAvailable: Bool = false + public let id = UUID() + public private(set) var name = NSLocalizedString("Proxy SSH Agent", comment: "Proxy SSH Agent") + @Published public private(set) var secrets: [Secret] = [] + + /// Initializes a Store. + public init() { + } + + // MARK: Public API + + public func create(name: String) throws { + fatalError("Keys must be created on the smart card.") + } + + public func delete(secret: Secret) throws { + fatalError("Keys must be deleted on the smart card.") + } + + public func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance) throws -> Data { + } + + public func existingPersistedAuthenticationContext(secret: ProxyAgent.Secret) -> PersistedAuthenticationContext? { + nil + } + + public func persistAuthentication(secret: ProxyAgent.Secret, forDuration: TimeInterval) throws { + } + + } + +} + +extension ProxyAgent.Store { + +} + +extension ProxyAgent { + + /// A signing-related error. + public struct SigningError: Error { + /// The underlying error reported by the API, if one was returned. + public let error: SecurityError? + } + +}