2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
27 #include <Security/SecBase.h>
28 #include <Security/SecItem.h>
30 #include <CoreFoundation/CFDictionary.h>
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>
41 #include "secd_regressions.h"
42 #include "SOSTestDataSource.h"
44 #include "SOSRegressionUtilities.h"
45 #include <utilities/SecCFWrappers.h>
46 #include <Security/SecKeyPriv.h>
48 #include <securityd/SOSCloudCircleServer.h>
50 #include "SOSAccountTesting.h"
52 #include "SecdTestKeychainUtilities.h"
54 static int kTestTestCount
= 215;
56 static bool purgeICloudIdentity(SOSAccountRef account
) {
58 SOSFullPeerInfoRef icfpi
= SOSCircleCopyiCloudFullPeerInfoRef(SOSAccountGetCircle(account
, NULL
), NULL
);
59 if(!icfpi
) return false;
60 retval
= SOSFullPeerInfoPurgePersistentKey(icfpi
, NULL
);
64 static void tests(void)
66 CFErrorRef error
= NULL
;
67 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
68 CFStringRef cfaccount
= CFSTR("test@test.org");
70 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
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"));
76 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
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");
81 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
84 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
86 ok(SOSAccountResetToOffering_wTxn(alice_account
, &error
), "Reset to offering (%@)", error
);
89 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
91 ok(SOSAccountJoinCircles_wTxn(bob_account
, &error
), "Bob Applies (%@)", error
);
93 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
96 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
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
);
104 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 3, "updates");
106 accounts_agree("bob&alice pair", bob_account
, alice_account
);
108 /*----- normal join after restore -----*/
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");
114 is(countApplicants(alice_account
), 0, "See no applicants");
116 is(countPeers(carole_account
), 3, "Carole sees 3 valid peers after sliding in");
118 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
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);
123 ok(SOSAccountLeaveCircle(carole_account
, &error
), "Carol Leaves again");
124 CFReleaseNull(error
);
126 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
128 /*----- join - join after restore -----*/
130 ok(SOSAccountJoinCircles_wTxn(carole_account
, &error
), "Carole normally joins (%@)", error
);
131 CFReleaseNull(error
);
133 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
135 is(countApplicants(alice_account
), 1, "See one applicant");
137 ok(SOSAccountJoinCirclesAfterRestore_wTxn(carole_account
, &error
), "Carole cloud identity joins (%@)", error
);
138 CFReleaseNull(error
);
140 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 4, "updates");
143 is(countApplicants(alice_account
), 0, "See no applicants");
145 is(countPeers(carole_account
), 3, "Carole sees 3 valid peers after sliding in");
147 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
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);
152 /* Break iCloud identity FPI in all peers */
154 ok(purgeICloudIdentity(alice_account
), "remove iCloud private key");
156 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
159 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
160 CFReleaseNull(error
);
162 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 4, "updates");
164 ok(SOSAccountLeaveCircle(carole_account
, &error
), "Carol Leaves again");
165 CFReleaseNull(error
);
167 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
169 /*----- join - join after restore -----*/
171 ok(SOSAccountJoinCircles_wTxn(carole_account
, &error
), "Carole normally joins (%@)", error
);
172 CFReleaseNull(error
);
174 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
176 is(countApplicants(alice_account
), 1, "See one applicant");
178 ok(SOSAccountJoinCirclesAfterRestore_wTxn(carole_account
, &error
), "Carole cloud identity joins (%@)", error
);
179 CFReleaseNull(error
);
181 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 4, "updates");
184 is(countApplicants(alice_account
), 0, "See no applicants");
186 is(countPeers(carole_account
), 3, "Carole sees 3 valid peers after sliding in");
188 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
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);
193 CFReleaseNull(bob_account
);
194 CFReleaseNull(alice_account
);
195 CFReleaseNull(carole_account
);
196 CFReleaseNull(cfpassword
);
198 SOSUnregisterAllTransportMessages();
199 SOSUnregisterAllTransportCircles();
200 SOSUnregisterAllTransportKeyParameters();
201 CFArrayRemoveAllValues(key_transports
);
202 CFArrayRemoveAllValues(circle_transports
);
203 CFArrayRemoveAllValues(message_transports
);
207 int secd_60_account_cloud_identity(int argc
, char *const *argv
)
209 plan_tests(kTestTestCount
);
211 secd_test_setup_temp_keychain(__FUNCTION__
, NULL
);