2 * Copyright (c) 2012-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 The functions provided in SOSPeer provide an interface to a
28 secure object syncing peer in a circle
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
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
;
44 // peerID is not optional everything else is.
45 SOSPeerMetaRef
SOSPeerMetaCreateWithComponents(CFStringRef peerID
, CFSetRef views
, CFDataRef keybag
);
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
);
50 CFTypeRef
SOSPeerOrStateSetViewsKeyBagAndCreateCopy(CFTypeRef peerOrState
, CFSetRef views
, CFDataRef keyBag
);
51 CFTypeRef
SOSPeerOrStateSetViewsAndCopyState(CFTypeRef peerOrState
, CFSetRef views
);
52 bool SOSPeerMapEntryIsBackup(const void *mapEntry
);
54 // peerID will always be returned, views, and publicKey might not be.
55 CFStringRef
SOSPeerMetaGetComponents(SOSPeerMetaRef peerMeta
, CFSetRef
*views
, CFDataRef
*keybag
, CFErrorRef
*error
);
58 typedef struct __OpaqueSOSPeer
*SOSPeerRef
;
60 CFTypeID
SOSPeerGetTypeID(void);
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
);
70 // Create a peer from an archived state.
71 SOSPeerRef
SOSPeerCreateWithState(SOSEngineRef engine
, CFStringRef peer_id
, CFDictionaryRef state
, CFErrorRef
*error
);
73 // Return encoded peerState dictionary
74 CFDictionaryRef
SOSPeerCopyState(SOSPeerRef peer
, CFErrorRef
*error
);
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
);
87 CFIndex
SOSPeerGetVersion(SOSPeerRef peer
);
88 CFStringRef
SOSPeerGetID(SOSPeerRef peer
);
89 bool SOSPeersEqual(SOSPeerRef peerA
, SOSPeerRef peerB
);
91 uint64_t SOSPeerNextSequenceNumber(SOSPeerRef peer
);
92 uint64_t SOSPeerGetMessageVersion(SOSPeerRef peer
);
95 // MARK: State tracking helpers
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
);
103 bool SOSPeerSendObjects(SOSPeerRef peer
);
104 void SOSPeerSetSendObjects(SOSPeerRef peer
, bool sendObjects
);
106 bool SOSPeerHasBeenInSync(SOSPeerRef peer
);
107 void SOSPeerSetHasBeenInSync(SOSPeerRef peer
, bool hasBeenInSync
);
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
);
120 SOSManifestRef
SOSPeerCopyManifestForDigest(SOSPeerRef peer
, CFDataRef digest
);
122 CFSetRef
SOSPeerGetViewNameSet(SOSPeerRef peer
);
123 void SOSPeerSetViewNameSet(SOSPeerRef peer
, CFSetRef views
);
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
);
132 // MARK: Backup Peers
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
);
139 void SOSBackupPeerPostNotification(const char *reason
);
142 // MARK: RateLimiting
144 void SOSPeerSetRateLimiter(SOSPeerRef peer
, CFTypeRef limiter
);
145 CFTypeRef
SOSPeerGetRateLimiter(SOSPeerRef peer
);
146 bool SOSPeerShouldRateLimit(CFArrayRef attributes
, SOSPeerRef peer
);
150 #endif /* !_SOSPEER_H_ */