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