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@
25 #include <AssertMacros.h>
32 #include <Security/SecBase.h>
33 #include <Security/SecItem.h>
35 #include <SecureObjectSync/SOSAccount.h>
36 #include <CKBridge/SOSCloudKeychainClient.h>
37 #include <utilities/SecCFWrappers.h>
38 #include <utilities/debugging.h>
40 #include "SOSCircle_regressions.h"
41 #include "SOSRegressionUtilities.h"
43 static bool verboseCKDClientDebugging
= false;
45 static CFStringRef kTestKeyIDTimestamp
= CFSTR("IDTimestamp");
47 static void printTimeNow(const char *msg
)
49 if (verboseCKDClientDebugging
)
51 CFAbsoluteTime now
= CFAbsoluteTimeGetCurrent();
52 const char *nowstr
= cfabsoluteTimeToString(now
);
55 printf("%s %s\n", nowstr
, msg
);
61 // MARK: ----- basicKVSTests -----
63 static bool postIDTimestamp(dispatch_queue_t theq
)
65 __block
bool result
= false;
66 CFStringRef macaddr
= myMacAddress();
67 CFAbsoluteTime now
= CFAbsoluteTimeGetCurrent();
68 const char *nowstr
= cfabsoluteTimeToStringLocal(now
);
69 CFStringRef cfidstr
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%@: %@ %s"), kTestKeyIDTimestamp
, macaddr
,nowstr
);
70 secerror("Setting %@ key: %@", kTestKeyIDTimestamp
, cfidstr
);
72 // create a dictionary with one key/value pair
73 CFDictionaryRef objects
= CFDictionaryCreateForCFTypes(kCFAllocatorDefault
, kTestKeyIDTimestamp
, cfidstr
, NULL
);
74 SOSCloudKeychainPutObjectsInCloud(objects
, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT
, 0),
75 ^(CFDictionaryRef returnedValues
, CFErrorRef error
) {
77 fail("Error putting: %@", error
);
82 CFMutableArrayRef keysToGet
= CFArrayCreateMutableForCFTypes(kCFAllocatorDefault
);
83 CFArrayAppendValue(keysToGet
, kTestKeyIDTimestamp
);
84 SOSCloudKeychainGetObjectsFromCloud(keysToGet
, theq
, ^ (CFDictionaryRef returnedValues
, CFErrorRef error
)
86 CFStringRef returnedTimestamp
= (CFStringRef
)CFDictionaryGetValue(returnedValues
, kTestKeyIDTimestamp
);
87 if (returnedTimestamp
)
88 result
= CFEqual(returnedTimestamp
, cfidstr
);
96 static const int kbasicKVSTestsCount
= 1;
97 static void basicKVSTests2()
99 dispatch_queue_t generalq
= dispatch_queue_create("general", DISPATCH_QUEUE_SERIAL
);
101 const UInt8 tdata
[] = {0x01, 0x02, 0x03, 0x04, 'a', 'b', 'c'};
102 CFDataRef testData
= CFDataCreate(kCFAllocatorDefault
, tdata
, sizeof(tdata
)/sizeof(UInt8
));
104 const CFStringRef adata
[] = {CFSTR("A"), CFSTR("b"), CFSTR("C"), CFSTR("D")};
105 CFArrayRef testArray
= CFArrayCreate(kCFAllocatorDefault
, (const void **)&adata
, sizeof(adata
)/sizeof(CFStringRef
), &kCFTypeArrayCallBacks
);
108 const CFStringRef circleKeyStrings
[] = {CFSTR("circleA"), CFSTR("circleB"), CFSTR("circleC"), CFSTR("circleD")};
109 CFArrayRef circleKeys
= CFArrayCreate(kCFAllocatorDefault
, (const void **)&circleKeyStrings
, sizeof(circleKeyStrings
)/sizeof(CFStringRef
), &kCFTypeArrayCallBacks
);
111 const CFStringRef keysWhenUnlockedKeyStrings
[] = {CFSTR("foo"), CFSTR("bar"), CFSTR("baz")};
112 CFArrayRef keysWhenUnlocked
= CFArrayCreate(kCFAllocatorDefault
, (const void **)&keysWhenUnlockedKeyStrings
, sizeof(keysWhenUnlockedKeyStrings
)/sizeof(CFStringRef
), &kCFTypeArrayCallBacks
);
114 printTimeNow("Start tests [basicKVSTests]");
116 ok(postIDTimestamp(generalq
), "testPostGet for %@", kTestKeyIDTimestamp
);
118 printTimeNow("Start tests [basicKVSTests2]");
122 CFRelease(testArray
);
123 CFRelease(circleKeys
);
124 CFRelease(keysWhenUnlocked
);
127 // MARK: ----- start of all tests -----
129 static const int kCloudTransportTestsCount
= 0;
130 static int kTestTestCount
= kbasicKVSTestsCount
+ kCloudTransportTestsCount
;
131 static void tests(void)
134 skip("Skipping ckdclient tests because CloudKeychainProxy.xpc is not installed", kTestTestCount
, XPCServiceInstalled());
136 // cloudTransportTests();
137 sleep(15); // on iOS, we need to hang around long enough for syncdefaultsd to see us
141 int sc_95_ckd2client(int argc
, char *const *argv
)
143 plan_tests(kTestTestCount
);