5 #define __KEYCHAINCORE__ 1
7 #include <Foundation/Foundation.h>
8 #include <Security/Security.h>
10 #include "SecRecoveryKey.h"
11 #include "shared_regressions.h"
13 int rk_01_recoverykey(int argc, char *const *argv)
15 NSArray *testData = @[
17 @"recoverykey" : @"AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAGW",
18 @"publicKey" : @"UUjq5Wv572RSsKahddvUPQAEIeErSHMK9J+NKb6sVdo=",
19 @"privateKey" : @"UUjq5Wv572RSsKahddvUPQAEIeErSHMK9J+NKb6sVdpi00pR5UGzfoARLnpxCFmqCh1XCRtjCptztGfN1XW11w==",
20 @"password" : @"Ze14tkzC8keZEnoIv+LoWvicxOTSSqUwhE8xyChmZAs=",
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=",
29 @"recoverykey" : @"BBBB-BBBB-BBBB-BBBB-BBBB-BBBB-BBAY",
30 @"publicKey" : @"fomczHhXphIMaCbuQlKPefXO8YEIH2M9TFslcBjvJXY=",
31 @"privateKey" : @"fomczHhXphIMaCbuQlKPefXO8YEIH2M9TFslcBjvJXa/W5BWvgJmZO9xShq1sePpLDfGf5lOkwhwzFzFypiXgw==",
32 @"password" : @"P7nC1leKBTJ3aMsXZImVsR2kIlqlsvoSEI8yFKv6xdw=",
37 plan_tests(7 * (int)[testData count]);
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"];
45 SecRecoveryKey *rk = SecRKCreateRecoveryKey(recoveryKey);
46 ok(rk, "got recovery key");
48 NSData *publicKey = SecRKCopyBackupPublicKey(rk);
49 ok(publicKey, "got publicKey");
51 ok([publicKey isEqualToData:[[NSData alloc] initWithBase64EncodedString:knownPublicKey options:0]],
52 "public key same: %@", [publicKey base64EncodedStringWithOptions:0]);
54 NSData *privateKey = SecRKCopyBackupFullKey(rk);
55 ok(privateKey, "got privateKey");
57 ok([privateKey isEqualToData:[[NSData alloc] initWithBase64EncodedString:knownPrivateKey options:0]],
58 "privateKey key same: %@", [privateKey base64EncodedStringWithOptions:0]);
60 NSString *recoveryPassword = SecRKCopyAccountRecoveryPassword(rk);
61 ok(recoveryPassword, "got account recovery password");
63 ok([recoveryPassword isEqualToString:knownPassword], "password same: %@", recoveryPassword);