]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/SecureObjectSync/SOSPeer.h
Security-58286.270.3.0.1.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / SecureObjectSync / SOSPeer.h
1 /*
2 * Copyright (c) 2012-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 SOSPeer
27 The functions provided in SOSPeer provide an interface to a
28 secure object syncing peer in a circle
29 */
30
31 #ifndef _SOSPEER_H_
32 #define _SOSPEER_H_
33
34 #include <Security/SecureObjectSync/SOSCoder.h>
35 #include <Security/SecureObjectSync/SOSDataSource.h> // For SOSEngineRef
36 #include <utilities/SecAKSWrappers.h> // TODO: Layer violation -> move to datasource or make schema based
37
38 __BEGIN_DECLS
39
40 // PeerMetaRef are used to paas info about peers between accout and engine as well as to serialize in the peerstate.
41 typedef CFTypeRef SOSPeerMetaRef;
42
43
44 // peerID is not optional everything else is.
45 SOSPeerMetaRef SOSPeerMetaCreateWithComponents(CFStringRef peerID, CFSetRef views, CFDataRef keybag);
46
47 // peerID and state are both required. State is excepted to contain the set of views for this peer.
48 SOSPeerMetaRef SOSPeerMetaCreateWithState(CFStringRef peerID, CFDictionaryRef state);
49
50 CFTypeRef SOSPeerOrStateSetViewsKeyBagAndCreateCopy(CFTypeRef peerOrState, CFSetRef views, CFDataRef keyBag);
51 CFTypeRef SOSPeerOrStateSetViewsAndCopyState(CFTypeRef peerOrState, CFSetRef views);
52 bool SOSPeerMapEntryIsBackup(const void *mapEntry);
53
54 // peerID will always be returned, views, and publicKey might not be.
55 CFStringRef SOSPeerMetaGetComponents(SOSPeerMetaRef peerMeta, CFSetRef *views, CFDataRef *keybag, CFErrorRef *error);
56
57
58 typedef struct __OpaqueSOSPeer *SOSPeerRef;
59
60 CFTypeID SOSPeerGetTypeID(void);
61
62 void SOSPeerMarkDigestsInUse(SOSPeerRef peer, struct SOSDigestVector *mdInUse);
63 void SOSPeerAddManifestsInUse(SOSPeerRef peer, CFMutableDictionaryRef mfc);
64 bool SOSPeerDidReceiveRemovalsAndAdditions(SOSPeerRef peer, SOSManifestRef absentFromRemote, SOSManifestRef additionsFromRemote,
65 SOSManifestRef unwantedFromRemote, SOSManifestRef local, CFErrorRef *error);
66 bool SOSPeerDataSourceWillCommit(SOSPeerRef peer, SOSDataSourceTransactionSource source, SOSManifestRef removals, SOSManifestRef additions, CFErrorRef *error);
67 bool SOSPeerDataSourceWillChange(SOSPeerRef peer, SOSDataSourceRef dataSource, SOSDataSourceTransactionSource source, CFArrayRef changes, CFErrorRef *error);
68 bool SOSPeerWriteAddEvent(FILE *journalFile, keybag_handle_t kbhandle, SOSDataSourceRef dataSource, SOSObjectRef object, CFErrorRef *error);
69
70 // Create a peer from an archived state.
71 SOSPeerRef SOSPeerCreateWithState(SOSEngineRef engine, CFStringRef peer_id, CFDictionaryRef state, CFErrorRef *error);
72
73 // Return encoded peerState dictionary
74 CFDictionaryRef SOSPeerCopyState(SOSPeerRef peer, CFErrorRef *error);
75
76 // (Re)initialize from a peerState dictionary
77 bool SOSPeerSetState(SOSPeerRef peer, SOSEngineRef engine, CFDictionaryRef state, CFErrorRef *error);
78 void SOSPeerSetOTRTimer(SOSPeerRef peer, dispatch_source_t timer);
79 dispatch_source_t SOSPeerGetOTRTimer(SOSPeerRef peer);
80 void SOSPeerRemoveOTRTimerEntry(SOSPeerRef peer);
81 bool SOSPeerTimerForPeerExist(SOSPeerRef peer);
82
83 //
84 //
85 //
86
87 CFIndex SOSPeerGetVersion(SOSPeerRef peer);
88 CFStringRef SOSPeerGetID(SOSPeerRef peer);
89 bool SOSPeersEqual(SOSPeerRef peerA, SOSPeerRef peerB);
90
91 uint64_t SOSPeerNextSequenceNumber(SOSPeerRef peer);
92 uint64_t SOSPeerGetMessageVersion(SOSPeerRef peer);
93
94 //
95 // MARK: State tracking helpers
96 //
97
98 // Return true if the peer needs saving.
99 bool SOSPeerDidConnect(SOSPeerRef peer);
100 bool SOSPeerMustSendMessage(SOSPeerRef peer);
101 void SOSPeerSetMustSendMessage(SOSPeerRef peer, bool must);
102
103 bool SOSPeerSendObjects(SOSPeerRef peer);
104 void SOSPeerSetSendObjects(SOSPeerRef peer, bool sendObjects);
105
106 bool SOSPeerHasBeenInSync(SOSPeerRef peer);
107 void SOSPeerSetHasBeenInSync(SOSPeerRef peer, bool hasBeenInSync);
108
109 SOSManifestRef SOSPeerGetProposedManifest(SOSPeerRef peer);
110 SOSManifestRef SOSPeerGetConfirmedManifest(SOSPeerRef peer);
111 void SOSPeerSetConfirmedManifest(SOSPeerRef peer, SOSManifestRef confirmed);
112 void SOSPeerAddProposedManifest(SOSPeerRef peer, SOSManifestRef pending);
113 void SOSPeerSetProposedManifest(SOSPeerRef peer, SOSManifestRef pending);
114 void SOSPeerAddLocalManifest(SOSPeerRef peer, SOSManifestRef local);
115 SOSManifestRef SOSPeerGetPendingObjects(SOSPeerRef peer);
116 void SOSPeerSetPendingObjects(SOSPeerRef peer, SOSManifestRef pendingObjects);
117 SOSManifestRef SOSPeerGetUnwantedManifest(SOSPeerRef peer);
118 void SOSPeerSetUnwantedManifest(SOSPeerRef peer, SOSManifestRef unwantedManifest);
119
120 SOSManifestRef SOSPeerCopyManifestForDigest(SOSPeerRef peer, CFDataRef digest);
121
122 CFSetRef SOSPeerGetViewNameSet(SOSPeerRef peer);
123 void SOSPeerSetViewNameSet(SOSPeerRef peer, CFSetRef views);
124
125 CFDataRef SOSPeerGetKeyBag(SOSPeerRef peer);
126 void SOSPeerKeyBagDidChange(SOSPeerRef peer);
127 void SOSPeerSetKeyBag(SOSPeerRef peer, CFDataRef keyBag);
128 // Write a reset event to the journal if mustSendMessage is true.
129 bool SOSPeerWritePendingReset(SOSPeerRef peer, CFErrorRef *error);
130
131 //
132 // MARK: Backup Peers
133 //
134
135 // TODO: Layer violation -> move to datasource or make schema based
136 bool SOSPeerAppendToJournal(SOSPeerRef peer, CFErrorRef *error, void(^with)(FILE *journalFile, keybag_handle_t kbhandle));
137 int SOSPeerHandoffFD(SOSPeerRef peer, CFErrorRef *error);
138
139 void SOSBackupPeerPostNotification(const char *reason);
140
141 //
142 // MARK: RateLimiting
143 //
144 void SOSPeerSetRateLimiter(SOSPeerRef peer, CFTypeRef limiter);
145 CFTypeRef SOSPeerGetRateLimiter(SOSPeerRef peer);
146 bool SOSPeerShouldRateLimit(CFArrayRef attributes, SOSPeerRef peer);
147
148 __END_DECLS
149
150 #endif /* !_SOSPEER_H_ */