5 // Created by Richard Murphy on 1/28/15.
9 #ifndef _sec_SOSRingUtils_
10 #define _sec_SOSRingUtils_
12 #include <CoreFoundation/CFRuntime.h>
13 #include <CoreFoundation/CoreFoundation.h>
14 #include <utilities/SecCFWrappers.h>
15 #include "keychain/SecureObjectSync/SOSGenCount.h"
18 #define ALLOCATOR NULL
21 struct __OpaqueSOSRing
{
23 CFMutableDictionaryRef unSignedInformation
;
24 CFMutableDictionaryRef signedInformation
;
25 CFMutableDictionaryRef signatures
; // Signatures keyed by peerid
26 CFMutableDictionaryRef data
; // Anything for ring-specific rule support
30 void SOSRingAssertStable(SOSRingRef ring
)
33 assert(ring
->unSignedInformation
);
34 assert(ring
->signedInformation
);
35 assert(ring
->signatures
);
40 bool SOSRingIsStable(SOSRingRef ring
) {
41 return (ring
) && (ring
->unSignedInformation
) && (ring
->signedInformation
) && (ring
->signatures
)&& (ring
->data
);
44 /* unSignedInformation Dictionary Keys */
45 extern CFStringRef sApplicantsKey
;
46 extern CFStringRef sRejectionsKey
;
47 extern CFStringRef sRetiredKey
;
48 extern CFStringRef sLastPeerToModifyKey
;
50 /* signedInformation Dictionary Keys */
51 extern CFStringRef sNameKey
;
52 extern CFStringRef sVersion
;
53 extern CFStringRef sTypeKey
;
54 extern CFStringRef sIdentifierKey
;
55 extern CFStringRef sGenerationKey
;
56 extern CFStringRef sPeerIDsKey
;
57 extern CFStringRef sRingVersionKey
;
59 CF_RETURNS_RETAINED SOSRingRef
SOSRingAllocate(void);
60 SOSRingRef
SOSRingCreate_Internal(CFStringRef name
, SOSRingType type
, CFErrorRef
*error
);
61 SOSRingRef
SOSRingCopyRing(SOSRingRef original
, CFErrorRef
*error
);
63 bool SOSRingRemoveSignatures(SOSRingRef ring
, CFErrorRef
*error
);
64 bool SOSRingVerifySignatureExists(SOSRingRef ring
, SecKeyRef pubKey
, CFErrorRef
*error
);
65 bool SOSRingVerify(SOSRingRef ring
, SecKeyRef pubKey
, CFErrorRef
*error
);
66 bool SOSRingVerifyPeerSigned(SOSRingRef ring
, SOSPeerInfoRef peer
, CFErrorRef
*error
);
67 bool SOSRingGenerationSign_Internal(SOSRingRef ring
, SecKeyRef privKey
, CFErrorRef
*error
);
68 bool SOSRingConcordanceSign_Internal(SOSRingRef ring
, SecKeyRef privKey
, CFErrorRef
*error
);
69 SOSConcordanceStatus
GetSignersStatus(CFSetRef peers
, SOSRingRef signersRing
, SOSRingRef statusRing
,
70 SecKeyRef userPubkey
, CFStringRef excludePeerID
, CFErrorRef
*error
);
71 SOSConcordanceStatus
GetSignersStatus_Transitive(CFSetRef peers
, SOSRingRef signersRing
, SOSRingRef statusRing
,
72 SecKeyRef userPubkey
, CFStringRef excludePeerID
, CFErrorRef
*error
);
73 SOSConcordanceStatus
SOSRingUserKeyConcordanceTrust(SOSFullPeerInfoRef me
, CFSetRef peers
, SOSRingRef knownRing
, SOSRingRef proposedRing
,
74 SecKeyRef knownPubkey
, SecKeyRef userPubkey
,
75 CFStringRef excludePeerID
, CFErrorRef
*error
);
76 SOSConcordanceStatus
SOSRingPeerKeyConcordanceTrust(SOSFullPeerInfoRef me
, CFSetRef peers
, SOSRingRef knownRing
, SOSRingRef proposedRing
,
77 __unused SecKeyRef knownPubkey
, SecKeyRef userPubkey
,
78 CFStringRef excludePeerID
, CFErrorRef
*error
);
80 bool SOSRingHasPeerWithID(SOSRingRef ring
, CFStringRef peerid
, CFErrorRef
*error
);
82 int SOSRingCountPeers(SOSRingRef ring
);
83 CFStringRef
SOSRingCopySignerList(SOSRingRef ring
);
84 CFDictionaryRef
SOSRingCopyPeerIDList(SOSRingRef ring
);
87 int SOSRingCountApplicants(SOSRingRef ring
);
88 bool SOSRingHasApplicant(SOSRingRef ring
, CFStringRef peerID
);
89 CFMutableSetRef
SOSRingCopyApplicants(SOSRingRef ring
);
91 int SOSRingCountRejections(SOSRingRef ring
);
92 bool SOSRingHasRejection(SOSRingRef ring
, CFStringRef peerID
);
93 CFMutableSetRef
SOSRingCopyRejections(SOSRingRef ring
);
94 bool SOSRingHasPeerWithID(SOSRingRef ring
, CFStringRef peerid
, CFErrorRef
*error
);
96 // Use this to determine whether a ring your interogating is the "same one" that you think you're going to change.
97 bool SOSRingIsSame(SOSRingRef ring1
, SOSRingRef ring2
);
99 const char *SOSRingGetNameC(SOSRingRef ring
);
101 void SOSRingGenerationIncrement(SOSRingRef ring
);
102 bool SOSRingIsOlderGeneration(SOSRingRef olderRing
, SOSRingRef newerRing
);
103 void SOSRingGenerationCreateWithBaseline(SOSRingRef newring
, SOSRingRef baseline
);
105 bool SOSRingSetApplicants(SOSRingRef ring
, CFMutableSetRef applicants
);
107 bool SOSRingSetLastModifier(SOSRingRef ring
, CFStringRef peerID
);
109 bool SOSRingResetToEmpty_Internal(SOSRingRef ring
, CFErrorRef
*error
);
110 bool SOSRingIsEmpty_Internal(SOSRingRef ring
);
111 bool SOSRingIsOffering_Internal(SOSRingRef ring
);
114 bool SOSRingAddApplicant(SOSRingRef ring
, CFStringRef peerid
);
115 bool SOSRingRemoveApplicant(SOSRingRef ring
, CFStringRef peerid
);
117 bool SOSRingAddRejection(SOSRingRef ring
, CFStringRef peerid
);
118 bool SOSRingRemoveRejection(SOSRingRef ring
, CFStringRef peerid
);
119 CFDataRef
SOSRingGetPayload_Internal(SOSRingRef ring
);
120 bool SOSRingSetPayload_Internal(SOSRingRef ring
, CFDataRef payload
);
121 CFSetRef
SOSRingGetBackupViewset_Internal(SOSRingRef ring
);
122 bool SOSRingSetBackupViewset_Internal(SOSRingRef ring
, CFSetRef viewSet
);
123 bool SOSRingSetPeerIDs(SOSRingRef ring
, CFMutableSetRef peers
);
124 int SOSRingCountPeerIDs(SOSRingRef ring
);
125 bool SOSRingHasPeerID(SOSRingRef ring
, CFStringRef peerID
);
126 CFMutableSetRef
SOSRingCopyPeerIDs(SOSRingRef ring
);
127 void SOSRingAddAll(SOSRingRef ring
, CFSetRef peerInfosOrIDs
);
128 bool SOSRingAddPeerID(SOSRingRef ring
, CFStringRef peerid
);
129 bool SOSRingRemovePeerID(SOSRingRef ring
, CFStringRef peerid
);
130 void SOSRingForEachPeerID(SOSRingRef ring
, void (^action
)(CFStringRef peerID
));
132 size_t SOSRingGetDEREncodedSize(SOSRingRef ring
, CFErrorRef
*error
);
133 uint8_t* SOSRingEncodeToDER(SOSRingRef ring
, CFErrorRef
* error
, const uint8_t* der
, uint8_t* der_end
);
134 SOSRingRef
SOSRingCreateFromDER(CFErrorRef
* error
, const uint8_t** der_p
, const uint8_t *der_end
);
136 CFDictionaryRef
SOSRingCreateRetirementTicket(SOSFullPeerInfoRef fpi
, CFErrorRef
*error
);
138 #endif /* defined(_sec_SOSRingUtils_) */