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