]> git.saurik.com Git - apple/security.git/blob - Security/sec/securityd/Regressions/secd-55-account-incompatibility.c
Security-57031.1.35.tar.gz
[apple/security.git] / Security / sec / securityd / Regressions / secd-55-account-incompatibility.c
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
27 #include <Security/SecBase.h>
28 #include <Security/SecItem.h>
29
30 #include <CoreFoundation/CFDictionary.h>
31
32 #include <SecureObjectSync/SOSAccount.h>
33 #include <SecureObjectSync/SOSCloudCircle.h>
34 #include <SecureObjectSync/SOSInternal.h>
35 #include <SecureObjectSync/SOSUserKeygen.h>
36 #include <SecureObjectSync/SOSKVSKeys.h>
37 #include <SecureObjectSync/SOSTransport.h>
38
39 #include <stdlib.h>
40 #include <unistd.h>
41
42 #include "secd_regressions.h"
43 #include "SOSTestDataSource.h"
44
45 #include "SOSRegressionUtilities.h"
46 #include <utilities/SecCFWrappers.h>
47 #include <Security/SecKeyPriv.h>
48
49 #include <securityd/SOSCloudCircleServer.h>
50
51 #include "SOSAccountTesting.h"
52
53
54 static int kTestTestCount = 10;
55
56 static void tests(void)
57 {
58 CFErrorRef error = NULL;
59 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
60 CFDataRef cfwrong_password = CFDataCreate(NULL, (uint8_t *) "NotFooFooFoo", 10);
61 CFStringRef cfaccount = CFSTR("test@test.org");
62 CFStringRef data_name = CFSTR("TestSource");
63 CFStringRef circle_key_name = SOSCircleKeyCreateWithName(data_name, NULL);
64
65 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
66
67 SOSAccountRef alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), data_name);
68 SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), data_name);
69 SOSAccountRef carol_account = CreateAccountForLocalChanges(CFSTR("Carol"), data_name);
70
71 ok(SOSAccountAssertUserCredentials(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
72
73 // Bob wins writing at this point, feed the changes back to alice.
74 FillAllChanges(changes);
75 FeedChangesToMulti(changes, alice_account, carol_account, NULL);
76
77 ok(SOSAccountAssertUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
78 CFReleaseNull(error);
79 ok(SOSAccountTryUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential trying (%@)", error);
80 CFReleaseNull(error);
81 CFReleaseNull(cfpassword);
82
83 ok(!SOSAccountTryUserCredentials(alice_account, cfaccount, cfwrong_password, &error), "Credential failing (%@)", error);
84 CFReleaseNull(cfwrong_password);
85 is(error ? CFErrorGetCode(error) : 0, kSOSErrorWrongPassword, "Expected SOSErrorWrongPassword");
86 CFReleaseNull(error);
87
88 CFDataRef incompatibleDER = SOSCircleCreateIncompatibleCircleDER(&error);
89
90 InjectChangeToMulti(changes, circle_key_name, incompatibleDER, alice_account, NULL);
91 CFReleaseNull(circle_key_name);
92 CFReleaseNull(incompatibleDER);
93
94 is(ProcessChangesUntilNoChange(changes, alice_account, NULL), 1, "updates");
95
96 #if 0
97 is(SOSAccountIsInCircles(alice_account, &error), kSOSCCError, "Is in circle");
98 CFReleaseNull(error);
99
100 //#if 0
101 ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error);
102 CFReleaseNull(error);
103 FillChanges(changes, CFSTR("Alice"));
104 FeedChangesTo(changes, bob_account, transport_bob);
105
106 ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error);
107 CFReleaseNull(error);
108
109 FeedChangesTo(changes, alice_account, transport_alice);
110
111 {
112 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
113
114 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
115 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error);
116 CFReleaseNull(error);
117 CFReleaseNull(applicants);
118 }
119
120 FillChanges(changes, CFSTR("Alice"));
121 FeedChangesTo(changes, bob_account, transport_bob); // Bob sees he's accepted
122
123 FillChanges(changes, CFSTR("Bob"));
124 FeedChangesTo(changes, alice_account, transport_alice); // Alice sees bob-concurring
125
126 ok(CFDictionaryGetCount(changes) == 0, "We converged. (%@)", changes);
127
128 FillChanges(changes, CFSTR("Alice"));
129 accounts_agree("bob&alice pair", bob_account, alice_account);
130
131 CFArrayRef peers = SOSAccountCopyPeers(alice_account, &error);
132 ok(peers && CFArrayGetCount(peers) == 2, "See two peers %@ (%@)", peers, error);
133 CFReleaseNull(peers);
134
135 CFDictionaryRef alice_new_gestalt = SOSCreatePeerGestaltFromName(CFSTR("Alice, but different"));
136
137 ok(SOSAccountUpdateGestalt(alice_account, alice_new_gestalt), "Update gestalt %@ (%@)", alice_account, error);
138 CFReleaseNull(alice_new_gestalt);
139
140 FillChanges(changes, CFSTR("Alice"));
141 FeedChangesTo(changes, bob_account, transport_bob); // Bob sees alice change her name.
142
143 FillChanges(changes, CFSTR("Bob"));
144 FeedChangesTo(changes, alice_account, transport_alice); // Alice sees the fallout.
145
146 accounts_agree("Alice's name changed", bob_account, alice_account);
147
148 ok(SOSAccountLeaveCircles(alice_account, &error), "Alice Leaves (%@)", error);
149 CFReleaseNull(error);
150
151 FillChanges(changes, CFSTR("Alice"));
152 FeedChangesTo(changes, bob_account, transport_bob); // Bob sees alice bail.
153
154 FillChanges(changes, CFSTR("Bob"));
155 FeedChangesTo(changes, alice_account), transport_alice; // Alice sees the fallout.
156
157 FillChanges(changes, CFSTR("Alice"));
158 FillChanges(changes, CFSTR("Bob"));
159 accounts_agree("Alice bails", bob_account, alice_account);
160
161 peers = SOSAccountCopyPeers(alice_account, &error);
162 ok(peers && CFArrayGetCount(peers) == 1, "See one peer %@ (%@)", peers, error);
163 CFReleaseNull(peers);
164
165 ok(SOSAccountJoinCircles(alice_account, &error), "Alice re-applies (%@)", error);
166 CFReleaseNull(error);
167
168 FillChanges(changes, CFSTR("Alice"));
169 FeedChangesTo(changes, bob_account, transport_bob);
170
171
172 {
173 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
174
175 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
176 ok(SOSAccountAcceptApplicants(bob_account, applicants, &error), "Bob accepts (%@)", error);
177 CFReleaseNull(error);
178 CFReleaseNull(applicants);
179 }
180
181 FillChanges(changes, CFSTR("Bob"));
182 FeedChangesTo(changes, alice_account, transport_alice); // Alice sees bob accepting
183
184 FillChanges(changes, CFSTR("Alice"));
185 FeedChangesTo(changes, bob_account, transport_bob); // Bob sees Alice concurring
186
187 accounts_agree("Alice accepts' Bob", bob_account, alice_account);
188
189 ok(SOSAccountLeaveCircles(alice_account, &error), "Alice Leaves (%@)", error);
190 CFReleaseNull(error);
191 ok(SOSAccountJoinCircles(alice_account, &error), "Alice re-applies (%@)", error);
192 CFReleaseNull(error);
193
194 FillChanges(changes, CFSTR("Alice"));
195 FeedChangesTo(changes, bob_account, transport_bob); // Bob sees Alice leaving and rejoining
196 FillChanges(changes, CFSTR("Bob"));
197 FeedChangesTo(changes, alice_account, transport_alice); // Alice sees bob concurring
198
199 {
200 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
201
202 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
203 ok(SOSAccountAcceptApplicants(bob_account, applicants, &error), "Bob accepts (%@)", error);
204 CFReleaseNull(error);
205 CFReleaseNull(applicants);
206 }
207 FillChanges(changes, CFSTR("Bob"));
208 FeedChangesTo(changes, alice_account, transport_alice); // Alice sees bob accepting
209 FillChanges(changes, CFSTR("Alice"));
210 FeedChangesTo(changes, bob_account, transport_bob); // Bob sees Alice concurring
211
212 accounts_agree("Bob accepts Alice", bob_account, alice_account);
213
214
215 CFReleaseNull(alice_new_gestalt);
216 #endif
217
218 CFReleaseNull(bob_account);
219 CFReleaseNull(alice_account);
220 CFReleaseNull(carol_account);
221
222 SOSUnregisterAllTransportMessages();
223 SOSUnregisterAllTransportCircles();
224 SOSUnregisterAllTransportKeyParameters();
225 CFArrayRemoveAllValues(key_transports);
226 CFArrayRemoveAllValues(circle_transports);
227 CFArrayRemoveAllValues(message_transports);
228
229
230 }
231
232 int secd_55_account_incompatibility(int argc, char *const *argv)
233 {
234 plan_tests(kTestTestCount);
235
236 tests();
237
238 return 0;
239 }