]> git.saurik.com Git - apple/security.git/blob - keychain/securityd/Regressions/secd-55-account-incompatibility.m
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / securityd / Regressions / secd-55-account-incompatibility.m
1 /*
2 * Copyright (c) 2012-2014 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 "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"
39
40 #include <stdlib.h>
41 #include <unistd.h>
42
43 #include "secd_regressions.h"
44 #include "SOSTestDataSource.h"
45
46 #include "SOSRegressionUtilities.h"
47 #include <utilities/SecCFWrappers.h>
48 #include <Security/SecKeyPriv.h>
49
50 #include "keychain/securityd/SOSCloudCircleServer.h"
51
52 #include "SOSAccountTesting.h"
53
54 #include "SecdTestKeychainUtilities.h"
55
56 #if SOS_ENABLED
57
58 static int kTestTestCount = 10;
59
60 static void tests(void)
61 {
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);
68
69 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
70
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);
74
75 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
76
77 // Bob wins writing at this point, feed the changes back to alice.
78 FillAllChanges(changes);
79 FeedChangesToMulti(changes, alice_account, carol_account, NULL);
80
81 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
82 CFReleaseNull(error);
83 ok(SOSAccountTryUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential trying (%@)", error);
84 CFReleaseNull(error);
85 CFReleaseNull(cfpassword);
86
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");
90 CFReleaseNull(error);
91
92 CFDataRef incompatibleDER = SOSCircleCreateIncompatibleCircleDER(&error);
93
94 InjectChangeToMulti(changes, circle_key_name, incompatibleDER, alice_account, NULL);
95 CFReleaseNull(circle_key_name);
96 CFReleaseNull(incompatibleDER);
97
98 is(ProcessChangesUntilNoChange(changes, alice_account, NULL), 1, "updates");
99
100 CFReleaseNull(changes);
101 alice_account = nil;
102 bob_account = nil;
103 carol_account = nil;
104 SOSTestCleanup();
105 }
106 #endif
107
108 int secd_55_account_incompatibility(int argc, char *const *argv)
109 {
110 #if SOS_ENABLED
111 plan_tests(kTestTestCount);
112 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
113 tests();
114 #else
115 plan_tests(0);
116 #endif
117 return 0;
118 }