]> git.saurik.com Git - apple/security.git/blob - keychain/securityd/Regressions/secd-130-other-peer-views.m
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / securityd / Regressions / secd-130-other-peer-views.m
1 //
2 // secd-130-other-peer-views.m
3 // sec
4 //
5 // Created by Mitch Adler on 7/9/16.
6 //
7 //
8
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 #include "secd_regressions.h"
13
14 #include "SOSRegressionUtilities.h"
15 #include <utilities/SecCFWrappers.h>
16 #include <Security/SecKeyPriv.h>
17
18 #include "SecdTestKeychainUtilities.h"
19
20 #include "SOSAccountTesting.h"
21
22 #include "keychain/SecureObjectSync/SOSAccount.h"
23 #if SOS_ENABLED
24
25 #define kAccountPasswordString ((uint8_t*) "FooFooFoo")
26 #define kAccountPasswordStringLen 10
27
28 static void tests(void) {
29 CFErrorRef error = NULL;
30
31 // Unretained aliases.
32 CFDataRef cfpassword = CFDataCreate(NULL, kAccountPasswordString, kAccountPasswordStringLen);
33 CFStringRef cfaccount = CFSTR("test@test.org");
34 CFMutableDictionaryRef cfchanges = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
35 CFSetRef initialSyncViews = SOSViewCopyViewSet(kViewSetInitial);
36 int initialSyncViewCount = (int) CFSetGetCount(initialSyncViews);
37 CFReleaseNull(initialSyncViews);
38
39 SOSAccount* alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
40 SOSAccount* bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
41 SOSAccount* carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
42 SOSAccount* david_account = CreateAccountForLocalChanges(CFSTR("David"), CFSTR("TestSource"));
43
44 CFArrayRef aView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
45 kSOSViewPCSMasterKey,
46 NULL);
47
48 CFArrayRef wifiView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
49 kSOSViewWiFi,
50 NULL);
51
52 CFArrayRef otherView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
53 kSOSViewOtherSyncable,
54 NULL);
55
56 CFArrayRef otherAndWifiViews = CFArrayCreateForCFTypes(kCFAllocatorDefault,
57 kSOSViewWiFi,
58 kSOSViewOtherSyncable,
59 NULL);
60
61 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
62 CFReleaseNull(error);
63
64 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
65
66 // Bob wins writing at this point, feed the changes back to alice.
67 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 1, "updates");
68
69 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
70 CFReleaseNull(error);
71
72 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
73 CFReleaseNull(error);
74
75 ok(SOSAccountAssertUserCredentialsAndUpdate(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
76 CFReleaseNull(cfpassword);
77 CFReleaseNull(error);
78
79 ok(SOSAccountResetToOffering_wTxn(alice_account, &error), "Reset to offering (%@)", error);
80 CFReleaseNull(error);
81
82 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 2, "updates");
83
84 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
85 CFReleaseNull(error);
86
87 ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
88 CFReleaseNull(error);
89
90 ok(SOSAccountJoinCircles_wTxn(carole_account, &error), "Carole Applies too (%@)", error);
91 CFReleaseNull(error);
92
93 ok(SOSAccountJoinCircles_wTxn(david_account, &error), "David Applies too (%@)", error);
94 CFReleaseNull(error);
95
96 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 4, "updates");
97
98 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
99 CFReleaseNull(error);
100
101 {
102 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
103
104 ok(applicants && CFArrayGetCount(applicants) == 3, "See three applicants %@ (%@)", applicants, error);
105 CFReleaseNull(error);
106 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Accept bob into the fold");
107 CFReleaseNull(error);
108 CFReleaseSafe(applicants);
109 }
110
111 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 5, "updates");
112
113 // Make all views work buy finishing initial sync.
114 SOSAccountPeerGotInSync_wTxn(bob_account, alice_account.peerInfo);
115 SOSAccountPeerGotInSync_wTxn(carole_account, alice_account.peerInfo);
116 SOSAccountPeerGotInSync_wTxn(david_account, alice_account.peerInfo);
117
118 int changeCount = (initialSyncViewCount) ? 4 : 1;
119 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), changeCount, "updates");
120
121 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanTrue, "Peer views empty (%@)", error);
122 CFReleaseNull(error);
123
124 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
125 CFReleaseNull(error);
126
127 ok(SOSAccountUpdateView_wTxn(alice_account, kSOSViewWiFi, kSOSCCViewEnable, &error), "Enable view (%@)", error);
128 CFReleaseNull(error);
129
130 ok(SOSAccountUpdateView_wTxn(bob_account, kSOSViewOtherSyncable, kSOSCCViewEnable, &error), "Enable view (%@)", error);
131 CFReleaseNull(error);
132
133 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 3, "updates");
134
135 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Wifi view for Alice (%@)", error);
136 CFReleaseNull(error);
137
138 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherView, &error), kCFBooleanTrue, "other view for Alice (%@)", error);
139 CFReleaseNull(error);
140
141 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Alice (%@)", error);
142 CFReleaseNull(error);
143
144 is(SOSAccountPeersHaveViewsEnabled(bob_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Bob (%@)", error);
145 CFReleaseNull(error);
146
147 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherView, &error), kCFBooleanFalse, "other view for Bob (%@)", error);
148 CFReleaseNull(error);
149
150 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Bob (%@)", error);
151 CFReleaseNull(error);
152
153 is(SOSAccountPeersHaveViewsEnabled(carole_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Carole (%@)", error);
154 CFReleaseNull(error);
155
156 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherView, &error), kCFBooleanTrue, "other view for Carole (%@)", error);
157 CFReleaseNull(error);
158
159 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherAndWifiViews, &error), kCFBooleanTrue, "both for Carole (%@)", error);
160 CFReleaseNull(error);
161
162 CFReleaseNull(aView);
163 CFReleaseNull(wifiView);
164 CFReleaseNull(otherView);
165 CFReleaseNull(otherAndWifiViews);
166
167 SOSTestCleanup();
168 }
169 #endif
170
171 int secd_130_other_peer_views(int argc, char *const *argv)
172 {
173 #if SOS_ENABLED
174 plan_tests(72);
175 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
176 secd_test_clear_testviews();
177 tests();
178 #else
179 plan_tests(0);
180 #endif
181 return 0;
182 }