2 * Copyright (c) 2013-2015 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/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>
42 #include "secd_regressions.h"
43 #include "SOSTestDataSource.h"
45 #include "SOSRegressionUtilities.h"
46 #include <utilities/SecCFWrappers.h>
47 #include <Security/SecKeyPriv.h>
49 #include <securityd/SOSCloudCircleServer.h>
51 #include "SOSAccountTesting.h"
53 #include "SecdTestKeychainUtilities.h"
55 static int kTestTestCount
= 102;
57 static void tests(void)
59 secd_test_setup_temp_keychain("secd_60_account_cloud_identity", NULL
);
61 CFErrorRef error
= NULL
;
62 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
63 CFStringRef cfaccount
= CFSTR("test@test.org");
65 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
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"));
71 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
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");
76 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
79 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
81 CFReleaseNull(cfpassword
);
82 ok(SOSAccountResetToOffering_wTxn(alice_account
, &error
), "Reset to offering (%@)", error
);
85 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
87 ok(SOSAccountJoinCircles_wTxn(bob_account
, &error
), "Bob Applies (%@)", error
);
89 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
92 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
94 ok(applicants
&& CFArrayGetCount(applicants
) == 1, "See one applicant %@ (%@)", applicants
, error
);
95 ok(SOSAccountAcceptApplicants(alice_account
, applicants
, &error
), "Alice accepts (%@)", error
);
97 CFReleaseNull(applicants
);
100 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 3, "updates");
102 accounts_agree("bob&alice pair", bob_account
, alice_account
);
104 ok(SOSAccountJoinCircles_wTxn(carole_account
, &error
), "Carole Applies (%@)", error
);
106 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
108 SOSPeerInfoRef carolePeerInfo
= SOSAccountGetMyPeerInfo(carole_account
);
110 ok(carolePeerInfo
, "got carole's peerinfo");
112 SecKeyRef carolePubKey
= SOSPeerInfoCopyPubKey(carolePeerInfo
, &error
);
114 ok(carolePubKey
, "got carole's pubkey (%@)", error
);
115 CFReleaseNull(error
);
117 CFDataRef pubKeyData
= NULL
;
118 OSStatus stat
= SecKeyCopyPublicBytes(carolePubKey
, &pubKeyData
);
120 ok(stat
== 0, "got carole's pubkey data ");
122 ok(SOSAccountSetHSAPubKeyExpected(bob_account
, pubKeyData
, &error
), "Bob arms to allow Carole to join (%@)", error
);
123 CFReleaseNull(error
);
125 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
127 is(countApplicants(alice_account
), 1, "See one applicant");
129 is(countPeers(carole_account
), 2, "Carole sees 2 valid peers still");
131 SOSAccountClientPing(carole_account
);
133 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 5, "updates");
135 is(countApplicants(alice_account
), 0, "See no applicants");
137 is(countPeers(carole_account
), 3, "Carole sees 3 valid peers");
139 accounts_agree_internal("Carole's in", bob_account
, alice_account
, false);
140 accounts_agree_internal("Carole's in - 2", bob_account
, carole_account
, false);
143 CFReleaseNull(bob_account
);
144 CFReleaseNull(alice_account
);
145 CFReleaseNull(carole_account
);
150 int secd_62_account_hsa_join(int argc
, char *const *argv
)
152 plan_tests(kTestTestCount
);