x509_crl.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * \file x509_crl.h
  3. *
  4. * \brief X.509 certificate revocation list parsing
  5. *
  6. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  7. * SPDX-License-Identifier: GPL-2.0
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. *
  23. * This file is part of mbed TLS (https://tls.mbed.org)
  24. */
  25. #ifndef MBEDTLS_X509_CRL_H
  26. #define MBEDTLS_X509_CRL_H
  27. #if !defined(MBEDTLS_CONFIG_FILE)
  28. #include "config.h"
  29. #else
  30. #include MBEDTLS_CONFIG_FILE
  31. #endif
  32. #include "x509.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /**
  37. * \addtogroup x509_module
  38. * \{ */
  39. /**
  40. * \name Structures and functions for parsing CRLs
  41. * \{
  42. */
  43. /**
  44. * Certificate revocation list entry.
  45. * Contains the CA-specific serial numbers and revocation dates.
  46. */
  47. typedef struct mbedtls_x509_crl_entry
  48. {
  49. mbedtls_x509_buf raw;
  50. mbedtls_x509_buf serial;
  51. mbedtls_x509_time revocation_date;
  52. mbedtls_x509_buf entry_ext;
  53. struct mbedtls_x509_crl_entry *next;
  54. }
  55. mbedtls_x509_crl_entry;
  56. /**
  57. * Certificate revocation list structure.
  58. * Every CRL may have multiple entries.
  59. */
  60. typedef struct mbedtls_x509_crl
  61. {
  62. mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
  63. mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
  64. int version; /**< CRL version (1=v1, 2=v2) */
  65. mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
  66. mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
  67. mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
  68. mbedtls_x509_time this_update;
  69. mbedtls_x509_time next_update;
  70. mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
  71. mbedtls_x509_buf crl_ext;
  72. mbedtls_x509_buf sig_oid2;
  73. mbedtls_x509_buf sig;
  74. mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
  75. mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
  76. void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
  77. struct mbedtls_x509_crl *next;
  78. }
  79. mbedtls_x509_crl;
  80. /**
  81. * \brief Parse a DER-encoded CRL and append it to the chained list
  82. *
  83. * \param chain points to the start of the chain
  84. * \param buf buffer holding the CRL data in DER format
  85. * \param buflen size of the buffer
  86. * (including the terminating null byte for PEM data)
  87. *
  88. * \return 0 if successful, or a specific X509 or PEM error code
  89. */
  90. int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
  91. const unsigned char *buf, size_t buflen );
  92. /**
  93. * \brief Parse one or more CRLs and append them to the chained list
  94. *
  95. * \note Mutliple CRLs are accepted only if using PEM format
  96. *
  97. * \param chain points to the start of the chain
  98. * \param buf buffer holding the CRL data in PEM or DER format
  99. * \param buflen size of the buffer
  100. * (including the terminating null byte for PEM data)
  101. *
  102. * \return 0 if successful, or a specific X509 or PEM error code
  103. */
  104. int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
  105. #if defined(MBEDTLS_FS_IO)
  106. /**
  107. * \brief Load one or more CRLs and append them to the chained list
  108. *
  109. * \note Mutliple CRLs are accepted only if using PEM format
  110. *
  111. * \param chain points to the start of the chain
  112. * \param path filename to read the CRLs from (in PEM or DER encoding)
  113. *
  114. * \return 0 if successful, or a specific X509 or PEM error code
  115. */
  116. int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
  117. #endif /* MBEDTLS_FS_IO */
  118. /**
  119. * \brief Returns an informational string about the CRL.
  120. *
  121. * \param buf Buffer to write to
  122. * \param size Maximum size of buffer
  123. * \param prefix A line prefix
  124. * \param crl The X509 CRL to represent
  125. *
  126. * \return The length of the string written (not including the
  127. * terminated nul byte), or a negative error code.
  128. */
  129. int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
  130. const mbedtls_x509_crl *crl );
  131. /**
  132. * \brief Initialize a CRL (chain)
  133. *
  134. * \param crl CRL chain to initialize
  135. */
  136. void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
  137. /**
  138. * \brief Unallocate all CRL data
  139. *
  140. * \param crl CRL chain to free
  141. */
  142. void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
  143. /* \} name */
  144. /* \} addtogroup x509_module */
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif /* mbedtls_x509_crl.h */