]> git.saurik.com Git - apple/security.git/blob - RegressionTests/secbackupntest/secbackupntest.m
Security-59754.41.1.tar.gz
[apple/security.git] / RegressionTests / secbackupntest / secbackupntest.m
1 //
2 // Copyright 2015 Apple. All rights reserved.
3 //
4
5 /*
6 * This is to fool os services to not provide the Keychain manager
7 * interface tht doens't work since we don't have unified headers
8 * between iOS and OS X. rdar://23405418/
9 */
10 #define __KEYCHAINCORE__ 1
11
12 #include <Foundation/Foundation.h>
13 #include <Security/Security.h>
14
15 #include <TargetConditionals.h>
16
17 #include <Security/SecItemPriv.h>
18 #include <err.h>
19
20 #if !TARGET_OS_SIMULATOR
21 #include <libaks.h>
22
23 static NSData *
24 BagMe(void)
25 {
26 keybag_handle_t handle;
27 kern_return_t result;
28 void *data = NULL;
29 int length;
30
31 result = aks_create_bag("foo", 3, kAppleKeyStoreAsymmetricBackupBag, &handle);
32 if (result)
33 errx(1, "aks_create_bag: %08x", result);
34
35 result = aks_save_bag(handle, &data, &length);
36 if (result)
37 errx(1, "aks_save_bag");
38
39 return [NSData dataWithBytes:data length:length];
40 }
41 #endif /* TARGET_OS_SIMULATOR */
42
43 int main (int argc, const char * argv[])
44 {
45 @autoreleasepool {
46 NSData *bag = NULL, *password = NULL;
47
48 #if !TARGET_OS_SIMULATOR
49 bag = BagMe();
50 password = [NSData dataWithBytes:"foo" length:3];
51 #endif
52
53 NSLog(@"backup bag: %@", bag);
54
55 NSData *backup = (__bridge NSData *)_SecKeychainCopyBackup((__bridge CFDataRef)bag, (__bridge CFDataRef)password);
56 if (backup != NULL) {
57 NSLog(@"backup data: %@", backup);
58 errx(1, "got backup");
59 }
60 return 0;
61 }
62 }
63
64