]> git.saurik.com Git - apple/security.git/blame - OSX/sec/SOSCircle/SecureObjectSync/SOSPeer.h
Security-57740.1.18.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / SecureObjectSync / SOSPeer.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 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.
41typedef CFTypeRef SOSPeerMetaRef;
42
43
44// peerID is not optional everything else is.
45SOSPeerMetaRef 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.
48SOSPeerMetaRef SOSPeerMetaCreateWithState(CFStringRef peerID, CFDictionaryRef state);
49
50CFTypeRef SOSPeerOrStateSetViewsKeyBagAndCreateCopy(CFTypeRef peerOrState, CFSetRef views, CFDataRef keyBag);
51CFTypeRef SOSPeerOrStateSetViewsAndCopyState(CFTypeRef peerOrState, CFSetRef views);
52bool SOSPeerMapEntryIsBackup(const void *mapEntry);
53
54// peerID will always be returned, views, and publicKey might not be.
55CFStringRef SOSPeerMetaGetComponents(SOSPeerMetaRef peerMeta, CFSetRef *views, CFDataRef *keybag, CFErrorRef *error);
56
57
58typedef struct __OpaqueSOSPeer *SOSPeerRef;
59
60CFTypeID SOSPeerGetTypeID(void);
61
62void SOSPeerMarkDigestsInUse(SOSPeerRef peer, struct SOSDigestVector *mdInUse);
63void SOSPeerAddManifestsInUse(SOSPeerRef peer, CFMutableDictionaryRef mfc);
64bool SOSPeerDidReceiveRemovalsAndAdditions(SOSPeerRef peer, SOSManifestRef absentFromRemote, SOSManifestRef additionsFromRemote,
65 SOSManifestRef unwantedFromRemote, SOSManifestRef local, CFErrorRef *error);
66bool SOSPeerDataSourceWillCommit(SOSPeerRef peer, SOSDataSourceTransactionSource source, SOSManifestRef removals, SOSManifestRef additions, CFErrorRef *error);
67bool SOSPeerDataSourceWillChange(SOSPeerRef peer, SOSDataSourceRef dataSource, SOSDataSourceTransactionSource source, CFArrayRef changes, CFErrorRef *error);
68bool SOSPeerWriteAddEvent(FILE *journalFile, keybag_handle_t kbhandle, SOSDataSourceRef dataSource, SOSObjectRef object, CFErrorRef *error);
69
70// Create a peer from an archived state.
71SOSPeerRef SOSPeerCreateWithState(SOSEngineRef engine, CFStringRef peer_id, CFDictionaryRef state, CFErrorRef *error);
72
73// Return encoded peerState dictionary
74CFDictionaryRef SOSPeerCopyState(SOSPeerRef peer, CFErrorRef *error);
75
76// (Re)initialize from a peerState dictionary
77bool SOSPeerSetState(SOSPeerRef peer, SOSEngineRef engine, CFDictionaryRef state, CFErrorRef *error);
78
79//
80//
81//
82
83CFIndex SOSPeerGetVersion(SOSPeerRef peer);
84CFStringRef SOSPeerGetID(SOSPeerRef peer);
85bool SOSPeersEqual(SOSPeerRef peerA, SOSPeerRef peerB);
86
5c19dc3a
A
87uint64_t SOSPeerNextSequenceNumber(SOSPeerRef peer);
88uint64_t SOSPeerGetMessageVersion(SOSPeerRef peer);
89
90//
91// MARK: State tracking helpers
92//
93
94// Return true if the peer needs saving.
95bool SOSPeerDidConnect(SOSPeerRef peer);
96bool SOSPeerMustSendMessage(SOSPeerRef peer);
97void SOSPeerSetMustSendMessage(SOSPeerRef peer, bool must);
98
99bool SOSPeerSendObjects(SOSPeerRef peer);
100void SOSPeerSetSendObjects(SOSPeerRef peer, bool sendObjects);
101
102SOSManifestRef SOSPeerGetProposedManifest(SOSPeerRef peer);
103SOSManifestRef SOSPeerGetConfirmedManifest(SOSPeerRef peer);
104void SOSPeerSetConfirmedManifest(SOSPeerRef peer, SOSManifestRef confirmed);
105void SOSPeerAddProposedManifest(SOSPeerRef peer, SOSManifestRef pending);
106void SOSPeerSetProposedManifest(SOSPeerRef peer, SOSManifestRef pending);
107void SOSPeerAddLocalManifest(SOSPeerRef peer, SOSManifestRef local);
108SOSManifestRef SOSPeerGetPendingObjects(SOSPeerRef peer);
109void SOSPeerSetPendingObjects(SOSPeerRef peer, SOSManifestRef pendingObjects);
110SOSManifestRef SOSPeerGetUnwantedManifest(SOSPeerRef peer);
111void SOSPeerSetUnwantedManifest(SOSPeerRef peer, SOSManifestRef unwantedManifest);
112
113SOSManifestRef SOSPeerCopyManifestForDigest(SOSPeerRef peer, CFDataRef digest);
114
115CFSetRef SOSPeerGetViewNameSet(SOSPeerRef peer);
116void SOSPeerSetViewNameSet(SOSPeerRef peer, CFSetRef views);
117
118CFDataRef SOSPeerGetKeyBag(SOSPeerRef peer);
119void SOSPeerKeyBagDidChange(SOSPeerRef peer);
120void SOSPeerSetKeyBag(SOSPeerRef peer, CFDataRef keyBag);
121// Write a reset event to the journal if mustSendMessage is true.
122bool SOSPeerWritePendingReset(SOSPeerRef peer, CFErrorRef *error);
123
124//
125// MARK: Backup Peers
126//
127
128// TODO: Layer violation -> move to datasource or make schema based
129bool SOSPeerAppendToJournal(SOSPeerRef peer, CFErrorRef *error, void(^with)(FILE *journalFile, keybag_handle_t kbhandle));
130int SOSPeerHandoffFD(SOSPeerRef peer, CFErrorRef *error);
131
132void SOSBackupPeerPostNotification(const char *reason);
133
134__END_DECLS
135
136#endif /* !_SOSPEER_H_ */