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