]> git.saurik.com Git - apple/security.git/blame - OSX/sec/SOSCircle/SecureObjectSync/SOSEngine.h
Security-57740.1.18.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / SecureObjectSync / SOSEngine.h
CommitLineData
5c19dc3a
A
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 SOSEngine.h - Manifest managent engine and decision making for
27 object syncing protocol.
28 */
29
30#ifndef _SEC_SOSENGINE_H_
31#define _SEC_SOSENGINE_H_
32
33#include <Security/SecureObjectSync/SOSDataSource.h>
34#include <Security/SecureObjectSync/SOSMessage.h>
35#include <Security/SecureObjectSync/SOSPeer.h>
36#include <dispatch/dispatch.h>
37
38__BEGIN_DECLS
39
40// TODO: Move this to SOSPeer.h?
41typedef void (^SOSEnginePeerMessageSentBlock)(bool success);
42
43// Return a new engine instance for a given data source.
44SOSEngineRef SOSEngineCreate(SOSDataSourceRef dataSource, CFErrorRef *error);
45
46// TODO: Nuke from orbit
47SOSManifestRef SOSEngineCopyManifest(SOSEngineRef engine, CFErrorRef *error);
48
49// Return a snapshot of the current manifest of the engines data source for the views that the given peer is in.
50SOSManifestRef SOSEngineCopyLocalPeerManifest(SOSEngineRef engine, SOSPeerRef peer, CFErrorRef *error);
51SOSManifestRef SOSEngineCopyLocalPeerManifest_locked(SOSEngineRef engine, SOSPeerRef peer, CFErrorRef *error);
52
53// Apply changes to all views manifests, and update all peers accordingly
54bool SOSEngineUpdateChanges(SOSEngineRef engine, SOSDataSourceTransactionSource source, CFArrayRef changes, CFErrorRef *error);
55
56// Store manifest indexed by it's own digest. Can be retrieved with SOSEngineGetManifestForDigest()
57void SOSEngineAddManifest(SOSEngineRef engine, SOSManifestRef manifest);
58
59// Retrive a digest stored with SOSEngineAddManifest()
60SOSManifestRef SOSEngineGetManifestForDigest(SOSEngineRef engine, CFDataRef digest);
61
62// Return the digest for a patched manifest (which is stored in the cache already).
63CFDataRef SOSEnginePatchRecordAndCopyDigest(SOSEngineRef engine, SOSManifestRef base, SOSManifestRef removals, SOSManifestRef additions, CFErrorRef *error);
64
65// Copy a manifest for a key persisted in a persisted dictionary
66SOSManifestRef SOSEngineCopyPersistedManifest(SOSEngineRef engine, CFDictionaryRef persisted, CFStringRef key);
67
68// Copy a manifest for a key persisted in a persisted dictionary
69CFMutableArrayRef SOSEngineCopyPersistedManifestArray(SOSEngineRef engine, CFDictionaryRef persisted, CFStringRef key, CFErrorRef *error);
70
71void SOSEngineClearCache(SOSEngineRef engine);
72
5c19dc3a
A
73// Dispose of an engine when it's no longer needed.
74void SOSEngineDispose(SOSEngineRef engine);
75
76// Handle incoming message from a remote peer.
77bool SOSEngineHandleMessage(SOSEngineRef engine, CFStringRef peerID,
78 CFDataRef message, CFErrorRef *error);
79
80// Change the set of peers we know about. trustedPeers and untrustedPeers are arrays of SOSPeerMetaRef
81// trustedPeers is an array of SOSPeerMetaRef (peer SOSPeer.h), untrustedpeers is redundant as the engine
82// treats a trustedPeer with no views and no publicKey the same as an untrustedPeer.
83// TODO: Fix the documentation above this line.
84void SOSEngineCircleChanged(SOSEngineRef engine, CFStringRef myPeerID, CFArrayRef trustedPeers, CFArrayRef untrustedPeers);
85
86// Iterate over all peers.
87void SOSEngineForEachPeer(SOSEngineRef engine, void (^with)(SOSPeerRef peer));
88
89// TODO: Move SOSTransportMessageIDSRef declarations somewhere we can get to them here.
fa7225c8 90bool SOSEngineSyncWithPeers(SOSEngineRef engine, CFErrorRef *error);
5c19dc3a
A
91
92// Don't call this unless you know what you are doing. If you do then still don't call it.
93bool SOSEngineHandleMessage_locked(SOSEngineRef engine, CFStringRef peerID, SOSMessageRef message,
94 SOSTransactionRef txn, bool *commit, bool *somethingChanged, CFErrorRef *error);
95
fa7225c8 96CFDataRef SOSEngineCreateMessage_locked(SOSEngineRef engine, SOSTransactionRef txn, SOSPeerRef peer,
5c19dc3a
A
97 CFErrorRef *error, SOSEnginePeerMessageSentBlock *sent);
98
99// Return a SOSPeerRef for a given peer_id.
100SOSPeerRef SOSEngineCopyPeerWithID(SOSEngineRef engine, CFStringRef peer_id, CFErrorRef *error);
101
102// Operate on a peer with a given peer_id under the engine lock
fa7225c8
A
103bool SOSEngineForPeerID(SOSEngineRef engine, CFStringRef peer_id, CFErrorRef *error, void (^forPeer)(SOSTransactionRef txn, SOSPeerRef peer, SOSCoderRef coder));
104bool SOSEngineForPeerIDNoCoder(SOSEngineRef engine, CFStringRef peerID, CFErrorRef *error, void (^forPeer)(SOSTransactionRef txn, SOSPeerRef peer));
5c19dc3a
A
105
106// Modify a peer inside a transaction under then engine lock and optionally force an engine state save when done.
fa7225c8
A
107bool SOSEngineWithPeerID(SOSEngineRef engine, CFStringRef peer_id, CFErrorRef *error, void (^with)(SOSPeerRef peer, SOSCoderRef coder, SOSDataSourceRef dataSource, SOSTransactionRef txn, bool *forceSaveState));
108
109bool SOSEngineInitializePeerCoder(SOSEngineRef engine, SOSFullPeerInfoRef myPeerInfo, SOSPeerInfoRef peerInfo, CFErrorRef *error);
5c19dc3a
A
110
111// Return a message to be sent for the current state. Returns NULL on errors,
112// return a zero length CFDataRef if there is nothing to send.
113// If *ProposedManifest is set the caller is responsible for updating their
114// proposed manifest upon successful transmission of the message.
115CFDataRef SOSEngineCreateMessageToSyncToPeer(SOSEngineRef engine, CFStringRef peerID, SOSEnginePeerMessageSentBlock *sentBlock, CFErrorRef *error);
116
117CFStringRef SOSEngineGetMyID(SOSEngineRef engine);
118bool SOSEnginePeerDidConnect(SOSEngineRef engine, CFStringRef peerID, CFErrorRef *error);
119bool SOSEngineSetPeerConfirmedManifest(SOSEngineRef engine, CFStringRef backupName,
120 CFDataRef keybagDigest, CFDataRef manifestData, CFErrorRef *error);
121CFArrayRef SOSEngineCopyBackupPeerNames(SOSEngineRef engine, CFErrorRef *error);
122
123void logRawMessage(CFDataRef message, bool sending, uint64_t seqno);
124
125// TODO: TEMPORARY: Get the list of IDs for cleanup, this shouldn't be used instead transport should iterate KVS.
126CFArrayRef SOSEngineGetPeerIDs(SOSEngineRef engine);
127
128CFArrayRef SOSEngineCopyPeerConfirmedDigests(SOSEngineRef engine, CFErrorRef *error);
129
130// Private do not use!
131SOSDataSourceRef SOSEngineGetDataSource(SOSEngineRef engine);
fa7225c8 132bool SOSTestEngineSaveWithDER(SOSEngineRef engine, CFDataRef derState, CFErrorRef *error);
5c19dc3a
A
133
134// MARK: Sync completion notification registration
135
fa7225c8
A
136typedef void (^SOSEnginePeerInSyncBlock)(CFStringRef peerID, CFSetRef views);
137void SOSEngineSetSyncCompleteListener(SOSEngineRef engine, SOSEnginePeerInSyncBlock notify_block);
5c19dc3a
A
138void SOSEngineSetSyncCompleteListenerQueue(SOSEngineRef engine, dispatch_queue_t notify_queue);
139
fa7225c8
A
140// Engine State by Log
141void SOSEngineLogState(SOSEngineRef engine);
5c19dc3a
A
142
143__END_DECLS
144
145#endif /* !_SEC_SOSENGINE_H_ */