]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-60-account-cloud-identity.c
Security-57740.60.18.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-60-account-cloud-identity.c
1 /*
2 * Copyright (c) 2013-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/SOSTransport.h>
37
38 #include <stdlib.h>
39 #include <unistd.h>
40
41 #include "secd_regressions.h"
42 #include "SOSTestDataSource.h"
43
44 #include "SOSRegressionUtilities.h"
45 #include <utilities/SecCFWrappers.h>
46 #include <Security/SecKeyPriv.h>
47
48 #include <securityd/SOSCloudCircleServer.h>
49
50 #include "SOSAccountTesting.h"
51
52 #include "SecdTestKeychainUtilities.h"
53
54 static int kTestTestCount = 215;
55
56 static bool purgeICloudIdentity(SOSAccountRef account) {
57 bool retval = false;
58 SOSFullPeerInfoRef icfpi = SOSCircleCopyiCloudFullPeerInfoRef(SOSAccountGetCircle(account, NULL), NULL);
59 if(!icfpi) return false;
60 retval = SOSFullPeerInfoPurgePersistentKey(icfpi, NULL);
61 return retval;
62 }
63
64 static void tests(void)
65 {
66 CFErrorRef error = NULL;
67 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
68 CFStringRef cfaccount = CFSTR("test@test.org");
69
70 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
71
72 SOSAccountRef alice_account = CreateAccountForLocalChanges( CFSTR("Alice"), CFSTR("TestSource"));
73 SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
74 SOSAccountRef carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
75
76 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
77
78 // Bob wins writing at this point, feed the changes back to alice.
79 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates");
80
81 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
82 CFReleaseNull(error);
83
84 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
85 CFReleaseNull(error);
86 ok(SOSAccountResetToOffering_wTxn(alice_account, &error), "Reset to offering (%@)", error);
87 CFReleaseNull(error);
88
89 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
90
91 ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
92 CFReleaseNull(error);
93 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
94
95 {
96 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
97
98 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
99 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error);
100 CFReleaseNull(error);
101 CFReleaseNull(applicants);
102 }
103
104 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 3, "updates");
105
106 accounts_agree("bob&alice pair", bob_account, alice_account);
107
108 /*----- normal join after restore -----*/
109
110 ok(SOSAccountJoinCirclesAfterRestore_wTxn(carole_account, &error), "Carole cloud identity joins (%@)", error);
111 CFReleaseNull(error);
112 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 4, "updates");
113
114 is(countApplicants(alice_account), 0, "See no applicants");
115
116 is(countPeers(carole_account), 3, "Carole sees 3 valid peers after sliding in");
117
118 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates");
119
120 accounts_agree_internal("Carole's in", bob_account, alice_account, false);
121 accounts_agree_internal("Carole's in - 2", bob_account, carole_account, false);
122
123 ok(SOSAccountLeaveCircle(carole_account, &error), "Carol Leaves again");
124 CFReleaseNull(error);
125
126 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
127
128 /*----- join - join after restore -----*/
129
130 ok(SOSAccountJoinCircles_wTxn(carole_account, &error), "Carole normally joins (%@)", error);
131 CFReleaseNull(error);
132
133 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
134
135 is(countApplicants(alice_account), 1, "See one applicant");
136
137 ok(SOSAccountJoinCirclesAfterRestore_wTxn(carole_account, &error), "Carole cloud identity joins (%@)", error);
138 CFReleaseNull(error);
139
140 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 4, "updates");
141
142
143 is(countApplicants(alice_account), 0, "See no applicants");
144
145 is(countPeers(carole_account), 3, "Carole sees 3 valid peers after sliding in");
146
147 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates");
148
149 accounts_agree_internal("Carole's in", bob_account, alice_account, false);
150 accounts_agree_internal("Carole's in - 2", bob_account, carole_account, false);
151
152 /* Break iCloud identity FPI in all peers */
153
154 ok(purgeICloudIdentity(alice_account), "remove iCloud private key");
155
156 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates");
157
158
159 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
160 CFReleaseNull(error);
161
162 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 4, "updates");
163
164 ok(SOSAccountLeaveCircle(carole_account, &error), "Carol Leaves again");
165 CFReleaseNull(error);
166
167 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
168
169 /*----- join - join after restore -----*/
170
171 ok(SOSAccountJoinCircles_wTxn(carole_account, &error), "Carole normally joins (%@)", error);
172 CFReleaseNull(error);
173
174 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
175
176 is(countApplicants(alice_account), 1, "See one applicant");
177
178 ok(SOSAccountJoinCirclesAfterRestore_wTxn(carole_account, &error), "Carole cloud identity joins (%@)", error);
179 CFReleaseNull(error);
180
181 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 4, "updates");
182
183
184 is(countApplicants(alice_account), 0, "See no applicants");
185
186 is(countPeers(carole_account), 3, "Carole sees 3 valid peers after sliding in");
187
188 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates");
189
190 accounts_agree_internal("Carole's in", bob_account, alice_account, false);
191 accounts_agree_internal("Carole's in - 2", bob_account, carole_account, false);
192
193 CFReleaseNull(bob_account);
194 CFReleaseNull(alice_account);
195 CFReleaseNull(carole_account);
196 CFReleaseNull(cfpassword);
197
198 SOSTestCleanup();
199 }
200
201 int secd_60_account_cloud_identity(int argc, char *const *argv)
202 {
203 plan_tests(kTestTestCount);
204
205 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
206
207 tests();
208
209 return 0;
210 }