2 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _SOSPEERINFO_H_
26 #define _SOSPEERINFO_H_
28 #include <CoreFoundation/CoreFoundation.h>
29 #include <Security/SecKey.h>
30 #include <CommonCrypto/CommonDigestSPI.h>
31 #include <corecrypto/ccdigest.h>
33 #include <Security/SecureObjectSync/SOSTypes.h>
37 typedef struct __OpaqueSOSPeerInfo
*SOSPeerInfoRef
;
39 // Bumped to 3 from 2 so we can identify pre-iCDP peers and add the proper views.
40 #define PEERINFO_CURRENT_VERSION 3
44 kSOSPeerV2BaseVersion
= 2,
49 SOSPeerCmpPubKeyHash
= 0,
52 typedef uint32_t SOSPeerInfoCmpSelect
;
54 CFTypeID
SOSPeerInfoGetTypeID(void);
56 static inline bool isSOSPeerInfo(CFTypeRef obj
) {
57 return obj
&& (CFGetTypeID(obj
) == SOSPeerInfoGetTypeID());
60 static inline SOSPeerInfoRef
asSOSPeerInfo(CFTypeRef obj
) {
61 return isSOSPeerInfo(obj
) ? (SOSPeerInfoRef
) obj
: NULL
;
64 SOSPeerInfoRef
SOSPeerInfoCreate(CFAllocatorRef allocator
, CFDictionaryRef gestalt
, CFDataRef backup_key
, SecKeyRef signingKey
, SecKeyRef octagonSigningKey
, SecKeyRef octagonPeerEncryptionKey
, CFErrorRef
* error
);
66 SOSPeerInfoRef
SOSPeerInfoCreateWithTransportAndViews(CFAllocatorRef allocator
, CFDictionaryRef gestalt
, CFDataRef backup_key
,
67 CFStringRef IDSID
, CFStringRef transportType
, CFBooleanRef preferIDS
,
68 CFBooleanRef preferFragmentation
, CFBooleanRef preferAckModel
, CFSetRef enabledViews
, SecKeyRef signingKey
, SecKeyRef octagonSigningKey
, SecKeyRef octagonPeerEncryptionKey
, CFErrorRef
* error
);
70 SOSPeerInfoRef
SOSPeerInfoCreateCloudIdentity(CFAllocatorRef allocator
, CFDictionaryRef gestalt
, SecKeyRef signingKey
, CFErrorRef
* error
);
72 SOSPeerInfoRef
SOSPeerInfoCreateCopy(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFErrorRef
* error
);
73 SOSPeerInfoRef
SOSPeerInfoCreateCurrentCopy(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
,
74 CFStringRef IDSID
, CFStringRef transportType
, CFBooleanRef preferIDS
, CFBooleanRef preferFragmentation
, CFBooleanRef preferAckModel
, CFSetRef enabledViews
,
75 SecKeyRef signingKey
, CFErrorRef
* error
);
76 bool SOSPeerInfoVersionIsCurrent(SOSPeerInfoRef pi
);
77 bool SOSPeerInfoVersionHasV2Data(SOSPeerInfoRef pi
);
78 SOSPeerInfoRef
SOSPeerInfoCopyWithGestaltUpdate(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFDictionaryRef gestalt
, SecKeyRef signingKey
, CFErrorRef
* error
);
79 SOSPeerInfoRef
SOSPeerInfoCopyWithBackupKeyUpdate(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFDataRef backupKey
, SecKeyRef signingKey
, CFErrorRef
* error
);
80 SOSPeerInfoRef
SOSPeerInfoCopyWithEscrowRecordUpdate(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFStringRef dsid
, CFDictionaryRef escrowRecord
, SecKeyRef signingKey
, CFErrorRef
*error
);
81 SOSPeerInfoRef
SOSPeerInfoCopyWithReplacedEscrowRecords(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFDictionaryRef escrowRecords
, SecKeyRef signingKey
, CFErrorRef
*error
);
84 SOSPeerInfoRef
SOSPeerInfoCopyWithViewsChange(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
,
85 SOSViewActionCode action
, CFStringRef viewname
, SOSViewResultCode
*retval
,
86 SecKeyRef signingKey
, CFErrorRef
* error
);
87 SOSPeerInfoRef
SOSPeerInfoCopyAsApplication(SOSPeerInfoRef pi
, SecKeyRef userkey
, SecKeyRef peerkey
, CFErrorRef
*error
);
89 SOSPeerInfoRef
SOSPeerInfoCopyWithPing(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, SecKeyRef signingKey
, CFErrorRef
* error
);
90 SOSPeerInfoRef
SOSPeerInfoCopyAsApplication(SOSPeerInfoRef pi
, SecKeyRef userkey
, SecKeyRef peerkey
, CFErrorRef
*error
);
92 bool SOSPeerInfoUpdateDigestWithPublicKeyBytes(SOSPeerInfoRef peer
, const struct ccdigest_info
*di
,
93 ccdigest_ctx_t ctx
, CFErrorRef
*error
);
94 bool SOSPeerInfoUpdateDigestWithDescription(SOSPeerInfoRef peer
, const struct ccdigest_info
*di
,
95 ccdigest_ctx_t ctx
, CFErrorRef
*error
);
97 bool SOSPeerInfoApplicationVerify(SOSPeerInfoRef pi
, SecKeyRef userkey
, CFErrorRef
*error
);
99 CF_RETURNS_RETAINED CFDateRef
SOSPeerInfoGetApplicationDate(SOSPeerInfoRef pi
);
105 bool SOSPeerInfoHasBackupKey(SOSPeerInfoRef peer
);
106 CFDataRef
SOSPeerInfoCopyBackupKey(SOSPeerInfoRef peer
);
107 CFMutableDictionaryRef
SOSPeerInfoCopyEscrowRecord(SOSPeerInfoRef peer
);
112 SOSPeerInfoRef
SOSPeerInfoCreateFromDER(CFAllocatorRef allocator
, CFErrorRef
* error
,
113 const uint8_t** der_p
, const uint8_t *der_end
);
115 SOSPeerInfoRef
SOSPeerInfoCreateFromData(CFAllocatorRef allocator
, CFErrorRef
* error
,
116 CFDataRef peerinfo_data
);
118 size_t SOSPeerInfoGetDEREncodedSize(SOSPeerInfoRef peer
, CFErrorRef
*error
);
119 uint8_t* SOSPeerInfoEncodeToDER(SOSPeerInfoRef peer
, CFErrorRef
* error
,
120 const uint8_t* der
, uint8_t* der_end
);
122 CFDataRef
SOSPeerInfoCopyEncodedData(SOSPeerInfoRef peer
, CFAllocatorRef allocator
, CFErrorRef
*error
);
125 // Gestalt info about the peer. It was fetched by the implementation on the other side.
126 // probably has what you're looking for..
128 CFTypeRef
SOSPeerInfoLookupGestaltValue(SOSPeerInfoRef pi
, CFStringRef key
);
129 CFDictionaryRef
SOSPeerInfoCopyPeerGestalt(SOSPeerInfoRef pi
);
130 CFDictionaryRef
SOSPeerGetGestalt(SOSPeerInfoRef pi
);
131 CFStringRef
SOSPeerInfoGetPeerName(SOSPeerInfoRef peer
);
134 // Syntactic Sugar for some commone ones, might get deprectated at this level.
137 CFStringRef
SOSPeerInfoGetPeerDeviceType(SOSPeerInfoRef peer
);
138 CFIndex
SOSPeerInfoGetPeerProtocolVersion(SOSPeerInfoRef peer
);
141 // Stringified ID for this peer, not human readable.
142 CFStringRef
SOSPeerInfoGetPeerID(SOSPeerInfoRef peer
);
143 bool SOSPeerInfoPeerIDEqual(SOSPeerInfoRef pi
, CFStringRef myPeerID
);
145 CFIndex
SOSPeerInfoGetVersion(SOSPeerInfoRef peer
);
148 // Peer Info Gestalt Helpers
150 CFStringRef
SOSPeerGestaltGetName(CFDictionaryRef gestalt
);
152 // These are Mobile Gestalt questions. Not all Gestalt questions are carried.
153 CFTypeRef
SOSPeerGestaltGetAnswer(CFDictionaryRef gestalt
, CFStringRef question
);
155 SecKeyRef
SOSPeerInfoCopyPubKey(SOSPeerInfoRef peer
, CFErrorRef
*error
);
156 SecKeyRef
SOSPeerInfoCopyOctagonSigningPublicKey(SOSPeerInfoRef peer
, CFErrorRef
* error
);
157 SecKeyRef
SOSPeerInfoCopyOctagonEncryptionPublicKey(SOSPeerInfoRef peer
, CFErrorRef
* error
);
158 void SOSPeerInfoSetOctagonKeysInDescription(SOSPeerInfoRef peer
, SecKeyRef octagonSigningKey
,
159 SecKeyRef octagonEncryptionKey
, CFErrorRef
*error
);
160 CFDataRef
SOSPeerInfoGetAutoAcceptInfo(SOSPeerInfoRef peer
);
162 CFComparisonResult
SOSPeerInfoCompareByID(const void *val1
, const void *val2
, void *context
);
163 CFComparisonResult
SOSPeerInfoCompareByApplicationDate(const void *val1
, const void *val2
, void *context
);
165 SOSPeerInfoRef
SOSPeerInfoCreateRetirementTicket(CFAllocatorRef allocator
, SecKeyRef privKey
, SOSPeerInfoRef peer
, CFErrorRef
*error
);
167 CFStringRef
SOSPeerInfoInspectRetirementTicket(SOSPeerInfoRef pi
, CFErrorRef
*error
);
169 bool SOSPeerInfoRetireRetirementTicket(size_t max_days
, SOSPeerInfoRef pi
);
171 CF_RETURNS_RETAINED CFDateRef
SOSPeerInfoGetRetirementDate(SOSPeerInfoRef pi
);
173 bool SOSPeerInfoIsRetirementTicket(SOSPeerInfoRef pi
);
175 bool SOSPeerInfoIsCloudIdentity(SOSPeerInfoRef pi
);
177 CF_RETURNS_RETAINED SOSPeerInfoRef
SOSPeerInfoUpgradeSignatures(CFAllocatorRef allocator
, SecKeyRef privKey
, SecKeyRef perKey
, SOSPeerInfoRef peer
, CFErrorRef
*error
);
179 SOSViewResultCode
SOSPeerInfoViewStatus(SOSPeerInfoRef pi
, CFStringRef view
, CFErrorRef
*error
);
181 CFSetRef
SOSPeerInfoGetPermittedViews(SOSPeerInfoRef peer
);
182 bool SOSPeerInfoIsEnabledView(SOSPeerInfoRef peer
, CFStringRef viewName
);
183 CFMutableSetRef
SOSPeerInfoCopyEnabledViews(SOSPeerInfoRef peer
);
184 void SOSPeerInfoWithEnabledViewSet(SOSPeerInfoRef pi
, void (^operation
)(CFSetRef enabled
));
185 uint64_t SOSViewBitmaskFromSet(CFSetRef views
);
186 uint64_t SOSPeerInfoViewBitMask(SOSPeerInfoRef pi
);
188 bool SOSPeerInfoKVSOnly(SOSPeerInfoRef pi
);
189 CFStringRef
SOSPeerInfoCopyTransportType(SOSPeerInfoRef peer
);
190 CFStringRef
SOSPeerInfoCopyDeviceID(SOSPeerInfoRef peer
);
193 SOSPeerInfoRef CF_RETURNS_RETAINED
194 SOSPeerInfoSetOctagonSigningKey(CFAllocatorRef allocator
,
195 SOSPeerInfoRef toCopy
,
196 SecKeyRef octagonSigningKey
,
197 SecKeyRef signingKey
,
200 SOSPeerInfoRef CF_RETURNS_RETAINED
201 SOSPeerInfoSetOctagonEncryptionKey(CFAllocatorRef allocator
,
202 SOSPeerInfoRef toCopy
,
203 SecKeyRef octagonEncryptionKey
,
204 SecKeyRef signingKey
,
207 SOSPeerInfoRef CF_RETURNS_RETAINED
208 SOSPeerInfoSetOctagonKeys(CFAllocatorRef allocator
,
209 SOSPeerInfoRef toCopy
,
210 SecKeyRef octagonSigningKey
,
211 SecKeyRef octagonEncryptionKey
,
212 SecKeyRef signingKey
,
215 CFStringRef
SOSPeerInfoCopySerialNumber(SOSPeerInfoRef pi
);
217 void SOSPeerInfoLogState(char *category
, SOSPeerInfoRef pi
, SecKeyRef pubKey
, CFStringRef myPID
, char sigchr
);
220 SOSPeerInfo_unknown
= 0,
221 SOSPeerInfo_iCloud
= 1,
223 SOSPeerInfo_macOS
= 3,
224 SOSPeerInfo_watchOS
= 4,
225 SOSPeerInfo_tvOS
= 5,
227 typedef uint32_t SOSPeerInfoDeviceClass
;
229 SOSPeerInfoDeviceClass
SOSPeerInfoGetClass(SOSPeerInfoRef pi
);
231 bool SOSPeerInfoSign(SecKeyRef privKey
, SOSPeerInfoRef peer
, CFErrorRef
*error
);