ct.h 22 KB

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