You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ct.h 24 kB

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