]> git.saurik.com Git - apple/security.git/blob - keychain/securityd/Regressions/secd-80-views-basic.m
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / securityd / Regressions / secd-80-views-basic.m
1 //
2 // secd-80-views-basic.c
3 // sec
4 //
5 // Created by Richard Murphy on 1/26/15.
6 //
7 //
8
9 #include <stdio.h>
10 /*
11 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
12 *
13 * @APPLE_LICENSE_HEADER_START@
14 *
15 * This file contains Original Code and/or Modifications of Original Code
16 * as defined in and that are subject to the Apple Public Source License
17 * Version 2.0 (the 'License'). You may not use this file except in
18 * compliance with the License. Please obtain a copy of the License at
19 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * file.
21 *
22 * The Original Code and all software distributed under the License are
23 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
24 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
25 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
27 * Please see the License for the specific language governing rights and
28 * limitations under the License.
29 *
30 * @APPLE_LICENSE_HEADER_END@
31 */
32
33
34
35 #include <Security/SecBase.h>
36 #include <Security/SecItem.h>
37
38 #include "keychain/SecureObjectSync/SOSAccount.h"
39 #include <Security/SecureObjectSync/SOSCloudCircle.h>
40 #include "keychain/SecureObjectSync/SOSInternal.h"
41 #include "keychain/SecureObjectSync/SOSFullPeerInfo.h"
42 #include "keychain/SecureObjectSync/SOSUserKeygen.h"
43 #include <Security/SecureObjectSync/SOSViews.h>
44
45 #include <stdlib.h>
46 #include <unistd.h>
47
48 #include "secd_regressions.h"
49 #include "SOSTestDataSource.h"
50
51 #include "SOSRegressionUtilities.h"
52 #include <utilities/SecCFWrappers.h>
53
54 #include "keychain/securityd/SOSCloudCircleServer.h"
55 #include "SecdTestKeychainUtilities.h"
56 #include "SOSAccountTesting.h"
57
58
59 static void testView(SOSAccount* account, SOSViewResultCode expected, CFStringRef view, SOSViewActionCode action, char *label) {
60 CFErrorRef error = NULL;
61 SOSViewResultCode vcode = 9999;
62 switch(action) {
63 case kSOSCCViewQuery:
64 vcode = [account.trust viewStatus:account name:view err:&error];
65 break;
66 case kSOSCCViewEnable:
67 case kSOSCCViewDisable: // fallthrough
68 vcode = [account.trust updateView:account name:view code:action err:&error];
69 break;
70 default:
71 break;
72 }
73 is(vcode, expected, "%s (%@)", label, error);
74 CFReleaseNull(error);
75 }
76
77 static void testViewLists(void) {
78 CFSetRef allViews = SOSViewCopyViewSet(kViewSetAll);
79 CFSetRef defaultViews = SOSViewCopyViewSet(kViewSetDefault);
80 CFSetRef initialViews = SOSViewCopyViewSet(kViewSetInitial);
81 CFSetRef alwaysOnViews = SOSViewCopyViewSet(kViewSetAlwaysOn);
82 CFSetRef backupRequiredViews = SOSViewCopyViewSet(kViewSetRequiredForBackup);
83 CFSetRef V0Views = SOSViewCopyViewSet(kViewSetV0);
84
85 is(CFSetGetCount(allViews), 24, "make sure count of allViews is correct");
86 is(CFSetGetCount(defaultViews), 20, "make sure count of defaultViews is correct");
87 is(CFSetGetCount(initialViews), 0, "make sure count of initialViews is correct");
88 is(CFSetGetCount(alwaysOnViews), 20, "make sure count of alwaysOnViews is correct");
89 is(CFSetGetCount(backupRequiredViews), 3, "make sure count of backupRequiredViews is correct");
90 is(CFSetGetCount(V0Views), 6, "make sure count of V0Views is correct");
91
92 CFReleaseNull(allViews);
93 CFReleaseNull(defaultViews);
94 CFReleaseNull(initialViews);
95 CFReleaseNull(alwaysOnViews);
96 CFReleaseNull(backupRequiredViews);
97 CFReleaseNull(V0Views);
98 }
99
100 static int kTestTestCount = 38;
101 static void tests(void)
102 {
103 CFErrorRef error = NULL;
104 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
105 CFStringRef cfaccount = CFSTR("test@test.org");
106 CFSetRef nullSet = CFSetCreateMutableForCFTypes(kCFAllocatorDefault);
107
108 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
109 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
110 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
111
112 SOSAccount* account = CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
113
114 ok(SOSAccountAssertUserCredentialsAndUpdate(account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
115 CFReleaseNull(error);
116 CFReleaseNull(cfpassword);
117
118 ok(SOSAccountJoinCircles_wTxn(account, &error), "Join circle: %@", error);
119
120 ok(NULL != account, "Created");
121
122 ok(SOSAccountCheckHasBeenInSync_wTxn(account), "In sync already");
123
124 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected view capability for kSOSViewKeychain");
125 // Default views no longer includes kSOSViewAppleTV
126 testView(account, kSOSCCViewMember, kSOSViewAppleTV, kSOSCCViewQuery, "Expected view capability for kSOSViewAppleTV");
127 testView(account, kSOSCCViewMember, kSOSViewPCSPhotos, kSOSCCViewQuery, "Expected no view capability for kSOSViewPCSPhotos");
128 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected no view capability for kSOSViewPCSiCloudDrive");
129 testView(account, kSOSCCNoSuchView, CFSTR("FOO"), kSOSCCViewQuery, "Expected no such view for FOO");
130
131 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewEnable, "Expected to enable kSOSViewPCSiCloudDrive");
132 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
133 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewDisable, "Expected cannot disable kSOSViewPCSiCloudDrive");
134 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
135
136 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewEnable, "Expected to enable kSOSViewPCSiCloudDrive");
137 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
138 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewEnable, "Expected to enable kSOSViewKeychainV0");
139 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
140 testView(account, kSOSCCViewMember, kSOSViewAppleTV, kSOSCCViewEnable, "Expected to enable kSOSViewAppleTV");
141
142 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
143 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected view capability for kSOSViewKeychainV0");
144 testView(account, kSOSCCViewMember, kSOSViewAppleTV, kSOSCCViewQuery, "Expected view capability for kSOSViewAppleTV");
145
146 ok([account.trust updateViewSetsWithAnalytics:account enabled:SOSViewsGetV0ViewSet() disabled:nullSet parentEvent: NULL], "Expect not accepting kSOSKeychainV0");
147 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected no addition of kSOSKeychainV0");
148
149 ok([account.trust updateViewSetsWithAnalytics:account enabled:SOSViewsGetV0ViewSet() disabled:nullSet parentEvent: NULL], "Expect not accepting kSOSKeychainV0");
150 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected no addition of kSOSKeychainV0");
151
152 SOSPeerInfoRef pi = account.peerInfo;
153 ok(pi, "should have the peerInfo");
154 SOSViewResultCode vr = SOSViewsEnable(pi, kSOSViewKeychainV0, NULL);
155
156 ok(vr == kSOSCCViewMember, "Set Virtual View manually");
157
158 ok(![account.trust updateViewSetsWithAnalytics:account enabled:nullSet disabled:SOSViewsGetV0ViewSet() parentEvent: NULL], "Expect not removing kSOSKeychainV0");
159 testView(account, kSOSCCViewMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected kSOSKeychainV0 is still there");
160
161 ok(![account.trust updateViewSetsWithAnalytics:account enabled:nullSet disabled:SOSViewsGetV0ViewSet() parentEvent: NULL], "Expect not removing kSOSKeychainV0");
162 testView(account, kSOSCCViewMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected kSOSKeychainV0 is still there");
163
164 SOSDataSourceRelease(test_source, NULL);
165 SOSDataSourceFactoryRelease(test_factory);
166
167 SOSTestCleanup();
168 }
169
170 int secd_80_views_basic(int argc, char *const *argv)
171 {
172 plan_tests(kTestTestCount);
173
174 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
175 secd_test_clear_testviews();
176 testViewLists();
177 tests();
178
179 return 0;
180 }