2 * Copyright (c) 2012-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 "keychain/SecureObjectSync/SOSAccount.h"
33 #include <Security/SecureObjectSync/SOSCloudCircle.h>
34 #include "keychain/SecureObjectSync/SOSInternal.h"
35 #include "keychain/SecureObjectSync/SOSUserKeygen.h"
36 #include "keychain/SecureObjectSync/SOSKVSKeys.h"
37 #include "keychain/SecureObjectSync/SOSTransport.h"
38 #include "keychain/SecureObjectSync/SOSAccountTrustClassic+Circle.h"
43 #include "secd_regressions.h"
44 #include "SOSTestDataSource.h"
46 #include "SOSRegressionUtilities.h"
47 #include <utilities/SecCFWrappers.h>
48 #include <Security/SecKeyPriv.h>
50 #include "keychain/securityd/SOSCloudCircleServer.h"
52 #include "SOSAccountTesting.h"
54 #include "SecdTestKeychainUtilities.h"
58 static int kTestTestCount = 10;
60 static void tests(void)
62 CFErrorRef error = NULL;
63 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
64 CFDataRef cfwrong_password = CFDataCreate(NULL, (uint8_t *) "NotFooFooFoo", 10);
65 CFStringRef cfaccount = CFSTR("test@test.org");
66 CFStringRef data_name = CFSTR("TestSource");
67 CFStringRef circle_key_name = SOSCircleKeyCreateWithName(data_name, NULL);
69 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
71 SOSAccount* alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), data_name);
72 SOSAccount* bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), data_name);
73 SOSAccount* carol_account = CreateAccountForLocalChanges(CFSTR("Carol"), data_name);
75 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
77 // Bob wins writing at this point, feed the changes back to alice.
78 FillAllChanges(changes);
79 FeedChangesToMulti(changes, alice_account, carol_account, NULL);
81 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
83 ok(SOSAccountTryUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential trying (%@)", error);
85 CFReleaseNull(cfpassword);
87 ok(!SOSAccountTryUserCredentials(alice_account, cfaccount, cfwrong_password, &error), "Credential failing (%@)", error);
88 CFReleaseNull(cfwrong_password);
89 is(error ? CFErrorGetCode(error) : 0, kSOSErrorWrongPassword, "Expected SOSErrorWrongPassword");
92 CFDataRef incompatibleDER = SOSCircleCreateIncompatibleCircleDER(&error);
94 InjectChangeToMulti(changes, circle_key_name, incompatibleDER, alice_account, NULL);
95 CFReleaseNull(circle_key_name);
96 CFReleaseNull(incompatibleDER);
98 is(ProcessChangesUntilNoChange(changes, alice_account, NULL), 1, "updates");
100 CFReleaseNull(changes);
108 int secd_55_account_incompatibility(int argc, char *const *argv)
111 plan_tests(kTestTestCount);
112 secd_test_setup_temp_keychain(__FUNCTION__, NULL);