2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 #include <Security/SecBase.h>
26 #include <Security/SecItem.h>
28 #include <SecureObjectSync/SOSAccount.h>
29 #include <SecureObjectSync/SOSCloudCircle.h>
30 #include <SecureObjectSync/SOSInternal.h>
31 #include <SecureObjectSync/SOSUserKeygen.h>
36 #include "secd_regressions.h"
37 #include "SOSTestDataSource.h"
39 #include "SOSRegressionUtilities.h"
40 #include <utilities/SecCFWrappers.h>
42 #include <securityd/SOSCloudCircleServer.h>
44 #include "SecdTestKeychainUtilities.h"
45 #include "SOSAccountTesting.h"
46 #include "SOSTransportTestTransports.h"
48 uint8_t staticbuffer
[439] = {
49 0x30, 0x82, 0x01, 0xB3, 0x31, 0x1D, 0x30, 0x1B, 0x0C, 0x0C, 0x43, 0x6F, 0x6D, 0x70, 0x75, 0x74,
50 0x65, 0x72, 0x4E, 0x61, 0x6D, 0x65, 0x0C, 0x0B, 0x54, 0x65, 0x73, 0x74, 0x20, 0x44, 0x65, 0x76,
51 0x69, 0x63, 0x65, 0x30, 0x82, 0x01, 0x1F, 0x30, 0x82, 0x01, 0x1B, 0x04, 0x1A, 0x30, 0x18, 0x02,
52 0x01, 0x01, 0x0C, 0x08, 0x54, 0x65, 0x73, 0x74, 0x54, 0x79, 0x70, 0x65, 0x02, 0x01, 0x01, 0x30,
53 0x00, 0x30, 0x00, 0x30, 0x00, 0x31, 0x00, 0x04, 0x81, 0xFC, 0x30, 0x81, 0xF9, 0x30, 0x81, 0xE8,
54 0x31, 0x81, 0x9D, 0x30, 0x14, 0x0C, 0x0F, 0x43, 0x6F, 0x6E, 0x66, 0x6C, 0x69, 0x63, 0x74, 0x56,
55 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x02, 0x01, 0x01, 0x30, 0x2E, 0x0C, 0x0D, 0x44, 0x65, 0x76,
56 0x69, 0x63, 0x65, 0x47, 0x65, 0x73, 0x74, 0x61, 0x6C, 0x74, 0x31, 0x1D, 0x30, 0x1B, 0x0C, 0x0C,
57 0x43, 0x6F, 0x6D, 0x70, 0x75, 0x74, 0x65, 0x72, 0x4E, 0x61, 0x6D, 0x65, 0x0C, 0x0B, 0x54, 0x65,
58 0x73, 0x74, 0x20, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x30, 0x55, 0x0C, 0x10, 0x50, 0x75, 0x62,
59 0x6C, 0x69, 0x63, 0x53, 0x69, 0x67, 0x6E, 0x69, 0x6E, 0x67, 0x4B, 0x65, 0x79, 0x04, 0x41, 0x04,
60 0x35, 0xD6, 0x80, 0xF7, 0xB1, 0xC8, 0x83, 0x78, 0x74, 0x27, 0x3B, 0xDD, 0x3C, 0xBB, 0x0E, 0x35,
61 0xA3, 0xAC, 0x6A, 0xC5, 0xD6, 0xB1, 0xC7, 0x17, 0x17, 0xD9, 0xEE, 0x51, 0x34, 0x3F, 0x83, 0x60,
62 0xE0, 0x99, 0xCB, 0xF7, 0x6B, 0xC1, 0x27, 0x34, 0xB8, 0x4B, 0xE9, 0x2F, 0x43, 0xF9, 0x2F, 0x47,
63 0xD3, 0x45, 0x45, 0xEA, 0x01, 0x68, 0x53, 0xAF, 0x99, 0xEE, 0x49, 0xD3, 0xC6, 0x04, 0x56, 0x95,
64 0x04, 0x46, 0x30, 0x44, 0x02, 0x20, 0x79, 0xC9, 0x7A, 0xC9, 0x5D, 0x96, 0x7A, 0x95, 0xCC, 0xD3,
65 0xE5, 0xEC, 0x45, 0x2A, 0x40, 0x06, 0x09, 0x72, 0xFB, 0xBB, 0x20, 0x0E, 0x4A, 0x8E, 0x4A, 0x0B,
66 0x22, 0xF1, 0xA5, 0x38, 0x74, 0x78, 0x02, 0x20, 0x2E, 0xB1, 0x92, 0x3A, 0x8F, 0x42, 0xEC, 0x15,
67 0x87, 0x53, 0x57, 0xCB, 0x70, 0x2E, 0x17, 0x58, 0xA1, 0x12, 0x3E, 0x77, 0xE2, 0xA9, 0x14, 0x82,
68 0x9F, 0xF4, 0x63, 0x4B, 0xB3, 0x0F, 0xEB, 0x55, 0x04, 0x0C, 0x6B, 0x65, 0x79, 0x73, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x41, 0x04, 0x1C, 0x1D, 0x2D, 0x00,
70 0x08, 0x30, 0x82, 0x5E, 0x98, 0x84, 0x83, 0x52, 0xEA, 0xA6, 0x65, 0x9B, 0x25, 0x27, 0x1E, 0x40,
71 0xBA, 0x36, 0x0C, 0x73, 0x07, 0xEA, 0x9B, 0x6F, 0xB4, 0x4E, 0x41, 0xD1, 0xF9, 0x49, 0x07, 0x59,
72 0x66, 0x63, 0xEE, 0x41, 0xB1, 0xF0, 0x7F, 0x5F, 0xBA, 0xE5, 0x3C, 0x0A, 0xDE, 0x42, 0xC6, 0x4A,
73 0xEF, 0x6F, 0x10, 0xC5, 0x8C, 0x1B, 0x5C, 0x1B, 0xDA, 0xD4, 0x5C, 0x3B, 0x04, 0x27, 0x30, 0x25,
74 0x04, 0x10, 0x24, 0x1F, 0x16, 0xC5, 0x82, 0xF9, 0xC3, 0xEE, 0x00, 0x09, 0x18, 0xF0, 0xFE, 0x55,
75 0xCC, 0x72, 0x02, 0x03, 0x00, 0xC3, 0x50, 0x02, 0x02, 0x01, 0x00, 0x06, 0x08, 0x2A, 0x86, 0x48,
76 0x86, 0xF7, 0x0D, 0x02, 0x07, 0x31, 0x00
81 static int kTestTestCount
= 7 + kSecdTestSetupTestCount
;
82 static void tests(void)
84 secd_test_setup_temp_keychain("secd_51_account_inflate", ^{
87 CFErrorRef error
= NULL
;
88 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
89 CFStringRef cfaccount
= CFSTR("test@test.org");
91 SOSDataSourceFactoryRef test_factory
= SOSTestDataSourceFactoryCreate();
92 SOSDataSourceRef test_source
= SOSTestDataSourceCreate();
93 SOSTestDataSourceFactoryAddDataSource(test_factory
, CFSTR("TestType"), test_source
);
95 SOSAccountRef account
= CreateAccountForLocalChanges(CFSTR("Test Device"), CFSTR("TestType"));
96 ok(SOSAccountAssertUserCredentials(account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
98 CFReleaseNull(cfpassword
);
100 ok(NULL
!= account
, "Created");
102 ok(1 == SOSAccountCountCircles(account
), "Has one circle");
104 // Use this part with suitable changes to test when we allow account upgrades.
105 size_t size
= SOSAccountGetDEREncodedSize(account
, &error
);
106 CFReleaseNull(error
);
107 uint8_t buffer
[size
];
108 uint8_t* start
= SOSAccountEncodeToDER(account
, &error
, buffer
, buffer
+ sizeof(buffer
));
109 CFReleaseNull(error
);
111 ok(start
, "successful encoding");
112 ok(start
== buffer
, "Used whole buffer");
114 const uint8_t *der
= buffer
;
115 SOSAccountRef inflated
= SOSAccountCreateFromDER(kCFAllocatorDefault
, test_factory
,
116 &error
, &der
, buffer
+ sizeof(buffer
));
118 ok(inflated
, "inflated");
119 ok(CFEqual(inflated
, account
), "Compares");
121 #if UPGRADE_FROM_PREVIOUS_VERSION
122 CFDictionaryRef new_gestalt
= SOSCreatePeerGestaltFromName(CFSTR("New Device"));
124 ok(SOSAccountResetToOffering(account
, &error
), "Reset to Offering (%@)", error
);
125 CFReleaseNull(error
);
127 is(SOSAccountIsInCircles(account
, &error
), kSOSCCInCircle
, "Was in Circle (%@)", error
);
128 CFReleaseNull(error
);
130 SOSAccountUpdateGestalt(account
, new_gestalt
);
132 is(SOSAccountIsInCircles(account
, &error
), kSOSCCInCircle
, "Still in Circle (%@)", error
);
133 CFReleaseNull(error
);
135 // See if this account inflates:
137 const uint8_t *der2
= staticbuffer
;
138 SOSAccountRef inflated2
= SOSAccountCreateFromDER(kCFAllocatorDefault
, test_factory
, interest_block
, update_block
,
139 &error
, &der2
, staticbuffer
+ sizeof(staticbuffer
));
141 ok(!inflated2
, "inflated2");
143 CFReleaseNull(account
);
146 SOSUnregisterAllTransportMessages();
147 SOSUnregisterAllTransportCircles();
148 SOSUnregisterAllTransportKeyParameters();
149 CFArrayRemoveAllValues(key_transports
);
150 CFArrayRemoveAllValues(circle_transports
);
151 CFArrayRemoveAllValues(message_transports
);
156 int secd_51_account_inflate(int argc
, char *const *argv
)
158 plan_tests(kTestTestCount
);