2 * Copyright (c) 2013-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 @header SOSForerunnerSession.h
26 Describes interfaces for both requesting and approving forerunner sessions. A
27 A forerunner session encapsulates the following control flow between two
28 devices, Requestor and Acceptor, when Requestor attempts to join a syncing
29 circle already inhabited by Acceptor.
31 0. Requestor creates a requesting session containing PAKE key pair
32 1. Requestor creates a packet to request membership in the syncing circle;
33 Packet includes session public key
34 2. Requestor sends RequestPacket to Acceptor using an interface of its
36 3. Acceptor receives RequestPacket.
37 4. Acceptor creates an approving session containing PAKE key pair with
39 5. Acceptor generates Secret, a six-digit code that never leaves Acceptor
40 6. Acceptor generates ChallengePacket, derived from the public key in
41 RequestPacket and Secret
42 7. Acceptor sends ChallengePacket to Requestor using an interface of its
44 8. Requestor receives ChallengePacket
45 9. Requestor asks User to enter Secret
46 10. Requestor creates ResponsePacket, derived from Secret and the public key
47 contained in ChallengePacket
48 11. Requestor sends ResponsePacket to Acceptor using an interface of its
50 12. Acceptor receives ResponsePacket
51 13. Acceptor validates ResponsePacket
52 14. Acceptor generates HSA2Code
53 14b. Acceptor encrypts and attests to the HSA2Code to its session key
54 15. Acceptor sends encrypted HSA2Code to Requestor using an interface of its
56 16. Requestor receives encrypted HSA2Code
57 16b. Requestor decrypts and verifies HSA2Code
58 17. Requestor sends HSA2Code to Apple
59 18. Apple adds Requestor to trusted device list
60 19. Requestor generates Identity
61 20. Requestor applies to syncing circle with Identity
64 #ifndef _SEC_SOSFORERUNNERSESSION_H_
65 #define _SEC_SOSFORERUNNERSESSION_H_
67 #include <sys/cdefs.h>
69 #include <os/object.h>
70 #include <CoreFoundation/CoreFoundation.h>
71 #include <CoreFoundation/CFError.h>
76 @const SECFR_API_VERSION
77 An API version that may be used during the preprocessing phase to determine
78 which version of the API is being built against. This may be used to guard
79 against breaking due to changes in the API that are not sync'ed against your
80 project. For example, if version 20150424 adds a new method,
81 SOSFRSNewMethod(), you may guard your use of that method with
83 #if SECFR_API_VERSION >= 20150424
85 #endif // SECFR_API_VERSION >= 20150424
87 #define SECFR_API_VERSION 20150424
90 @type SOSForerunnerRequestorSessionRef
91 An opaque type representing the requesting side of a session being used to
92 enter the requestor into a syncing circle. The object has no thread affinity,
93 but it is not safe to invoke methods on the same object from multiple threads
96 typedef struct __OpaqueSOSForerunnerRequestorSession
97 *SOSForerunnerRequestorSessionRef
;
100 @function SOSForerunnerRequestorSessionGetTypeID
103 Returns the type identifier for the requestor session class.
108 OS_EXPORT OS_WARN_RESULT
110 SOSForerunnerRequestorSessionGetTypeID(void);
113 @function SOSForerunnerRequestorSessionCreate
116 Creates a new requesting session object to negotiate entry into a syncing
120 The vestigal CoreFoundation allocator. Pass NULL or
121 {@link kCFAllocatorDefault}.
124 The AppleID for the account whose syncing circle is to be joined.
127 The DirectoryServices identifier for the AppleID given in {@param username}.
130 A new session object. This object must be released with {@link CFRelease} when
131 it is no longer needed.
133 OS_EXPORT OS_MALLOC OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT
134 SOSForerunnerRequestorSessionRef
135 SOSForerunnerRequestorSessionCreate(CFAllocatorRef allocator
,
136 CFStringRef username
, uint64_t dsid
);
139 @function SOSFRSCopyRequestPacket
142 Returns a request packet suitable for requesting to join a syncing circle.
145 The session from which to copy the request packet.
148 Upon unsuccessful return, an error object describing the failure condition. May
152 A new data object representing the request packet.
154 OS_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NONNULL1
156 SOSFRSCopyRequestPacket(SOSForerunnerRequestorSessionRef session
,
160 @function SOSFRSCopyResponsePacket
163 Returns a response packet suitable for responding to a challenge to join a
167 The session from which to copy the response packet.
170 The challenge packet received from the approving device.
173 The six-digit secret generated by the approving device and entered by the user
174 on the requesting device.
177 A dictionary containing information about the peer, such as GPS location,
178 device type, etc. Pass NULL for now. This contents of this dictionary will be
179 defined at a future date.
182 Upon unsuccessful return, an error object describing the failure condition. May
186 A new data object representing the response packet.
188 OS_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NONNULL1 OS_NONNULL2
191 SOSFRSCopyResponsePacket(SOSForerunnerRequestorSessionRef session
,
192 CFDataRef challenge
, CFStringRef secret
, CFDictionaryRef peerInfo
,
196 @function SOSFRSCopyHSA2CodeFromPacket
199 Returns the HSA2 join code from the encrypted packet sent by the approving
203 The session from which to copy the HSA2 join code.
206 The encrypted packet containing the HSA2 join code sent by the approving
210 A new data object representing the HSA2 join code.
212 OS_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NONNULL1 OS_NONNULL2
214 SOSFRSCopyHSA2CodeFromPacket(SOSForerunnerRequestorSessionRef session
,
215 CFDataRef hsa2packet
, CFErrorRef
*error
);
218 @function SOSFRSCopyDecryptedData
221 Decrypts data received through the secured communication channel negotiated by
225 The session that the encrypted data is associated with.
228 The encrypted data received from the approving device.
231 A new data object representing the decrypted data received from the approving
234 OS_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NONNULL1 OS_NONNULL2
236 SOSFRSCopyDecryptedData(SOSForerunnerRequestorSessionRef session
,
237 CFDataRef encrypted
);
240 @type SOSForerunnerAcceptorSessionRef
241 An opaque type representing the accepting side of a session being used to
242 enter a new requesting device into the syncing circle of which the acceptor is
243 a member. The object has no thread affinity, but it is not safe to invoke
244 methods on the same object from multiple threads concurrently.
246 typedef struct __OpaqueSOSForerunnerAcceptorSession
247 *SOSForerunnerAcceptorSessionRef
;
250 @function SOSForerunnerAcceptorSessionGetTypeID
253 Returns the type identifier for the acceptor session class.
258 OS_EXPORT OS_WARN_RESULT
260 SOSForerunnerAcceptorSessionGetTypeID(void);
263 @function SOSForerunnerAcceptorSessionCreate
266 Creates a new accepting session object to negotiate entry of a requesting
267 device into a syncing circle.
270 The vestigal CoreFoundation allocator. Pass NULL or
271 {@link kCFAllocatorDefault}.
274 The AppleID for the account whose syncing circle is to be joined.
277 The DirectoryServices identifier for the AppleID given in {@param username}.
280 The six-digit secret generated to join the syncing circle.
283 A new session object. This object must be released with {@link CFRelease} when
284 it is no longer needed.
286 OS_EXPORT OS_MALLOC OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NONNULL2
288 SOSForerunnerAcceptorSessionRef
289 SOSForerunnerAcceptorSessionCreate(CFAllocatorRef allocator
,
290 CFStringRef username
, uint64_t dsid
, CFStringRef circleSecret
);
293 @function SOSFASCopyChallengePacket
296 Returns a challenge packet that a requesting device must satisfy to join the
297 syncing circle of which the accepting device is a member.
300 The session from which to copy the challenge packet.
302 @param requestorPacket
303 The initial requestor packet received from the device requesting to join the
307 Upon unsuccessful return, an error object describing the failure condition. May
311 A new data object representing the challenge packet.
313 OS_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NONNULL1 OS_NONNULL2
315 SOSFASCopyChallengePacket(SOSForerunnerAcceptorSessionRef session
,
316 CFDataRef requestorPacket
, CFErrorRef
*error
);
319 @function SOSFASCopyHSA2Packet
322 Processes the packet sent in response to the challenge packet by the requesting
323 device and, if the challenge is satisfied, arms auto-acceptance into the HSA2
324 trusted device list and returns a packet containing the HSA2 join code to be
325 sent to the requestor.
328 The session associated with the challenge that the response was sent to
331 @param responsePacket
332 The packet sent by the requestor in response to the challenge.
335 The code for the requestor to use to join the HSA2 trusted device list.
338 Upon unsuccessful return, an error object describing the failure condition.
339 Unlike the other interfaces in this API suite, this parameter cannot be NULL,
340 as different error codes indicate different caller responsibilities.
342 If the underlying error is EAGAIN, the caller may attempt to re-negotiate with
343 the requesting device. If too many attempts are made to re-negotiate, EBADMSG
344 will be returned. At this point, the caller may not attempt to create another
345 HSA2 packet; the connection should be terminated and the session torn down.
348 An encrypted packet containing the HSA2 join code. NULL in the event of
351 OS_EXPORT OS_MALLOC OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NONNULL1
352 OS_NONNULL2 OS_NONNULL3 OS_NONNULL4
354 SOSFASCopyHSA2Packet(SOSForerunnerAcceptorSessionRef session
,
355 CFDataRef responsePacket
, CFDataRef hsa2Code
, CFErrorRef
*error
);
358 @function SOSFASCopyEncryptedData
361 Encrypts data for transport over the negotiated session.
364 The session object for which to encrypt the given data.
370 The encrypted representation of {@param data}.
372 OS_EXPORT OS_MALLOC OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NONNULL1
375 SOSFASCopyEncryptedData(SOSForerunnerAcceptorSessionRef session
,
380 #endif /* _SEC_SOSFORERUNNERSESSION_H_ */