]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/SecureObjectSync/SOSRingUtils.h
Security-57337.40.85.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / 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 SOSRingCopySignerList(SOSRingRef ring);
78 CFDictionaryRef SOSRingCopyPeerIDList(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 void SOSRingGenerationCreateWithBaseline(SOSRingRef newring, SOSRingRef baseline);
98
99 bool SOSRingSetApplicants(SOSRingRef ring, CFMutableSetRef applicants);
100
101 bool SOSRingSetLastModifier(SOSRingRef ring, CFStringRef peerID);
102
103 bool SOSRingResetToEmpty_Internal(SOSRingRef ring, CFErrorRef *error);
104 bool SOSRingIsEmpty_Internal(SOSRingRef ring);
105 bool SOSRingIsOffering_Internal(SOSRingRef ring);
106
107
108 bool SOSRingAddApplicant(SOSRingRef ring, CFStringRef peerid);
109 bool SOSRingRemoveApplicant(SOSRingRef ring, CFStringRef peerid);
110
111 bool SOSRingAddRejection(SOSRingRef ring, CFStringRef peerid);
112 bool SOSRingRemoveRejection(SOSRingRef ring, CFStringRef peerid);
113 CFDataRef SOSRingGetPayload_Internal(SOSRingRef ring);
114 bool SOSRingSetPayload_Internal(SOSRingRef ring, CFDataRef payload);
115 CFSetRef SOSRingGetBackupViewset_Internal(SOSRingRef ring);
116 bool SOSRingSetBackupViewset_Internal(SOSRingRef ring, CFSetRef viewSet);
117 bool SOSRingSetPeerIDs(SOSRingRef ring, CFMutableSetRef peers);
118 int SOSRingCountPeerIDs(SOSRingRef ring);
119 bool SOSRingHasPeerID(SOSRingRef ring, CFStringRef peerID);
120 CFMutableSetRef SOSRingCopyPeerIDs(SOSRingRef ring);
121 void SOSRingAddAll(SOSRingRef ring, CFSetRef peerInfosOrIDs);
122 bool SOSRingAddPeerID(SOSRingRef ring, CFStringRef peerid);
123 bool SOSRingRemovePeerID(SOSRingRef ring, CFStringRef peerid);
124 void SOSRingForEachPeerID(SOSRingRef ring, void (^action)(CFStringRef peerID));
125
126 size_t SOSRingGetDEREncodedSize(SOSRingRef ring, CFErrorRef *error);
127 uint8_t* SOSRingEncodeToDER(SOSRingRef ring, CFErrorRef* error, const uint8_t* der, uint8_t* der_end);
128 SOSRingRef SOSRingCreateFromDER(CFErrorRef* error, const uint8_t** der_p, const uint8_t *der_end);
129
130 CFDictionaryRef SOSRingCreateRetirementTicket(SOSFullPeerInfoRef fpi, CFErrorRef *error);
131
132 #if 0
133 int SOSRingCountActivePeers(SOSCircleRef circle, SOSRingRef ring);
134 int SOSRingCountActiveValidPeers(SOSCircleRef circle, SOSRingRef ring, SecKeyRef pubkey);
135 int SOSRingCountRetiredPeers(SOSCircleRef circle, SOSRingRef ring);
136 void SOSRingForEachPeer(SOSCircleRef circle, SOSRingRef ring, void (^action)(SOSPeerInfoRef peer));
137 void SOSRingForEachRetiredPeer(SOSCircleRef circle, SOSRingRef ring, void (^action)(SOSPeerInfoRef peer));
138 void SOSRingForEachActivePeer(SOSCircleRef circle, SOSRingRef ring, void (^action)(SOSPeerInfoRef peer));
139 void SOSRingForEachActiveValidPeer(SOSCircleRef circle, SOSRingRef ring, SecKeyRef user_public_key, void (^action)(SOSPeerInfoRef peer));
140 SOSPeerInfoRef SOSRingCopyPeerWithID(SOSCircleRef circle, SOSRingRef ring, CFStringRef peerid, CFErrorRef *error);
141 bool SOSRingHasActivePeerWithID(SOSCircleRef circle, SOSRingRef ring, CFStringRef peerid, CFErrorRef *error);
142 bool SOSRingHasActiveValidPeerWithID(SOSCircleRef circle, SOSRingRef ring, CFStringRef peerid, SecKeyRef user_public_key, CFErrorRef *error);
143 void SOSRingForEachApplicant(SOSCircleRef circle, SOSRingRef ring, void (^action)(SOSPeerInfoRef peer));
144 bool SOSRingResetToOffering_Internal(SOSCircleRef circle, SOSRingRef ring, SecKeyRef user_privkey, SOSFullPeerInfoRef requestor, CFErrorRef *error);
145 #endif
146
147 #endif /* defined(_sec_SOSRingUtils_) */