]> git.saurik.com Git - apple/security.git/blob - sec/securityd/Regressions/secd-56-account-apply.c
Security-55471.14.8.tar.gz
[apple/security.git] / sec / securityd / Regressions / secd-56-account-apply.c
1 //
2 // sc-60-account-cloud-identity.c
3 // sec
4 //
5 // Created by Mitch Adler on 6/25/13.
6 //
7 //
8
9
10
11 #include <Security/SecBase.h>
12 #include <Security/SecItem.h>
13
14 #include <CoreFoundation/CFDictionary.h>
15
16 #include <SecureObjectSync/SOSAccount.h>
17 #include <SecureObjectSync/SOSCloudCircle.h>
18 #include <SecureObjectSync/SOSInternal.h>
19 #include <SecureObjectSync/SOSUserKeygen.h>
20
21 #include <stdlib.h>
22 #include <unistd.h>
23
24 #include "secd_regressions.h"
25 #include "SOSTestDataSource.h"
26
27 #include "SOSRegressionUtilities.h"
28 #include <utilities/SecCFWrappers.h>
29 #include <Security/SecKeyPriv.h>
30
31 #include <securityd/SOSCloudCircleServer.h>
32
33 #include "SOSAccountTesting.h"
34
35
36 static int kTestTestCount = 97;
37
38 #if 0
39 static int countPeers(SOSAccountRef account, bool active) {
40 CFErrorRef error = NULL;
41 CFArrayRef peers;
42
43 if(active) peers = SOSAccountCopyActivePeers(account, &error);
44 else peers = SOSAccountCopyPeers(account, &error);
45 int retval = (int) CFArrayGetCount(peers);
46 CFReleaseNull(error);
47 CFReleaseNull(peers);
48 return retval;
49 }
50 #endif
51
52 static void tests(void)
53 {
54 CFErrorRef error = NULL;
55 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
56 CFStringRef cfaccount = CFSTR("test@test.org");
57
58 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
59
60 SOSAccountRef alice_account = CreateAccountForLocalChanges(changes, CFSTR("Alice"), CFSTR("TestSource"));
61 SOSAccountRef bob_account = CreateAccountForLocalChanges(changes, CFSTR("Bob"), CFSTR("TestSource"));
62 SOSAccountRef carole_account = CreateAccountForLocalChanges(changes, CFSTR("Carole"), CFSTR("TestSource"));
63 SOSAccountRef david_account = CreateAccountForLocalChanges(changes, CFSTR("David"), CFSTR("TestSource"));
64
65 ok(SOSAccountAssertUserCredentials(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
66
67 // Bob wins writing at this point, feed the changes back to alice.
68
69 FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL);
70
71 ok(SOSAccountAssertUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
72 CFReleaseNull(error);
73
74 ok(SOSAccountAssertUserCredentials(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
75 CFReleaseNull(error);
76
77 ok(SOSAccountAssertUserCredentials(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
78 CFReleaseNull(cfpassword);
79 CFReleaseNull(error);
80
81 ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error);
82 CFReleaseNull(error);
83
84 // Lost Application Scenario
85 FeedChangesToMulti(changes, bob_account, carole_account, NULL);
86
87 ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error);
88 CFReleaseNull(error);
89
90 ok(SOSAccountJoinCircles(carole_account, &error), "Carole Applies too (%@)", error);
91 CFReleaseNull(error);
92
93 FeedChangesToMulti(changes, alice_account, bob_account, NULL);
94 FeedChangesToMulti(changes, alice_account, bob_account, carole_account, NULL);
95
96 accounts_agree("alice and carole agree", alice_account, carole_account);
97 accounts_agree("alice and bob agree", alice_account, bob_account);
98
99 {
100 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
101
102 ok(applicants && CFArrayGetCount(applicants) == 2, "See two applicants %@ (%@)", applicants, error);
103 CFReleaseNull(error);
104 CFReleaseSafe(applicants);
105 }
106
107 FeedChangesToMulti(changes, bob_account, carole_account, NULL);
108 FeedChangesToMulti(changes, bob_account, alice_account, carole_account, NULL);
109 accounts_agree("alice and carole agree", alice_account, carole_account);
110 ok(CFDictionaryGetCount(changes) == 0, "Nothing left to deal with (%@)", changes);
111 CFReleaseNull(error);
112
113 {
114 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
115 ok(applicants && CFArrayGetCount(applicants) == 2, "See two applicants %@ (%@)", applicants, error);
116 ok(SOSAccountRejectApplicants(alice_account, applicants, &error), "Everyone out the pool");
117 CFReleaseNull(error);
118 CFReleaseSafe(applicants);
119 }
120
121 FeedChangesToMulti(changes, bob_account, carole_account, NULL);
122 FeedChangesToMulti(changes, bob_account, alice_account, carole_account, NULL);
123 accounts_agree("alice and carole agree", alice_account, carole_account);
124 ok(CFDictionaryGetCount(changes) == 0, "Nothing left to deal with (%@)", changes);
125
126 {
127 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
128 ok(applicants && CFArrayGetCount(applicants) == 0, "See no applicants %@ (%@)", applicants, error);
129 CFReleaseNull(error);
130 CFReleaseSafe(applicants);
131 }
132
133 ok(SOSAccountJoinCircles(bob_account, &error), "Bob asks again");
134 CFReleaseNull(error);
135 FeedChangesToMulti(changes, bob_account, alice_account, carole_account, NULL);
136 ok(CFDictionaryGetCount(changes) == 0, "Nothing left to deal with (%@)", changes);
137
138 {
139 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
140 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicants %@ (%@)", applicants, error);
141 CFReleaseNull(error);
142 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Accept bob into the fold");
143 CFReleaseNull(error);
144 CFReleaseSafe(applicants);
145 }
146
147 FeedChangesTo(changes, bob_account); // Countersign
148 FeedChangesToMulti(changes, alice_account, bob_account, carole_account, NULL); // Everyone sees the fallout.
149 ok(CFDictionaryGetCount(changes) == 0, "Nothing left to deal with (%@)", changes);
150
151 #if 0
152
153 {
154 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
155
156 ok(applicants && CFArrayGetCount(applicants) == 1, "Bob automatically re-applied %@ (%@)", applicants, error);
157 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error);
158 CFReleaseNull(error);
159 CFReleaseNull(applicants);
160 }
161
162 is(countPeers(alice_account, 0), 3, "Bob is accepted after auto-reapply");
163 FeedChangesToMulti(changes, bob_account, carole_account, david_account, NULL);
164 FeedChangesToMulti(changes, alice_account, bob_account, carole_account, david_account, NULL);
165 FeedChangesToMulti(changes, alice_account, bob_account, carole_account, david_account, NULL);
166 accounts_agree("alice and carole agree after bob gets in", alice_account, carole_account);
167
168 // Rejected Application Scenario
169 ok(SOSAccountJoinCircles(david_account, &error), "Dave Applies (%@)", error);
170 CFReleaseNull(error);
171
172 FeedChangesTo(changes, alice_account);
173 SOSAccountPurgePrivateCredential(alice_account);
174
175 {
176 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
177
178 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
179 ok(SOSAccountRejectApplicants(alice_account, applicants, &error), "Alice rejects (%@)", error);
180 CFReleaseNull(error);
181 CFReleaseNull(applicants);
182 }
183 FeedChangesToMulti(changes, alice_account, bob_account, carole_account, david_account, NULL);
184 FeedChangesToMulti(changes, alice_account, bob_account, carole_account, david_account, NULL);
185 FeedChangesToMulti(changes, alice_account, bob_account, carole_account, david_account, NULL);
186 accounts_agree("alice and carole still agree after david is rejected", alice_account, carole_account);
187 ok(SOSAccountTryUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
188 CFReleaseNull(error);
189
190
191
192
193 FeedChangesToMulti(changes, alice_account, carole_account, NULL); // Everyone sees conurring circle
194
195 ok(CFDictionaryGetCount(changes) == 0, "We converged. (%@)", changes);
196
197 accounts_agree("bob&alice pair", bob_account, alice_account);
198
199 ok(SOSAccountJoinCirclesAfterRestore(carole_account, &error), "Carole cloud identiy joins (%@)", error);
200 CFReleaseNull(error);
201
202 is(countPeers(carole_account, false), 3, "Carole sees 3 valid peers after sliding in");
203
204 FeedChangesTo(changes, bob_account);
205 FeedChangesTo(changes, alice_account);
206 FeedChangesToMulti(changes, bob_account, carole_account, NULL); // Bob and carole see the final result.
207
208 accounts_agree_internal("Carole's in", bob_account, alice_account, false);
209 accounts_agree_internal("Carole's in - 2", bob_account, carole_account, false);
210 #endif
211 CFReleaseNull(bob_account);
212 CFReleaseNull(alice_account);
213 CFReleaseNull(carole_account);
214 }
215
216 int secd_56_account_apply(int argc, char *const *argv)
217 {
218 plan_tests(kTestTestCount);
219
220 tests();
221
222 return 0;
223 }