]> git.saurik.com Git - apple/security.git/blob - keychain/SecureObjectSync/SOSPeerInfo.h
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / SecureObjectSync / SOSPeerInfo.h
1 /*
2 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 #ifndef _SOSPEERINFO_H_
26 #define _SOSPEERINFO_H_
27
28 #include <CoreFoundation/CoreFoundation.h>
29 #include <Security/SecKey.h>
30 #include <CommonCrypto/CommonDigestSPI.h>
31 #include <corecrypto/ccdigest.h>
32
33 #include <Security/SecureObjectSync/SOSTypes.h>
34
35 __BEGIN_DECLS
36
37 typedef struct __OpaqueSOSPeerInfo *SOSPeerInfoRef;
38
39 // Bumped to 3 from 2 so we can identify pre-iCDP peers and add the proper views.
40 #define PEERINFO_CURRENT_VERSION 3
41
42 enum {
43 kSOSPeerVersion = 2,
44 kSOSPeerV2BaseVersion = 2,
45 };
46
47
48 enum {
49 SOSPeerCmpPubKeyHash = 0,
50 SOSPeerCmpName = 1,
51 };
52 typedef uint32_t SOSPeerInfoCmpSelect;
53
54 CFTypeID SOSPeerInfoGetTypeID(void);
55
56 static inline bool isSOSPeerInfo(CFTypeRef obj) {
57 return obj && (CFGetTypeID(obj) == SOSPeerInfoGetTypeID());
58 }
59
60 static inline SOSPeerInfoRef asSOSPeerInfo(CFTypeRef obj) {
61 return isSOSPeerInfo(obj) ? (SOSPeerInfoRef) obj : NULL;
62 }
63
64 SOSPeerInfoRef SOSPeerInfoCreate(CFAllocatorRef allocator, CFDictionaryRef gestalt, CFDataRef backup_key, SecKeyRef signingKey,
65 SecKeyRef octagonSigningKey, SecKeyRef octagonPeerEncryptionKey, bool supportsCKKS4All,
66 CFErrorRef* error);
67
68 SOSPeerInfoRef SOSPeerInfoCreateWithTransportAndViews(CFAllocatorRef allocator, CFDictionaryRef gestalt, CFDataRef backup_key,
69 CFStringRef IDSID, CFStringRef transportType, CFBooleanRef preferIDS,
70 CFBooleanRef preferFragmentation, CFBooleanRef preferAckModel, CFSetRef enabledViews, SecKeyRef signingKey,
71 SecKeyRef octagonSigningKey, SecKeyRef octagonPeerEncryptionKey, bool supportsCKKS4All,
72 CFErrorRef* error);
73
74 SOSPeerInfoRef SOSPeerInfoCreateCloudIdentity(CFAllocatorRef allocator, CFDictionaryRef gestalt, SecKeyRef signingKey, CFErrorRef* error);
75
76 SOSPeerInfoRef SOSPeerInfoCreateCopy(CFAllocatorRef allocator, SOSPeerInfoRef toCopy, CFErrorRef* error);
77 SOSPeerInfoRef SOSPeerInfoCreateCurrentCopy(CFAllocatorRef allocator, SOSPeerInfoRef toCopy,
78 CFStringRef IDSID, CFStringRef transportType, CFBooleanRef preferIDS, CFBooleanRef preferFragmentation, CFBooleanRef preferAckModel, CFSetRef enabledViews,
79 SecKeyRef signingKey, CFErrorRef* error);
80 bool SOSPeerInfoVersionIsCurrent(SOSPeerInfoRef pi);
81 bool SOSPeerInfoVersionHasV2Data(SOSPeerInfoRef pi);
82 SOSPeerInfoRef SOSPeerInfoCopyWithGestaltUpdate(CFAllocatorRef allocator, SOSPeerInfoRef toCopy, CFDictionaryRef gestalt, SecKeyRef signingKey, CFErrorRef* error);
83 SOSPeerInfoRef SOSPeerInfoCopyWithBackupKeyUpdate(CFAllocatorRef allocator, SOSPeerInfoRef toCopy, CFDataRef backupKey, SecKeyRef signingKey, CFErrorRef* error);
84 SOSPeerInfoRef SOSPeerInfoCopyWithReplacedEscrowRecords(CFAllocatorRef allocator, SOSPeerInfoRef toCopy, CFDictionaryRef escrowRecords, SecKeyRef signingKey, CFErrorRef *error);
85
86
87 SOSPeerInfoRef SOSPeerInfoCopyWithViewsChange(CFAllocatorRef allocator, SOSPeerInfoRef toCopy,
88 SOSViewActionCode action, CFStringRef viewname, SOSViewResultCode *retval,
89 SecKeyRef signingKey, CFErrorRef* error);
90 SOSPeerInfoRef SOSPeerInfoCopyAsApplication(SOSPeerInfoRef pi, SecKeyRef userkey, SecKeyRef peerkey, CFErrorRef *error);
91
92 SOSPeerInfoRef SOSPeerInfoCopyWithPing(CFAllocatorRef allocator, SOSPeerInfoRef toCopy, SecKeyRef signingKey, CFErrorRef* error);
93 SOSPeerInfoRef SOSPeerInfoCopyAsApplication(SOSPeerInfoRef pi, SecKeyRef userkey, SecKeyRef peerkey, CFErrorRef *error);
94
95 bool SOSPeerInfoUpdateDigestWithPublicKeyBytes(SOSPeerInfoRef peer, const struct ccdigest_info *di,
96 ccdigest_ctx_t ctx, CFErrorRef *error);
97 bool SOSPeerInfoUpdateDigestWithDescription(SOSPeerInfoRef peer, const struct ccdigest_info *di,
98 ccdigest_ctx_t ctx, CFErrorRef *error);
99
100 bool SOSPeerInfoApplicationVerify(SOSPeerInfoRef pi, SecKeyRef userkey, CFErrorRef *error);
101
102 CF_RETURNS_RETAINED CFDateRef SOSPeerInfoGetApplicationDate(SOSPeerInfoRef pi);
103
104
105 //
106 // Transfered Data
107 //
108 bool SOSPeerInfoHasBackupKey(SOSPeerInfoRef peer);
109 CFDataRef SOSPeerInfoCopyBackupKey(SOSPeerInfoRef peer);
110
111 //
112 // DER Import Export
113 //
114 SOSPeerInfoRef SOSPeerInfoCreateFromDER(CFAllocatorRef allocator, CFErrorRef* error,
115 const uint8_t** der_p, const uint8_t *der_end);
116
117 SOSPeerInfoRef SOSPeerInfoCreateFromData(CFAllocatorRef allocator, CFErrorRef* error,
118 CFDataRef peerinfo_data);
119
120 size_t SOSPeerInfoGetDEREncodedSize(SOSPeerInfoRef peer, CFErrorRef *error);
121 uint8_t* SOSPeerInfoEncodeToDER(SOSPeerInfoRef peer, CFErrorRef* error,
122 const uint8_t* der, uint8_t* der_end);
123
124 CFDataRef SOSPeerInfoCopyEncodedData(SOSPeerInfoRef peer, CFAllocatorRef allocator, CFErrorRef *error);
125
126 //
127 // Gestalt info about the peer. It was fetched by the implementation on the other side.
128 // probably has what you're looking for..
129 //
130 CFTypeRef SOSPeerInfoLookupGestaltValue(SOSPeerInfoRef pi, CFStringRef key);
131 CFDictionaryRef SOSPeerInfoCopyPeerGestalt(SOSPeerInfoRef pi);
132 CFDictionaryRef SOSPeerGetGestalt(SOSPeerInfoRef pi);
133 CFStringRef SOSPeerInfoGetPeerName(SOSPeerInfoRef peer);
134
135 //
136 // Syntactic Sugar for some commone ones, might get deprectated at this level.
137 //
138
139 CFStringRef SOSPeerInfoGetPeerDeviceType(SOSPeerInfoRef peer);
140 CFIndex SOSPeerInfoGetPeerProtocolVersion(SOSPeerInfoRef peer);
141
142
143 // Stringified ID for this peer, not human readable.
144 CFStringRef SOSPeerInfoGetPeerID(SOSPeerInfoRef peer);
145 CFStringRef SOSPeerInfoGetSPID(SOSPeerInfoRef pi);
146
147 bool SOSPeerInfoPeerIDEqual(SOSPeerInfoRef pi, CFStringRef myPeerID);
148
149 CFIndex SOSPeerInfoGetVersion(SOSPeerInfoRef peer);
150
151 //
152 // Peer Info Gestalt Helpers
153 //
154 CFStringRef SOSPeerGestaltGetName(CFDictionaryRef gestalt);
155
156 // These are Mobile Gestalt questions. Not all Gestalt questions are carried.
157 CFTypeRef SOSPeerGestaltGetAnswer(CFDictionaryRef gestalt, CFStringRef question);
158
159 SecKeyRef SOSPeerInfoCopyPubKey(SOSPeerInfoRef peer, CFErrorRef *error);
160 SecKeyRef SOSPeerInfoCopyOctagonSigningPublicKey(SOSPeerInfoRef peer, CFErrorRef* error);
161 SecKeyRef SOSPeerInfoCopyOctagonEncryptionPublicKey(SOSPeerInfoRef peer, CFErrorRef* error);
162 bool SOSPeerInfoSetOctagonKeysInDescription(SOSPeerInfoRef peer, SecKeyRef octagonSigningKey,
163 SecKeyRef octagonEncryptionKey, CFErrorRef *error);
164 CFDataRef SOSPeerInfoGetAutoAcceptInfo(SOSPeerInfoRef peer);
165
166 CFComparisonResult SOSPeerInfoCompareByID(const void *val1, const void *val2, void *context);
167 CFComparisonResult SOSPeerInfoCompareByApplicationDate(const void *val1, const void *val2, void *context);
168
169 SOSPeerInfoRef SOSPeerInfoCreateRetirementTicket(CFAllocatorRef allocator, SecKeyRef privKey, SOSPeerInfoRef peer, CFErrorRef *error);
170
171 CFStringRef SOSPeerInfoInspectRetirementTicket(SOSPeerInfoRef pi, CFErrorRef *error);
172
173 bool SOSPeerInfoRetireRetirementTicket(size_t max_days, SOSPeerInfoRef pi);
174
175 CF_RETURNS_RETAINED CFDateRef SOSPeerInfoGetRetirementDate(SOSPeerInfoRef pi);
176
177 bool SOSPeerInfoIsRetirementTicket(SOSPeerInfoRef pi);
178
179 bool SOSPeerInfoIsCloudIdentity(SOSPeerInfoRef pi);
180
181 CF_RETURNS_RETAINED SOSPeerInfoRef SOSPeerInfoUpgradeSignatures(CFAllocatorRef allocator, SecKeyRef privKey, SecKeyRef perKey, SOSPeerInfoRef peer, CFErrorRef *error);
182
183 SOSViewResultCode SOSPeerInfoViewStatus(SOSPeerInfoRef pi, CFStringRef view, CFErrorRef *error);
184
185 CFSetRef SOSPeerInfoGetPermittedViews(SOSPeerInfoRef peer);
186 bool SOSPeerInfoIsEnabledView(SOSPeerInfoRef peer, CFStringRef viewName);
187 CFMutableSetRef SOSPeerInfoCopyEnabledViews(SOSPeerInfoRef peer);
188 void SOSPeerInfoWithEnabledViewSet(SOSPeerInfoRef pi, void (^operation)(CFSetRef enabled));
189 uint64_t SOSViewBitmaskFromSet(CFSetRef views);
190 uint64_t SOSPeerInfoViewBitMask(SOSPeerInfoRef pi);
191
192 bool SOSPeerInfoSupportsCKKSForAll(SOSPeerInfoRef peerInfo);
193 void SOSPeerInfoSetSupportsCKKSForAll(SOSPeerInfoRef peerInfo, bool supports);
194
195 bool SOSPeerInfoKVSOnly(SOSPeerInfoRef pi);
196 CFStringRef SOSPeerInfoCopyTransportType(SOSPeerInfoRef peer);
197 CFStringRef SOSPeerInfoCopyDeviceID(SOSPeerInfoRef peer);
198
199 /* octagon keys */
200 SOSPeerInfoRef CF_RETURNS_RETAINED
201 SOSPeerInfoSetOctagonSigningKey(CFAllocatorRef allocator,
202 SOSPeerInfoRef toCopy,
203 SecKeyRef octagonSigningKey,
204 SecKeyRef signingKey,
205 CFErrorRef *error);
206
207 SOSPeerInfoRef CF_RETURNS_RETAINED
208 SOSPeerInfoSetOctagonEncryptionKey(CFAllocatorRef allocator,
209 SOSPeerInfoRef toCopy,
210 SecKeyRef octagonEncryptionKey,
211 SecKeyRef signingKey,
212 CFErrorRef *error);
213
214 SOSPeerInfoRef CF_RETURNS_RETAINED
215 SOSPeerInfoSetOctagonKeys(CFAllocatorRef allocator,
216 SOSPeerInfoRef toCopy,
217 SecKeyRef octagonSigningKey,
218 SecKeyRef octagonEncryptionKey,
219 SecKeyRef signingKey,
220 CFErrorRef *error);
221
222 CFStringRef SOSPeerInfoCopySerialNumber(SOSPeerInfoRef pi);
223
224 void SOSPeerInfoLogState(char *category, SOSPeerInfoRef pi, SecKeyRef pubKey, CFStringRef myPID, char sigchr);
225
226 enum {
227 SOSPeerInfo_unknown = 0,
228 SOSPeerInfo_iCloud = 1,
229 SOSPeerInfo_iOS = 2,
230 SOSPeerInfo_macOS = 3,
231 SOSPeerInfo_watchOS = 4,
232 SOSPeerInfo_tvOS = 5,
233 };
234 typedef uint32_t SOSPeerInfoDeviceClass;
235
236 SOSPeerInfoDeviceClass SOSPeerInfoGetClass(SOSPeerInfoRef pi);
237
238 bool SOSPeerInfoSign(SecKeyRef privKey, SOSPeerInfoRef peer, CFErrorRef *error);
239
240 __END_DECLS
241
242 #endif