]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-50-account.c
Security-57337.50.23.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-50-account.c
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 <Security/SecureObjectSync/SOSAccount.h>
30 #include <Security/SecureObjectSync/SOSCloudCircle.h>
31 #include <Security/SecureObjectSync/SOSInternal.h>
32 #include <Security/SecureObjectSync/SOSUserKeygen.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35
36 #include "secd_regressions.h"
37 #include "SOSTestDataSource.h"
38
39 #include "SOSRegressionUtilities.h"
40 #include <utilities/SecCFWrappers.h>
41
42 #include <securityd/SOSCloudCircleServer.h>
43 #include "SecdTestKeychainUtilities.h"
44 #include "SOSAccountTesting.h"
45
46 static int kTestTestCount = 9 + kSecdTestSetupTestCount;
47 static void tests(void)
48 {
49 CFErrorRef error = NULL;
50 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
51 CFStringRef cfaccount = CFSTR("test@test.org");
52
53 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
54 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
55 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
56
57 SOSAccountRef account = CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
58
59 ok(SOSAccountAssertUserCredentialsAndUpdate(account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
60 CFReleaseNull(error);
61 CFReleaseNull(cfpassword);
62
63 ok(NULL != account, "Created");
64
65 size_t size = SOSAccountGetDEREncodedSize(account, &error);
66 CFReleaseNull(error);
67 uint8_t buffer[size];
68 uint8_t* start = SOSAccountEncodeToDER(account, &error, buffer, buffer + sizeof(buffer));
69 CFReleaseNull(error);
70
71 ok(start, "successful encoding");
72 ok(start == buffer, "Used whole buffer");
73
74 const uint8_t *der = buffer;
75 SOSAccountRef inflated = SOSAccountCreateFromDER(kCFAllocatorDefault, test_factory,
76 &error, &der, buffer + sizeof(buffer));
77
78 SOSAccountEnsureFactoryCirclesTest(inflated, CFSTR("Test Device"));
79 ok(inflated, "inflated");
80 ok(CFEqual(inflated, account), "Compares");
81 CFReleaseNull(inflated);
82
83 CFDictionaryRef new_gestalt = SOSCreatePeerGestaltFromName(CFSTR("New Device"));
84 ok(SOSAccountResetToOffering(account, &error), "Reset to Offering (%@)", error);
85 CFReleaseNull(error);
86 is(SOSAccountGetCircleStatus(account, &error), kSOSCCInCircle, "Was in Circle (%@)", error);
87 CFReleaseNull(error);
88
89 SOSAccountUpdateGestalt(account, new_gestalt);
90
91 is(SOSAccountGetCircleStatus(account, &error), kSOSCCInCircle, "Still in Circle (%@)", error);
92 CFReleaseNull(error);
93
94 CFReleaseNull(new_gestalt);
95 CFReleaseNull(account);
96
97 SOSDataSourceFactoryRelease(test_factory);
98 SOSDataSourceRelease(test_source, NULL);
99
100 SOSUnregisterAllTransportMessages();
101 SOSUnregisterAllTransportCircles();
102 SOSUnregisterAllTransportKeyParameters();
103
104 CFArrayRemoveAllValues(key_transports);
105 CFArrayRemoveAllValues(circle_transports);
106 CFArrayRemoveAllValues(message_transports);
107
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 }