]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/SecureObjectSync/SOSPeer.h
Security-57337.50.23.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
79 //
80 //
81 //
82
83 CFIndex SOSPeerGetVersion(SOSPeerRef peer);
84 CFStringRef SOSPeerGetID(SOSPeerRef peer);
85 bool SOSPeersEqual(SOSPeerRef peerA, SOSPeerRef peerB);
86
87 // Coders
88 SOSCoderRef SOSPeerGetCoder(SOSPeerRef peer, CFErrorRef *error);
89 bool SOSPeerEnsureCoder(SOSPeerRef peer, SOSFullPeerInfoRef myPeerInfo, SOSPeerInfoRef peerInfo, CFErrorRef *error);
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 SOSManifestRef SOSPeerGetProposedManifest(SOSPeerRef peer);
107 SOSManifestRef SOSPeerGetConfirmedManifest(SOSPeerRef peer);
108 void SOSPeerSetConfirmedManifest(SOSPeerRef peer, SOSManifestRef confirmed);
109 void SOSPeerAddProposedManifest(SOSPeerRef peer, SOSManifestRef pending);
110 void SOSPeerSetProposedManifest(SOSPeerRef peer, SOSManifestRef pending);
111 void SOSPeerAddLocalManifest(SOSPeerRef peer, SOSManifestRef local);
112 SOSManifestRef SOSPeerGetPendingObjects(SOSPeerRef peer);
113 void SOSPeerSetPendingObjects(SOSPeerRef peer, SOSManifestRef pendingObjects);
114 SOSManifestRef SOSPeerGetUnwantedManifest(SOSPeerRef peer);
115 void SOSPeerSetUnwantedManifest(SOSPeerRef peer, SOSManifestRef unwantedManifest);
116
117 SOSManifestRef SOSPeerCopyManifestForDigest(SOSPeerRef peer, CFDataRef digest);
118
119 CFSetRef SOSPeerGetViewNameSet(SOSPeerRef peer);
120 void SOSPeerSetViewNameSet(SOSPeerRef peer, CFSetRef views);
121
122 CFDataRef SOSPeerGetKeyBag(SOSPeerRef peer);
123 void SOSPeerKeyBagDidChange(SOSPeerRef peer);
124 void SOSPeerSetKeyBag(SOSPeerRef peer, CFDataRef keyBag);
125 // Write a reset event to the journal if mustSendMessage is true.
126 bool SOSPeerWritePendingReset(SOSPeerRef peer, CFErrorRef *error);
127
128 //
129 // MARK: Backup Peers
130 //
131
132 // TODO: Layer violation -> move to datasource or make schema based
133 bool SOSPeerAppendToJournal(SOSPeerRef peer, CFErrorRef *error, void(^with)(FILE *journalFile, keybag_handle_t kbhandle));
134 int SOSPeerHandoffFD(SOSPeerRef peer, CFErrorRef *error);
135
136 void SOSBackupPeerPostNotification(const char *reason);
137
138 __END_DECLS
139
140 #endif /* !_SOSPEER_H_ */