]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/SecureObjectSync/SOSMessage.h
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / 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 <Security/SecureObjectSync/SOSDataSource.h>
36 #include <Security/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 #define kSOSBackupMaxFileSize (65536)
67
68 #define kEngineMessageProtocolVersion 2
69
70 //
71 // MARK: SOSMessage encoding
72 //
73
74 // Create an SOSMessage ready to be encoded.
75 SOSMessageRef SOSMessageCreate(CFAllocatorRef allocator, uint64_t version, CFErrorRef *error);
76
77 SOSMessageRef SOSMessageCreateWithManifests(CFAllocatorRef allocator, SOSManifestRef sender,
78 SOSManifestRef base, SOSManifestRef proposed,
79 bool includeManifestDeltas, CFErrorRef *error);
80
81 bool SOSMessageSetManifests(SOSMessageRef message, SOSManifestRef sender,
82 SOSManifestRef base, SOSManifestRef proposed,
83 bool includeManifestDeltas, SOSManifestRef objectsSent,
84 CFErrorRef *error);
85
86
87 // Add an extension to this message
88 void SOSMessageAddExtension(SOSMessageRef message, CFDataRef oid, bool isCritical, CFDataRef extension);
89
90 bool SOSMessageAppendObject(SOSMessageRef message, CFDataRef object, CFErrorRef *error);
91
92 void SOSMessageSetFlags(SOSMessageRef message, SOSMessageFlags flags);
93
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);
97
98 //
99 // MARK: SOSMessage decoding
100 //
101
102 // Decode a SOSMessage
103 SOSMessageRef SOSMessageCreateWithData(CFAllocatorRef allocator, CFDataRef derData, CFErrorRef *error);
104
105 // Read values from a decoded messgage
106
107 CFDataRef SOSMessageGetBaseDigest(SOSMessageRef message);
108
109 CFDataRef SOSMessageGetProposedDigest(SOSMessageRef message);
110
111 CFDataRef SOSMessageGetSenderDigest(SOSMessageRef message);
112
113 SOSMessageFlags SOSMessageGetFlags(SOSMessageRef message);
114
115 uint64_t SOSMessageGetSequenceNumber(SOSMessageRef message);
116
117 SOSManifestRef SOSMessageGetRemovals(SOSMessageRef message);
118
119 SOSManifestRef SOSMessageGetAdditions(SOSMessageRef message);
120
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));
126
127 size_t SOSMessageCountObjects(SOSMessageRef message);
128
129 // Iterate though the objects in a decoded SOSMessage.
130 bool SOSMessageWithObjects(SOSMessageRef message, CFErrorRef *error,
131 void(^withObject)(CFDataRef object, bool *stop));
132
133 bool SOSMessageWithSOSObjects(SOSMessageRef message, SOSDataSourceRef dataSource, CFErrorRef *error,
134 void(^withObject)(SOSObjectRef object, bool *stop));
135
136 __END_DECLS
137
138 #endif /* _SEC_SOSMESSAGE_H_ */