]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/rk_01_recoverykey.m
Security-57740.51.3.tar.gz
[apple/security.git] / OSX / sec / Security / Regressions / rk_01_recoverykey.m
1 //
2 // rk_01_recoverykey.m
3 //
4
5 #define __KEYCHAINCORE__ 1
6
7 #include <Foundation/Foundation.h>
8 #include <Security/Security.h>
9
10 #include "SecRecoveryKey.h"
11 #include "shared_regressions.h"
12
13 int rk_01_recoverykey(int argc, char *const *argv)
14 {
15 NSArray *testData = @[
16 @{
17 @"recoverykey" : @"AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAGW",
18 @"publicKey" : @"UUjq5Wv572RSsKahddvUPQAEIeErSHMK9J+NKb6sVdo=",
19 @"privateKey" : @"UUjq5Wv572RSsKahddvUPQAEIeErSHMK9J+NKb6sVdpi00pR5UGzfoARLnpxCFmqCh1XCRtjCptztGfN1XW11w==",
20 @"password" : @"Ze14tkzC8keZEnoIv+LoWvicxOTSSqUwhE8xyChmZAs=",
21 },
22 @{ // same again to make sure it works
23 @"recoverykey" : @"AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAGW",
24 @"publicKey" : @"UUjq5Wv572RSsKahddvUPQAEIeErSHMK9J+NKb6sVdo=",
25 @"privateKey" : @"UUjq5Wv572RSsKahddvUPQAEIeErSHMK9J+NKb6sVdpi00pR5UGzfoARLnpxCFmqCh1XCRtjCptztGfN1XW11w==",
26 @"password" : @"Ze14tkzC8keZEnoIv+LoWvicxOTSSqUwhE8xyChmZAs=",
27 },
28 @{
29 @"recoverykey" : @"BBBB-BBBB-BBBB-BBBB-BBBB-BBBB-BBAY",
30 @"publicKey" : @"fomczHhXphIMaCbuQlKPefXO8YEIH2M9TFslcBjvJXY=",
31 @"privateKey" : @"fomczHhXphIMaCbuQlKPefXO8YEIH2M9TFslcBjvJXa/W5BWvgJmZO9xShq1sePpLDfGf5lOkwhwzFzFypiXgw==",
32 @"password" : @"P7nC1leKBTJ3aMsXZImVsR2kIlqlsvoSEI8yFKv6xdw=",
33 },
34 ];
35
36
37 plan_tests(7 * (int)[testData count]);
38
39 [testData enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
40 NSString *recoveryKey = obj[@"recoverykey"];
41 NSString *knownPublicKey = obj[@"publicKey"];
42 NSString *knownPrivateKey = obj[@"privateKey"];
43 NSString *knownPassword = obj[@"password"];
44
45 SecRecoveryKey *rk = SecRKCreateRecoveryKey(recoveryKey);
46 ok(rk, "got recovery key");
47
48 NSData *publicKey = SecRKCopyBackupPublicKey(rk);
49 ok(publicKey, "got publicKey");
50
51 ok([publicKey isEqualToData:[[NSData alloc] initWithBase64EncodedString:knownPublicKey options:0]],
52 "public key same: %@", [publicKey base64EncodedStringWithOptions:0]);
53
54 NSData *privateKey = SecRKCopyBackupFullKey(rk);
55 ok(privateKey, "got privateKey");
56
57 ok([privateKey isEqualToData:[[NSData alloc] initWithBase64EncodedString:knownPrivateKey options:0]],
58 "privateKey key same: %@", [privateKey base64EncodedStringWithOptions:0]);
59
60 NSString *recoveryPassword = SecRKCopyAccountRecoveryPassword(rk);
61 ok(recoveryPassword, "got account recovery password");
62
63 ok([recoveryPassword isEqualToString:knownPassword], "password same: %@", recoveryPassword);
64 }];
65
66 return 0;
67 }