1/*
2 * WARNING: do not edit!
3 * Generated by Makefile from include/openssl/ct.h.in
4 *
5 * Copyright 2016-2026 The OpenSSL Project Authors. All Rights Reserved.
6 *
7 * Licensed under the Apache License 2.0 (the "License"). You may not use
8 * this file except in compliance with the License. You can obtain a copy
9 * in the file LICENSE in the source distribution or at
10 * https://www.openssl.org/source/license.html
11 */
12
13/* clang-format off */
14
15/* clang-format on */
16
17#ifndef OPENSSL_CT_H
18#define OPENSSL_CT_H
19#pragma once
20
21#include <openssl/macros.h>
22#ifndef OPENSSL_NO_DEPRECATED_3_0
23#define HEADER_CT_H
24#endif
25
26#include <openssl/opensslconf.h>
27
28#ifndef OPENSSL_NO_CT
29#include <openssl/types.h>
30#include <openssl/safestack.h>
31#include <openssl/x509.h>
32#include <openssl/cterr.h>
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/* Minimum RSA key size, from RFC6962 */
38#define SCT_MIN_RSA_BITS 2048
39
40/* All hashes are SHA256 in v1 of Certificate Transparency */
41#define CT_V1_HASHLEN SHA256_DIGEST_LENGTH
42
43/* clang-format off */
44SKM_DEFINE_STACK_OF_INTERNAL(SCT, SCT, SCT)
45#define sk_SCT_num(sk) OPENSSL_sk_num(ossl_check_const_SCT_sk_type(sk))
46#define sk_SCT_value(sk, idx) ((SCT *)OPENSSL_sk_value(ossl_check_const_SCT_sk_type(sk), (idx)))
47#define sk_SCT_new(cmp) \
48 ((STACK_OF(SCT) *)OPENSSL_sk_set_thunks( \
49 OPENSSL_sk_set_copy_thunks( \
50 OPENSSL_sk_set_cmp_thunks( \
51 OPENSSL_sk_new(ossl_check_SCT_compfunc_type(cmp)), \
52 sk_SCT_cmpfunc_thunk), \
53 sk_SCT_copyfunc_thunk), \
54 sk_SCT_freefunc_thunk))
55#define sk_SCT_new_null() \
56 ((STACK_OF(SCT) *)OPENSSL_sk_set_thunks( \
57 OPENSSL_sk_set_copy_thunks( \
58 OPENSSL_sk_set_cmp_thunks( \
59 OPENSSL_sk_new_null(), \
60 sk_SCT_cmpfunc_thunk), \
61 sk_SCT_copyfunc_thunk), \
62 sk_SCT_freefunc_thunk))
63#define sk_SCT_new_reserve(cmp, n) \
64 ((STACK_OF(SCT) *)OPENSSL_sk_set_thunks( \
65 OPENSSL_sk_set_copy_thunks( \
66 OPENSSL_sk_set_cmp_thunks( \
67 OPENSSL_sk_new_reserve(ossl_check_SCT_compfunc_type(cmp), (n)), \
68 sk_SCT_cmpfunc_thunk), \
69 sk_SCT_copyfunc_thunk), \
70 sk_SCT_freefunc_thunk))
71#define sk_SCT_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SCT_sk_type(sk), (n))
72#define sk_SCT_free(sk) OPENSSL_sk_free(ossl_check_SCT_sk_type(sk))
73#define sk_SCT_zero(sk) OPENSSL_sk_zero(ossl_check_SCT_sk_type(sk))
74#define sk_SCT_delete(sk, i) ((SCT *)OPENSSL_sk_delete(ossl_check_SCT_sk_type(sk), (i)))
75#define sk_SCT_delete_ptr(sk, ptr) ((SCT *)OPENSSL_sk_delete_ptr(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr)))
76#define sk_SCT_push(sk, ptr) OPENSSL_sk_push(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr))
77#define sk_SCT_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr))
78#define sk_SCT_pop(sk) ((SCT *)OPENSSL_sk_pop(ossl_check_SCT_sk_type(sk)))
79#define sk_SCT_shift(sk) ((SCT *)OPENSSL_sk_shift(ossl_check_SCT_sk_type(sk)))
80#define sk_SCT_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SCT_sk_type(sk), ossl_check_SCT_freefunc_type(freefunc))
81#define sk_SCT_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr), (idx))
82#define sk_SCT_set(sk, idx, ptr) ((SCT *)OPENSSL_sk_set(ossl_check_SCT_sk_type(sk), (idx), ossl_check_SCT_type(ptr)))
83#define sk_SCT_find(sk, ptr) OPENSSL_sk_find(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr))
84#define sk_SCT_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr))
85#define sk_SCT_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr), pnum)
86#define sk_SCT_sort(sk) OPENSSL_sk_sort(ossl_check_SCT_sk_type(sk))
87#define sk_SCT_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SCT_sk_type(sk))
88#define sk_SCT_dup(sk) \
89 ((STACK_OF(SCT) *)OPENSSL_sk_set_thunks( \
90 OPENSSL_sk_set_copy_thunks( \
91 OPENSSL_sk_set_cmp_thunks( \
92 OPENSSL_sk_dup(ossl_check_const_SCT_sk_type(sk)), \
93 sk_SCT_cmpfunc_thunk), \
94 sk_SCT_copyfunc_thunk), \
95 sk_SCT_freefunc_thunk))
96#define sk_SCT_deep_copy(sk, copyfunc, freefunc) \
97 ((STACK_OF(SCT) *)OPENSSL_sk_set_thunks( \
98 OPENSSL_sk_set_copy_thunks( \
99 OPENSSL_sk_set_cmp_thunks( \
100 OPENSSL_sk_deep_copy( \
101 ossl_check_const_SCT_sk_type(sk), \
102 ossl_check_SCT_copyfunc_type(copyfunc), \
103 ossl_check_SCT_freefunc_type(freefunc)), \
104 sk_SCT_cmpfunc_thunk), \
105 sk_SCT_copyfunc_thunk), \
106 sk_SCT_freefunc_thunk))
107#define sk_SCT_set_cmp_func(sk, cmp) ((sk_SCT_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SCT_sk_type(sk), ossl_check_SCT_compfunc_type(cmp)))
108SKM_DEFINE_STACK_OF_INTERNAL(CTLOG, CTLOG, CTLOG)
109#define sk_CTLOG_num(sk) OPENSSL_sk_num(ossl_check_const_CTLOG_sk_type(sk))
110#define sk_CTLOG_value(sk, idx) ((CTLOG *)OPENSSL_sk_value(ossl_check_const_CTLOG_sk_type(sk), (idx)))
111#define sk_CTLOG_new(cmp) \
112 ((STACK_OF(CTLOG) *)OPENSSL_sk_set_thunks( \
113 OPENSSL_sk_set_copy_thunks( \
114 OPENSSL_sk_set_cmp_thunks( \
115 OPENSSL_sk_new(ossl_check_CTLOG_compfunc_type(cmp)), \
116 sk_CTLOG_cmpfunc_thunk), \
117 sk_CTLOG_copyfunc_thunk), \
118 sk_CTLOG_freefunc_thunk))
119#define sk_CTLOG_new_null() \
120 ((STACK_OF(CTLOG) *)OPENSSL_sk_set_thunks( \
121 OPENSSL_sk_set_copy_thunks( \
122 OPENSSL_sk_set_cmp_thunks( \
123 OPENSSL_sk_new_null(), \
124 sk_CTLOG_cmpfunc_thunk), \
125 sk_CTLOG_copyfunc_thunk), \
126 sk_CTLOG_freefunc_thunk))
127#define sk_CTLOG_new_reserve(cmp, n) \
128 ((STACK_OF(CTLOG) *)OPENSSL_sk_set_thunks( \
129 OPENSSL_sk_set_copy_thunks( \
130 OPENSSL_sk_set_cmp_thunks( \
131 OPENSSL_sk_new_reserve(ossl_check_CTLOG_compfunc_type(cmp), (n)), \
132 sk_CTLOG_cmpfunc_thunk), \
133 sk_CTLOG_copyfunc_thunk), \
134 sk_CTLOG_freefunc_thunk))
135#define sk_CTLOG_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_CTLOG_sk_type(sk), (n))
136#define sk_CTLOG_free(sk) OPENSSL_sk_free(ossl_check_CTLOG_sk_type(sk))
137#define sk_CTLOG_zero(sk) OPENSSL_sk_zero(ossl_check_CTLOG_sk_type(sk))
138#define sk_CTLOG_delete(sk, i) ((CTLOG *)OPENSSL_sk_delete(ossl_check_CTLOG_sk_type(sk), (i)))
139#define sk_CTLOG_delete_ptr(sk, ptr) ((CTLOG *)OPENSSL_sk_delete_ptr(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr)))
140#define sk_CTLOG_push(sk, ptr) OPENSSL_sk_push(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr))
141#define sk_CTLOG_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr))
142#define sk_CTLOG_pop(sk) ((CTLOG *)OPENSSL_sk_pop(ossl_check_CTLOG_sk_type(sk)))
143#define sk_CTLOG_shift(sk) ((CTLOG *)OPENSSL_sk_shift(ossl_check_CTLOG_sk_type(sk)))
144#define sk_CTLOG_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_freefunc_type(freefunc))
145#define sk_CTLOG_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr), (idx))
146#define sk_CTLOG_set(sk, idx, ptr) ((CTLOG *)OPENSSL_sk_set(ossl_check_CTLOG_sk_type(sk), (idx), ossl_check_CTLOG_type(ptr)))
147#define sk_CTLOG_find(sk, ptr) OPENSSL_sk_find(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr))
148#define sk_CTLOG_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr))
149#define sk_CTLOG_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr), pnum)
150#define sk_CTLOG_sort(sk) OPENSSL_sk_sort(ossl_check_CTLOG_sk_type(sk))
151#define sk_CTLOG_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_CTLOG_sk_type(sk))
152#define sk_CTLOG_dup(sk) \
153 ((STACK_OF(CTLOG) *)OPENSSL_sk_set_thunks( \
154 OPENSSL_sk_set_copy_thunks( \
155 OPENSSL_sk_set_cmp_thunks( \
156 OPENSSL_sk_dup(ossl_check_const_CTLOG_sk_type(sk)), \
157 sk_CTLOG_cmpfunc_thunk), \
158 sk_CTLOG_copyfunc_thunk), \
159 sk_CTLOG_freefunc_thunk))
160#define sk_CTLOG_deep_copy(sk, copyfunc, freefunc) \
161 ((STACK_OF(CTLOG) *)OPENSSL_sk_set_thunks( \
162 OPENSSL_sk_set_copy_thunks( \
163 OPENSSL_sk_set_cmp_thunks( \
164 OPENSSL_sk_deep_copy( \
165 ossl_check_const_CTLOG_sk_type(sk), \
166 ossl_check_CTLOG_copyfunc_type(copyfunc), \
167 ossl_check_CTLOG_freefunc_type(freefunc)), \
168 sk_CTLOG_cmpfunc_thunk), \
169 sk_CTLOG_copyfunc_thunk), \
170 sk_CTLOG_freefunc_thunk))
171#define sk_CTLOG_set_cmp_func(sk, cmp) ((sk_CTLOG_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_compfunc_type(cmp)))
172
173/* clang-format on */
174
175typedef enum {
176 CT_LOG_ENTRY_TYPE_NOT_SET = -1,
177 CT_LOG_ENTRY_TYPE_X509 = 0,
178 CT_LOG_ENTRY_TYPE_PRECERT = 1
179} ct_log_entry_type_t;
180
181typedef enum {
182 SCT_VERSION_NOT_SET = -1,
183 SCT_VERSION_V1 = 0
184} sct_version_t;
185
186typedef enum {
187 SCT_SOURCE_UNKNOWN,
188 SCT_SOURCE_TLS_EXTENSION,
189 SCT_SOURCE_X509V3_EXTENSION,
190 SCT_SOURCE_OCSP_STAPLED_RESPONSE
191} sct_source_t;
192
193typedef enum {
194 SCT_VALIDATION_STATUS_NOT_SET,
195 SCT_VALIDATION_STATUS_UNKNOWN_LOG,
196 SCT_VALIDATION_STATUS_VALID,
197 SCT_VALIDATION_STATUS_INVALID,
198 SCT_VALIDATION_STATUS_UNVERIFIED,
199 SCT_VALIDATION_STATUS_UNKNOWN_VERSION
200} sct_validation_status_t;
201
202/******************************************
203 * CT policy evaluation context functions *
204 ******************************************/
205
206/*
207 * Creates a new, empty policy evaluation context associated with the given
208 * library context and property query string.
209 * The caller is responsible for calling CT_POLICY_EVAL_CTX_free when finished
210 * with the CT_POLICY_EVAL_CTX.
211 */
212CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new_ex(OSSL_LIB_CTX *libctx,
213 const char *propq);
214
215/*
216 * The same as CT_POLICY_EVAL_CTX_new_ex() but the default library
217 * context and property query string is used.
218 */
219CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void);
220
221/* Deletes a policy evaluation context and anything it owns. */
222void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx);
223
224/* Gets the peer certificate that the SCTs are for */
225X509 *CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx);
226
227/*
228 * Sets the certificate associated with the received SCTs.
229 * Increments the reference count of cert.
230 * Returns 1 on success, 0 otherwise.
231 */
232int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert);
233
234/* Gets the issuer of the aforementioned certificate */
235X509 *CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx);
236
237/*
238 * Sets the issuer of the certificate associated with the received SCTs.
239 * Increments the reference count of issuer.
240 * Returns 1 on success, 0 otherwise.
241 */
242int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer);
243
244/* Gets the CT logs that are trusted sources of SCTs */
245const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *ctx);
246
247/* Sets the log store that is in use. It must outlive the CT_POLICY_EVAL_CTX. */
248void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
249 CTLOG_STORE *log_store);
250
251/*
252 * Gets the time, in milliseconds since the Unix epoch, that will be used as the
253 * current time when checking whether an SCT was issued in the future.
254 * Such SCTs will fail validation, as required by RFC6962.
255 */
256uint64_t CT_POLICY_EVAL_CTX_get_time(const CT_POLICY_EVAL_CTX *ctx);
257
258/*
259 * Sets the time to evaluate SCTs against, in milliseconds since the Unix epoch.
260 * If an SCT's timestamp is after this time, it will be interpreted as having
261 * been issued in the future. RFC6962 states that "TLS clients MUST reject SCTs
262 * whose timestamp is in the future", so an SCT will not validate in this case.
263 */
264void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms);
265
266/*****************
267 * SCT functions *
268 *****************/
269
270/*
271 * Creates a new, blank SCT.
272 * The caller is responsible for calling SCT_free when finished with the SCT.
273 */
274SCT *SCT_new(void);
275
276/*
277 * Creates a new SCT from some base64-encoded strings.
278 * The caller is responsible for calling SCT_free when finished with the SCT.
279 */
280SCT *SCT_new_from_base64(unsigned char version,
281 const char *logid_base64,
282 ct_log_entry_type_t entry_type,
283 uint64_t timestamp,
284 const char *extensions_base64,
285 const char *signature_base64);
286
287/*
288 * Frees the SCT and the underlying data structures.
289 */
290void SCT_free(SCT *sct);
291
292/*
293 * Free a stack of SCTs, and the underlying SCTs themselves.
294 * Intended to be compatible with X509V3_EXT_FREE.
295 */
296void SCT_LIST_free(STACK_OF(SCT) *a);
297
298/*
299 * Returns the version of the SCT.
300 */
301sct_version_t SCT_get_version(const SCT *sct);
302
303/*
304 * Set the version of an SCT.
305 * Returns 1 on success, 0 if the version is unrecognized.
306 */
307__owur int SCT_set_version(SCT *sct, sct_version_t version);
308
309/*
310 * Returns the log entry type of the SCT.
311 */
312ct_log_entry_type_t SCT_get_log_entry_type(const SCT *sct);
313
314/*
315 * Set the log entry type of an SCT.
316 * Returns 1 on success, 0 otherwise.
317 */
318__owur int SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type);
319
320/*
321 * Gets the ID of the log that an SCT came from.
322 * Ownership of the log ID remains with the SCT.
323 * Returns the length of the log ID.
324 */
325size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id);
326
327/*
328 * Set the log ID of an SCT to point directly to the *log_id specified.
329 * The SCT takes ownership of the specified pointer.
330 * Returns 1 on success, 0 otherwise.
331 */
332__owur int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len);
333
334/*
335 * Set the log ID of an SCT.
336 * This makes a copy of the log_id.
337 * Returns 1 on success, 0 otherwise.
338 */
339__owur int SCT_set1_log_id(SCT *sct, const unsigned char *log_id,
340 size_t log_id_len);
341
342/*
343 * Returns the timestamp for the SCT (epoch time in milliseconds).
344 */
345uint64_t SCT_get_timestamp(const SCT *sct);
346
347/*
348 * Set the timestamp of an SCT (epoch time in milliseconds).
349 */
350void SCT_set_timestamp(SCT *sct, uint64_t timestamp);
351
352/*
353 * Return the NID for the signature used by the SCT.
354 * For CT v1, this will be either NID_sha256WithRSAEncryption or
355 * NID_ecdsa_with_SHA256 (or NID_undef if incorrect/unset).
356 */
357int SCT_get_signature_nid(const SCT *sct);
358
359/*
360 * Set the signature type of an SCT
361 * For CT v1, this should be either NID_sha256WithRSAEncryption or
362 * NID_ecdsa_with_SHA256.
363 * Returns 1 on success, 0 otherwise.
364 */
365__owur int SCT_set_signature_nid(SCT *sct, int nid);
366
367/*
368 * Set *ext to point to the extension data for the SCT. ext must not be NULL.
369 * The SCT retains ownership of this pointer.
370 * Returns length of the data pointed to.
371 */
372size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext);
373
374/*
375 * Set the extensions of an SCT to point directly to the *ext specified.
376 * The SCT takes ownership of the specified pointer.
377 */
378void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len);
379
380/*
381 * Set the extensions of an SCT.
382 * This takes a copy of the ext.
383 * Returns 1 on success, 0 otherwise.
384 */
385__owur int SCT_set1_extensions(SCT *sct, const unsigned char *ext,
386 size_t ext_len);
387
388/*
389 * Set *sig to point to the signature for the SCT. sig must not be NULL.
390 * The SCT retains ownership of this pointer.
391 * Returns length of the data pointed to.
392 */
393size_t SCT_get0_signature(const SCT *sct, unsigned char **sig);
394
395/*
396 * Set the signature of an SCT to point directly to the *sig specified.
397 * The SCT takes ownership of the specified pointer.
398 */
399void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len);
400
401/*
402 * Set the signature of an SCT to be a copy of the *sig specified.
403 * Returns 1 on success, 0 otherwise.
404 */
405__owur int SCT_set1_signature(SCT *sct, const unsigned char *sig,
406 size_t sig_len);
407
408/*
409 * The origin of this SCT, e.g. TLS extension, OCSP response, etc.
410 */
411sct_source_t SCT_get_source(const SCT *sct);
412
413/*
414 * Set the origin of this SCT, e.g. TLS extension, OCSP response, etc.
415 * Returns 1 on success, 0 otherwise.
416 */
417__owur int SCT_set_source(SCT *sct, sct_source_t source);
418
419/*
420 * Returns a text string describing the validation status of |sct|.
421 */
422const char *SCT_validation_status_string(const SCT *sct);
423
424/*
425 * Pretty-prints an |sct| to |out|.
426 * It will be indented by the number of spaces specified by |indent|.
427 * If |logs| is not NULL, it will be used to lookup the CT log that the SCT came
428 * from, so that the log name can be printed.
429 */
430void SCT_print(const SCT *sct, BIO *out, int indent, const CTLOG_STORE *logs);
431
432/*
433 * Pretty-prints an |sct_list| to |out|.
434 * It will be indented by the number of spaces specified by |indent|.
435 * SCTs will be delimited by |separator|.
436 * If |logs| is not NULL, it will be used to lookup the CT log that each SCT
437 * came from, so that the log names can be printed.
438 */
439void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent,
440 const char *separator, const CTLOG_STORE *logs);
441
442/*
443 * Gets the last result of validating this SCT.
444 * If it has not been validated yet, returns SCT_VALIDATION_STATUS_NOT_SET.
445 */
446sct_validation_status_t SCT_get_validation_status(const SCT *sct);
447
448/*
449 * Validates the given SCT with the provided context.
450 * Sets the "validation_status" field of the SCT.
451 * Returns 1 if the SCT is valid and the signature verifies.
452 * Returns 0 if the SCT is invalid or could not be verified.
453 * Returns -1 if an error occurs.
454 */
455__owur int SCT_validate(SCT *sct, const CT_POLICY_EVAL_CTX *ctx);
456
457/*
458 * Validates the given list of SCTs with the provided context.
459 * Sets the "validation_status" field of each SCT.
460 * Returns 1 if there are no invalid SCTs and all signatures verify.
461 * Returns 0 if at least one SCT is invalid or could not be verified.
462 * Returns a negative integer if an error occurs.
463 */
464__owur int SCT_LIST_validate(const STACK_OF(SCT) *scts,
465 CT_POLICY_EVAL_CTX *ctx);
466
467/*********************************
468 * SCT parsing and serialization *
469 *********************************/
470
471/*
472 * Serialize (to TLS format) a stack of SCTs and return the length.
473 * "a" must not be NULL.
474 * If "pp" is NULL, just return the length of what would have been serialized.
475 * If "pp" is not NULL and "*pp" is null, function will allocate a new pointer
476 * for data that caller is responsible for freeing (only if function returns
477 * successfully).
478 * If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring
479 * that "*pp" is large enough to accept all of the serialized data.
480 * Returns < 0 on error, >= 0 indicating bytes written (or would have been)
481 * on success.
482 */
483__owur int i2o_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp);
484
485/*
486 * Convert TLS format SCT list to a stack of SCTs.
487 * If "a" or "*a" is NULL, a new stack will be created that the caller is
488 * responsible for freeing (by calling SCT_LIST_free).
489 * "**pp" and "*pp" must not be NULL.
490 * Upon success, "*pp" will point to after the last bytes read, and a stack
491 * will be returned.
492 * Upon failure, a NULL pointer will be returned, and the position of "*pp" is
493 * not defined.
494 */
495STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,
496 size_t len);
497
498/*
499 * Serialize (to DER format) a stack of SCTs and return the length.
500 * "a" must not be NULL.
501 * If "pp" is NULL, just returns the length of what would have been serialized.
502 * If "pp" is not NULL and "*pp" is null, function will allocate a new pointer
503 * for data that caller is responsible for freeing (only if function returns
504 * successfully).
505 * If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring
506 * that "*pp" is large enough to accept all of the serialized data.
507 * Returns < 0 on error, >= 0 indicating bytes written (or would have been)
508 * on success.
509 */
510__owur int i2d_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp);
511
512/*
513 * Parses an SCT list in DER format and returns it.
514 * If "a" or "*a" is NULL, a new stack will be created that the caller is
515 * responsible for freeing (by calling SCT_LIST_free).
516 * "**pp" and "*pp" must not be NULL.
517 * Upon success, "*pp" will point to after the last bytes read, and a stack
518 * will be returned.
519 * Upon failure, a NULL pointer will be returned, and the position of "*pp" is
520 * not defined.
521 */
522STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,
523 long len);
524
525/*
526 * Serialize (to TLS format) an |sct| and write it to |out|.
527 * If |out| is null, no SCT will be output but the length will still be returned.
528 * If |out| points to a null pointer, a string will be allocated to hold the
529 * TLS-format SCT. It is the responsibility of the caller to free it.
530 * If |out| points to an allocated string, the TLS-format SCT will be written
531 * to it.
532 * The length of the SCT in TLS format will be returned.
533 */
534__owur int i2o_SCT(const SCT *sct, unsigned char **out);
535
536/*
537 * Parses an SCT in TLS format and returns it.
538 * If |psct| is not null, it will end up pointing to the parsed SCT. If it
539 * already points to a non-null pointer, the pointer will be free'd.
540 * |in| should be a pointer to a string containing the TLS-format SCT.
541 * |in| will be advanced to the end of the SCT if parsing succeeds.
542 * |len| should be the length of the SCT in |in|.
543 * Returns NULL if an error occurs.
544 * If the SCT is an unsupported version, only the SCT's 'sct' and 'sct_len'
545 * fields will be populated (with |in| and |len| respectively).
546 */
547SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len);
548
549/********************
550 * CT log functions *
551 ********************/
552
553/*
554 * Creates a new CT log instance with the given |public_key| and |name| and
555 * associates it with the give library context |libctx| and property query
556 * string |propq|.
557 * Takes ownership of |public_key| but copies |name|.
558 * Returns NULL if malloc fails or if |public_key| cannot be converted to DER.
559 * Should be deleted by the caller using CTLOG_free when no longer needed.
560 */
561CTLOG *CTLOG_new_ex(EVP_PKEY *public_key, const char *name, OSSL_LIB_CTX *libctx,
562 const char *propq);
563
564/*
565 * The same as CTLOG_new_ex except that the default library context and
566 * property query string are used.
567 */
568CTLOG *CTLOG_new(EVP_PKEY *public_key, const char *name);
569
570/*
571 * Creates a new CTLOG instance with the base64-encoded SubjectPublicKeyInfo DER
572 * in |pkey_base64| and associated with the given library context |libctx| and
573 * property query string |propq|. The |name| is a string to help users identify
574 * this log.
575 * Returns 1 on success, 0 on failure.
576 * Should be deleted by the caller using CTLOG_free when no longer needed.
577 */
578int CTLOG_new_from_base64_ex(CTLOG **ct_log, const char *pkey_base64,
579 const char *name, OSSL_LIB_CTX *libctx,
580 const char *propq);
581
582/*
583 * The same as CTLOG_new_from_base64_ex() except that the default
584 * library context and property query string are used.
585 * Returns 1 on success, 0 on failure.
586 */
587int CTLOG_new_from_base64(CTLOG **ct_log,
588 const char *pkey_base64, const char *name);
589
590/*
591 * Deletes a CT log instance and its fields.
592 */
593void CTLOG_free(CTLOG *log);
594
595/* Gets the name of the CT log */
596const char *CTLOG_get0_name(const CTLOG *log);
597/* Gets the ID of the CT log */
598void CTLOG_get0_log_id(const CTLOG *log, const uint8_t **log_id,
599 size_t *log_id_len);
600/* Gets the public key of the CT log */
601EVP_PKEY *CTLOG_get0_public_key(const CTLOG *log);
602
603/**************************
604 * CT log store functions *
605 **************************/
606
607/*
608 * Creates a new CT log store and associates it with the given libctx and
609 * property query string.
610 * Should be deleted by the caller using CTLOG_STORE_free when no longer needed.
611 */
612CTLOG_STORE *CTLOG_STORE_new_ex(OSSL_LIB_CTX *libctx, const char *propq);
613
614/*
615 * Same as CTLOG_STORE_new_ex except that the default libctx and
616 * property query string are used.
617 * Should be deleted by the caller using CTLOG_STORE_free when no longer needed.
618 */
619CTLOG_STORE *CTLOG_STORE_new(void);
620
621/*
622 * Deletes a CT log store and all of the CT log instances held within.
623 */
624void CTLOG_STORE_free(CTLOG_STORE *store);
625
626/*
627 * Adds a CT log to a CTLOG_STORE.
628 * Takes ownership of the CTLOG on success - the caller must not free it after
629 * a successful call. On failure, the caller retains ownership.
630 * Returns 1 on success, 0 on failure.
631 */
632__owur int CTLOG_STORE_add0_log(CTLOG_STORE *store, CTLOG *log);
633
634/*
635 * Finds a CT log in the store based on its log ID.
636 * Returns the CT log, or NULL if no match is found.
637 */
638const CTLOG *CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store,
639 const uint8_t *log_id,
640 size_t log_id_len);
641
642/*
643 * Loads a CT log list into a |store| from a |file|.
644 * Returns 1 if loading is successful, or 0 otherwise.
645 */
646__owur int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file);
647
648/*
649 * Loads the default CT log list into a |store|.
650 * Returns 1 if loading is successful, or 0 otherwise.
651 */
652__owur int CTLOG_STORE_load_default_file(CTLOG_STORE *store);
653
654#ifdef __cplusplus
655}
656#endif
657#endif
658#endif
659