]> git.saurik.com Git - apple/security.git/blob - Security/sec/SOSCircle/SecureObjectSync/SOSMessage.h
Security-57031.10.10.tar.gz
[apple/security.git] / Security / sec / SOSCircle / SecureObjectSync / SOSMessage.h
1 /*
2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 /*!
26 @header SOSMessage.h
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.
30 */
31
32 #ifndef _SEC_SOSMESSAGE_H_
33 #define _SEC_SOSMESSAGE_H_
34
35 #include <SecureObjectSync/SOSDataSource.h>
36 #include <SecureObjectSync/SOSManifest.h>
37
38 __BEGIN_DECLS
39
40 enum SOSMessageFlags {
41 kSOSMessageGetObjects = (0),
42 kSOSMessageJoinRequest = (1),
43 kSOSMessagePartial = (2),
44 kSOSMessageDigestTypesProposed = (3),
45 kSOSMessageClearGetObjects = (4),
46 kSOSMessageDidClearGetObjectsSinceLastDelta = (5),
47 kSOSMessageSkipHello = (6),
48 };
49 typedef uint64_t SOSMessageFlags;
50
51 enum SOSDigestTypes {
52 kSOSDigestTypeSHA1 = (0),
53 kSOSDigestTypeDefault = kSOSDigestTypeSHA1,
54 kSOSDigestTypeSHA224 = (1),
55 kSOSDigestTypeSHA256 = (2),
56 kSOSDigestTypeSHA384 = (3),
57 kSOSDigestTypeSHA512 = (4),
58 };
59 typedef uint64_t SOSDigestTypes;
60
61 /* SOSMessage interface. */
62 typedef struct __OpaqueSOSMessage *SOSMessageRef;
63
64 //#define kSOSMessageMaxObjectsSize (8192)
65 #define kSOSMessageMaxObjectsSize (65536)
66
67 #define kEngineMessageProtocolVersion 2
68
69 //
70 // MARK: SOSMessage encoding
71 //
72
73 // Create an SOSMessage ready to be encoded.
74 SOSMessageRef SOSMessageCreate(CFAllocatorRef allocator, uint64_t version, CFErrorRef *error);
75
76 SOSMessageRef SOSMessageCreateWithManifests(CFAllocatorRef allocator, SOSManifestRef sender,
77 SOSManifestRef base, SOSManifestRef proposed,
78 bool includeManifestDeltas, CFErrorRef *error);
79
80 bool SOSMessageSetManifests(SOSMessageRef message, SOSManifestRef sender,
81 SOSManifestRef base, SOSManifestRef proposed,
82 bool includeManifestDeltas, SOSManifestRef objectsSent,
83 CFErrorRef *error);
84
85
86 // Add an extension to this message
87 void SOSMessageAddExtension(SOSMessageRef message, CFDataRef oid, bool isCritical, CFDataRef extension);
88
89 bool SOSMessageAppendObject(SOSMessageRef message, CFDataRef object, CFErrorRef *error);
90
91 void SOSMessageSetFlags(SOSMessageRef message, SOSMessageFlags flags);
92
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);
96
97 //
98 // MARK: SOSMessage decoding
99 //
100
101 // Decode a SOSMessage
102 SOSMessageRef SOSMessageCreateWithData(CFAllocatorRef allocator, CFDataRef derData, CFErrorRef *error);
103
104 // Read values from a decoded messgage
105
106 CFDataRef SOSMessageGetBaseDigest(SOSMessageRef message);
107
108 CFDataRef SOSMessageGetProposedDigest(SOSMessageRef message);
109
110 CFDataRef SOSMessageGetSenderDigest(SOSMessageRef message);
111
112 SOSMessageFlags SOSMessageGetFlags(SOSMessageRef message);
113
114 uint64_t SOSMessageGetSequenceNumber(SOSMessageRef message);
115
116 SOSManifestRef SOSMessageGetRemovals(SOSMessageRef message);
117
118 SOSManifestRef SOSMessageGetAdditions(SOSMessageRef message);
119
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));
125
126 size_t SOSMessageCountObjects(SOSMessageRef message);
127
128 // Iterate though the objects in a decoded SOSMessage.
129 bool SOSMessageWithObjects(SOSMessageRef message, CFErrorRef *error,
130 void(^withObject)(CFDataRef object, bool *stop));
131
132 bool SOSMessageWithSOSObjects(SOSMessageRef message, SOSDataSourceRef dataSource, CFErrorRef *error,
133 void(^withObject)(SOSObjectRef object, bool *stop));
134
135 __END_DECLS
136
137 #endif /* _SEC_SOSMESSAGE_H_ */