ct.h 22 KB

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