ct_x509v3.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifdef OPENSSL_NO_CT
  10. # error "CT is disabled"
  11. #endif
  12. #include "ct_local.h"
  13. DEFINE_STACK_OF(SCT)
  14. static char *i2s_poison(const X509V3_EXT_METHOD *method, void *val)
  15. {
  16. return OPENSSL_strdup("NULL");
  17. }
  18. static void *s2i_poison(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, const char *str)
  19. {
  20. return ASN1_NULL_new();
  21. }
  22. static int i2r_SCT_LIST(X509V3_EXT_METHOD *method, STACK_OF(SCT) *sct_list,
  23. BIO *out, int indent)
  24. {
  25. SCT_LIST_print(sct_list, out, indent, "\n", NULL);
  26. return 1;
  27. }
  28. static int set_sct_list_source(STACK_OF(SCT) *s, sct_source_t source)
  29. {
  30. if (s != NULL) {
  31. int i;
  32. for (i = 0; i < sk_SCT_num(s); i++) {
  33. int res = SCT_set_source(sk_SCT_value(s, i), source);
  34. if (res != 1) {
  35. return 0;
  36. }
  37. }
  38. }
  39. return 1;
  40. }
  41. static STACK_OF(SCT) *x509_ext_d2i_SCT_LIST(STACK_OF(SCT) **a,
  42. const unsigned char **pp,
  43. long len)
  44. {
  45. STACK_OF(SCT) *s = d2i_SCT_LIST(a, pp, len);
  46. if (set_sct_list_source(s, SCT_SOURCE_X509V3_EXTENSION) != 1) {
  47. SCT_LIST_free(s);
  48. *a = NULL;
  49. return NULL;
  50. }
  51. return s;
  52. }
  53. static STACK_OF(SCT) *ocsp_ext_d2i_SCT_LIST(STACK_OF(SCT) **a,
  54. const unsigned char **pp,
  55. long len)
  56. {
  57. STACK_OF(SCT) *s = d2i_SCT_LIST(a, pp, len);
  58. if (set_sct_list_source(s, SCT_SOURCE_OCSP_STAPLED_RESPONSE) != 1) {
  59. SCT_LIST_free(s);
  60. *a = NULL;
  61. return NULL;
  62. }
  63. return s;
  64. }
  65. /* Handlers for X509v3/OCSP Certificate Transparency extensions */
  66. const X509V3_EXT_METHOD v3_ct_scts[3] = {
  67. /* X509v3 extension in certificates that contains SCTs */
  68. { NID_ct_precert_scts, 0, NULL,
  69. NULL, (X509V3_EXT_FREE)SCT_LIST_free,
  70. (X509V3_EXT_D2I)x509_ext_d2i_SCT_LIST, (X509V3_EXT_I2D)i2d_SCT_LIST,
  71. NULL, NULL,
  72. NULL, NULL,
  73. (X509V3_EXT_I2R)i2r_SCT_LIST, NULL,
  74. NULL },
  75. /* X509v3 extension to mark a certificate as a pre-certificate */
  76. { NID_ct_precert_poison, 0, ASN1_ITEM_ref(ASN1_NULL),
  77. NULL, NULL, NULL, NULL,
  78. i2s_poison, s2i_poison,
  79. NULL, NULL,
  80. NULL, NULL,
  81. NULL },
  82. /* OCSP extension that contains SCTs */
  83. { NID_ct_cert_scts, 0, NULL,
  84. 0, (X509V3_EXT_FREE)SCT_LIST_free,
  85. (X509V3_EXT_D2I)ocsp_ext_d2i_SCT_LIST, (X509V3_EXT_I2D)i2d_SCT_LIST,
  86. NULL, NULL,
  87. NULL, NULL,
  88. (X509V3_EXT_I2R)i2r_SCT_LIST, NULL,
  89. NULL },
  90. };