]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-55-account-incompatibility.m
Security-58286.200.222.tar.gz
[apple/security.git] / OSX / sec / 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 <Security/SecureObjectSync/SOSAccount.h>
33 #include <Security/SecureObjectSync/SOSCloudCircle.h>
34 #include <Security/SecureObjectSync/SOSInternal.h>
35 #include <Security/SecureObjectSync/SOSUserKeygen.h>
36 #include <Security/SecureObjectSync/SOSKVSKeys.h>
37 #include <Security/SecureObjectSync/SOSTransport.h>
38 #include <Security/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 <securityd/SOSCloudCircleServer.h>
51
52 #include "SOSAccountTesting.h"
53
54 #include "SecdTestKeychainUtilities.h"
55
56 static int kTestTestCount = 10;
57
58 static void tests(void)
59 {
60 CFErrorRef error = NULL;
61 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
62 CFDataRef cfwrong_password = CFDataCreate(NULL, (uint8_t *) "NotFooFooFoo", 10);
63 CFStringRef cfaccount = CFSTR("test@test.org");
64 CFStringRef data_name = CFSTR("TestSource");
65 CFStringRef circle_key_name = SOSCircleKeyCreateWithName(data_name, NULL);
66
67 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
68
69 SOSAccount* alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), data_name);
70 SOSAccount* bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), data_name);
71 SOSAccount* carol_account = CreateAccountForLocalChanges(CFSTR("Carol"), data_name);
72
73 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
74
75 // Bob wins writing at this point, feed the changes back to alice.
76 FillAllChanges(changes);
77 FeedChangesToMulti(changes, alice_account, carol_account, NULL);
78
79 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
80 CFReleaseNull(error);
81 ok(SOSAccountTryUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential trying (%@)", error);
82 CFReleaseNull(error);
83 CFReleaseNull(cfpassword);
84
85 ok(!SOSAccountTryUserCredentials(alice_account, cfaccount, cfwrong_password, &error), "Credential failing (%@)", error);
86 CFReleaseNull(cfwrong_password);
87 is(error ? CFErrorGetCode(error) : 0, kSOSErrorWrongPassword, "Expected SOSErrorWrongPassword");
88 CFReleaseNull(error);
89
90 CFDataRef incompatibleDER = SOSCircleCreateIncompatibleCircleDER(&error);
91
92 InjectChangeToMulti(changes, circle_key_name, incompatibleDER, alice_account, NULL);
93 CFReleaseNull(circle_key_name);
94 CFReleaseNull(incompatibleDER);
95
96 is(ProcessChangesUntilNoChange(changes, alice_account, NULL), 1, "updates");
97
98 CFReleaseNull(changes);
99 alice_account = nil;
100 bob_account = nil;
101 carol_account = nil;
102 SOSTestCleanup();
103 }
104
105 int secd_55_account_incompatibility(int argc, char *const *argv)
106 {
107 plan_tests(kTestTestCount);
108
109 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
110
111 tests();
112
113 return 0;
114 }