]> git.saurik.com Git - apple/security.git/blame - keychain/SecureObjectSync/SOSMessage.h
Security-59754.80.3.tar.gz
[apple/security.git] / keychain / SecureObjectSync / SOSMessage.h
CommitLineData
d8f41ccd
A
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
b54c578e
A
35#include "keychain/SecureObjectSync/SOSDataSource.h"
36#include "keychain/SecureObjectSync/SOSManifest.h"
d8f41ccd
A
37
38__BEGIN_DECLS
39
40enum SOSMessageFlags {
41 kSOSMessageGetObjects = (0),
42 kSOSMessageJoinRequest = (1),
43 kSOSMessagePartial = (2),
44 kSOSMessageDigestTypesProposed = (3),
45 kSOSMessageClearGetObjects = (4),
46 kSOSMessageDidClearGetObjectsSinceLastDelta = (5),
47 kSOSMessageSkipHello = (6),
48};
49typedef uint64_t SOSMessageFlags;
50
51enum SOSDigestTypes {
52 kSOSDigestTypeSHA1 = (0),
53 kSOSDigestTypeDefault = kSOSDigestTypeSHA1,
54 kSOSDigestTypeSHA224 = (1),
55 kSOSDigestTypeSHA256 = (2),
56 kSOSDigestTypeSHA384 = (3),
57 kSOSDigestTypeSHA512 = (4),
58};
59typedef uint64_t SOSDigestTypes;
60
61/* SOSMessage interface. */
62typedef struct __OpaqueSOSMessage *SOSMessageRef;
63
6b200bc3
A
64#define kSOSMessageMaxObjectsSize (64000)
65#define kSOSBackupMaxFileSize (64000)
d8f41ccd
A
66
67#define kEngineMessageProtocolVersion 2
68
69//
70// MARK: SOSMessage encoding
71//
72
73// Create an SOSMessage ready to be encoded.
74SOSMessageRef SOSMessageCreate(CFAllocatorRef allocator, uint64_t version, CFErrorRef *error);
75
76SOSMessageRef SOSMessageCreateWithManifests(CFAllocatorRef allocator, SOSManifestRef sender,
77 SOSManifestRef base, SOSManifestRef proposed,
78 bool includeManifestDeltas, CFErrorRef *error);
79
80bool 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
87void SOSMessageAddExtension(SOSMessageRef message, CFDataRef oid, bool isCritical, CFDataRef extension);
88
89bool SOSMessageAppendObject(SOSMessageRef message, CFDataRef object, CFErrorRef *error);
90
91void 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.
95CFDataRef SOSMessageCreateData(SOSMessageRef message, uint64_t sequenceNumber, CFErrorRef *error);
96
97//
98// MARK: SOSMessage decoding
99//
100
101// Decode a SOSMessage
102SOSMessageRef SOSMessageCreateWithData(CFAllocatorRef allocator, CFDataRef derData, CFErrorRef *error);
103
104// Read values from a decoded messgage
105
106CFDataRef SOSMessageGetBaseDigest(SOSMessageRef message);
107
108CFDataRef SOSMessageGetProposedDigest(SOSMessageRef message);
109
110CFDataRef SOSMessageGetSenderDigest(SOSMessageRef message);
111
112SOSMessageFlags SOSMessageGetFlags(SOSMessageRef message);
113
114uint64_t SOSMessageGetSequenceNumber(SOSMessageRef message);
115
116SOSManifestRef SOSMessageGetRemovals(SOSMessageRef message);
117
118SOSManifestRef SOSMessageGetAdditions(SOSMessageRef message);
119
120// Iterate though the extensions in a decoded SOSMessage. If criticalOnly is
121// true all non critical extensions are skipped.
122void SOSMessageWithExtensions(SOSMessageRef message, bool criticalOnly,
123 void(^withExtension)(CFDataRef oid, bool isCritical,
124 CFDataRef extension, bool *stop));
125
126size_t SOSMessageCountObjects(SOSMessageRef message);
127
128// Iterate though the objects in a decoded SOSMessage.
129bool SOSMessageWithObjects(SOSMessageRef message, CFErrorRef *error,
130 void(^withObject)(CFDataRef object, bool *stop));
131
132bool SOSMessageWithSOSObjects(SOSMessageRef message, SOSDataSourceRef dataSource, CFErrorRef *error,
133 void(^withObject)(SOSObjectRef object, bool *stop));
134
135__END_DECLS
136
137#endif /* _SEC_SOSMESSAGE_H_ */