x509_txt.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright 1995-2023 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. #include <stdio.h>
  10. #include <time.h>
  11. #include <errno.h>
  12. #include "internal/cryptlib.h"
  13. #include <openssl/buffer.h>
  14. #include <openssl/evp.h>
  15. #include <openssl/asn1.h>
  16. #include <openssl/x509.h>
  17. #include <openssl/objects.h>
  18. const char *X509_verify_cert_error_string(long n)
  19. {
  20. switch ((int)n) {
  21. case X509_V_OK:
  22. return "ok";
  23. case X509_V_ERR_UNSPECIFIED:
  24. return "unspecified certificate verification error";
  25. case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
  26. return "unable to get issuer certificate";
  27. case X509_V_ERR_UNABLE_TO_GET_CRL:
  28. return "unable to get certificate CRL";
  29. case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
  30. return "unable to decrypt certificate's signature";
  31. case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
  32. return "unable to decrypt CRL's signature";
  33. case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
  34. return "unable to decode issuer public key";
  35. case X509_V_ERR_CERT_SIGNATURE_FAILURE:
  36. return "certificate signature failure";
  37. case X509_V_ERR_CRL_SIGNATURE_FAILURE:
  38. return "CRL signature failure";
  39. case X509_V_ERR_CERT_NOT_YET_VALID:
  40. return "certificate is not yet valid";
  41. case X509_V_ERR_CERT_HAS_EXPIRED:
  42. return "certificate has expired";
  43. case X509_V_ERR_CRL_NOT_YET_VALID:
  44. return "CRL is not yet valid";
  45. case X509_V_ERR_CRL_HAS_EXPIRED:
  46. return "CRL has expired";
  47. case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
  48. return "format error in certificate's notBefore field";
  49. case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
  50. return "format error in certificate's notAfter field";
  51. case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
  52. return "format error in CRL's lastUpdate field";
  53. case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
  54. return "format error in CRL's nextUpdate field";
  55. case X509_V_ERR_OUT_OF_MEM:
  56. return "out of memory";
  57. case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
  58. return "self-signed certificate";
  59. case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
  60. return "self-signed certificate in certificate chain";
  61. case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
  62. return "unable to get local issuer certificate";
  63. case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
  64. return "unable to verify the first certificate";
  65. case X509_V_ERR_CERT_CHAIN_TOO_LONG:
  66. return "certificate chain too long";
  67. case X509_V_ERR_CERT_REVOKED:
  68. return "certificate revoked";
  69. case X509_V_ERR_NO_ISSUER_PUBLIC_KEY:
  70. return "issuer certificate doesn't have a public key";
  71. case X509_V_ERR_PATH_LENGTH_EXCEEDED:
  72. return "path length constraint exceeded";
  73. case X509_V_ERR_INVALID_PURPOSE:
  74. return "unsuitable certificate purpose";
  75. case X509_V_ERR_CERT_UNTRUSTED:
  76. return "certificate not trusted";
  77. case X509_V_ERR_CERT_REJECTED:
  78. return "certificate rejected";
  79. case X509_V_ERR_SUBJECT_ISSUER_MISMATCH:
  80. return "subject issuer mismatch";
  81. case X509_V_ERR_AKID_SKID_MISMATCH:
  82. return "authority and subject key identifier mismatch";
  83. case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH:
  84. return "authority and issuer serial number mismatch";
  85. case X509_V_ERR_KEYUSAGE_NO_CERTSIGN:
  86. return "key usage does not include certificate signing";
  87. case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
  88. return "unable to get CRL issuer certificate";
  89. case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
  90. return "unhandled critical extension";
  91. case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN:
  92. return "key usage does not include CRL signing";
  93. case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION:
  94. return "unhandled critical CRL extension";
  95. case X509_V_ERR_INVALID_NON_CA:
  96. return "invalid non-CA certificate (has CA markings)";
  97. case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED:
  98. return "proxy path length constraint exceeded";
  99. case X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE:
  100. return "key usage does not include digital signature";
  101. case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED:
  102. return
  103. "proxy certificates not allowed, please set the appropriate flag";
  104. case X509_V_ERR_INVALID_EXTENSION:
  105. return "invalid or inconsistent certificate extension";
  106. case X509_V_ERR_INVALID_POLICY_EXTENSION:
  107. return "invalid or inconsistent certificate policy extension";
  108. case X509_V_ERR_NO_EXPLICIT_POLICY:
  109. return "no explicit policy";
  110. case X509_V_ERR_DIFFERENT_CRL_SCOPE:
  111. return "different CRL scope";
  112. case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE:
  113. return "unsupported extension feature";
  114. case X509_V_ERR_UNNESTED_RESOURCE:
  115. return "RFC 3779 resource not subset of parent's resources";
  116. case X509_V_ERR_PERMITTED_VIOLATION:
  117. return "permitted subtree violation";
  118. case X509_V_ERR_EXCLUDED_VIOLATION:
  119. return "excluded subtree violation";
  120. case X509_V_ERR_SUBTREE_MINMAX:
  121. return "name constraints minimum and maximum not supported";
  122. case X509_V_ERR_APPLICATION_VERIFICATION:
  123. return "application verification failure";
  124. case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE:
  125. return "unsupported name constraint type";
  126. case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX:
  127. return "unsupported or invalid name constraint syntax";
  128. case X509_V_ERR_UNSUPPORTED_NAME_SYNTAX:
  129. return "unsupported or invalid name syntax";
  130. case X509_V_ERR_CRL_PATH_VALIDATION_ERROR:
  131. return "CRL path validation error";
  132. case X509_V_ERR_PATH_LOOP:
  133. return "path loop";
  134. case X509_V_ERR_SUITE_B_INVALID_VERSION:
  135. return "Suite B: certificate version invalid";
  136. case X509_V_ERR_SUITE_B_INVALID_ALGORITHM:
  137. return "Suite B: invalid public key algorithm";
  138. case X509_V_ERR_SUITE_B_INVALID_CURVE:
  139. return "Suite B: invalid ECC curve";
  140. case X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM:
  141. return "Suite B: invalid signature algorithm";
  142. case X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED:
  143. return "Suite B: curve not allowed for this LOS";
  144. case X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256:
  145. return "Suite B: cannot sign P-384 with P-256";
  146. case X509_V_ERR_HOSTNAME_MISMATCH:
  147. return "hostname mismatch";
  148. case X509_V_ERR_EMAIL_MISMATCH:
  149. return "email address mismatch";
  150. case X509_V_ERR_IP_ADDRESS_MISMATCH:
  151. return "IP address mismatch";
  152. case X509_V_ERR_DANE_NO_MATCH:
  153. return "no matching DANE TLSA records";
  154. case X509_V_ERR_EE_KEY_TOO_SMALL:
  155. return "EE certificate key too weak";
  156. case X509_V_ERR_CA_KEY_TOO_SMALL:
  157. return "CA certificate key too weak";
  158. case X509_V_ERR_CA_MD_TOO_WEAK:
  159. return "CA signature digest algorithm too weak";
  160. case X509_V_ERR_INVALID_CALL:
  161. return "invalid certificate verification context";
  162. case X509_V_ERR_STORE_LOOKUP:
  163. return "issuer certificate lookup error";
  164. case X509_V_ERR_NO_VALID_SCTS:
  165. return "Certificate Transparency required, but no valid SCTs found";
  166. case X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION:
  167. return "proxy subject name violation";
  168. case X509_V_ERR_OCSP_VERIFY_NEEDED:
  169. return "OCSP verification needed";
  170. case X509_V_ERR_OCSP_VERIFY_FAILED:
  171. return "OCSP verification failed";
  172. case X509_V_ERR_OCSP_CERT_UNKNOWN:
  173. return "OCSP unknown cert";
  174. case X509_V_ERR_UNSUPPORTED_SIGNATURE_ALGORITHM:
  175. return "Cannot find certificate signature algorithm";
  176. case X509_V_ERR_SIGNATURE_ALGORITHM_MISMATCH:
  177. return "subject signature algorithm and issuer public key algorithm mismatch";
  178. case X509_V_ERR_SIGNATURE_ALGORITHM_INCONSISTENCY:
  179. return "cert info signature and signature algorithm mismatch";
  180. case X509_V_ERR_INVALID_CA:
  181. return "invalid CA certificate";
  182. case X509_V_ERR_PATHLEN_INVALID_FOR_NON_CA:
  183. return "Path length invalid for non-CA cert";
  184. case X509_V_ERR_PATHLEN_WITHOUT_KU_KEY_CERT_SIGN:
  185. return "Path length given without key usage keyCertSign";
  186. case X509_V_ERR_KU_KEY_CERT_SIGN_INVALID_FOR_NON_CA:
  187. return "Key usage keyCertSign invalid for non-CA cert";
  188. case X509_V_ERR_ISSUER_NAME_EMPTY:
  189. return "Issuer name empty";
  190. case X509_V_ERR_SUBJECT_NAME_EMPTY:
  191. return "Subject name empty";
  192. case X509_V_ERR_MISSING_AUTHORITY_KEY_IDENTIFIER:
  193. return "Missing Authority Key Identifier";
  194. case X509_V_ERR_MISSING_SUBJECT_KEY_IDENTIFIER:
  195. return "Missing Subject Key Identifier";
  196. case X509_V_ERR_EMPTY_SUBJECT_ALT_NAME:
  197. return "Empty Subject Alternative Name extension";
  198. case X509_V_ERR_CA_BCONS_NOT_CRITICAL:
  199. return "Basic Constraints of CA cert not marked critical";
  200. case X509_V_ERR_EMPTY_SUBJECT_SAN_NOT_CRITICAL:
  201. return "Subject empty and Subject Alt Name extension not critical";
  202. case X509_V_ERR_AUTHORITY_KEY_IDENTIFIER_CRITICAL:
  203. return "Authority Key Identifier marked critical";
  204. case X509_V_ERR_SUBJECT_KEY_IDENTIFIER_CRITICAL:
  205. return "Subject Key Identifier marked critical";
  206. case X509_V_ERR_CA_CERT_MISSING_KEY_USAGE:
  207. return "CA cert does not include key usage extension";
  208. case X509_V_ERR_EXTENSIONS_REQUIRE_VERSION_3:
  209. return "Using cert extension requires at least X509v3";
  210. case X509_V_ERR_EC_KEY_EXPLICIT_PARAMS:
  211. return "Certificate public key has explicit ECC parameters";
  212. case X509_V_ERR_RPK_UNTRUSTED:
  213. return "Raw public key untrusted, no trusted keys configured";
  214. /*
  215. * Entries must be kept consistent with include/openssl/x509_vfy.h.in
  216. * and with doc/man3/X509_STORE_CTX_get_error.pod
  217. */
  218. default:
  219. /* Printing an error number into a static buffer is not thread-safe */
  220. return "unknown certificate verification error";
  221. }
  222. }