]> git.saurik.com Git - apple/security.git/blob - keychain/otctl/EscrowRequestCLI.m
Security-59306.11.20.tar.gz
[apple/security.git] / keychain / otctl / EscrowRequestCLI.m
1
2 #import <Foundation/Foundation.h>
3 #import <Foundation/NSXPCConnection_Private.h>
4 #import <Security/SecItemPriv.h>
5 #import <Security/Security.h>
6 #import <xpc/xpc.h>
7
8 #include "utilities/SecCFWrappers.h"
9 #include "utilities/SecInternalReleasePriv.h"
10 #import "utilities/debugging.h"
11
12 #import "keychain/otctl/EscrowRequestCLI.h"
13
14 @implementation EscrowRequestCLI
15
16 - (instancetype)initWithEscrowRequest:(SecEscrowRequest*)escrowRequest
17 {
18 if((self = [super init])) {
19 _escrowRequest = escrowRequest;
20 }
21
22 return self;
23 }
24
25 - (long)trigger
26 {
27 NSError* error = nil;
28 [self.escrowRequest triggerEscrowUpdate:@"cli" error:&error];
29
30 if(error) {
31 printf("Errored: %s", [[error description] UTF8String]);
32 return 1;
33
34 } else {
35 printf("Complete.\n");
36 }
37 return 0;
38 }
39
40 - (long)status
41 {
42 NSError* error = nil;
43 NSDictionary* statuses = [self.escrowRequest fetchStatuses:&error];
44
45 if(error) {
46 printf("Errored: %s\n", [[error description] UTF8String]);
47 return 1;
48 }
49
50 if(statuses.count == 0) {
51 printf("No requests are waiting for a passcode.\n");
52 return 0;
53 }
54
55 for(NSString* uuid in statuses.allKeys) {
56 printf("Request %s: %s\n", [uuid UTF8String], [[statuses[uuid] description] UTF8String]);
57 }
58
59 return 0;
60 }
61
62 - (long)reset
63 {
64 NSError* error = nil;
65 [self.escrowRequest resetAllRequests:&error];
66
67 if(error) {
68 printf("Errored: %s\n", [[error description] UTF8String]);
69 return 1;
70 }
71
72 printf("Complete.\n");
73 return 0;
74 }
75
76 - (long)storePrerecordsInEscrow
77 {
78 NSError* error = nil;
79 uint64_t recordsWritten = [self.escrowRequest storePrerecordsInEscrow:&error];
80
81 if(error) {
82 printf("Errored: %s\n", [[error description] UTF8String]);
83 return 1;
84 }
85
86 printf("Complete: %d records written.\n", (int)recordsWritten);
87 return 0;
88 }
89
90 @end