x509_crl.h 5.2 KB

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