2 * Copyright (c) 2012-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@
26 #include <Security/SecBase.h>
27 #include <Security/SecItem.h>
29 #include <Security/SecureObjectSync/SOSAccount.h>
30 #include <Security/SecureObjectSync/SOSCloudCircle.h>
31 #include <Security/SecureObjectSync/SOSInternal.h>
32 #include <Security/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>
43 #include "SecdTestKeychainUtilities.h"
44 #include "SOSAccountTesting.h"
46 static int kTestTestCount
= 9 + kSecdTestSetupTestCount
;
47 static void tests(void)
49 CFErrorRef error
= NULL
;
50 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
51 CFStringRef cfaccount
= CFSTR("test@test.org");
53 SOSDataSourceFactoryRef test_factory
= SOSTestDataSourceFactoryCreate();
54 SOSDataSourceRef test_source
= SOSTestDataSourceCreate();
55 SOSTestDataSourceFactorySetDataSource(test_factory
, CFSTR("TestType"), test_source
);
57 SOSAccountRef account
= CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
59 ok(SOSAccountAssertUserCredentialsAndUpdate(account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
61 CFReleaseNull(cfpassword
);
63 ok(NULL
!= account
, "Created");
65 size_t size
= SOSAccountGetDEREncodedSize(account
, &error
);
68 uint8_t* start
= SOSAccountEncodeToDER(account
, &error
, buffer
, buffer
+ sizeof(buffer
));
71 ok(start
, "successful encoding");
72 ok(start
== buffer
, "Used whole buffer");
74 const uint8_t *der
= buffer
;
75 SOSAccountRef inflated
= SOSAccountCreateFromDER(kCFAllocatorDefault
, test_factory
,
76 &error
, &der
, buffer
+ sizeof(buffer
));
78 SOSAccountEnsureFactoryCirclesTest(inflated
, CFSTR("Test Device"));
79 ok(inflated
, "inflated");
80 ok(CFEqual(inflated
, account
), "Compares");
81 CFReleaseNull(inflated
);
83 CFDictionaryRef new_gestalt
= SOSCreatePeerGestaltFromName(CFSTR("New Device"));
84 ok(SOSAccountResetToOffering_wTxn(account
, &error
), "Reset to Offering (%@)", error
);
86 is(SOSAccountGetCircleStatus(account
, &error
), kSOSCCInCircle
, "Was in Circle (%@)", error
);
89 SOSAccountUpdateGestalt(account
, new_gestalt
);
91 is(SOSAccountGetCircleStatus(account
, &error
), kSOSCCInCircle
, "Still in Circle (%@)", error
);
94 CFReleaseNull(new_gestalt
);
95 CFReleaseNull(account
);
97 SOSDataSourceFactoryRelease(test_factory
);
98 SOSDataSourceRelease(test_source
, NULL
);
103 int secd_50_account(int argc
, char *const *argv
)
105 plan_tests(kTestTestCount
);
107 secd_test_setup_temp_keychain(__FUNCTION__
, NULL
);