]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-50-account.m
Security-59306.11.20.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-50-account.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 #include <Security/SecBase.h>
27 #include <Security/SecItem.h>
28
29 #include "keychain/SecureObjectSync/SOSAccount.h"
30 #include <Security/SecureObjectSync/SOSCloudCircle.h>
31 #include "keychain/SecureObjectSync/SOSInternal.h"
32 #include "keychain/SecureObjectSync/SOSUserKeygen.h"
33 #include "keychain/SecureObjectSync/SOSAccountTrustClassic.h"
34 #include "keychain/SecureObjectSync/SOSAccountTrustClassic+Circle.h"
35 #include <stdlib.h>
36 #include <unistd.h>
37
38 #include "secd_regressions.h"
39 #include "SOSTestDataSource.h"
40
41 #include "SOSRegressionUtilities.h"
42 #include <utilities/SecCFWrappers.h>
43
44 #include <securityd/SOSCloudCircleServer.h>
45 #include "SecdTestKeychainUtilities.h"
46 #include "SOSAccountTesting.h"
47
48 static int kTestTestCount = 9 + kSecdTestSetupTestCount;
49 static void tests(void)
50 {
51 NSError* error = nil;
52 CFErrorRef cfError = NULL;
53 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
54 CFStringRef cfaccount = CFSTR("test@test.org");
55
56 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
57 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
58 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
59
60 SOSAccount* account = CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
61
62 ok(SOSAccountAssertUserCredentialsAndUpdate(account, cfaccount, cfpassword, &cfError), "Credential setting (%@)", cfError);
63 CFReleaseNull(cfError);
64 CFReleaseNull(cfpassword);
65
66 ok(NULL != account, "Created");
67
68 size_t size = [account.trust getDEREncodedSize:account err:&error];
69
70 error = nil;
71 uint8_t buffer[size];
72
73 uint8_t* start = [account.trust encodeToDER:account err:&error start:buffer end:buffer + sizeof(buffer)];
74 error = nil;
75
76 ok(start, "successful encoding");
77 ok(start == buffer, "Used whole buffer");
78
79 const uint8_t *der = buffer;
80 SOSAccount* inflated = [SOSAccount accountFromDER:&der end:buffer + sizeof(buffer)
81 factory:test_factory error:&error];
82
83 ok(inflated, "inflated %@", error);
84 ok([inflated isEqual:account], "Compares");
85
86 error = nil;
87
88 CFDictionaryRef new_gestalt = SOSCreatePeerGestaltFromName(CFSTR("New Device"));
89 ok(SOSAccountResetToOffering_wTxn(account, &cfError), "Reset to Offering (%@)", error);
90 CFReleaseNull(cfError);
91
92 is([account getCircleStatus:&cfError], kSOSCCInCircle, "Was in Circle (%@)", error);
93 CFReleaseNull(cfError);
94
95 [account.trust updateGestalt:account newGestalt:new_gestalt];
96 is([account getCircleStatus:&cfError], kSOSCCInCircle, "Still in Circle (%@)", error);
97 CFReleaseNull(cfError);
98
99 CFReleaseNull(new_gestalt);
100
101 SOSDataSourceFactoryRelease(test_factory);
102 SOSDataSourceRelease(test_source, NULL);
103
104 account = nil;
105 inflated = nil;
106
107 SOSTestCleanup();
108 }
109
110 int secd_50_account(int argc, char *const *argv)
111 {
112 plan_tests(kTestTestCount);
113
114 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
115
116 tests();
117
118 return 0;
119 }