]> git.saurik.com Git - apple/security.git/blob - keychain/TrustedPeersHelper/CuttlefishAPIHelpers.swift
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / TrustedPeersHelper / CuttlefishAPIHelpers.swift
1 import Foundation
2
3 extension ViewKey {
4 static func convert(ckksKey: CKKSKeychainBackedKey) -> ViewKey {
5 let kc: ViewKeyClass
6 switch ckksKey.keyclass {
7 case SecCKKSKeyClassTLK:
8 kc = .tlk
9 case SecCKKSKeyClassA:
10 kc = .classA
11 case SecCKKSKeyClassC:
12 kc = .classC
13 default:
14 kc = .tlk
15 }
16
17 return ViewKey.with {
18 $0.uuid = ckksKey.uuid
19 $0.parentkeyUuid = ckksKey.parentKeyUUID
20 $0.keyclass = kc
21 $0.wrappedkeyBase64 = ckksKey.wrappedkey.base64WrappedKey()
22 $0.uploadOsVersion = SecCKKSHostOSVersion()
23 }
24 }
25 }
26
27 // TODO: We need to support key rolling as well...
28 extension ViewKeys {
29 static func convert(ckksKeySet: CKKSKeychainBackedKeySet) -> ViewKeys {
30 return ViewKeys.with {
31 $0.view = ckksKeySet.tlk.zoneID.zoneName
32 $0.newTlk = ViewKey.convert(ckksKey: ckksKeySet.tlk)
33 $0.newClassA = ViewKey.convert(ckksKey: ckksKeySet.classA)
34 $0.newClassC = ViewKey.convert(ckksKey: ckksKeySet.classC)
35 }
36 }
37 }
38
39 extension TLKShare {
40 static func convert(ckksTLKShare: CKKSTLKShare) -> TLKShare {
41 return TLKShare.with {
42 $0.view = ckksTLKShare.zoneID.zoneName
43 $0.curve = Int64(ckksTLKShare.curve.rawValue)
44 $0.epoch = Int64(ckksTLKShare.epoch)
45 $0.keyUuid = ckksTLKShare.tlkUUID
46 $0.poisoned = Int64(ckksTLKShare.poisoned)
47 $0.receiver = ckksTLKShare.receiverPeerID
48 $0.receiverPublicEncryptionKey = ckksTLKShare.receiverPublicEncryptionKeySPKI.base64EncodedString()
49 $0.sender = ckksTLKShare.senderPeerID
50 $0.signature = ckksTLKShare.signature?.base64EncodedString() ?? ""
51 $0.version = Int64(ckksTLKShare.version.rawValue)
52 $0.wrappedkey = ckksTLKShare.wrappedTLK?.base64EncodedString() ?? ""
53 }
54 }
55 }