19# include <openssl/macros.h>
20# ifndef OPENSSL_NO_DEPRECATED_3_0
24# include <openssl/opensslconf.h>
27# include <openssl/types.h>
28# include <openssl/safestack.h>
29# include <openssl/x509.h>
30# include <openssl/cterr.h>
37# define SCT_MIN_RSA_BITS 2048
40# define CT_V1_HASHLEN SHA256_DIGEST_LENGTH
42SKM_DEFINE_STACK_OF_INTERNAL(SCT, SCT, SCT)
43#define sk_SCT_num(sk) OPENSSL_sk_num(ossl_check_const_SCT_sk_type(sk))
44#define sk_SCT_value(sk, idx) ((SCT *)OPENSSL_sk_value(ossl_check_const_SCT_sk_type(sk), (idx)))
45#define sk_SCT_new(cmp) ((STACK_OF(SCT) *)OPENSSL_sk_new(ossl_check_SCT_compfunc_type(cmp)))
46#define sk_SCT_new_null() ((STACK_OF(SCT) *)OPENSSL_sk_new_null())
47#define sk_SCT_new_reserve(cmp, n) ((STACK_OF(SCT) *)OPENSSL_sk_new_reserve(ossl_check_SCT_compfunc_type(cmp), (n)))
48#define sk_SCT_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SCT_sk_type(sk), (n))
49#define sk_SCT_free(sk) OPENSSL_sk_free(ossl_check_SCT_sk_type(sk))
50#define sk_SCT_zero(sk) OPENSSL_sk_zero(ossl_check_SCT_sk_type(sk))
51#define sk_SCT_delete(sk, i) ((SCT *)OPENSSL_sk_delete(ossl_check_SCT_sk_type(sk), (i)))
52#define sk_SCT_delete_ptr(sk, ptr) ((SCT *)OPENSSL_sk_delete_ptr(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr)))
53#define sk_SCT_push(sk, ptr) OPENSSL_sk_push(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr))
54#define sk_SCT_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr))
55#define sk_SCT_pop(sk) ((SCT *)OPENSSL_sk_pop(ossl_check_SCT_sk_type(sk)))
56#define sk_SCT_shift(sk) ((SCT *)OPENSSL_sk_shift(ossl_check_SCT_sk_type(sk)))
57#define sk_SCT_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SCT_sk_type(sk),ossl_check_SCT_freefunc_type(freefunc))
58#define sk_SCT_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr), (idx))
59#define sk_SCT_set(sk, idx, ptr) ((SCT *)OPENSSL_sk_set(ossl_check_SCT_sk_type(sk), (idx), ossl_check_SCT_type(ptr)))
60#define sk_SCT_find(sk, ptr) OPENSSL_sk_find(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr))
61#define sk_SCT_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr))
62#define sk_SCT_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SCT_sk_type(sk), ossl_check_SCT_type(ptr), pnum)
63#define sk_SCT_sort(sk) OPENSSL_sk_sort(ossl_check_SCT_sk_type(sk))
64#define sk_SCT_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SCT_sk_type(sk))
65#define sk_SCT_dup(sk) ((STACK_OF(SCT) *)OPENSSL_sk_dup(ossl_check_const_SCT_sk_type(sk)))
66#define sk_SCT_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SCT) *)OPENSSL_sk_deep_copy(ossl_check_const_SCT_sk_type(sk), ossl_check_SCT_copyfunc_type(copyfunc), ossl_check_SCT_freefunc_type(freefunc)))
67#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)))
68SKM_DEFINE_STACK_OF_INTERNAL(CTLOG, CTLOG, CTLOG)
69#define sk_CTLOG_num(sk) OPENSSL_sk_num(ossl_check_const_CTLOG_sk_type(sk))
70#define sk_CTLOG_value(sk, idx) ((CTLOG *)OPENSSL_sk_value(ossl_check_const_CTLOG_sk_type(sk), (idx)))
71#define sk_CTLOG_new(cmp) ((STACK_OF(CTLOG) *)OPENSSL_sk_new(ossl_check_CTLOG_compfunc_type(cmp)))
72#define sk_CTLOG_new_null() ((STACK_OF(CTLOG) *)OPENSSL_sk_new_null())
73#define sk_CTLOG_new_reserve(cmp, n) ((STACK_OF(CTLOG) *)OPENSSL_sk_new_reserve(ossl_check_CTLOG_compfunc_type(cmp), (n)))
74#define sk_CTLOG_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_CTLOG_sk_type(sk), (n))
75#define sk_CTLOG_free(sk) OPENSSL_sk_free(ossl_check_CTLOG_sk_type(sk))
76#define sk_CTLOG_zero(sk) OPENSSL_sk_zero(ossl_check_CTLOG_sk_type(sk))
77#define sk_CTLOG_delete(sk, i) ((CTLOG *)OPENSSL_sk_delete(ossl_check_CTLOG_sk_type(sk), (i)))
78#define sk_CTLOG_delete_ptr(sk, ptr) ((CTLOG *)OPENSSL_sk_delete_ptr(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr)))
79#define sk_CTLOG_push(sk, ptr) OPENSSL_sk_push(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr))
80#define sk_CTLOG_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr))
81#define sk_CTLOG_pop(sk) ((CTLOG *)OPENSSL_sk_pop(ossl_check_CTLOG_sk_type(sk)))
82#define sk_CTLOG_shift(sk) ((CTLOG *)OPENSSL_sk_shift(ossl_check_CTLOG_sk_type(sk)))
83#define sk_CTLOG_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_CTLOG_sk_type(sk),ossl_check_CTLOG_freefunc_type(freefunc))
84#define sk_CTLOG_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr), (idx))
85#define sk_CTLOG_set(sk, idx, ptr) ((CTLOG *)OPENSSL_sk_set(ossl_check_CTLOG_sk_type(sk), (idx), ossl_check_CTLOG_type(ptr)))
86#define sk_CTLOG_find(sk, ptr) OPENSSL_sk_find(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr))
87#define sk_CTLOG_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr))
88#define sk_CTLOG_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_type(ptr), pnum)
89#define sk_CTLOG_sort(sk) OPENSSL_sk_sort(ossl_check_CTLOG_sk_type(sk))
90#define sk_CTLOG_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_CTLOG_sk_type(sk))
91#define sk_CTLOG_dup(sk) ((STACK_OF(CTLOG) *)OPENSSL_sk_dup(ossl_check_const_CTLOG_sk_type(sk)))
92#define sk_CTLOG_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(CTLOG) *)OPENSSL_sk_deep_copy(ossl_check_const_CTLOG_sk_type(sk), ossl_check_CTLOG_copyfunc_type(copyfunc), ossl_check_CTLOG_freefunc_type(freefunc)))
93#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)))
98 CT_LOG_ENTRY_TYPE_NOT_SET = -1,
99 CT_LOG_ENTRY_TYPE_X509 = 0,
100 CT_LOG_ENTRY_TYPE_PRECERT = 1
101} ct_log_entry_type_t;
104 SCT_VERSION_NOT_SET = -1,
110 SCT_SOURCE_TLS_EXTENSION,
111 SCT_SOURCE_X509V3_EXTENSION,
112 SCT_SOURCE_OCSP_STAPLED_RESPONSE
116 SCT_VALIDATION_STATUS_NOT_SET,
117 SCT_VALIDATION_STATUS_UNKNOWN_LOG,
118 SCT_VALIDATION_STATUS_VALID,
119 SCT_VALIDATION_STATUS_INVALID,
120 SCT_VALIDATION_STATUS_UNVERIFIED,
121 SCT_VALIDATION_STATUS_UNKNOWN_VERSION
122} sct_validation_status_t;
134CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new_ex(OSSL_LIB_CTX *libctx,
141CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(
void);
144void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx);
147X509* CT_POLICY_EVAL_CTX_get0_cert(
const CT_POLICY_EVAL_CTX *ctx);
154int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert);
157X509* CT_POLICY_EVAL_CTX_get0_issuer(
const CT_POLICY_EVAL_CTX *ctx);
164int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer);
167const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(
const CT_POLICY_EVAL_CTX *ctx);
170void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
171 CTLOG_STORE *log_store);
178uint64_t CT_POLICY_EVAL_CTX_get_time(
const CT_POLICY_EVAL_CTX *ctx);
186void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms);
202SCT *SCT_new_from_base64(
unsigned char version,
203 const char *logid_base64,
204 ct_log_entry_type_t entry_type,
206 const char *extensions_base64,
207 const char *signature_base64);
212void SCT_free(SCT *sct);
218void SCT_LIST_free(STACK_OF(SCT) *a);
223sct_version_t SCT_get_version(
const SCT *sct);
229__owur
int SCT_set_version(SCT *sct, sct_version_t version);
234ct_log_entry_type_t SCT_get_log_entry_type(
const SCT *sct);
240__owur
int SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type);
247size_t SCT_get0_log_id(
const SCT *sct,
unsigned char **log_id);
254__owur
int SCT_set0_log_id(SCT *sct,
unsigned char *log_id,
size_t log_id_len);
261__owur
int SCT_set1_log_id(SCT *sct,
const unsigned char *log_id,
267uint64_t SCT_get_timestamp(
const SCT *sct);
272void SCT_set_timestamp(SCT *sct, uint64_t timestamp);
279int SCT_get_signature_nid(
const SCT *sct);
287__owur
int SCT_set_signature_nid(SCT *sct,
int nid);
294size_t SCT_get0_extensions(
const SCT *sct,
unsigned char **ext);
300void SCT_set0_extensions(SCT *sct,
unsigned char *ext,
size_t ext_len);
307__owur
int SCT_set1_extensions(SCT *sct,
const unsigned char *ext,
315size_t SCT_get0_signature(
const SCT *sct,
unsigned char **sig);
321void SCT_set0_signature(SCT *sct,
unsigned char *sig,
size_t sig_len);
327__owur
int SCT_set1_signature(SCT *sct,
const unsigned char *sig,
333sct_source_t SCT_get_source(
const SCT *sct);
339__owur
int SCT_set_source(SCT *sct, sct_source_t source);
344const char *SCT_validation_status_string(
const SCT *sct);
352void SCT_print(
const SCT *sct, BIO *out,
int indent,
const CTLOG_STORE *logs);
361void SCT_LIST_print(
const STACK_OF(SCT) *sct_list, BIO *out,
int indent,
362 const char *separator,
const CTLOG_STORE *logs);
368sct_validation_status_t SCT_get_validation_status(
const SCT *sct);
377__owur
int SCT_validate(SCT *sct,
const CT_POLICY_EVAL_CTX *ctx);
386__owur
int SCT_LIST_validate(
const STACK_OF(SCT) *scts,
387 CT_POLICY_EVAL_CTX *ctx);
406__owur
int i2o_SCT_LIST(
const STACK_OF(SCT) *a,
unsigned char **pp);
418STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a,
const unsigned char **pp,
433__owur
int i2d_SCT_LIST(
const STACK_OF(SCT) *a,
unsigned char **pp);
445STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a,
const unsigned char **pp,
457__owur
int i2o_SCT(
const SCT *sct,
unsigned char **out);
470SCT *o2i_SCT(SCT **psct,
const unsigned char **in,
size_t len);
484CTLOG *CTLOG_new_ex(EVP_PKEY *public_key,
const char *name, OSSL_LIB_CTX *libctx,
491CTLOG *CTLOG_new(EVP_PKEY *public_key,
const char *name);
501int CTLOG_new_from_base64_ex(CTLOG **ct_log,
const char *pkey_base64,
502 const char *name, OSSL_LIB_CTX *libctx,
510int CTLOG_new_from_base64(CTLOG ** ct_log,
511 const char *pkey_base64,
const char *name);
516void CTLOG_free(CTLOG *log);
519const char *CTLOG_get0_name(
const CTLOG *log);
521void CTLOG_get0_log_id(
const CTLOG *log,
const uint8_t **log_id,
524EVP_PKEY *CTLOG_get0_public_key(
const CTLOG *log);
535CTLOG_STORE *CTLOG_STORE_new_ex(OSSL_LIB_CTX *libctx,
const char *propq);
542CTLOG_STORE *CTLOG_STORE_new(
void);
547void CTLOG_STORE_free(CTLOG_STORE *store);
553const CTLOG *CTLOG_STORE_get0_log_by_id(
const CTLOG_STORE *store,
554 const uint8_t *log_id,
561__owur
int CTLOG_STORE_load_file(CTLOG_STORE *store,
const char *file);
567__owur
int CTLOG_STORE_load_default_file(CTLOG_STORE *store);