]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-62-account-hsa-join.c
Security-57337.60.2.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-62-account-hsa-join.c
1 /*
2 * Copyright (c) 2013-2015 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/SOSAccountHSAJoin.h>
34 #include <Security/SecureObjectSync/SOSCloudCircle.h>
35 #include <Security/SecureObjectSync/SOSInternal.h>
36 #include <Security/SecureObjectSync/SOSUserKeygen.h>
37 #include <Security/SecureObjectSync/SOSTransport.h>
38
39 #include <stdlib.h>
40 #include <unistd.h>
41
42 #include "secd_regressions.h"
43 #include "SOSTestDataSource.h"
44
45 #include "SOSRegressionUtilities.h"
46 #include <utilities/SecCFWrappers.h>
47 #include <Security/SecKeyPriv.h>
48
49 #include <securityd/SOSCloudCircleServer.h>
50
51 #include "SOSAccountTesting.h"
52
53 #include "SecdTestKeychainUtilities.h"
54
55 static int kTestTestCount = 102;
56
57 static void tests(void)
58 {
59 secd_test_setup_temp_keychain("secd_60_account_cloud_identity", NULL);
60
61 CFErrorRef error = NULL;
62 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
63 CFStringRef cfaccount = CFSTR("test@test.org");
64
65 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
66
67 SOSAccountRef alice_account = CreateAccountForLocalChanges( CFSTR("Alice"), CFSTR("TestSource"));
68 SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
69 SOSAccountRef carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
70
71 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
72
73 // Bob wins writing at this point, feed the changes back to alice.
74 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates");
75
76 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
77 CFReleaseNull(error);
78
79 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
80 CFReleaseNull(error);
81 CFReleaseNull(cfpassword);
82 ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error);
83 CFReleaseNull(error);
84
85 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
86
87 ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error);
88 CFReleaseNull(error);
89 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
90
91 {
92 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
93
94 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
95 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error);
96 CFReleaseNull(error);
97 CFReleaseNull(applicants);
98 }
99
100 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 3, "updates");
101
102 accounts_agree("bob&alice pair", bob_account, alice_account);
103
104 ok(SOSAccountJoinCircles(carole_account, &error), "Carole Applies (%@)", error);
105
106 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates");
107
108 SOSPeerInfoRef carolePeerInfo = SOSAccountGetMyPeerInfo(carole_account);
109
110 ok(carolePeerInfo, "got carole's peerinfo");
111
112 SecKeyRef carolePubKey = SOSPeerInfoCopyPubKey(carolePeerInfo);
113
114 ok(carolePubKey, "got carole's pubkey");
115
116 CFDataRef pubKeyData = NULL;
117 OSStatus stat = SecKeyCopyPublicBytes(carolePubKey, &pubKeyData);
118
119 ok(stat == 0, "got carole's pubkey data ");
120
121 ok(SOSAccountSetHSAPubKeyExpected(bob_account, pubKeyData, &error), "Bob arms to allow Carole to join (%@)", error);
122 CFReleaseNull(error);
123
124 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates");
125
126 is(countApplicants(alice_account), 1, "See one applicant");
127
128 is(countPeers(carole_account), 2, "Carole sees 2 valid peers still");
129
130 SOSAccountClientPing(carole_account);
131
132 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 5, "updates");
133
134 is(countApplicants(alice_account), 0, "See no applicants");
135
136 is(countPeers(carole_account), 3, "Carole sees 3 valid peers");
137
138 accounts_agree_internal("Carole's in", bob_account, alice_account, false);
139 accounts_agree_internal("Carole's in - 2", bob_account, carole_account, false);
140
141
142 CFReleaseNull(bob_account);
143 CFReleaseNull(alice_account);
144 CFReleaseNull(carole_account);
145
146 SOSUnregisterAllTransportMessages();
147 SOSUnregisterAllTransportCircles();
148 SOSUnregisterAllTransportKeyParameters();
149 CFArrayRemoveAllValues(key_transports);
150 CFArrayRemoveAllValues(circle_transports);
151 CFArrayRemoveAllValues(message_transports);
152
153 }
154
155 int secd_62_account_hsa_join(int argc, char *const *argv)
156 {
157 plan_tests(kTestTestCount);
158
159 tests();
160
161 return 0;
162 }