2 // secd-51-account-inflate.c
5 // Created by Richard Murphy on 7/22/13.
9 #include <Security/SecBase.h>
10 #include <Security/SecItem.h>
12 #include <SecureObjectSync/SOSAccount.h>
13 #include <SecureObjectSync/SOSCloudCircle.h>
14 #include <SecureObjectSync/SOSInternal.h>
15 #include <SecureObjectSync/SOSUserKeygen.h>
20 #include "secd_regressions.h"
21 #include "SOSTestDataSource.h"
23 #include "SOSRegressionUtilities.h"
24 #include <utilities/SecCFWrappers.h>
26 #include <securityd/SOSCloudCircleServer.h>
28 #include "SecdTestKeychainUtilities.h"
30 uint8_t staticbuffer
[439] = {
31 0x30, 0x82, 0x01, 0xB3, 0x31, 0x1D, 0x30, 0x1B, 0x0C, 0x0C, 0x43, 0x6F, 0x6D, 0x70, 0x75, 0x74,
32 0x65, 0x72, 0x4E, 0x61, 0x6D, 0x65, 0x0C, 0x0B, 0x54, 0x65, 0x73, 0x74, 0x20, 0x44, 0x65, 0x76,
33 0x69, 0x63, 0x65, 0x30, 0x82, 0x01, 0x1F, 0x30, 0x82, 0x01, 0x1B, 0x04, 0x1A, 0x30, 0x18, 0x02,
34 0x01, 0x01, 0x0C, 0x08, 0x54, 0x65, 0x73, 0x74, 0x54, 0x79, 0x70, 0x65, 0x02, 0x01, 0x01, 0x30,
35 0x00, 0x30, 0x00, 0x30, 0x00, 0x31, 0x00, 0x04, 0x81, 0xFC, 0x30, 0x81, 0xF9, 0x30, 0x81, 0xE8,
36 0x31, 0x81, 0x9D, 0x30, 0x14, 0x0C, 0x0F, 0x43, 0x6F, 0x6E, 0x66, 0x6C, 0x69, 0x63, 0x74, 0x56,
37 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x02, 0x01, 0x01, 0x30, 0x2E, 0x0C, 0x0D, 0x44, 0x65, 0x76,
38 0x69, 0x63, 0x65, 0x47, 0x65, 0x73, 0x74, 0x61, 0x6C, 0x74, 0x31, 0x1D, 0x30, 0x1B, 0x0C, 0x0C,
39 0x43, 0x6F, 0x6D, 0x70, 0x75, 0x74, 0x65, 0x72, 0x4E, 0x61, 0x6D, 0x65, 0x0C, 0x0B, 0x54, 0x65,
40 0x73, 0x74, 0x20, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x30, 0x55, 0x0C, 0x10, 0x50, 0x75, 0x62,
41 0x6C, 0x69, 0x63, 0x53, 0x69, 0x67, 0x6E, 0x69, 0x6E, 0x67, 0x4B, 0x65, 0x79, 0x04, 0x41, 0x04,
42 0x35, 0xD6, 0x80, 0xF7, 0xB1, 0xC8, 0x83, 0x78, 0x74, 0x27, 0x3B, 0xDD, 0x3C, 0xBB, 0x0E, 0x35,
43 0xA3, 0xAC, 0x6A, 0xC5, 0xD6, 0xB1, 0xC7, 0x17, 0x17, 0xD9, 0xEE, 0x51, 0x34, 0x3F, 0x83, 0x60,
44 0xE0, 0x99, 0xCB, 0xF7, 0x6B, 0xC1, 0x27, 0x34, 0xB8, 0x4B, 0xE9, 0x2F, 0x43, 0xF9, 0x2F, 0x47,
45 0xD3, 0x45, 0x45, 0xEA, 0x01, 0x68, 0x53, 0xAF, 0x99, 0xEE, 0x49, 0xD3, 0xC6, 0x04, 0x56, 0x95,
46 0x04, 0x46, 0x30, 0x44, 0x02, 0x20, 0x79, 0xC9, 0x7A, 0xC9, 0x5D, 0x96, 0x7A, 0x95, 0xCC, 0xD3,
47 0xE5, 0xEC, 0x45, 0x2A, 0x40, 0x06, 0x09, 0x72, 0xFB, 0xBB, 0x20, 0x0E, 0x4A, 0x8E, 0x4A, 0x0B,
48 0x22, 0xF1, 0xA5, 0x38, 0x74, 0x78, 0x02, 0x20, 0x2E, 0xB1, 0x92, 0x3A, 0x8F, 0x42, 0xEC, 0x15,
49 0x87, 0x53, 0x57, 0xCB, 0x70, 0x2E, 0x17, 0x58, 0xA1, 0x12, 0x3E, 0x77, 0xE2, 0xA9, 0x14, 0x82,
50 0x9F, 0xF4, 0x63, 0x4B, 0xB3, 0x0F, 0xEB, 0x55, 0x04, 0x0C, 0x6B, 0x65, 0x79, 0x73, 0x00, 0x00,
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x41, 0x04, 0x1C, 0x1D, 0x2D, 0x00,
52 0x08, 0x30, 0x82, 0x5E, 0x98, 0x84, 0x83, 0x52, 0xEA, 0xA6, 0x65, 0x9B, 0x25, 0x27, 0x1E, 0x40,
53 0xBA, 0x36, 0x0C, 0x73, 0x07, 0xEA, 0x9B, 0x6F, 0xB4, 0x4E, 0x41, 0xD1, 0xF9, 0x49, 0x07, 0x59,
54 0x66, 0x63, 0xEE, 0x41, 0xB1, 0xF0, 0x7F, 0x5F, 0xBA, 0xE5, 0x3C, 0x0A, 0xDE, 0x42, 0xC6, 0x4A,
55 0xEF, 0x6F, 0x10, 0xC5, 0x8C, 0x1B, 0x5C, 0x1B, 0xDA, 0xD4, 0x5C, 0x3B, 0x04, 0x27, 0x30, 0x25,
56 0x04, 0x10, 0x24, 0x1F, 0x16, 0xC5, 0x82, 0xF9, 0xC3, 0xEE, 0x00, 0x09, 0x18, 0xF0, 0xFE, 0x55,
57 0xCC, 0x72, 0x02, 0x03, 0x00, 0xC3, 0x50, 0x02, 0x02, 0x01, 0x00, 0x06, 0x08, 0x2A, 0x86, 0x48,
58 0x86, 0xF7, 0x0D, 0x02, 0x07, 0x31, 0x00
63 static int kTestTestCount
= 11 + kSecdTestSetupTestCount
;
64 static void tests(void)
66 secd_test_setup_temp_keychain("secd_51_account_inflate", ^{
69 CFErrorRef error
= NULL
;
70 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
71 CFStringRef cfaccount
= CFSTR("test@test.org");
73 SOSAccountKeyInterestBlock interest_block
= ^(bool getNewKeysOnly
, CFArrayRef alwaysKeys
, CFArrayRef afterFirstUnlockKeys
, CFArrayRef unlockedKeys
) {};
74 SOSAccountDataUpdateBlock update_block
= ^ bool (CFDictionaryRef keys
, CFErrorRef
*error
) {return true;};
76 SOSDataSourceFactoryRef test_factory
= SOSTestDataSourceFactoryCreate();
77 SOSDataSourceRef test_source
= SOSTestDataSourceCreate();
78 SOSTestDataSourceFactoryAddDataSource(test_factory
, CFSTR("TestType"), test_source
);
80 CFDictionaryRef gestalt
= SOSCreatePeerGestaltFromName(CFSTR("Test Device"));
81 SOSAccountRef account
= SOSAccountCreate(kCFAllocatorDefault
, gestalt
, test_factory
,
82 interest_block
, update_block
);
83 ok(SOSAccountAssertUserCredentials(account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
85 CFReleaseNull(cfpassword
);
87 ok(NULL
!= account
, "Created");
89 ok(1 == SOSAccountCountCircles(account
), "Has one circle");
91 // Use this part with suitable changes to test when we allow account upgrades.
92 size_t size
= SOSAccountGetDEREncodedSize(account
, &error
);
95 uint8_t* start
= SOSAccountEncodeToDER(account
, &error
, buffer
, buffer
+ sizeof(buffer
));
98 ok(start
, "successful encoding");
99 ok(start
== buffer
, "Used whole buffer");
101 const uint8_t *der
= buffer
;
102 SOSAccountRef inflated
= SOSAccountCreateFromDER(kCFAllocatorDefault
, test_factory
, interest_block
, update_block
,
103 &error
, &der
, buffer
+ sizeof(buffer
));
105 ok(inflated
, "inflated");
106 ok(CFEqual(inflated
, account
), "Compares");
108 #if UPGRADE_FROM_PREVIOUS_VERSION
109 CFDictionaryRef new_gestalt
= SOSCreatePeerGestaltFromName(CFSTR("New Device"));
111 ok(SOSAccountResetToOffering(account
, &error
), "Reset to Offering (%@)", error
);
112 CFReleaseNull(error
);
114 is(SOSAccountIsInCircles(account
, &error
), kSOSCCInCircle
, "Was in Circle (%@)", error
);
115 CFReleaseNull(error
);
117 SOSAccountUpdateGestalt(account
, new_gestalt
);
119 is(SOSAccountIsInCircles(account
, &error
), kSOSCCInCircle
, "Still in Circle (%@)", error
);
120 CFReleaseNull(error
);
122 // See if this account inflates:
124 const uint8_t *der2
= staticbuffer
;
125 SOSAccountRef inflated2
= SOSAccountCreateFromDER(kCFAllocatorDefault
, test_factory
, interest_block
, update_block
,
126 &error
, &der2
, staticbuffer
+ sizeof(staticbuffer
));
128 ok(!inflated2
, "inflated2");
130 CFReleaseNull(gestalt
);
131 CFReleaseNull(account
);
134 int secd_51_account_inflate(int argc
, char *const *argv
)
136 plan_tests(kTestTestCount
);