jpayne@69
|
1 /*
|
jpayne@69
|
2 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
jpayne@69
|
3 *
|
jpayne@69
|
4 * Licensed under the OpenSSL license (the "License"). You may not use
|
jpayne@69
|
5 * this file except in compliance with the License. You can obtain a copy
|
jpayne@69
|
6 * in the file LICENSE in the source distribution or at
|
jpayne@69
|
7 * https://www.openssl.org/source/license.html
|
jpayne@69
|
8 */
|
jpayne@69
|
9
|
jpayne@69
|
10 #ifndef HEADER_CT_H
|
jpayne@69
|
11 # define HEADER_CT_H
|
jpayne@69
|
12
|
jpayne@69
|
13 # include <openssl/opensslconf.h>
|
jpayne@69
|
14
|
jpayne@69
|
15 # ifndef OPENSSL_NO_CT
|
jpayne@69
|
16 # include <openssl/ossl_typ.h>
|
jpayne@69
|
17 # include <openssl/safestack.h>
|
jpayne@69
|
18 # include <openssl/x509.h>
|
jpayne@69
|
19 # include <openssl/cterr.h>
|
jpayne@69
|
20 # ifdef __cplusplus
|
jpayne@69
|
21 extern "C" {
|
jpayne@69
|
22 # endif
|
jpayne@69
|
23
|
jpayne@69
|
24
|
jpayne@69
|
25 /* Minimum RSA key size, from RFC6962 */
|
jpayne@69
|
26 # define SCT_MIN_RSA_BITS 2048
|
jpayne@69
|
27
|
jpayne@69
|
28 /* All hashes are SHA256 in v1 of Certificate Transparency */
|
jpayne@69
|
29 # define CT_V1_HASHLEN SHA256_DIGEST_LENGTH
|
jpayne@69
|
30
|
jpayne@69
|
31 typedef enum {
|
jpayne@69
|
32 CT_LOG_ENTRY_TYPE_NOT_SET = -1,
|
jpayne@69
|
33 CT_LOG_ENTRY_TYPE_X509 = 0,
|
jpayne@69
|
34 CT_LOG_ENTRY_TYPE_PRECERT = 1
|
jpayne@69
|
35 } ct_log_entry_type_t;
|
jpayne@69
|
36
|
jpayne@69
|
37 typedef enum {
|
jpayne@69
|
38 SCT_VERSION_NOT_SET = -1,
|
jpayne@69
|
39 SCT_VERSION_V1 = 0
|
jpayne@69
|
40 } sct_version_t;
|
jpayne@69
|
41
|
jpayne@69
|
42 typedef enum {
|
jpayne@69
|
43 SCT_SOURCE_UNKNOWN,
|
jpayne@69
|
44 SCT_SOURCE_TLS_EXTENSION,
|
jpayne@69
|
45 SCT_SOURCE_X509V3_EXTENSION,
|
jpayne@69
|
46 SCT_SOURCE_OCSP_STAPLED_RESPONSE
|
jpayne@69
|
47 } sct_source_t;
|
jpayne@69
|
48
|
jpayne@69
|
49 typedef enum {
|
jpayne@69
|
50 SCT_VALIDATION_STATUS_NOT_SET,
|
jpayne@69
|
51 SCT_VALIDATION_STATUS_UNKNOWN_LOG,
|
jpayne@69
|
52 SCT_VALIDATION_STATUS_VALID,
|
jpayne@69
|
53 SCT_VALIDATION_STATUS_INVALID,
|
jpayne@69
|
54 SCT_VALIDATION_STATUS_UNVERIFIED,
|
jpayne@69
|
55 SCT_VALIDATION_STATUS_UNKNOWN_VERSION
|
jpayne@69
|
56 } sct_validation_status_t;
|
jpayne@69
|
57
|
jpayne@69
|
58 DEFINE_STACK_OF(SCT)
|
jpayne@69
|
59 DEFINE_STACK_OF(CTLOG)
|
jpayne@69
|
60
|
jpayne@69
|
61 /******************************************
|
jpayne@69
|
62 * CT policy evaluation context functions *
|
jpayne@69
|
63 ******************************************/
|
jpayne@69
|
64
|
jpayne@69
|
65 /*
|
jpayne@69
|
66 * Creates a new, empty policy evaluation context.
|
jpayne@69
|
67 * The caller is responsible for calling CT_POLICY_EVAL_CTX_free when finished
|
jpayne@69
|
68 * with the CT_POLICY_EVAL_CTX.
|
jpayne@69
|
69 */
|
jpayne@69
|
70 CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void);
|
jpayne@69
|
71
|
jpayne@69
|
72 /* Deletes a policy evaluation context and anything it owns. */
|
jpayne@69
|
73 void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx);
|
jpayne@69
|
74
|
jpayne@69
|
75 /* Gets the peer certificate that the SCTs are for */
|
jpayne@69
|
76 X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx);
|
jpayne@69
|
77
|
jpayne@69
|
78 /*
|
jpayne@69
|
79 * Sets the certificate associated with the received SCTs.
|
jpayne@69
|
80 * Increments the reference count of cert.
|
jpayne@69
|
81 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
82 */
|
jpayne@69
|
83 int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert);
|
jpayne@69
|
84
|
jpayne@69
|
85 /* Gets the issuer of the aforementioned certificate */
|
jpayne@69
|
86 X509* CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx);
|
jpayne@69
|
87
|
jpayne@69
|
88 /*
|
jpayne@69
|
89 * Sets the issuer of the certificate associated with the received SCTs.
|
jpayne@69
|
90 * Increments the reference count of issuer.
|
jpayne@69
|
91 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
92 */
|
jpayne@69
|
93 int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer);
|
jpayne@69
|
94
|
jpayne@69
|
95 /* Gets the CT logs that are trusted sources of SCTs */
|
jpayne@69
|
96 const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *ctx);
|
jpayne@69
|
97
|
jpayne@69
|
98 /* Sets the log store that is in use. It must outlive the CT_POLICY_EVAL_CTX. */
|
jpayne@69
|
99 void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
|
jpayne@69
|
100 CTLOG_STORE *log_store);
|
jpayne@69
|
101
|
jpayne@69
|
102 /*
|
jpayne@69
|
103 * Gets the time, in milliseconds since the Unix epoch, that will be used as the
|
jpayne@69
|
104 * current time when checking whether an SCT was issued in the future.
|
jpayne@69
|
105 * Such SCTs will fail validation, as required by RFC6962.
|
jpayne@69
|
106 */
|
jpayne@69
|
107 uint64_t CT_POLICY_EVAL_CTX_get_time(const CT_POLICY_EVAL_CTX *ctx);
|
jpayne@69
|
108
|
jpayne@69
|
109 /*
|
jpayne@69
|
110 * Sets the time to evaluate SCTs against, in milliseconds since the Unix epoch.
|
jpayne@69
|
111 * If an SCT's timestamp is after this time, it will be interpreted as having
|
jpayne@69
|
112 * been issued in the future. RFC6962 states that "TLS clients MUST reject SCTs
|
jpayne@69
|
113 * whose timestamp is in the future", so an SCT will not validate in this case.
|
jpayne@69
|
114 */
|
jpayne@69
|
115 void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms);
|
jpayne@69
|
116
|
jpayne@69
|
117 /*****************
|
jpayne@69
|
118 * SCT functions *
|
jpayne@69
|
119 *****************/
|
jpayne@69
|
120
|
jpayne@69
|
121 /*
|
jpayne@69
|
122 * Creates a new, blank SCT.
|
jpayne@69
|
123 * The caller is responsible for calling SCT_free when finished with the SCT.
|
jpayne@69
|
124 */
|
jpayne@69
|
125 SCT *SCT_new(void);
|
jpayne@69
|
126
|
jpayne@69
|
127 /*
|
jpayne@69
|
128 * Creates a new SCT from some base64-encoded strings.
|
jpayne@69
|
129 * The caller is responsible for calling SCT_free when finished with the SCT.
|
jpayne@69
|
130 */
|
jpayne@69
|
131 SCT *SCT_new_from_base64(unsigned char version,
|
jpayne@69
|
132 const char *logid_base64,
|
jpayne@69
|
133 ct_log_entry_type_t entry_type,
|
jpayne@69
|
134 uint64_t timestamp,
|
jpayne@69
|
135 const char *extensions_base64,
|
jpayne@69
|
136 const char *signature_base64);
|
jpayne@69
|
137
|
jpayne@69
|
138 /*
|
jpayne@69
|
139 * Frees the SCT and the underlying data structures.
|
jpayne@69
|
140 */
|
jpayne@69
|
141 void SCT_free(SCT *sct);
|
jpayne@69
|
142
|
jpayne@69
|
143 /*
|
jpayne@69
|
144 * Free a stack of SCTs, and the underlying SCTs themselves.
|
jpayne@69
|
145 * Intended to be compatible with X509V3_EXT_FREE.
|
jpayne@69
|
146 */
|
jpayne@69
|
147 void SCT_LIST_free(STACK_OF(SCT) *a);
|
jpayne@69
|
148
|
jpayne@69
|
149 /*
|
jpayne@69
|
150 * Returns the version of the SCT.
|
jpayne@69
|
151 */
|
jpayne@69
|
152 sct_version_t SCT_get_version(const SCT *sct);
|
jpayne@69
|
153
|
jpayne@69
|
154 /*
|
jpayne@69
|
155 * Set the version of an SCT.
|
jpayne@69
|
156 * Returns 1 on success, 0 if the version is unrecognized.
|
jpayne@69
|
157 */
|
jpayne@69
|
158 __owur int SCT_set_version(SCT *sct, sct_version_t version);
|
jpayne@69
|
159
|
jpayne@69
|
160 /*
|
jpayne@69
|
161 * Returns the log entry type of the SCT.
|
jpayne@69
|
162 */
|
jpayne@69
|
163 ct_log_entry_type_t SCT_get_log_entry_type(const SCT *sct);
|
jpayne@69
|
164
|
jpayne@69
|
165 /*
|
jpayne@69
|
166 * Set the log entry type of an SCT.
|
jpayne@69
|
167 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
168 */
|
jpayne@69
|
169 __owur int SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type);
|
jpayne@69
|
170
|
jpayne@69
|
171 /*
|
jpayne@69
|
172 * Gets the ID of the log that an SCT came from.
|
jpayne@69
|
173 * Ownership of the log ID remains with the SCT.
|
jpayne@69
|
174 * Returns the length of the log ID.
|
jpayne@69
|
175 */
|
jpayne@69
|
176 size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id);
|
jpayne@69
|
177
|
jpayne@69
|
178 /*
|
jpayne@69
|
179 * Set the log ID of an SCT to point directly to the *log_id specified.
|
jpayne@69
|
180 * The SCT takes ownership of the specified pointer.
|
jpayne@69
|
181 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
182 */
|
jpayne@69
|
183 __owur int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len);
|
jpayne@69
|
184
|
jpayne@69
|
185 /*
|
jpayne@69
|
186 * Set the log ID of an SCT.
|
jpayne@69
|
187 * This makes a copy of the log_id.
|
jpayne@69
|
188 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
189 */
|
jpayne@69
|
190 __owur int SCT_set1_log_id(SCT *sct, const unsigned char *log_id,
|
jpayne@69
|
191 size_t log_id_len);
|
jpayne@69
|
192
|
jpayne@69
|
193 /*
|
jpayne@69
|
194 * Returns the timestamp for the SCT (epoch time in milliseconds).
|
jpayne@69
|
195 */
|
jpayne@69
|
196 uint64_t SCT_get_timestamp(const SCT *sct);
|
jpayne@69
|
197
|
jpayne@69
|
198 /*
|
jpayne@69
|
199 * Set the timestamp of an SCT (epoch time in milliseconds).
|
jpayne@69
|
200 */
|
jpayne@69
|
201 void SCT_set_timestamp(SCT *sct, uint64_t timestamp);
|
jpayne@69
|
202
|
jpayne@69
|
203 /*
|
jpayne@69
|
204 * Return the NID for the signature used by the SCT.
|
jpayne@69
|
205 * For CT v1, this will be either NID_sha256WithRSAEncryption or
|
jpayne@69
|
206 * NID_ecdsa_with_SHA256 (or NID_undef if incorrect/unset).
|
jpayne@69
|
207 */
|
jpayne@69
|
208 int SCT_get_signature_nid(const SCT *sct);
|
jpayne@69
|
209
|
jpayne@69
|
210 /*
|
jpayne@69
|
211 * Set the signature type of an SCT
|
jpayne@69
|
212 * For CT v1, this should be either NID_sha256WithRSAEncryption or
|
jpayne@69
|
213 * NID_ecdsa_with_SHA256.
|
jpayne@69
|
214 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
215 */
|
jpayne@69
|
216 __owur int SCT_set_signature_nid(SCT *sct, int nid);
|
jpayne@69
|
217
|
jpayne@69
|
218 /*
|
jpayne@69
|
219 * Set *ext to point to the extension data for the SCT. ext must not be NULL.
|
jpayne@69
|
220 * The SCT retains ownership of this pointer.
|
jpayne@69
|
221 * Returns length of the data pointed to.
|
jpayne@69
|
222 */
|
jpayne@69
|
223 size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext);
|
jpayne@69
|
224
|
jpayne@69
|
225 /*
|
jpayne@69
|
226 * Set the extensions of an SCT to point directly to the *ext specified.
|
jpayne@69
|
227 * The SCT takes ownership of the specified pointer.
|
jpayne@69
|
228 */
|
jpayne@69
|
229 void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len);
|
jpayne@69
|
230
|
jpayne@69
|
231 /*
|
jpayne@69
|
232 * Set the extensions of an SCT.
|
jpayne@69
|
233 * This takes a copy of the ext.
|
jpayne@69
|
234 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
235 */
|
jpayne@69
|
236 __owur int SCT_set1_extensions(SCT *sct, const unsigned char *ext,
|
jpayne@69
|
237 size_t ext_len);
|
jpayne@69
|
238
|
jpayne@69
|
239 /*
|
jpayne@69
|
240 * Set *sig to point to the signature for the SCT. sig must not be NULL.
|
jpayne@69
|
241 * The SCT retains ownership of this pointer.
|
jpayne@69
|
242 * Returns length of the data pointed to.
|
jpayne@69
|
243 */
|
jpayne@69
|
244 size_t SCT_get0_signature(const SCT *sct, unsigned char **sig);
|
jpayne@69
|
245
|
jpayne@69
|
246 /*
|
jpayne@69
|
247 * Set the signature of an SCT to point directly to the *sig specified.
|
jpayne@69
|
248 * The SCT takes ownership of the specified pointer.
|
jpayne@69
|
249 */
|
jpayne@69
|
250 void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len);
|
jpayne@69
|
251
|
jpayne@69
|
252 /*
|
jpayne@69
|
253 * Set the signature of an SCT to be a copy of the *sig specified.
|
jpayne@69
|
254 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
255 */
|
jpayne@69
|
256 __owur int SCT_set1_signature(SCT *sct, const unsigned char *sig,
|
jpayne@69
|
257 size_t sig_len);
|
jpayne@69
|
258
|
jpayne@69
|
259 /*
|
jpayne@69
|
260 * The origin of this SCT, e.g. TLS extension, OCSP response, etc.
|
jpayne@69
|
261 */
|
jpayne@69
|
262 sct_source_t SCT_get_source(const SCT *sct);
|
jpayne@69
|
263
|
jpayne@69
|
264 /*
|
jpayne@69
|
265 * Set the origin of this SCT, e.g. TLS extension, OCSP response, etc.
|
jpayne@69
|
266 * Returns 1 on success, 0 otherwise.
|
jpayne@69
|
267 */
|
jpayne@69
|
268 __owur int SCT_set_source(SCT *sct, sct_source_t source);
|
jpayne@69
|
269
|
jpayne@69
|
270 /*
|
jpayne@69
|
271 * Returns a text string describing the validation status of |sct|.
|
jpayne@69
|
272 */
|
jpayne@69
|
273 const char *SCT_validation_status_string(const SCT *sct);
|
jpayne@69
|
274
|
jpayne@69
|
275 /*
|
jpayne@69
|
276 * Pretty-prints an |sct| to |out|.
|
jpayne@69
|
277 * It will be indented by the number of spaces specified by |indent|.
|
jpayne@69
|
278 * If |logs| is not NULL, it will be used to lookup the CT log that the SCT came
|
jpayne@69
|
279 * from, so that the log name can be printed.
|
jpayne@69
|
280 */
|
jpayne@69
|
281 void SCT_print(const SCT *sct, BIO *out, int indent, const CTLOG_STORE *logs);
|
jpayne@69
|
282
|
jpayne@69
|
283 /*
|
jpayne@69
|
284 * Pretty-prints an |sct_list| to |out|.
|
jpayne@69
|
285 * It will be indented by the number of spaces specified by |indent|.
|
jpayne@69
|
286 * SCTs will be delimited by |separator|.
|
jpayne@69
|
287 * If |logs| is not NULL, it will be used to lookup the CT log that each SCT
|
jpayne@69
|
288 * came from, so that the log names can be printed.
|
jpayne@69
|
289 */
|
jpayne@69
|
290 void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent,
|
jpayne@69
|
291 const char *separator, const CTLOG_STORE *logs);
|
jpayne@69
|
292
|
jpayne@69
|
293 /*
|
jpayne@69
|
294 * Gets the last result of validating this SCT.
|
jpayne@69
|
295 * If it has not been validated yet, returns SCT_VALIDATION_STATUS_NOT_SET.
|
jpayne@69
|
296 */
|
jpayne@69
|
297 sct_validation_status_t SCT_get_validation_status(const SCT *sct);
|
jpayne@69
|
298
|
jpayne@69
|
299 /*
|
jpayne@69
|
300 * Validates the given SCT with the provided context.
|
jpayne@69
|
301 * Sets the "validation_status" field of the SCT.
|
jpayne@69
|
302 * Returns 1 if the SCT is valid and the signature verifies.
|
jpayne@69
|
303 * Returns 0 if the SCT is invalid or could not be verified.
|
jpayne@69
|
304 * Returns -1 if an error occurs.
|
jpayne@69
|
305 */
|
jpayne@69
|
306 __owur int SCT_validate(SCT *sct, const CT_POLICY_EVAL_CTX *ctx);
|
jpayne@69
|
307
|
jpayne@69
|
308 /*
|
jpayne@69
|
309 * Validates the given list of SCTs with the provided context.
|
jpayne@69
|
310 * Sets the "validation_status" field of each SCT.
|
jpayne@69
|
311 * Returns 1 if there are no invalid SCTs and all signatures verify.
|
jpayne@69
|
312 * Returns 0 if at least one SCT is invalid or could not be verified.
|
jpayne@69
|
313 * Returns a negative integer if an error occurs.
|
jpayne@69
|
314 */
|
jpayne@69
|
315 __owur int SCT_LIST_validate(const STACK_OF(SCT) *scts,
|
jpayne@69
|
316 CT_POLICY_EVAL_CTX *ctx);
|
jpayne@69
|
317
|
jpayne@69
|
318
|
jpayne@69
|
319 /*********************************
|
jpayne@69
|
320 * SCT parsing and serialisation *
|
jpayne@69
|
321 *********************************/
|
jpayne@69
|
322
|
jpayne@69
|
323 /*
|
jpayne@69
|
324 * Serialize (to TLS format) a stack of SCTs and return the length.
|
jpayne@69
|
325 * "a" must not be NULL.
|
jpayne@69
|
326 * If "pp" is NULL, just return the length of what would have been serialized.
|
jpayne@69
|
327 * If "pp" is not NULL and "*pp" is null, function will allocate a new pointer
|
jpayne@69
|
328 * for data that caller is responsible for freeing (only if function returns
|
jpayne@69
|
329 * successfully).
|
jpayne@69
|
330 * If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring
|
jpayne@69
|
331 * that "*pp" is large enough to accept all of the serialized data.
|
jpayne@69
|
332 * Returns < 0 on error, >= 0 indicating bytes written (or would have been)
|
jpayne@69
|
333 * on success.
|
jpayne@69
|
334 */
|
jpayne@69
|
335 __owur int i2o_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp);
|
jpayne@69
|
336
|
jpayne@69
|
337 /*
|
jpayne@69
|
338 * Convert TLS format SCT list to a stack of SCTs.
|
jpayne@69
|
339 * If "a" or "*a" is NULL, a new stack will be created that the caller is
|
jpayne@69
|
340 * responsible for freeing (by calling SCT_LIST_free).
|
jpayne@69
|
341 * "**pp" and "*pp" must not be NULL.
|
jpayne@69
|
342 * Upon success, "*pp" will point to after the last bytes read, and a stack
|
jpayne@69
|
343 * will be returned.
|
jpayne@69
|
344 * Upon failure, a NULL pointer will be returned, and the position of "*pp" is
|
jpayne@69
|
345 * not defined.
|
jpayne@69
|
346 */
|
jpayne@69
|
347 STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,
|
jpayne@69
|
348 size_t len);
|
jpayne@69
|
349
|
jpayne@69
|
350 /*
|
jpayne@69
|
351 * Serialize (to DER format) a stack of SCTs and return the length.
|
jpayne@69
|
352 * "a" must not be NULL.
|
jpayne@69
|
353 * If "pp" is NULL, just returns the length of what would have been serialized.
|
jpayne@69
|
354 * If "pp" is not NULL and "*pp" is null, function will allocate a new pointer
|
jpayne@69
|
355 * for data that caller is responsible for freeing (only if function returns
|
jpayne@69
|
356 * successfully).
|
jpayne@69
|
357 * If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring
|
jpayne@69
|
358 * that "*pp" is large enough to accept all of the serialized data.
|
jpayne@69
|
359 * Returns < 0 on error, >= 0 indicating bytes written (or would have been)
|
jpayne@69
|
360 * on success.
|
jpayne@69
|
361 */
|
jpayne@69
|
362 __owur int i2d_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp);
|
jpayne@69
|
363
|
jpayne@69
|
364 /*
|
jpayne@69
|
365 * Parses an SCT list in DER format and returns it.
|
jpayne@69
|
366 * If "a" or "*a" is NULL, a new stack will be created that the caller is
|
jpayne@69
|
367 * responsible for freeing (by calling SCT_LIST_free).
|
jpayne@69
|
368 * "**pp" and "*pp" must not be NULL.
|
jpayne@69
|
369 * Upon success, "*pp" will point to after the last bytes read, and a stack
|
jpayne@69
|
370 * will be returned.
|
jpayne@69
|
371 * Upon failure, a NULL pointer will be returned, and the position of "*pp" is
|
jpayne@69
|
372 * not defined.
|
jpayne@69
|
373 */
|
jpayne@69
|
374 STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,
|
jpayne@69
|
375 long len);
|
jpayne@69
|
376
|
jpayne@69
|
377 /*
|
jpayne@69
|
378 * Serialize (to TLS format) an |sct| and write it to |out|.
|
jpayne@69
|
379 * If |out| is null, no SCT will be output but the length will still be returned.
|
jpayne@69
|
380 * If |out| points to a null pointer, a string will be allocated to hold the
|
jpayne@69
|
381 * TLS-format SCT. It is the responsibility of the caller to free it.
|
jpayne@69
|
382 * If |out| points to an allocated string, the TLS-format SCT will be written
|
jpayne@69
|
383 * to it.
|
jpayne@69
|
384 * The length of the SCT in TLS format will be returned.
|
jpayne@69
|
385 */
|
jpayne@69
|
386 __owur int i2o_SCT(const SCT *sct, unsigned char **out);
|
jpayne@69
|
387
|
jpayne@69
|
388 /*
|
jpayne@69
|
389 * Parses an SCT in TLS format and returns it.
|
jpayne@69
|
390 * If |psct| is not null, it will end up pointing to the parsed SCT. If it
|
jpayne@69
|
391 * already points to a non-null pointer, the pointer will be free'd.
|
jpayne@69
|
392 * |in| should be a pointer to a string containing the TLS-format SCT.
|
jpayne@69
|
393 * |in| will be advanced to the end of the SCT if parsing succeeds.
|
jpayne@69
|
394 * |len| should be the length of the SCT in |in|.
|
jpayne@69
|
395 * Returns NULL if an error occurs.
|
jpayne@69
|
396 * If the SCT is an unsupported version, only the SCT's 'sct' and 'sct_len'
|
jpayne@69
|
397 * fields will be populated (with |in| and |len| respectively).
|
jpayne@69
|
398 */
|
jpayne@69
|
399 SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len);
|
jpayne@69
|
400
|
jpayne@69
|
401 /********************
|
jpayne@69
|
402 * CT log functions *
|
jpayne@69
|
403 ********************/
|
jpayne@69
|
404
|
jpayne@69
|
405 /*
|
jpayne@69
|
406 * Creates a new CT log instance with the given |public_key| and |name|.
|
jpayne@69
|
407 * Takes ownership of |public_key| but copies |name|.
|
jpayne@69
|
408 * Returns NULL if malloc fails or if |public_key| cannot be converted to DER.
|
jpayne@69
|
409 * Should be deleted by the caller using CTLOG_free when no longer needed.
|
jpayne@69
|
410 */
|
jpayne@69
|
411 CTLOG *CTLOG_new(EVP_PKEY *public_key, const char *name);
|
jpayne@69
|
412
|
jpayne@69
|
413 /*
|
jpayne@69
|
414 * Creates a new CTLOG instance with the base64-encoded SubjectPublicKeyInfo DER
|
jpayne@69
|
415 * in |pkey_base64|. The |name| is a string to help users identify this log.
|
jpayne@69
|
416 * Returns 1 on success, 0 on failure.
|
jpayne@69
|
417 * Should be deleted by the caller using CTLOG_free when no longer needed.
|
jpayne@69
|
418 */
|
jpayne@69
|
419 int CTLOG_new_from_base64(CTLOG ** ct_log,
|
jpayne@69
|
420 const char *pkey_base64, const char *name);
|
jpayne@69
|
421
|
jpayne@69
|
422 /*
|
jpayne@69
|
423 * Deletes a CT log instance and its fields.
|
jpayne@69
|
424 */
|
jpayne@69
|
425 void CTLOG_free(CTLOG *log);
|
jpayne@69
|
426
|
jpayne@69
|
427 /* Gets the name of the CT log */
|
jpayne@69
|
428 const char *CTLOG_get0_name(const CTLOG *log);
|
jpayne@69
|
429 /* Gets the ID of the CT log */
|
jpayne@69
|
430 void CTLOG_get0_log_id(const CTLOG *log, const uint8_t **log_id,
|
jpayne@69
|
431 size_t *log_id_len);
|
jpayne@69
|
432 /* Gets the public key of the CT log */
|
jpayne@69
|
433 EVP_PKEY *CTLOG_get0_public_key(const CTLOG *log);
|
jpayne@69
|
434
|
jpayne@69
|
435 /**************************
|
jpayne@69
|
436 * CT log store functions *
|
jpayne@69
|
437 **************************/
|
jpayne@69
|
438
|
jpayne@69
|
439 /*
|
jpayne@69
|
440 * Creates a new CT log store.
|
jpayne@69
|
441 * Should be deleted by the caller using CTLOG_STORE_free when no longer needed.
|
jpayne@69
|
442 */
|
jpayne@69
|
443 CTLOG_STORE *CTLOG_STORE_new(void);
|
jpayne@69
|
444
|
jpayne@69
|
445 /*
|
jpayne@69
|
446 * Deletes a CT log store and all of the CT log instances held within.
|
jpayne@69
|
447 */
|
jpayne@69
|
448 void CTLOG_STORE_free(CTLOG_STORE *store);
|
jpayne@69
|
449
|
jpayne@69
|
450 /*
|
jpayne@69
|
451 * Finds a CT log in the store based on its log ID.
|
jpayne@69
|
452 * Returns the CT log, or NULL if no match is found.
|
jpayne@69
|
453 */
|
jpayne@69
|
454 const CTLOG *CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store,
|
jpayne@69
|
455 const uint8_t *log_id,
|
jpayne@69
|
456 size_t log_id_len);
|
jpayne@69
|
457
|
jpayne@69
|
458 /*
|
jpayne@69
|
459 * Loads a CT log list into a |store| from a |file|.
|
jpayne@69
|
460 * Returns 1 if loading is successful, or 0 otherwise.
|
jpayne@69
|
461 */
|
jpayne@69
|
462 __owur int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file);
|
jpayne@69
|
463
|
jpayne@69
|
464 /*
|
jpayne@69
|
465 * Loads the default CT log list into a |store|.
|
jpayne@69
|
466 * Returns 1 if loading is successful, or 0 otherwise.
|
jpayne@69
|
467 */
|
jpayne@69
|
468 __owur int CTLOG_STORE_load_default_file(CTLOG_STORE *store);
|
jpayne@69
|
469
|
jpayne@69
|
470 # ifdef __cplusplus
|
jpayne@69
|
471 }
|
jpayne@69
|
472 # endif
|
jpayne@69
|
473 # endif
|
jpayne@69
|
474 #endif
|