2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 #import <Foundation/Foundation.h>
28 #import <utilities/SecCFWrappers.h>
29 #import <Security/SecTrustPriv.h>
31 #include "SecurityCommands.h"
33 static int check_OTA_Supplementals_asset(void) {
34 CFErrorRef error = NULL;
35 uint64_t version = SecTrustOTAPKIGetUpdatedAsset(&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);
44 fprintf(stdout, "Update failed: no description\n");
48 fprintf(stdout, "Updated succeeded\n");
51 fprintf(stdout, "Asset Content Version: %llu\n", version);
58 static int check_OTA_sec_experiment_asset(void) {
59 CFErrorRef error = NULL;
60 uint64_t version = SecTrustOTASecExperimentGetUpdatedAsset(&error);
62 CFStringRef errorDescription = CFErrorCopyDescription(error);
63 if (errorDescription) {
64 char *errMsg = CFStringToCString(errorDescription);
65 fprintf(stdout, "Update failed: %s\n", errMsg);
66 if (errMsg) { free(errMsg); }
67 CFRelease(errorDescription);
69 fprintf(stdout, "Update failed: no description\n");
73 fprintf(stdout, "Updated succeeded\n");
76 fprintf(stdout, "Asset Content Version: %llu\n", version);
83 static int check_valid_update(void) {
84 CFErrorRef error = NULL;
85 bool result = SecTrustTriggerValidUpdate(&error);
87 CFStringRef errorDescription = error ? CFErrorCopyDescription(error) : NULL;
88 if (errorDescription) {
89 char *errMsg = CFStringToCString(errorDescription);
90 fprintf(stdout, "Update failed: %s\n", errMsg ? errMsg : "no error message");
92 CFRelease(errorDescription);
94 fprintf(stdout, "Update failed: no description\n");
98 fprintf(stdout, "Updated triggered\n");
103 int check_trust_update(int argc, char * const *argv) {
107 return SHOW_USAGE_MESSAGE;
110 while ((arg = getopt(argc, argv, "ser")) != -1) {
113 return check_OTA_Supplementals_asset();
115 return check_OTA_sec_experiment_asset();
117 return check_valid_update();
120 return SHOW_USAGE_MESSAGE;