From 0944d65ccb0d0b71a686995f7beeef4a8e9ad516 Mon Sep 17 00:00:00 2001 From: Chris Eldredge Date: Sun, 12 Mar 2023 20:43:19 -0400 Subject: [PATCH] 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 --- .../Sources/SecretAgentKit/Agent.swift | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Sources/Packages/Sources/SecretAgentKit/Agent.swift b/Sources/Packages/Sources/SecretAgentKit/Agent.swift index 84cd238..7588cf3 100644 --- a/Sources/Packages/Sources/SecretAgentKit/Agent.swift +++ b/Sources/Packages/Sources/SecretAgentKit/Agent.swift @@ -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 }