]> git.saurik.com Git - apple/security.git/blob - OSX/sec/ProjectHeaders/Security/SecureObjectSync/SOSRingUtils.h
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / sec / ProjectHeaders / Security / SecureObjectSync / SOSRingUtils.h
1 //
2 // SOSRingUtils.h
3 // sec
4 //
5 // Created by Richard Murphy on 1/28/15.
6 //
7 //
8
9 #ifndef _sec_SOSRingUtils_
10 #define _sec_SOSRingUtils_
11
12 #include <CoreFoundation/CFRuntime.h>
13 #include <CoreFoundation/CoreFoundation.h>
14 #include <utilities/SecCFWrappers.h>
15 #include <Security/SecureObjectSync/SOSGenCount.h>
16 #include "SOSRing.h"
17
18 #define ALLOCATOR NULL
19
20
21 struct __OpaqueSOSRing {
22 CFRuntimeBase _base;
23 CFMutableDictionaryRef unSignedInformation;
24 CFMutableDictionaryRef signedInformation;
25 CFMutableDictionaryRef signatures; // Signatures keyed by peerid
26 CFMutableDictionaryRef data; // Anything for ring-specific rule support
27 };
28
29 static inline
30 void SOSRingAssertStable(SOSRingRef ring)
31 {
32 assert(ring);
33 assert(ring->unSignedInformation);
34 assert(ring->signedInformation);
35 assert(ring->signatures);
36 assert(ring->data);
37 }
38
39 /* unSignedInformation Dictionary Keys */
40 extern CFStringRef sApplicantsKey;
41 extern CFStringRef sRejectionsKey;
42 extern CFStringRef sRetiredKey;
43 extern CFStringRef sLastPeerToModifyKey;
44
45 /* signedInformation Dictionary Keys */
46 extern CFStringRef sNameKey;
47 extern CFStringRef sVersion;
48 extern CFStringRef sTypeKey;
49 extern CFStringRef sIdentifierKey;
50 extern CFStringRef sGenerationKey;
51 extern CFStringRef sPeerIDsKey;
52 extern CFStringRef sRingVersionKey;
53
54 SOSRingRef SOSRingAllocate(void);
55 SOSRingRef SOSRingCreate_Internal(CFStringRef name, SOSRingType type, CFErrorRef *error);
56 SOSRingRef SOSRingCopyRing(SOSRingRef original, CFErrorRef *error);
57
58 bool SOSRingVerifySignatureExists(SOSRingRef ring, SecKeyRef pubKey, CFErrorRef *error);
59 bool SOSRingVerify(SOSRingRef ring, SecKeyRef pubKey, CFErrorRef *error);
60 bool SOSRingVerifyPeerSigned(SOSRingRef ring, SOSPeerInfoRef peer, CFErrorRef *error);
61 bool SOSRingGenerationSign_Internal(SOSRingRef ring, SecKeyRef privKey, CFErrorRef *error);
62 bool SOSRingConcordanceSign_Internal(SOSRingRef ring, SecKeyRef privKey, CFErrorRef *error);
63 SOSConcordanceStatus GetSignersStatus(CFSetRef peers, SOSRingRef signersRing, SOSRingRef statusRing,
64 SecKeyRef userPubkey, CFStringRef excludePeerID, CFErrorRef *error);
65 SOSConcordanceStatus GetSignersStatus_Transitive(CFSetRef peers, SOSRingRef signersRing, SOSRingRef statusRing,
66 SecKeyRef userPubkey, CFStringRef excludePeerID, CFErrorRef *error);
67 SOSConcordanceStatus SOSRingUserKeyConcordanceTrust(SOSFullPeerInfoRef me, CFSetRef peers, SOSRingRef knownRing, SOSRingRef proposedRing,
68 SecKeyRef knownPubkey, SecKeyRef userPubkey,
69 CFStringRef excludePeerID, CFErrorRef *error);
70 SOSConcordanceStatus SOSRingPeerKeyConcordanceTrust(SOSFullPeerInfoRef me, CFSetRef peers, SOSRingRef knownRing, SOSRingRef proposedRing,
71 __unused SecKeyRef knownPubkey, SecKeyRef userPubkey,
72 CFStringRef excludePeerID, CFErrorRef *error);
73
74 bool SOSRingHasPeerWithID(SOSRingRef ring, CFStringRef peerid, CFErrorRef *error);
75
76 int SOSRingCountPeers(SOSRingRef ring);
77 CFStringRef SOSRingSignerList(SOSRingRef ring);
78 CFDictionaryRef SOSRingPeerIDList(SOSRingRef ring);
79
80
81 int SOSRingCountApplicants(SOSRingRef ring);
82 bool SOSRingHasApplicant(SOSRingRef ring, CFStringRef peerID);
83 CFMutableSetRef SOSRingCopyApplicants(SOSRingRef ring);
84
85 int SOSRingCountRejections(SOSRingRef ring);
86 bool SOSRingHasRejection(SOSRingRef ring, CFStringRef peerID);
87 CFMutableSetRef SOSRingCopyRejections(SOSRingRef ring);
88 bool SOSRingHasPeerWithID(SOSRingRef ring, CFStringRef peerid, CFErrorRef *error);
89
90 // Use this to determine whether a ring your interogating is the "same one" that you think you're going to change.
91 bool SOSRingIsSame(SOSRingRef ring1, SOSRingRef ring2);
92
93 const char *SOSRingGetNameC(SOSRingRef ring);
94
95 void SOSRingGenerationIncrement(SOSRingRef ring);
96 bool SOSRingIsOlderGeneration(SOSRingRef olderRing, SOSRingRef newerRing);
97
98 bool SOSRingSetApplicants(SOSRingRef ring, CFMutableSetRef applicants);
99
100 bool SOSRingSetLastModifier(SOSRingRef ring, CFStringRef peerID);
101
102 bool SOSRingResetToEmpty_Internal(SOSRingRef ring, CFErrorRef *error);
103 bool SOSRingIsEmpty_Internal(SOSRingRef ring);
104 bool SOSRingIsOffering_Internal(SOSRingRef ring);
105
106
107 bool SOSRingAddApplicant(SOSRingRef ring, CFStringRef peerid);
108 bool SOSRingRemoveApplicant(SOSRingRef ring, CFStringRef peerid);
109
110 bool SOSRingAddRejection(SOSRingRef ring, CFStringRef peerid);
111 bool SOSRingRemoveRejection(SOSRingRef ring, CFStringRef peerid);
112 CFDataRef SOSRingGetPayload_Internal(SOSRingRef ring);
113 bool SOSRingSetPayload_Internal(SOSRingRef ring, CFDataRef payload);
114 CFSetRef SOSRingGetBackupViewset_Internal(SOSRingRef ring);
115 bool SOSRingSetBackupViewset_Internal(SOSRingRef ring, CFSetRef viewSet);
116 bool SOSRingSetPeerIDs(SOSRingRef ring, CFMutableSetRef peers);
117 int SOSRingCountPeerIDs(SOSRingRef ring);
118 bool SOSRingHasPeerID(SOSRingRef ring, CFStringRef peerID);
119 CFMutableSetRef SOSRingCopyPeerIDs(SOSRingRef ring);
120 void SOSRingAddAll(SOSRingRef ring, CFSetRef peerInfosOrIDs);
121 bool SOSRingAddPeerID(SOSRingRef ring, CFStringRef peerid);
122 bool SOSRingRemovePeerID(SOSRingRef ring, CFStringRef peerid);
123 void SOSRingForEachPeerID(SOSRingRef ring, void (^action)(CFStringRef peerID));
124
125 size_t SOSRingGetDEREncodedSize(SOSRingRef ring, CFErrorRef *error);
126 uint8_t* SOSRingEncodeToDER(SOSRingRef ring, CFErrorRef* error, const uint8_t* der, uint8_t* der_end);
127 SOSRingRef SOSRingCreateFromDER(CFErrorRef* error, const uint8_t** der_p, const uint8_t *der_end);
128
129 CFDictionaryRef SOSRingCreateRetirementTicket(SOSFullPeerInfoRef fpi, CFErrorRef *error);
130
131 #if 0
132 int SOSRingCountActivePeers(SOSCircleRef circle, SOSRingRef ring);
133 int SOSRingCountActiveValidPeers(SOSCircleRef circle, SOSRingRef ring, SecKeyRef pubkey);
134 int SOSRingCountRetiredPeers(SOSCircleRef circle, SOSRingRef ring);
135 void SOSRingForEachPeer(SOSCircleRef circle, SOSRingRef ring, void (^action)(SOSPeerInfoRef peer));
136 void SOSRingForEachRetiredPeer(SOSCircleRef circle, SOSRingRef ring, void (^action)(SOSPeerInfoRef peer));
137 void SOSRingForEachActivePeer(SOSCircleRef circle, SOSRingRef ring, void (^action)(SOSPeerInfoRef peer));
138 void SOSRingForEachActiveValidPeer(SOSCircleRef circle, SOSRingRef ring, SecKeyRef user_public_key, void (^action)(SOSPeerInfoRef peer));
139 SOSPeerInfoRef SOSRingCopyPeerWithID(SOSCircleRef circle, SOSRingRef ring, CFStringRef peerid, CFErrorRef *error);
140 bool SOSRingHasActivePeerWithID(SOSCircleRef circle, SOSRingRef ring, CFStringRef peerid, CFErrorRef *error);
141 bool SOSRingHasActiveValidPeerWithID(SOSCircleRef circle, SOSRingRef ring, CFStringRef peerid, SecKeyRef user_public_key, CFErrorRef *error);
142 void SOSRingForEachApplicant(SOSCircleRef circle, SOSRingRef ring, void (^action)(SOSPeerInfoRef peer));
143 bool SOSRingResetToOffering_Internal(SOSCircleRef circle, SOSRingRef ring, SecKeyRef user_privkey, SOSFullPeerInfoRef requestor, CFErrorRef *error);
144 #endif
145
146 #endif /* defined(_sec_SOSRingUtils_) */