This commit is contained in:
Max Goedjen 2020-03-22 21:33:52 -07:00
parent cb259b2657
commit ebeae2fe7a
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
1 changed files with 18 additions and 6 deletions

View File

@ -13,7 +13,7 @@ extension Stub {
public var secrets: [Secret] = []
public init() {
try! create(size: 256)
// try! create(size: 256)
}
public func create(size: Int) throws {
@ -32,7 +32,7 @@ extension Stub {
kSecAttrIsPermanent: true,
kSecAttrAccessControl: access
]
] as CFDictionary
] as CFDictionary
var privateKey: SecKey! = nil
var publicKey: SecKey! = nil
@ -46,11 +46,23 @@ extension Stub {
print("Public Key OpenSSH: \(OpenSSHKeyWriter().openSSHString(secret: secret))")
}
public func delete(secret: Secret) throws {
}
public func sign(data: Data, with secret: Secret) throws -> Data {
return Data()
let privateKey = SecKeyCreateWithData(secret.privateKey as CFData, [
kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom,
kSecAttrKeySizeInBits: secret.keySize,
kSecAttrKeyClass: kSecAttrKeyClassPrivate
] as CFDictionary
, nil)!
let signatureAlgorithm: SecKeyAlgorithm
switch secret.keySize {
case 256:
signatureAlgorithm = .ecdsaSignatureMessageX962SHA256
case 384:
signatureAlgorithm = .ecdsaSignatureMessageX962SHA384
default:
fatalError()
}
return SecKeyCreateSignature(privateKey, signatureAlgorithm, data as CFData, nil) as! Data
}
}