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@
27 This provides interfaces to the encoding and decoding of peer to peer
28 messages in the Secure Object Syncing protocol.
29 SOSMessageRef is a CFTypeRef.
32 #ifndef _SEC_SOSMESSAGE_H_
33 #define _SEC_SOSMESSAGE_H_
35 #include <Security/SecureObjectSync/SOSDataSource.h>
36 #include <Security/SecureObjectSync/SOSManifest.h>
40 enum SOSMessageFlags
{
41 kSOSMessageGetObjects
= (0),
42 kSOSMessageJoinRequest
= (1),
43 kSOSMessagePartial
= (2),
44 kSOSMessageDigestTypesProposed
= (3),
45 kSOSMessageClearGetObjects
= (4),
46 kSOSMessageDidClearGetObjectsSinceLastDelta
= (5),
47 kSOSMessageSkipHello
= (6),
49 typedef uint64_t SOSMessageFlags
;
52 kSOSDigestTypeSHA1
= (0),
53 kSOSDigestTypeDefault
= kSOSDigestTypeSHA1
,
54 kSOSDigestTypeSHA224
= (1),
55 kSOSDigestTypeSHA256
= (2),
56 kSOSDigestTypeSHA384
= (3),
57 kSOSDigestTypeSHA512
= (4),
59 typedef uint64_t SOSDigestTypes
;
61 /* SOSMessage interface. */
62 typedef struct __OpaqueSOSMessage
*SOSMessageRef
;
64 //#define kSOSMessageMaxObjectsSize (8192)
65 #define kSOSMessageMaxObjectsSize (65536)
66 #define kSOSBackupMaxFileSize (65536)
68 #define kEngineMessageProtocolVersion 2
71 // MARK: SOSMessage encoding
74 // Create an SOSMessage ready to be encoded.
75 SOSMessageRef
SOSMessageCreate(CFAllocatorRef allocator
, uint64_t version
, CFErrorRef
*error
);
77 SOSMessageRef
SOSMessageCreateWithManifests(CFAllocatorRef allocator
, SOSManifestRef sender
,
78 SOSManifestRef base
, SOSManifestRef proposed
,
79 bool includeManifestDeltas
, CFErrorRef
*error
);
81 bool SOSMessageSetManifests(SOSMessageRef message
, SOSManifestRef sender
,
82 SOSManifestRef base
, SOSManifestRef proposed
,
83 bool includeManifestDeltas
, SOSManifestRef objectsSent
,
87 // Add an extension to this message
88 void SOSMessageAddExtension(SOSMessageRef message
, CFDataRef oid
, bool isCritical
, CFDataRef extension
);
90 bool SOSMessageAppendObject(SOSMessageRef message
, CFDataRef object
, CFErrorRef
*error
);
92 void SOSMessageSetFlags(SOSMessageRef message
, SOSMessageFlags flags
);
94 // Encode an SOSMessage, calls addObject callback and appends returned objects
95 // one by one, until addObject returns NULL.
96 CFDataRef
SOSMessageCreateData(SOSMessageRef message
, uint64_t sequenceNumber
, CFErrorRef
*error
);
99 // MARK: SOSMessage decoding
102 // Decode a SOSMessage
103 SOSMessageRef
SOSMessageCreateWithData(CFAllocatorRef allocator
, CFDataRef derData
, CFErrorRef
*error
);
105 // Read values from a decoded messgage
107 CFDataRef
SOSMessageGetBaseDigest(SOSMessageRef message
);
109 CFDataRef
SOSMessageGetProposedDigest(SOSMessageRef message
);
111 CFDataRef
SOSMessageGetSenderDigest(SOSMessageRef message
);
113 SOSMessageFlags
SOSMessageGetFlags(SOSMessageRef message
);
115 uint64_t SOSMessageGetSequenceNumber(SOSMessageRef message
);
117 SOSManifestRef
SOSMessageGetRemovals(SOSMessageRef message
);
119 SOSManifestRef
SOSMessageGetAdditions(SOSMessageRef message
);
121 // Iterate though the extensions in a decoded SOSMessage. If criticalOnly is
122 // true all non critical extensions are skipped.
123 void SOSMessageWithExtensions(SOSMessageRef message
, bool criticalOnly
,
124 void(^withExtension
)(CFDataRef oid
, bool isCritical
,
125 CFDataRef extension
, bool *stop
));
127 size_t SOSMessageCountObjects(SOSMessageRef message
);
129 // Iterate though the objects in a decoded SOSMessage.
130 bool SOSMessageWithObjects(SOSMessageRef message
, CFErrorRef
*error
,
131 void(^withObject
)(CFDataRef object
, bool *stop
));
133 bool SOSMessageWithSOSObjects(SOSMessageRef message
, SOSDataSourceRef dataSource
, CFErrorRef
*error
,
134 void(^withObject
)(SOSObjectRef object
, bool *stop
));
138 #endif /* _SEC_SOSMESSAGE_H_ */