2 * Copyright (c) 2003-2018 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 #ifndef _OTATRUSTUTILITIES_H_
27 #define _OTATRUSTUTILITIES_H_ 1
29 #include <CoreFoundation/CoreFoundation.h>
30 #include <sys/types.h>
32 #include <dispatch/dispatch.h>
36 // Opaque type that holds the data for a specific version of the OTA PKI assets
37 typedef struct _OpaqueSecOTAPKI
*SecOTAPKIRef
;
39 // Returns a boolean for whether the current instance is the system trustd
40 bool SecOTAPKIIsSystemTrustd(void);
42 // Returns the trust server workloop
43 dispatch_queue_t
SecTrustServerGetWorkloop(void);
45 // Convert a trusted CT log array to a trusted CT log dictionary, indexed by the LogID
47 CFDictionaryRef
SecOTAPKICreateTrustedCTLogsDictionaryFromArray(CFArrayRef trustedCTLogsArray
);
49 // Get a reference to the current OTA PKI asset data
50 // Caller is responsible for releasing the returned SecOTAPKIRef
51 CF_EXPORT CF_RETURNS_RETAINED
52 SecOTAPKIRef
SecOTAPKICopyCurrentOTAPKIRef(void);
54 // Accessor to retrieve a copy of the current black listed key.
55 // Caller is responsible for releasing the returned CFSetRef
57 CFSetRef
SecOTAPKICopyBlackListSet(SecOTAPKIRef otapkiRef
);
59 // Accessor to retrieve a copy of the current gray listed key.
60 // Caller is responsible for releasing the returned CFSetRef
62 CFSetRef
SecOTAPKICopyGrayList(SecOTAPKIRef otapkiRef
);
64 // Accessor to retrieve a copy of the current allow list dictionary.
65 // Caller is responsible for releasing the returned CFDictionaryRef
67 CFDictionaryRef
SecOTAPKICopyAllowList(SecOTAPKIRef otapkiRef
);
69 // Accessor to retrieve a copy of the allow list for a specific authority key ID.
70 // Caller is responsible for releasing the returned CFArrayRef
72 CFArrayRef
SecOTAPKICopyAllowListForAuthKeyID(SecOTAPKIRef otapkiRef
, CFStringRef authKeyID
);
74 // Accessor to retrieve a copy of the current trusted certificate transparency logs.
75 // Caller is responsible for releasing the returned CFArrayRef
77 CFDictionaryRef
SecOTAPKICopyTrustedCTLogs(SecOTAPKIRef otapkiRef
);
79 // Accessor to retrieve the path of the current pinning list.
80 // Caller is responsible for releasing the returned CFURLRef
82 CFURLRef
SecOTAPKICopyPinningList(SecOTAPKIRef otapkiRef
);
84 // Accessor to retrieve the array of Escrow certificates.
85 // Caller is responsible for releasing the returned CFArrayRef
87 CFArrayRef
SecOTAPKICopyEscrowCertificates(uint32_t escrowRootType
, SecOTAPKIRef otapkiRef
);
89 // Accessor to retrieve the dictionary of EV Policy OIDs to Anchor digest.
90 // Caller is responsible for releasing the returned CFDictionaryRef
92 CFDictionaryRef
SecOTAPKICopyEVPolicyToAnchorMapping(SecOTAPKIRef otapkiRef
);
94 // Accessor to retrieve the dictionary of anchor digest to file offset.
95 // Caller is responsible for releasing the returned CFDictionaryRef
97 CFDictionaryRef
SecOTAPKICopyAnchorLookupTable(SecOTAPKIRef otapkiRef
);
99 // Accessor to retrieve the pointer to the top of the anchor certs file.
100 // Caller should NOT free the returned pointer. The caller should hold
101 // a reference to the SecOTAPKIRef object until finished with
102 // the returned pointer.
104 const char* SecOTAPKIGetAnchorTable(SecOTAPKIRef otapkiRef
);
106 // Accessor to retrieve the full path to the valid update snapshot resource.
107 // The return value may be NULL if the resource does not exist.
108 // Caller should NOT free the returned pointer. The caller should hold
109 // a reference to the SecOTAPKIRef object until finished with
110 // the returned pointer.
112 const char* SecOTAPKIGetValidUpdateSnapshot(SecOTAPKIRef otapkiRef
);
114 // Accessor to retrieve the full path to the valid database snapshot resource.
115 // The return value may be NULL if the resource does not exist.
116 // Caller should NOT free the returned pointer. The caller should hold
117 // a reference to the SecOTAPKIRef object until finished with
118 // the returned pointer.
120 const char* SecOTAPKIGetValidDatabaseSnapshot(SecOTAPKIRef otapkiRef
);
122 // Accessor to retrieve the current valid snapshot version.
124 CFIndex
SecOTAPKIGetValidSnapshotVersion(SecOTAPKIRef otapkiRef
);
126 // Accessor to retrieve the current valid snapshot format.
128 CFIndex
SecOTAPKIGetValidSnapshotFormat(SecOTAPKIRef otapkiRef
);
130 // Accessor to retrieve the OTAPKI trust store version
131 // Note: Trust store is not mutable by assets
133 uint64_t SecOTAPKIGetTrustStoreVersion(SecOTAPKIRef otapkiRef
);
135 // Accessor to retrieve the OTAPKI asset version
137 uint64_t SecOTAPKIGetAssetVersion(SecOTAPKIRef otapkiRef
);
139 // Accessors to retrieve the last check in time for the OTAPKI asset
141 CFDateRef
SecOTAPKICopyLastAssetCheckInDate(SecOTAPKIRef otapkiRef
);
143 #define kSecOTAPKIAssetStalenessAtRisk (60*60*24*30) // 30 days
144 #define kSecOTAPKIAssetStalenessWarning (60*60*24*45) // 45 days
145 #define kSecOTAPKIAssetStalenessDisable (60*60*24*60) // 60 days
146 bool SecOTAPKIAssetStalenessLessThanSeconds(SecOTAPKIRef otapkiRef
, CFTimeInterval seconds
);
149 // SPI to return the current sampling rate for the event name
150 // This rate is actually n where we sample 1 out of every n
151 NSNumber
*SecOTAPKIGetSamplingRateForEvent(SecOTAPKIRef otapkiRef
, NSString
*eventName
);
154 CFArrayRef
SecOTAPKICopyAppleCertificateAuthorities(SecOTAPKIRef otapkiRef
);
156 extern const CFStringRef kOTAPKIKillSwitchCT
;
157 bool SecOTAPKIKillSwitchEnabled(SecOTAPKIRef otapkiRef
, CFStringRef switchKey
);
159 // SPI to return the array of currently trusted Escrow certificates
161 CFArrayRef
SecOTAPKICopyCurrentEscrowCertificates(uint32_t escrowRootType
, CFErrorRef
* error
);
163 // SPI to return the array of currently trusted CT logs
165 CFDictionaryRef
SecOTAPKICopyCurrentTrustedCTLogs(CFErrorRef
* error
);
167 // SPI to return dictionary of CT log matching specified key id */
169 CFDictionaryRef
SecOTAPKICopyCTLogForKeyID(CFDataRef keyID
, CFErrorRef
* error
);
171 // SPI to return the current OTA PKI trust store version
172 // Note: Trust store is not mutable by assets
174 uint64_t SecOTAPKIGetCurrentTrustStoreVersion(CFErrorRef
* CF_RETURNS_RETAINED error
);
176 // SPI to return the current OTA PKI asset version
178 uint64_t SecOTAPKIGetCurrentAssetVersion(CFErrorRef
* error
);
180 // SPI to return the current OTA SecExperiment asset version
182 uint64_t SecOTASecExperimentGetCurrentAssetVersion(CFErrorRef
* error
);
184 // SPI to reset the current OTA PKI asset version to the version shipped
187 uint64_t SecOTAPKIResetCurrentAssetVersion(CFErrorRef
* CF_RETURNS_RETAINED error
);
189 // SPI to signal trustd to get a new set of trust data
190 // Always returns the current asset version. Returns an error with
191 // a reason if the update was not successful.
193 uint64_t SecOTAPKISignalNewAsset(CFErrorRef
* CF_RETURNS_RETAINED error
);
195 // SPI to signal trustd to get a new set of SecExperiment data
196 // Always returns the current asset version. Returns an error with
197 // a reason if the update was not successful.
199 uint64_t SecOTASecExperimentGetNewAsset(CFErrorRef
* error
);
201 // SPI to copy current SecExperiment asset data
203 CFDictionaryRef
SecOTASecExperimentCopyAsset(CFErrorRef
* error
);
205 /* "Internal" interfaces for tests */
206 #if !TARGET_OS_BRIDGE && __OBJC__
207 BOOL
UpdateOTACheckInDate(void);
208 void UpdateKillSwitch(NSString
*key
, bool value
);
213 #endif /* _OTATRUSTUTILITIES_H_ */