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
, CFErrorRef
* error
);
66 SOSPeerInfoRef
SOSPeerInfoCreateWithTransportAndViews(CFAllocatorRef allocator
, CFDictionaryRef gestalt
, CFDataRef backup_key
,
67 CFStringRef IDSID
, CFStringRef transportType
, CFBooleanRef preferIDS
,
68 CFSetRef enabledViews
,
69 SecKeyRef signingKey
, CFErrorRef
* error
);
71 SOSPeerInfoRef
SOSPeerInfoCreateCloudIdentity(CFAllocatorRef allocator
, CFDictionaryRef gestalt
, SecKeyRef signingKey
, CFErrorRef
* error
);
73 SOSPeerInfoRef
SOSPeerInfoCreateCopy(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFErrorRef
* error
);
74 SOSPeerInfoRef
SOSPeerInfoCreateCurrentCopy(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
,
75 CFStringRef IDSID
, CFStringRef transportType
, CFBooleanRef preferIDS
, CFSetRef enabledViews
,
76 SecKeyRef signingKey
, CFErrorRef
* error
);
77 bool SOSPeerInfoVersionIsCurrent(SOSPeerInfoRef pi
);
78 bool SOSPeerInfoVersionHasV2Data(SOSPeerInfoRef pi
);
79 SOSPeerInfoRef
SOSPeerInfoCopyWithGestaltUpdate(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFDictionaryRef gestalt
, SecKeyRef signingKey
, CFErrorRef
* error
);
80 SOSPeerInfoRef
SOSPeerInfoCopyWithBackupKeyUpdate(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFDataRef backupKey
, SecKeyRef signingKey
, CFErrorRef
* error
);
81 SOSPeerInfoRef
SOSPeerInfoCopyWithEscrowRecordUpdate(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFStringRef dsid
, CFDictionaryRef escrowRecord
, SecKeyRef signingKey
, CFErrorRef
*error
);
82 SOSPeerInfoRef
SOSPeerInfoCopyWithReplacedEscrowRecords(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFDictionaryRef escrowRecords
, SecKeyRef signingKey
, CFErrorRef
*error
);
85 SOSPeerInfoRef
SOSPeerInfoCopyWithViewsChange(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
,
86 SOSViewActionCode action
, CFStringRef viewname
, SOSViewResultCode
*retval
,
87 SecKeyRef signingKey
, CFErrorRef
* error
);
88 SOSPeerInfoRef
SOSPeerInfoCopyAsApplication(SOSPeerInfoRef pi
, SecKeyRef userkey
, SecKeyRef peerkey
, CFErrorRef
*error
);
90 SOSPeerInfoRef
SOSPeerInfoCopyWithSecurityPropertyChange(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
,
91 SOSSecurityPropertyActionCode action
, CFStringRef property
, SOSSecurityPropertyResultCode
*retval
,
92 SecKeyRef signingKey
, CFErrorRef
* error
);
94 SOSPeerInfoRef
SOSPeerInfoCopyWithPing(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, SecKeyRef signingKey
, CFErrorRef
* error
);
95 SOSPeerInfoRef
SOSPeerInfoCopyAsApplication(SOSPeerInfoRef pi
, SecKeyRef userkey
, SecKeyRef peerkey
, CFErrorRef
*error
);
97 bool SOSPeerInfoUpdateDigestWithPublicKeyBytes(SOSPeerInfoRef peer
, const struct ccdigest_info
*di
,
98 ccdigest_ctx_t ctx
, CFErrorRef
*error
);
99 bool SOSPeerInfoUpdateDigestWithDescription(SOSPeerInfoRef peer
, const struct ccdigest_info
*di
,
100 ccdigest_ctx_t ctx
, CFErrorRef
*error
);
103 bool SOSPeerInfoApplicationVerify(SOSPeerInfoRef pi
, SecKeyRef userkey
, CFErrorRef
*error
);
105 CF_RETURNS_RETAINED CFDateRef
SOSPeerInfoGetApplicationDate(SOSPeerInfoRef pi
);
110 SOSPeerInfoRef
SOSPeerInfoCreateFromDER(CFAllocatorRef allocator
, CFErrorRef
* error
,
111 const uint8_t** der_p
, const uint8_t *der_end
);
113 SOSPeerInfoRef
SOSPeerInfoCreateFromData(CFAllocatorRef allocator
, CFErrorRef
* error
,
114 CFDataRef peerinfo_data
);
116 size_t SOSPeerInfoGetDEREncodedSize(SOSPeerInfoRef peer
, CFErrorRef
*error
);
117 uint8_t* SOSPeerInfoEncodeToDER(SOSPeerInfoRef peer
, CFErrorRef
* error
,
118 const uint8_t* der
, uint8_t* der_end
);
120 CFDataRef
SOSPeerInfoCopyEncodedData(SOSPeerInfoRef peer
, CFAllocatorRef allocator
, CFErrorRef
*error
);
125 bool SOSPeerInfoHasBackupKey(SOSPeerInfoRef peer
);
126 CFDataRef
SOSPeerInfoCopyBackupKey(SOSPeerInfoRef peer
);
127 CFMutableDictionaryRef
SOSPeerInfoCopyEscrowRecord(SOSPeerInfoRef peer
);
132 SOSPeerInfoRef
SOSPeerInfoCreateFromDER(CFAllocatorRef allocator
, CFErrorRef
* error
,
133 const uint8_t** der_p
, const uint8_t *der_end
);
135 SOSPeerInfoRef
SOSPeerInfoCreateFromData(CFAllocatorRef allocator
, CFErrorRef
* error
,
136 CFDataRef peerinfo_data
);
138 size_t SOSPeerInfoGetDEREncodedSize(SOSPeerInfoRef peer
, CFErrorRef
*error
);
139 uint8_t* SOSPeerInfoEncodeToDER(SOSPeerInfoRef peer
, CFErrorRef
* error
,
140 const uint8_t* der
, uint8_t* der_end
);
142 CFDataRef
SOSPeerInfoCopyEncodedData(SOSPeerInfoRef peer
, CFAllocatorRef allocator
, CFErrorRef
*error
);
145 // Gestalt info about the peer. It was fetched by the implementation on the other side.
146 // probably has what you're looking for..
148 CFTypeRef
SOSPeerInfoLookupGestaltValue(SOSPeerInfoRef pi
, CFStringRef key
);
149 CFDictionaryRef
SOSPeerInfoCopyPeerGestalt(SOSPeerInfoRef pi
);
150 CFDictionaryRef
SOSPeerGetGestalt(SOSPeerInfoRef pi
);
151 CFStringRef
SOSPeerInfoGetPeerName(SOSPeerInfoRef peer
);
154 // Syntactic Sugar for some commone ones, might get deprectated at this level.
157 CFStringRef
SOSPeerInfoGetPeerDeviceType(SOSPeerInfoRef peer
);
158 CFIndex
SOSPeerInfoGetPeerProtocolVersion(SOSPeerInfoRef peer
);
161 // Stringified ID for this peer, not human readable.
162 CFStringRef
SOSPeerInfoGetPeerID(SOSPeerInfoRef peer
);
163 bool SOSPeerInfoPeerIDEqual(SOSPeerInfoRef pi
, CFStringRef myPeerID
);
165 CFIndex
SOSPeerInfoGetVersion(SOSPeerInfoRef peer
);
168 // Peer Info Gestalt Helpers
170 CFStringRef
SOSPeerGestaltGetName(CFDictionaryRef gestalt
);
172 // These are Mobile Gestalt questions. Not all Gestalt questions are carried.
173 CFTypeRef
SOSPeerGestaltGetAnswer(CFDictionaryRef gestalt
, CFStringRef question
);
175 SecKeyRef
SOSPeerInfoCopyPubKey(SOSPeerInfoRef peer
);
177 CFDataRef
SOSPeerInfoGetAutoAcceptInfo(SOSPeerInfoRef peer
);
179 CFComparisonResult
SOSPeerInfoCompareByID(const void *val1
, const void *val2
, void *context
);
181 SOSPeerInfoRef
SOSPeerInfoCreateRetirementTicket(CFAllocatorRef allocator
, SecKeyRef privKey
, SOSPeerInfoRef peer
, CFErrorRef
*error
);
183 CFStringRef
SOSPeerInfoInspectRetirementTicket(SOSPeerInfoRef pi
, CFErrorRef
*error
);
185 bool SOSPeerInfoRetireRetirementTicket(size_t max_days
, SOSPeerInfoRef pi
);
187 CF_RETURNS_RETAINED CFDateRef
SOSPeerInfoGetRetirementDate(SOSPeerInfoRef pi
);
189 bool SOSPeerInfoIsRetirementTicket(SOSPeerInfoRef pi
);
191 bool SOSPeerInfoIsCloudIdentity(SOSPeerInfoRef pi
);
193 SOSPeerInfoRef
SOSPeerInfoUpgradeSignatures(CFAllocatorRef allocator
, SecKeyRef privKey
, SecKeyRef perKey
, SOSPeerInfoRef peer
, CFErrorRef
*error
);
195 SOSViewResultCode
SOSPeerInfoViewStatus(SOSPeerInfoRef pi
, CFStringRef view
, CFErrorRef
*error
);
197 CFSetRef
SOSPeerInfoGetPermittedViews(SOSPeerInfoRef peer
);
198 bool SOSPeerInfoIsEnabledView(SOSPeerInfoRef peer
, CFStringRef viewName
);
199 CFMutableSetRef
SOSPeerInfoCopyEnabledViews(SOSPeerInfoRef peer
);
200 void SOSPeerInfoWithEnabledViewSet(SOSPeerInfoRef pi
, void (^operation
)(CFSetRef enabled
));
202 SOSSecurityPropertyResultCode
SOSPeerInfoSecurityPropertyStatus(SOSPeerInfoRef pi
, CFStringRef property
, CFErrorRef
*error
);
205 CFBooleanRef
SOSPeerInfoCopyIDSPreference(SOSPeerInfoRef peer
);
206 SOSPeerInfoRef
SOSPeerInfoSetIDSPreference(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFBooleanRef preference
, SecKeyRef signingKey
, CFErrorRef
*error
);
208 CFStringRef
SOSPeerInfoCopyTransportType(SOSPeerInfoRef peer
);
209 SOSPeerInfoRef
SOSPeerInfoSetTransportType(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFStringRef transportType
, SecKeyRef signingKey
, CFErrorRef
*error
);
212 bool SOSPeerInfoHasDeviceID(SOSPeerInfoRef peer
);
213 CFStringRef
SOSPeerInfoCopyDeviceID(SOSPeerInfoRef peer
);
214 SOSPeerInfoRef
SOSPeerInfoSetDeviceID(CFAllocatorRef allocator
, SOSPeerInfoRef toCopy
, CFStringRef IDS
, SecKeyRef signingKey
, CFErrorRef
*error
);
216 bool SOSPeerInfoShouldUseIDSTransport(SOSPeerInfoRef myPeer
, SOSPeerInfoRef theirPeer
);