Compare commits

..

2 Commits

Author SHA1 Message Date
513a93fd18 . 2022-03-20 15:59:36 -07:00
747279f837 Setup 2022-03-20 15:02:29 -07:00
12 changed files with 117 additions and 26 deletions

View File

@ -18,6 +18,9 @@ let package = Package(
.library( .library(
name: "SmartCardSecretKit", name: "SmartCardSecretKit",
targets: ["SmartCardSecretKit"]), targets: ["SmartCardSecretKit"]),
.library(
name: "ProxyAgentSecretKit",
targets: ["ProxyAgentSecretKit"]),
.library( .library(
name: "SecretAgentKit", name: "SecretAgentKit",
targets: ["SecretAgentKit"]), targets: ["SecretAgentKit"]),
@ -47,6 +50,10 @@ let package = Package(
name: "SmartCardSecretKit", name: "SmartCardSecretKit",
dependencies: ["SecretKit"] dependencies: ["SecretKit"]
), ),
.target(
name: "ProxyAgentSecretKit",
dependencies: ["SecretKit", "SecretAgentKit"]
),
.target( .target(
name: "SecretAgentKit", name: "SecretAgentKit",
dependencies: ["SecretKit", "SecretAgentKitHeaders"] dependencies: ["SecretKit", "SecretAgentKitHeaders"]

View File

@ -0,0 +1,2 @@
/// Namespace for the Proxy Agent implementations.
public enum ProxyAgent {}

View File

@ -0,0 +1,19 @@
import Foundation
import Combine
import SecretKit
extension ProxyAgent {
/// 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
}
}

View File

@ -0,0 +1,59 @@
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 = true
public let id = UUID()
public private(set) var name = NSLocalizedString("Proxy SSH Agent", comment: "Proxy SSH Agent")
@Published public private(set) var secrets: [Secret] = []
private let agentPath: String
/// Initializes a Store.
public init(path: String) {
agentPath = path
secrets.append(Secret(id: "hello".data(using: .utf8)!, name: "Test", algorithm: .ellipticCurve, keySize: 256, publicKey: Data(base64Encoded: "AAAAC3NzaC1lZDI1NTE5AAAAIINQz8WohBS46ICEUtkJ/vdxJPM63T5Dy4bQC35JVgGR")!))
}
// 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 {
fatalError()
}
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 {
}
}

View File

@ -64,6 +64,10 @@ extension OpenSSHKeyWriter {
switch algorithm { switch algorithm {
case .ellipticCurve: case .ellipticCurve:
return "ecdsa-sha2-nistp" + String(describing: length) return "ecdsa-sha2-nistp" + String(describing: length)
case .rsa:
return "ssh-rsa"
case .ed25519:
return "ssh-ed25519"
} }
} }
@ -76,6 +80,11 @@ extension OpenSSHKeyWriter {
switch algorithm { switch algorithm {
case .ellipticCurve: case .ellipticCurve:
return "nistp" + String(describing: length) return "nistp" + String(describing: length)
// TODO: VERIFY
case .rsa:
return "rsa"
case .ed25519:
return "ed25519"
} }
} }

View File

@ -19,6 +19,8 @@ public protocol Secret: Identifiable, Hashable {
/// The type of algorithm the Secret uses. Currently, only elliptic curve algorithms are supported. /// The type of algorithm the Secret uses. Currently, only elliptic curve algorithms are supported.
public enum Algorithm: Hashable { public enum Algorithm: Hashable {
case rsa
case ed25519
case ellipticCurve case ellipticCurve
/// Initializes the Algorithm with a secAttr representation of an algorithm. /// Initializes the Algorithm with a secAttr representation of an algorithm.

View File

@ -47,10 +47,11 @@
50A3B79124026B7600D209EA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50A3B79024026B7600D209EA /* Assets.xcassets */; }; 50A3B79124026B7600D209EA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50A3B79024026B7600D209EA /* Assets.xcassets */; };
50A3B79424026B7600D209EA /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50A3B79324026B7600D209EA /* Preview Assets.xcassets */; }; 50A3B79424026B7600D209EA /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50A3B79324026B7600D209EA /* Preview Assets.xcassets */; };
50A3B79724026B7600D209EA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50A3B79524026B7600D209EA /* Main.storyboard */; }; 50A3B79724026B7600D209EA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50A3B79524026B7600D209EA /* Main.storyboard */; };
50A63F6B27E7DC5700085D7B /* ProxyAgentSecretKit in Frameworks */ = {isa = PBXBuildFile; productRef = 50A63F6A27E7DC5700085D7B /* ProxyAgentSecretKit */; };
50A63F6D27E7E04800085D7B /* ProxyAgentSecretKit in Frameworks */ = {isa = PBXBuildFile; productRef = 50A63F6C27E7E04800085D7B /* ProxyAgentSecretKit */; };
50B8550D24138C4F009958AC /* DeleteSecretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50B8550C24138C4F009958AC /* DeleteSecretView.swift */; }; 50B8550D24138C4F009958AC /* DeleteSecretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50B8550C24138C4F009958AC /* DeleteSecretView.swift */; };
50BB046B2418AAAE00D6E079 /* EmptyStoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */; }; 50BB046B2418AAAE00D6E079 /* EmptyStoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */; };
50C385A52407A76D00AF2719 /* SecretDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C385A42407A76D00AF2719 /* SecretDetailView.swift */; }; 50C385A52407A76D00AF2719 /* SecretDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C385A42407A76D00AF2719 /* SecretDetailView.swift */; };
50C511B0285064DB00704B27 /* MainActorWrappers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C511AF285064DB00704B27 /* MainActorWrappers.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -148,7 +149,6 @@
50B8550C24138C4F009958AC /* DeleteSecretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeleteSecretView.swift; sourceTree = "<group>"; }; 50B8550C24138C4F009958AC /* DeleteSecretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeleteSecretView.swift; sourceTree = "<group>"; };
50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStoreView.swift; sourceTree = "<group>"; }; 50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStoreView.swift; sourceTree = "<group>"; };
50C385A42407A76D00AF2719 /* SecretDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretDetailView.swift; sourceTree = "<group>"; }; 50C385A42407A76D00AF2719 /* SecretDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretDetailView.swift; sourceTree = "<group>"; };
50C511AF285064DB00704B27 /* MainActorWrappers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainActorWrappers.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -156,6 +156,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
50A63F6D27E7E04800085D7B /* ProxyAgentSecretKit in Frameworks */,
5003EF3B278005E800DF2006 /* SecretKit in Frameworks */, 5003EF3B278005E800DF2006 /* SecretKit in Frameworks */,
501421622781262300BBAA70 /* Brief in Frameworks */, 501421622781262300BBAA70 /* Brief in Frameworks */,
5003EF5F2780081600DF2006 /* SecureEnclaveSecretKit in Frameworks */, 5003EF5F2780081600DF2006 /* SecureEnclaveSecretKit in Frameworks */,
@ -176,6 +177,7 @@
files = ( files = (
5003EF3D278005F300DF2006 /* Brief in Frameworks */, 5003EF3D278005F300DF2006 /* Brief in Frameworks */,
5003EF632780081B00DF2006 /* SecureEnclaveSecretKit in Frameworks */, 5003EF632780081B00DF2006 /* SecureEnclaveSecretKit in Frameworks */,
50A63F6B27E7DC5700085D7B /* ProxyAgentSecretKit in Frameworks */,
5003EF652780081B00DF2006 /* SmartCardSecretKit in Frameworks */, 5003EF652780081B00DF2006 /* SmartCardSecretKit in Frameworks */,
5003EF3F278005F300DF2006 /* SecretAgentKit in Frameworks */, 5003EF3F278005F300DF2006 /* SecretAgentKit in Frameworks */,
5003EF41278005FA00DF2006 /* SecretKit in Frameworks */, 5003EF41278005FA00DF2006 /* SecretKit in Frameworks */,
@ -189,7 +191,6 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
50033AC227813F1700253856 /* BundleIDs.swift */, 50033AC227813F1700253856 /* BundleIDs.swift */,
50C511AF285064DB00704B27 /* MainActorWrappers.swift */,
); );
path = Helpers; path = Helpers;
sourceTree = "<group>"; sourceTree = "<group>";
@ -348,6 +349,7 @@
5003EF5E2780081600DF2006 /* SecureEnclaveSecretKit */, 5003EF5E2780081600DF2006 /* SecureEnclaveSecretKit */,
5003EF602780081600DF2006 /* SmartCardSecretKit */, 5003EF602780081600DF2006 /* SmartCardSecretKit */,
501421612781262300BBAA70 /* Brief */, 501421612781262300BBAA70 /* Brief */,
50A63F6C27E7E04800085D7B /* ProxyAgentSecretKit */,
); );
productName = Secretive; productName = Secretive;
productReference = 50617D7F23FCE48E0099B055 /* Secretive.app */; productReference = 50617D7F23FCE48E0099B055 /* Secretive.app */;
@ -391,6 +393,7 @@
5003EF40278005FA00DF2006 /* SecretKit */, 5003EF40278005FA00DF2006 /* SecretKit */,
5003EF622780081B00DF2006 /* SecureEnclaveSecretKit */, 5003EF622780081B00DF2006 /* SecureEnclaveSecretKit */,
5003EF642780081B00DF2006 /* SmartCardSecretKit */, 5003EF642780081B00DF2006 /* SmartCardSecretKit */,
50A63F6A27E7DC5700085D7B /* ProxyAgentSecretKit */,
); );
productName = SecretAgent; productName = SecretAgent;
productReference = 50A3B78A24026B7500D209EA /* SecretAgent.app */; productReference = 50A3B78A24026B7500D209EA /* SecretAgent.app */;
@ -482,7 +485,6 @@
50571E0324393C2600F76F6C /* JustUpdatedChecker.swift in Sources */, 50571E0324393C2600F76F6C /* JustUpdatedChecker.swift in Sources */,
5079BA0F250F29BF00EA86F4 /* StoreListView.swift in Sources */, 5079BA0F250F29BF00EA86F4 /* StoreListView.swift in Sources */,
50617DD223FCEFA90099B055 /* PreviewStore.swift in Sources */, 50617DD223FCEFA90099B055 /* PreviewStore.swift in Sources */,
50C511B0285064DB00704B27 /* MainActorWrappers.swift in Sources */,
5066A6F7251829B1004B5A36 /* ShellConfigurationController.swift in Sources */, 5066A6F7251829B1004B5A36 /* ShellConfigurationController.swift in Sources */,
50033AC327813F1700253856 /* BundleIDs.swift in Sources */, 50033AC327813F1700253856 /* BundleIDs.swift in Sources */,
508A58B3241ED2180069DC07 /* AgentStatusChecker.swift in Sources */, 508A58B3241ED2180069DC07 /* AgentStatusChecker.swift in Sources */,
@ -1025,6 +1027,14 @@
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
productName = Brief; productName = Brief;
}; };
50A63F6A27E7DC5700085D7B /* ProxyAgentSecretKit */ = {
isa = XCSwiftPackageProductDependency;
productName = ProxyAgentSecretKit;
};
50A63F6C27E7E04800085D7B /* ProxyAgentSecretKit */ = {
isa = XCSwiftPackageProductDependency;
productName = ProxyAgentSecretKit;
};
/* End XCSwiftPackageProductDependency section */ /* End XCSwiftPackageProductDependency section */
}; };
rootObject = 50617D7723FCE48D0099B055 /* Project object */; rootObject = 50617D7723FCE48D0099B055 /* Project object */;

View File

@ -1,17 +0,0 @@
import Foundation
func mainActorWrapped(_ f: @escaping @MainActor () -> Void) -> () -> Void {
return {
DispatchQueue.main.async {
f()
}
}
}
func mainActorWrapped<T: Sendable>(_ f: @escaping @MainActor (T) -> Void) -> (T) -> Void {
return { x in
DispatchQueue.main.async {
f(x)
}
}
}

View File

@ -43,7 +43,7 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
showing = false showing = false
} }
.keyboardShortcut(.cancelAction) .keyboardShortcut(.cancelAction)
Button("Create", action: mainActorWrapped(save)) Button("Create", action: save)
.disabled(name.isEmpty) .disabled(name.isEmpty)
.keyboardShortcut(.defaultAction) .keyboardShortcut(.defaultAction)
} }

View File

@ -33,7 +33,7 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
} }
HStack { HStack {
Spacer() Spacer()
Button("Delete", action: mainActorWrapped(delete)) Button("Delete", action: delete)
.disabled(confirm != secret.name) .disabled(confirm != secret.name)
.keyboardShortcut(.delete) .keyboardShortcut(.delete)
Button("Don't Delete") { Button("Don't Delete") {

View File

@ -28,7 +28,7 @@ struct RenameSecretView<StoreType: SecretStoreModifiable>: View {
} }
HStack { HStack {
Spacer() Spacer()
Button("Rename", action: mainActorWrapped(rename)) Button("Rename", action: rename)
.disabled(newName.count == 0) .disabled(newName.count == 0)
.keyboardShortcut(.return) .keyboardShortcut(.return)
Button("Cancel") { Button("Cancel") {

View File

@ -31,8 +31,8 @@ struct StoreListView: View {
store: store, store: store,
secret: secret, secret: secret,
activeSecret: $activeSecret, activeSecret: $activeSecret,
deletedSecret: mainActorWrapped(self.secretDeleted), deletedSecret: self.secretDeleted,
renamedSecret: mainActorWrapped(self.secretRenamed) renamedSecret: self.secretRenamed
) )
} }
} }