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 <SecureObjectSync/SOSAccount.h>
33 #include <SecureObjectSync/SOSCloudCircle.h>
34 #include <SecureObjectSync/SOSInternal.h>
35 #include <SecureObjectSync/SOSUserKeygen.h>
36 #include <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 static int kTestTestCount
= 244;
54 static bool AssertCreds(SOSAccountRef account
,CFStringRef acct_name
, CFDataRef password
) {
55 CFErrorRef error
= NULL
;
57 ok((retval
= SOSAccountAssertUserCredentials(account
, acct_name
, password
, &error
)), "Credential setting (%@)", error
);
62 static bool ResetToOffering(SOSAccountRef account
) {
63 CFErrorRef error
= NULL
;
65 ok((retval
= SOSAccountResetToOffering(account
, &error
)), "Reset to offering (%@)", error
);
70 static bool JoinCircle(SOSAccountRef account
) {
71 CFErrorRef error
= NULL
;
73 ok((retval
= SOSAccountJoinCircles(account
, &error
)), "Join Circle (%@)", error
);
78 static bool AcceptApplicants(SOSAccountRef account
, CFIndex cnt
) {
79 CFErrorRef error
= NULL
;
81 CFArrayRef applicants
= SOSAccountCopyApplicants(account
, &error
);
83 ok((retval
= (applicants
&& CFArrayGetCount(applicants
) == cnt
)), "See applicants %@ (%@)", applicants
, error
);
84 if(retval
) ok((retval
= SOSAccountAcceptApplicants(account
, applicants
, &error
)), "Accept Applicants (%@)", error
);
85 CFReleaseNull(applicants
);
90 static void tests(void)
92 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
93 CFStringRef cfaccount
= CFSTR("test@test.org");
95 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
96 SOSAccountRef alice_account
= CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
97 SOSAccountRef bob_account
= CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
98 SOSAccountRef carol_account
= CreateAccountForLocalChanges(CFSTR("Carol"), CFSTR("TestSource"));
100 /* Set Initial Credentials and Parameters for the Syncing Circles ---------------------------------------*/
101 ok(AssertCreds(bob_account
, cfaccount
, cfpassword
), "Setting credentials for Bob");
102 // Bob wins writing at this point, feed the changes back to alice.
104 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 1, "updates");
106 ok(AssertCreds(alice_account
, cfaccount
, cfpassword
), "Setting credentials for Alice");
107 ok(AssertCreds(carol_account
, cfaccount
, cfpassword
), "Setting credentials for Carol");
108 CFReleaseNull(cfpassword
);
110 /* Make Alice First Peer -------------------------------------------------------------------------------*/
111 ok(ResetToOffering(alice_account
), "Reset to offering - Alice as first peer");
113 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 2, "updates");
115 /* Bob Joins -------------------------------------------------------------------------------------------*/
116 ok(JoinCircle(bob_account
), "Bob Applies");
118 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 2, "updates");
120 /* Alice Accepts -------------------------------------------------------------------------------------------*/
121 ok(AcceptApplicants(alice_account
, 1), "Alice Accepts Bob's Application");
123 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 3, "4 updates");
124 accounts_agree("bob&alice pair", bob_account
, alice_account
);
126 /* Carol Applies -------------------------------------------------------------------------------------------*/
127 ok(JoinCircle(carol_account
), "Carol Applies");
129 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 2, "updates");
130 is(countPeers(alice_account
), 2, "See two peers");
133 /* Change Password ------------------------------------------------------------------------------------------*/
134 CFDataRef cfnewpassword
= CFDataCreate(NULL
, (uint8_t *) "ooFooFooF", 10);
136 ok(AssertCreds(bob_account
, cfaccount
, cfnewpassword
), "Credential resetting for Bob");
137 is(countPeers(bob_account
), 2, "There are two valid peers - iCloud and Bob");
138 is(countActivePeers(bob_account
), 3, "There are three active peers - bob, alice, and iCloud");
139 is(countActiveValidPeers(bob_account
), 2, "There is two active valid peer - Bob and iCloud");
141 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 2, "updates");
143 ok(AssertCreds(alice_account
, cfaccount
, cfnewpassword
), "Credential resetting for Alice");
145 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 3, "updates");
147 is(countPeers(alice_account
), 2, "There are two peers - bob and alice");
148 is(countActiveValidPeers(alice_account
), 3, "There are three active valid peers - alice, bob, and icloud");
150 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 1, "updates");
152 accounts_agree("bob&alice pair", bob_account
, alice_account
);
153 is(countPeers(alice_account
), 2, "There are two peers - bob and alice");
154 is(countActiveValidPeers(alice_account
), 3, "There are three active valid peers - alice, bob, and icloud");
156 ok(AssertCreds(carol_account
, cfaccount
, cfnewpassword
), "Credential resetting for Carol");
158 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 1, "updates");
159 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 2, "updates");
161 accounts_agree("bob&alice pair", bob_account
, alice_account
);
162 accounts_agree_internal("bob&carol pair", bob_account
, carol_account
, false);
164 ok(AcceptApplicants(alice_account
, 1), "Alice Accepts Carol's Application");
166 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 4, "updates");
168 accounts_agree_internal("bob&alice pair", bob_account
, alice_account
, false);
169 accounts_agree_internal("bob&carol pair", bob_account
, carol_account
, false);
170 accounts_agree_internal("carol&alice pair", alice_account
, carol_account
, false);
173 /* Change Password 2 ----------------------------------------------------------------------------------------*/
174 CFReleaseNull(cfnewpassword
);
175 cfnewpassword
= CFDataCreate(NULL
, (uint8_t *) "ffoffoffo", 10);
178 ok(AssertCreds(bob_account
, cfaccount
, cfnewpassword
), "Credential resetting for Bob");
179 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 2, "updates");
181 is(countPeers(bob_account
), 3, "There are three peers - Alice, Carol, Bob");
182 is(countActivePeers(bob_account
), 4, "There are four active peers - bob, alice, carol and iCloud");
183 is(countActiveValidPeers(bob_account
), 2, "There is two active valid peer - Bob and iCloud");
187 ok(AssertCreds(alice_account
, cfaccount
, cfnewpassword
), "Credential resetting for Alice");
188 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 3, "updates");
190 is(countPeers(alice_account
), 3, "There are three peers - Alice, Carol, Bob");
191 is(countActivePeers(alice_account
), 4, "There are four active peers - bob, alice, carol and iCloud");
192 is(countActiveValidPeers(alice_account
), 3, "There are three active valid peers - alice, bob, and icloud");
196 ok(AssertCreds(carol_account
, cfaccount
, cfnewpassword
), "Credential resetting for Carol");
197 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carol_account
, NULL
), 4, "updates");
199 is(countPeers(carol_account
), 3, "There are three peers - Alice, Carol, Bob");
200 is(countActivePeers(carol_account
), 4, "There are four active peers - bob, alice, carol and iCloud");
201 is(countActiveValidPeers(carol_account
), 4, "There are three active valid peers - alice, bob, carol, and icloud");
204 accounts_agree_internal("bob&alice pair", bob_account
, alice_account
, false);
206 CFReleaseNull(bob_account
);
207 CFReleaseNull(alice_account
);
208 CFReleaseNull(carol_account
);
209 CFReleaseNull(cfnewpassword
);
211 SOSUnregisterAllTransportMessages();
212 SOSUnregisterAllTransportCircles();
213 SOSUnregisterAllTransportKeyParameters();
214 CFArrayRemoveAllValues(key_transports
);
215 CFArrayRemoveAllValues(circle_transports
);
216 CFArrayRemoveAllValues(message_transports
);
220 int secd_58_password_change(int argc
, char *const *argv
)
222 plan_tests(kTestTestCount
);