]> git.saurik.com Git - apple/security.git/blob - sec/securityd/Regressions/secd-50-account.c
Security-55471.14.tar.gz
[apple/security.git] / sec / securityd / Regressions / secd-50-account.c
1 /*
2 * secd_50_account.c
3 *
4 * Created by Mitch Adler on 1/25/121.
5 * Copyright 2012 Apple Inc. All rights reserved.
6 *
7 */
8
9
10 #include <Security/SecBase.h>
11 #include <Security/SecItem.h>
12
13 #include <SecureObjectSync/SOSAccount.h>
14 #include <SecureObjectSync/SOSCloudCircle.h>
15 #include <SecureObjectSync/SOSInternal.h>
16 #include <SecureObjectSync/SOSUserKeygen.h>
17
18 #include <stdlib.h>
19 #include <unistd.h>
20
21 #include "secd_regressions.h"
22 #include "SOSTestDataSource.h"
23
24 #include "SOSRegressionUtilities.h"
25 #include <utilities/SecCFWrappers.h>
26
27 #include <securityd/SOSCloudCircleServer.h>
28
29 #include "SecdTestKeychainUtilities.h"
30
31 static int kTestTestCount = 10 + kSecdTestSetupTestCount;
32 static void tests(void)
33 {
34 secd_test_setup_temp_keychain("secd_50_account", ^{
35 });
36
37 CFErrorRef error = NULL;
38 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
39 CFStringRef cfaccount = CFSTR("test@test.org");
40
41 SOSAccountKeyInterestBlock interest_block = ^(bool getNewKeysOnly, CFArrayRef alwaysKeys, CFArrayRef afterFirstUnlockKeys, CFArrayRef unlockedKeys) {};
42 SOSAccountDataUpdateBlock update_block = ^ bool (CFDictionaryRef keys, CFErrorRef *error) {return true;};
43
44 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
45 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
46 SOSTestDataSourceFactoryAddDataSource(test_factory, CFSTR("TestType"), test_source);
47
48 CFDictionaryRef gestalt = SOSCreatePeerGestaltFromName(CFSTR("Test Device"));
49 SOSAccountRef account = SOSAccountCreate(kCFAllocatorDefault, gestalt, test_factory, interest_block, update_block);
50 ok(SOSAccountAssertUserCredentials(account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
51 CFReleaseNull(error);
52 CFReleaseNull(cfpassword);
53
54 ok(NULL != account, "Created");
55
56 ok(1 == SOSAccountCountCircles(account), "Has one circle");
57
58 size_t size = SOSAccountGetDEREncodedSize(account, &error);
59 CFReleaseNull(error);
60 uint8_t buffer[size];
61 uint8_t* start = SOSAccountEncodeToDER(account, &error, buffer, buffer + sizeof(buffer));
62 CFReleaseNull(error);
63
64 ok(start, "successful encoding");
65 ok(start == buffer, "Used whole buffer");
66
67 const uint8_t *der = buffer;
68 SOSAccountRef inflated = SOSAccountCreateFromDER(kCFAllocatorDefault, test_factory, interest_block, update_block,
69 &error, &der, buffer + sizeof(buffer));
70
71 ok(inflated, "inflated");
72 ok(CFEqual(inflated, account), "Compares");
73
74 CFDictionaryRef new_gestalt = SOSCreatePeerGestaltFromName(CFSTR("New Device"));
75
76 ok(SOSAccountResetToOffering(account, &error), "Reset to Offering (%@)", error);
77 CFReleaseNull(error);
78
79 is(SOSAccountIsInCircles(account, &error), kSOSCCInCircle, "Was in Circle (%@)", error);
80 CFReleaseNull(error);
81
82 SOSAccountUpdateGestalt(account, new_gestalt);
83
84 is(SOSAccountIsInCircles(account, &error), kSOSCCInCircle, "Still in Circle (%@)", error);
85 CFReleaseNull(error);
86
87 CFReleaseNull(gestalt);
88 CFReleaseNull(new_gestalt);
89 CFReleaseNull(account);
90 }
91
92 int secd_50_account(int argc, char *const *argv)
93 {
94 plan_tests(kTestTestCount);
95
96 tests();
97
98 return 0;
99 }