]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Tool/trust_update.m
Security-58286.270.3.0.1.tar.gz
[apple/security.git] / OSX / sec / Security / Tool / trust_update.m
1 /*
2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 *
23 * trust_update.m
24 */
25
26 #import <Foundation/Foundation.h>
27
28 #import <utilities/SecCFWrappers.h>
29 #import <Security/SecTrustPriv.h>
30
31 #include "SecurityCommands.h"
32
33 static int check_OTA_Supplementals_asset(void) {
34 CFErrorRef error = NULL;
35 uint64_t version = SecTrustOTAPKIGetUpdatedAsset(&error);
36 if (error) {
37 CFStringRef errorDescription = CFErrorCopyDescription(error);
38 if (errorDescription) {
39 char *errMsg = CFStringToCString(errorDescription);
40 fprintf(stdout, "Update failed: %s\n", errMsg);
41 if (errMsg) { free(errMsg); }
42 CFRelease(errorDescription);
43 } else {
44 fprintf(stdout, "Update failed: no description\n");
45 }
46 CFRelease(error);
47 } else {
48 fprintf(stdout, "Updated succeeded\n");
49 }
50 if (version != 0) {
51 fprintf(stdout, "Asset Content Version: %llu\n", version);
52 } else {
53 return 1;
54 }
55 return 0;
56 }
57
58 int check_trust_update(int argc, char * const *argv) {
59 int arg;
60 bool check_trust_supplementals = false;
61
62 if (argc == 1) {
63 return SHOW_USAGE_MESSAGE;
64 }
65
66 while ((arg = getopt(argc, argv, "s")) != -1) {
67 switch(arg) {
68 case 's':
69 check_trust_supplementals = true;
70 break;
71 case '?':
72 default:
73 return SHOW_USAGE_MESSAGE;
74 }
75 }
76
77 if (check_trust_supplementals) {
78 return check_OTA_Supplementals_asset();
79 }
80 return 0;
81 }