1 | /*
|
---|
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
---|
3 | *
|
---|
4 | * Licensed under the OpenSSL license (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/lhash.h>
|
---|
16 | #include <openssl/buffer.h>
|
---|
17 | #include <openssl/evp.h>
|
---|
18 | #include <openssl/asn1.h>
|
---|
19 | #include <openssl/x509.h>
|
---|
20 | #include <openssl/objects.h>
|
---|
21 |
|
---|
22 | const char *X509_verify_cert_error_string(long n)
|
---|
23 | {
|
---|
24 | switch ((int)n) {
|
---|
25 | case X509_V_OK:
|
---|
26 | return ("ok");
|
---|
27 | case X509_V_ERR_UNSPECIFIED:
|
---|
28 | return ("unspecified certificate verification error");
|
---|
29 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
|
---|
30 | return ("unable to get issuer certificate");
|
---|
31 | case X509_V_ERR_UNABLE_TO_GET_CRL:
|
---|
32 | return ("unable to get certificate CRL");
|
---|
33 | case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
|
---|
34 | return ("unable to decrypt certificate's signature");
|
---|
35 | case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
|
---|
36 | return ("unable to decrypt CRL's signature");
|
---|
37 | case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
|
---|
38 | return ("unable to decode issuer public key");
|
---|
39 | case X509_V_ERR_CERT_SIGNATURE_FAILURE:
|
---|
40 | return ("certificate signature failure");
|
---|
41 | case X509_V_ERR_CRL_SIGNATURE_FAILURE:
|
---|
42 | return ("CRL signature failure");
|
---|
43 | case X509_V_ERR_CERT_NOT_YET_VALID:
|
---|
44 | return ("certificate is not yet valid");
|
---|
45 | case X509_V_ERR_CERT_HAS_EXPIRED:
|
---|
46 | return ("certificate has expired");
|
---|
47 | case X509_V_ERR_CRL_NOT_YET_VALID:
|
---|
48 | return ("CRL is not yet valid");
|
---|
49 | case X509_V_ERR_CRL_HAS_EXPIRED:
|
---|
50 | return ("CRL has expired");
|
---|
51 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
|
---|
52 | return ("format error in certificate's notBefore field");
|
---|
53 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
|
---|
54 | return ("format error in certificate's notAfter field");
|
---|
55 | case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
|
---|
56 | return ("format error in CRL's lastUpdate field");
|
---|
57 | case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
|
---|
58 | return ("format error in CRL's nextUpdate field");
|
---|
59 | case X509_V_ERR_OUT_OF_MEM:
|
---|
60 | return ("out of memory");
|
---|
61 | case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
|
---|
62 | return ("self signed certificate");
|
---|
63 | case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
|
---|
64 | return ("self signed certificate in certificate chain");
|
---|
65 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
|
---|
66 | return ("unable to get local issuer certificate");
|
---|
67 | case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
|
---|
68 | return ("unable to verify the first certificate");
|
---|
69 | case X509_V_ERR_CERT_CHAIN_TOO_LONG:
|
---|
70 | return ("certificate chain too long");
|
---|
71 | case X509_V_ERR_CERT_REVOKED:
|
---|
72 | return ("certificate revoked");
|
---|
73 | case X509_V_ERR_INVALID_CA:
|
---|
74 | return ("invalid CA certificate");
|
---|
75 | case X509_V_ERR_PATH_LENGTH_EXCEEDED:
|
---|
76 | return ("path length constraint exceeded");
|
---|
77 | case X509_V_ERR_INVALID_PURPOSE:
|
---|
78 | return ("unsupported certificate purpose");
|
---|
79 | case X509_V_ERR_CERT_UNTRUSTED:
|
---|
80 | return ("certificate not trusted");
|
---|
81 | case X509_V_ERR_CERT_REJECTED:
|
---|
82 | return ("certificate rejected");
|
---|
83 | case X509_V_ERR_SUBJECT_ISSUER_MISMATCH:
|
---|
84 | return ("subject issuer mismatch");
|
---|
85 | case X509_V_ERR_AKID_SKID_MISMATCH:
|
---|
86 | return ("authority and subject key identifier mismatch");
|
---|
87 | case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH:
|
---|
88 | return ("authority and issuer serial number mismatch");
|
---|
89 | case X509_V_ERR_KEYUSAGE_NO_CERTSIGN:
|
---|
90 | return ("key usage does not include certificate signing");
|
---|
91 | case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
|
---|
92 | return ("unable to get CRL issuer certificate");
|
---|
93 | case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
|
---|
94 | return ("unhandled critical extension");
|
---|
95 | case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN:
|
---|
96 | return ("key usage does not include CRL signing");
|
---|
97 | case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION:
|
---|
98 | return ("unhandled critical CRL extension");
|
---|
99 | case X509_V_ERR_INVALID_NON_CA:
|
---|
100 | return ("invalid non-CA certificate (has CA markings)");
|
---|
101 | case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED:
|
---|
102 | return ("proxy path length constraint exceeded");
|
---|
103 | case X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE:
|
---|
104 | return ("key usage does not include digital signature");
|
---|
105 | case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED:
|
---|
106 | return
|
---|
107 | ("proxy certificates not allowed, please set the appropriate flag");
|
---|
108 | case X509_V_ERR_INVALID_EXTENSION:
|
---|
109 | return ("invalid or inconsistent certificate extension");
|
---|
110 | case X509_V_ERR_INVALID_POLICY_EXTENSION:
|
---|
111 | return ("invalid or inconsistent certificate policy extension");
|
---|
112 | case X509_V_ERR_NO_EXPLICIT_POLICY:
|
---|
113 | return ("no explicit policy");
|
---|
114 | case X509_V_ERR_DIFFERENT_CRL_SCOPE:
|
---|
115 | return ("Different CRL scope");
|
---|
116 | case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE:
|
---|
117 | return ("Unsupported extension feature");
|
---|
118 | case X509_V_ERR_UNNESTED_RESOURCE:
|
---|
119 | return ("RFC 3779 resource not subset of parent's resources");
|
---|
120 | case X509_V_ERR_PERMITTED_VIOLATION:
|
---|
121 | return ("permitted subtree violation");
|
---|
122 | case X509_V_ERR_EXCLUDED_VIOLATION:
|
---|
123 | return ("excluded subtree violation");
|
---|
124 | case X509_V_ERR_SUBTREE_MINMAX:
|
---|
125 | return ("name constraints minimum and maximum not supported");
|
---|
126 | case X509_V_ERR_APPLICATION_VERIFICATION:
|
---|
127 | return ("application verification failure");
|
---|
128 | case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE:
|
---|
129 | return ("unsupported name constraint type");
|
---|
130 | case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX:
|
---|
131 | return ("unsupported or invalid name constraint syntax");
|
---|
132 | case X509_V_ERR_UNSUPPORTED_NAME_SYNTAX:
|
---|
133 | return ("unsupported or invalid name syntax");
|
---|
134 | case X509_V_ERR_CRL_PATH_VALIDATION_ERROR:
|
---|
135 | return ("CRL path validation error");
|
---|
136 | case X509_V_ERR_PATH_LOOP:
|
---|
137 | return ("Path Loop");
|
---|
138 | case X509_V_ERR_SUITE_B_INVALID_VERSION:
|
---|
139 | return ("Suite B: certificate version invalid");
|
---|
140 | case X509_V_ERR_SUITE_B_INVALID_ALGORITHM:
|
---|
141 | return ("Suite B: invalid public key algorithm");
|
---|
142 | case X509_V_ERR_SUITE_B_INVALID_CURVE:
|
---|
143 | return ("Suite B: invalid ECC curve");
|
---|
144 | case X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM:
|
---|
145 | return ("Suite B: invalid signature algorithm");
|
---|
146 | case X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED:
|
---|
147 | return ("Suite B: curve not allowed for this LOS");
|
---|
148 | case X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256:
|
---|
149 | return ("Suite B: cannot sign P-384 with P-256");
|
---|
150 | case X509_V_ERR_HOSTNAME_MISMATCH:
|
---|
151 | return ("Hostname mismatch");
|
---|
152 | case X509_V_ERR_EMAIL_MISMATCH:
|
---|
153 | return ("Email address mismatch");
|
---|
154 | case X509_V_ERR_IP_ADDRESS_MISMATCH:
|
---|
155 | return ("IP address mismatch");
|
---|
156 | case X509_V_ERR_DANE_NO_MATCH:
|
---|
157 | return ("No matching DANE TLSA records");
|
---|
158 | case X509_V_ERR_EE_KEY_TOO_SMALL:
|
---|
159 | return ("EE certificate key too weak");
|
---|
160 | case X509_V_ERR_CA_KEY_TOO_SMALL:
|
---|
161 | return ("CA certificate key too weak");
|
---|
162 | case X509_V_ERR_CA_MD_TOO_WEAK:
|
---|
163 | return ("CA signature digest algorithm too weak");
|
---|
164 | case X509_V_ERR_INVALID_CALL:
|
---|
165 | return ("Invalid certificate verification context");
|
---|
166 | case X509_V_ERR_STORE_LOOKUP:
|
---|
167 | return ("Issuer certificate lookup error");
|
---|
168 | case X509_V_ERR_NO_VALID_SCTS:
|
---|
169 | return ("Certificate Transparency required, but no valid SCTs found");
|
---|
170 | case X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION:
|
---|
171 | return ("proxy subject name violation");
|
---|
172 |
|
---|
173 | default:
|
---|
174 | /* Printing an error number into a static buffer is not thread-safe */
|
---|
175 | return ("unknown certificate verification error");
|
---|
176 | }
|
---|
177 | }
|
---|