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 "keychain/SecureObjectSync/SOSDataSource.h"
36 #include "keychain/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 (64000)
65 #define kSOSBackupMaxFileSize (64000)
67 #define kEngineMessageProtocolVersion 2
70 // MARK: SOSMessage encoding
73 // Create an SOSMessage ready to be encoded.
74 SOSMessageRef
SOSMessageCreate(CFAllocatorRef allocator
, uint64_t version
, CFErrorRef
*error
);
76 SOSMessageRef
SOSMessageCreateWithManifests(CFAllocatorRef allocator
, SOSManifestRef sender
,
77 SOSManifestRef base
, SOSManifestRef proposed
,
78 bool includeManifestDeltas
, CFErrorRef
*error
);
80 bool SOSMessageSetManifests(SOSMessageRef message
, SOSManifestRef sender
,
81 SOSManifestRef base
, SOSManifestRef proposed
,
82 bool includeManifestDeltas
, SOSManifestRef objectsSent
,
86 // Add an extension to this message
87 void SOSMessageAddExtension(SOSMessageRef message
, CFDataRef oid
, bool isCritical
, CFDataRef extension
);
89 bool SOSMessageAppendObject(SOSMessageRef message
, CFDataRef object
, CFErrorRef
*error
);
91 void SOSMessageSetFlags(SOSMessageRef message
, SOSMessageFlags flags
);
93 // Encode an SOSMessage, calls addObject callback and appends returned objects
94 // one by one, until addObject returns NULL.
95 CFDataRef
SOSMessageCreateData(SOSMessageRef message
, uint64_t sequenceNumber
, CFErrorRef
*error
);
98 // MARK: SOSMessage decoding
101 // Decode a SOSMessage
102 SOSMessageRef
SOSMessageCreateWithData(CFAllocatorRef allocator
, CFDataRef derData
, CFErrorRef
*error
);
104 // Read values from a decoded messgage
106 CFDataRef
SOSMessageGetBaseDigest(SOSMessageRef message
);
108 CFDataRef
SOSMessageGetProposedDigest(SOSMessageRef message
);
110 CFDataRef
SOSMessageGetSenderDigest(SOSMessageRef message
);
112 SOSMessageFlags
SOSMessageGetFlags(SOSMessageRef message
);
114 uint64_t SOSMessageGetSequenceNumber(SOSMessageRef message
);
116 SOSManifestRef
SOSMessageGetRemovals(SOSMessageRef message
);
118 SOSManifestRef
SOSMessageGetAdditions(SOSMessageRef message
);
120 // Iterate though the extensions in a decoded SOSMessage. If criticalOnly is
121 // true all non critical extensions are skipped.
122 void SOSMessageWithExtensions(SOSMessageRef message
, bool criticalOnly
,
123 void(^withExtension
)(CFDataRef oid
, bool isCritical
,
124 CFDataRef extension
, bool *stop
));
126 size_t SOSMessageCountObjects(SOSMessageRef message
);
128 // Iterate though the objects in a decoded SOSMessage.
129 bool SOSMessageWithObjects(SOSMessageRef message
, CFErrorRef
*error
,
130 void(^withObject
)(CFDataRef object
, bool *stop
));
132 bool SOSMessageWithSOSObjects(SOSMessageRef message
, SOSDataSourceRef dataSource
, CFErrorRef
*error
,
133 void(^withObject
)(SOSObjectRef object
, bool *stop
));
137 #endif /* _SEC_SOSMESSAGE_H_ */