Identities offers both key and certificate when both are present (#454)

* Identities offers both key and certificate when both are present

* Update Sources/Packages/Sources/SecretAgentKit/Agent.swift

---------

Co-authored-by: Max Goedjen <max.goedjen@gmail.com>
This commit is contained in:
Chris Eldredge 2023-03-12 20:43:19 -04:00 committed by GitHub
parent 2ca8279187
commit 0944d65ccb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -86,27 +86,24 @@ extension Agent {
func identities() -> Data {
let secrets = storeList.allSecrets
certificateHandler.reloadCertificates(for: secrets)
var count = UInt32(secrets.count).bigEndian
let countData = Data(bytes: &count, count: UInt32.bitWidth/8)
var count = secrets.count
var keyData = Data()
for secret in secrets {
let keyBlob: Data
let curveData: Data
if let (certificateData, name) = try? certificateHandler.keyBlobAndName(for: secret) {
keyBlob = certificateData
curveData = name
} else {
keyBlob = writer.data(secret: secret)
curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
}
let keyBlob = writer.data(secret: secret)
let curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
keyData.append(writer.lengthAndData(of: keyBlob))
keyData.append(writer.lengthAndData(of: curveData))
if let (certificateData, name) = try? certificateHandler.keyBlobAndName(for: secret) {
keyData.append(writer.lengthAndData(of: certificateData))
keyData.append(writer.lengthAndData(of: name))
count += 1
}
}
logger.log("Agent enumerated \(secrets.count) identities")
logger.log("Agent enumerated \(count) identities")
var countBigEndian = UInt32(count).bigEndian
let countData = Data(bytes: &countBigEndian, count: UInt32.bitWidth/8)
return countData + keyData
}