2 // secd-58-password-change.c
5 // Created by Mitch Adler on 6/18/13.
11 #include <Security/SecBase.h>
12 #include <Security/SecItem.h>
14 #include <CoreFoundation/CFDictionary.h>
16 #include <SecureObjectSync/SOSAccount.h>
17 #include <SecureObjectSync/SOSCloudCircle.h>
18 #include <SecureObjectSync/SOSInternal.h>
19 #include <SecureObjectSync/SOSUserKeygen.h>
24 #include "secd_regressions.h"
25 #include "SOSTestDataSource.h"
27 #include "SOSRegressionUtilities.h"
28 #include <utilities/SecCFWrappers.h>
29 #include <Security/SecKeyPriv.h>
31 #include <securityd/SOSCloudCircleServer.h>
33 #include "SOSAccountTesting.h"
36 static int kTestTestCount
= 300;
38 static bool AssertCreds(SOSAccountRef account
, CFStringRef acct_name
, CFDataRef password
) {
39 CFErrorRef error
= NULL
;
41 ok((retval
= SOSAccountAssertUserCredentials(account
, acct_name
, password
, &error
)), "Credential setting (%@)", error
);
46 static bool ResetToOffering(SOSAccountRef account
) {
47 CFErrorRef error
= NULL
;
49 ok((retval
= SOSAccountResetToOffering(account
, &error
)), "Reset to offering (%@)", error
);
54 static bool JoinCircle(SOSAccountRef account
) {
55 CFErrorRef error
= NULL
;
57 ok((retval
= SOSAccountJoinCircles(account
, &error
)), "Join Circle (%@)", error
);
62 static bool AcceptApplicants(SOSAccountRef account
, CFIndex cnt
) {
63 CFErrorRef error
= NULL
;
65 CFArrayRef applicants
= SOSAccountCopyApplicants(account
, &error
);
67 ok((retval
= (applicants
&& CFArrayGetCount(applicants
) == cnt
)), "See applicants %@ (%@)", applicants
, error
);
68 if(retval
) ok((retval
= SOSAccountAcceptApplicants(account
, applicants
, &error
)), "Accept Applicants (%@)", error
);
69 CFReleaseNull(applicants
);
75 static void tests(void)
77 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
78 CFStringRef cfaccount
= CFSTR("test@test.org");
80 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
82 SOSAccountRef alice_account
= CreateAccountForLocalChanges(changes
, CFSTR("Alice"), CFSTR("TestSource"));
83 SOSAccountRef bob_account
= CreateAccountForLocalChanges(changes
, CFSTR("Bob"), CFSTR("TestSource"));
84 SOSAccountRef carol_account
= CreateAccountForLocalChanges(changes
, CFSTR("Carol"), CFSTR("TestSource"));
86 /* Set Initial Credentials and Parameters for the Syncing Circles ---------------------------------------*/
87 ok(AssertCreds(bob_account
, cfaccount
, cfpassword
), "Setting credentials for Bob");
88 // Bob wins writing at this point, feed the changes back to alice.
89 FeedChangesToMulti(changes
, alice_account
, carol_account
, NULL
);
90 ok(AssertCreds(alice_account
, cfaccount
, cfpassword
), "Setting credentials for Alice");
91 ok(AssertCreds(carol_account
, cfaccount
, cfpassword
), "Setting credentials for Carol");
92 CFReleaseNull(cfpassword
);
94 /* Make Alice First Peer -------------------------------------------------------------------------------*/
95 ok(ResetToOffering(alice_account
), "Reset to offering - Alice as first peer");
96 FeedChangesToMulti(changes
, bob_account
, carol_account
, NULL
);
98 /* Bob Joins -------------------------------------------------------------------------------------------*/
99 ok(JoinCircle(bob_account
), "Bob Applies");
100 FeedChangesToMulti(changes
, alice_account
, carol_account
, NULL
);
102 /* Alice Accepts -------------------------------------------------------------------------------------------*/
103 ok(AcceptApplicants(alice_account
, 1), "Alice Accepts Bob's Application");
104 FeedChangesToMulti(changes
, bob_account
, carol_account
, NULL
); // Bob sees he's accepted
105 FeedChangesToMulti(changes
, alice_account
, carol_account
, NULL
); // Alice sees bob-concurring
106 ok(CFDictionaryGetCount(changes
) == 0, "We converged. (%@)", changes
);
107 accounts_agree("bob&alice pair", bob_account
, alice_account
);
109 /* Carol Applies -------------------------------------------------------------------------------------------*/
110 ok(JoinCircle(carol_account
), "Carol Applies");
111 FeedChangesToMulti(changes
, alice_account
, bob_account
, NULL
);
113 is(countPeers(alice_account
), 2, "See two peers");
116 /* Change Password ------------------------------------------------------------------------------------------*/
117 CFDataRef cfnewpassword
= CFDataCreate(NULL
, (uint8_t *) "ooFooFooF", 10);
119 ok(AssertCreds(bob_account
, cfaccount
, cfnewpassword
), "Credential resetting for Bob");
120 is(countPeers(bob_account
), 2, "There are two valid peers - iCloud and Bob");
121 is(countActivePeers(bob_account
), 3, "There are three active peers - bob, alice, and iCloud");
122 is(countActiveValidPeers(bob_account
), 2, "There is two active valid peer - Bob and iCloud");
123 FeedChangesToMulti(changes
, alice_account
, carol_account
, NULL
);
125 ok(AssertCreds(alice_account
, cfaccount
, cfnewpassword
), "Credential resetting for Alice");
126 is(countPeers(alice_account
), 2, "There are two peers - bob and alice");
127 is(countActiveValidPeers(alice_account
), 3, "There are three active valid peers - alice, bob, and icloud");
128 FeedChangesToMulti(changes
, bob_account
, carol_account
, NULL
);
129 FeedChangesToMulti(changes
, alice_account
, carol_account
, NULL
);
130 FeedChangesToMulti(changes
, alice_account
, bob_account
, NULL
);
131 accounts_agree("bob&alice pair", bob_account
, alice_account
);
132 is(countPeers(alice_account
), 2, "There are two peers - bob and alice");
133 is(countActiveValidPeers(alice_account
), 3, "There are three active valid peers - alice, bob, and icloud");
135 ok(AssertCreds(carol_account
, cfaccount
, cfnewpassword
), "Credential resetting for Carol");
136 FeedChangesToMulti(changes
, alice_account
, bob_account
, NULL
);
137 FeedChangesToMulti(changes
, bob_account
, carol_account
, alice_account
, NULL
);
138 FeedChangesToMulti(changes
, bob_account
, carol_account
, alice_account
, NULL
);
139 FeedChangesToMulti(changes
, bob_account
, carol_account
, alice_account
, NULL
);
140 accounts_agree("bob&alice pair", bob_account
, alice_account
);
142 ok(AcceptApplicants(alice_account
, 1), "Alice Accepts Carol's Application");
143 FeedChangesToMulti(changes
, bob_account
, carol_account
, NULL
); // Carol sees she's accepted
144 FeedChangesToMulti(changes
, alice_account
, bob_account
, carol_account
, NULL
); // Alice sees bob-concurring
145 FeedChangesToMulti(changes
, alice_account
, bob_account
, carol_account
, NULL
); // Alice sees bob-concurring
146 FeedChangesToMulti(changes
, alice_account
, bob_account
, carol_account
, NULL
); // Alice sees bob-concurring
147 accounts_agree_internal("bob&alice pair", bob_account
, alice_account
, false);
148 accounts_agree_internal("bob&carol pair", bob_account
, carol_account
, false);
149 accounts_agree_internal("carol&alice pair", alice_account
, carol_account
, false);
152 /* Change Password 2 ----------------------------------------------------------------------------------------*/
153 CFReleaseNull(cfnewpassword
);
154 cfnewpassword
= CFDataCreate(NULL
, (uint8_t *) "ffoffoffo", 10);
157 ok(AssertCreds(bob_account
, cfaccount
, cfnewpassword
), "Credential resetting for Bob");
158 is(countPeers(bob_account
), 3, "There are three peers - Alice, Carol, Bob");
159 is(countActivePeers(bob_account
), 4, "There are four active peers - bob, alice, carol and iCloud");
160 is(countActiveValidPeers(bob_account
), 2, "There is two active valid peer - Bob and iCloud");
161 FeedChangesToMulti(changes
, alice_account
, carol_account
, NULL
);
164 ok(AssertCreds(alice_account
, cfaccount
, cfnewpassword
), "Credential resetting for Alice");
165 is(countPeers(alice_account
), 3, "There are three peers - Alice, Carol, Bob");
166 is(countActivePeers(alice_account
), 4, "There are four active peers - bob, alice, carol and iCloud");
167 is(countActiveValidPeers(alice_account
), 3, "There are three active valid peers - alice, bob, and icloud");
168 FeedChangesToMulti(changes
, bob_account
, carol_account
, NULL
);
169 FeedChangesToMulti(changes
, alice_account
, bob_account
, carol_account
, NULL
);
170 FeedChangesToMulti(changes
, alice_account
, bob_account
, carol_account
, NULL
);
173 ok(AssertCreds(carol_account
, cfaccount
, cfnewpassword
), "Credential resetting for Carol");
174 is(countPeers(carol_account
), 3, "There are three peers - Alice, Carol, Bob");
175 is(countActivePeers(carol_account
), 4, "There are four active peers - bob, alice, carol and iCloud");
176 is(countActiveValidPeers(carol_account
), 4, "There are three active valid peers - alice, bob, carol, and icloud");
178 FeedChangesToMulti(changes
, alice_account
, bob_account
, NULL
);
179 FeedChangesToMulti(changes
, bob_account
, carol_account
, alice_account
, NULL
);
180 FeedChangesToMulti(changes
, bob_account
, carol_account
, alice_account
, NULL
);
181 FeedChangesToMulti(changes
, bob_account
, carol_account
, alice_account
, NULL
);
182 accounts_agree_internal("bob&alice pair", bob_account
, alice_account
, false);
184 CFReleaseNull(bob_account
);
185 CFReleaseNull(alice_account
);
186 CFReleaseNull(carol_account
);
187 CFReleaseNull(cfnewpassword
);
191 int secd_58_password_change(int argc
, char *const *argv
)
193 plan_tests(kTestTestCount
);