1ebfedea0SLionel Sambuc /* apps/verify.c */
2ebfedea0SLionel Sambuc /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3ebfedea0SLionel Sambuc  * All rights reserved.
4ebfedea0SLionel Sambuc  *
5ebfedea0SLionel Sambuc  * This package is an SSL implementation written
6ebfedea0SLionel Sambuc  * by Eric Young (eay@cryptsoft.com).
7ebfedea0SLionel Sambuc  * The implementation was written so as to conform with Netscapes SSL.
8ebfedea0SLionel Sambuc  *
9ebfedea0SLionel Sambuc  * This library is free for commercial and non-commercial use as long as
10ebfedea0SLionel Sambuc  * the following conditions are aheared to.  The following conditions
11ebfedea0SLionel Sambuc  * apply to all code found in this distribution, be it the RC4, RSA,
12ebfedea0SLionel Sambuc  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13ebfedea0SLionel Sambuc  * included with this distribution is covered by the same copyright terms
14ebfedea0SLionel Sambuc  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15ebfedea0SLionel Sambuc  *
16ebfedea0SLionel Sambuc  * Copyright remains Eric Young's, and as such any Copyright notices in
17ebfedea0SLionel Sambuc  * the code are not to be removed.
18ebfedea0SLionel Sambuc  * If this package is used in a product, Eric Young should be given attribution
19ebfedea0SLionel Sambuc  * as the author of the parts of the library used.
20ebfedea0SLionel Sambuc  * This can be in the form of a textual message at program startup or
21ebfedea0SLionel Sambuc  * in documentation (online or textual) provided with the package.
22ebfedea0SLionel Sambuc  *
23ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
24ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
25ebfedea0SLionel Sambuc  * are met:
26ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the copyright
27ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
28ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
29ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
30ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
31ebfedea0SLionel Sambuc  * 3. All advertising materials mentioning features or use of this software
32ebfedea0SLionel Sambuc  *    must display the following acknowledgement:
33ebfedea0SLionel Sambuc  *    "This product includes cryptographic software written by
34ebfedea0SLionel Sambuc  *     Eric Young (eay@cryptsoft.com)"
35ebfedea0SLionel Sambuc  *    The word 'cryptographic' can be left out if the rouines from the library
36ebfedea0SLionel Sambuc  *    being used are not cryptographic related :-).
37ebfedea0SLionel Sambuc  * 4. If you include any Windows specific code (or a derivative thereof) from
38ebfedea0SLionel Sambuc  *    the apps directory (application code) you must include an acknowledgement:
39ebfedea0SLionel Sambuc  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40ebfedea0SLionel Sambuc  *
41ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51ebfedea0SLionel Sambuc  * SUCH DAMAGE.
52ebfedea0SLionel Sambuc  *
53ebfedea0SLionel Sambuc  * The licence and distribution terms for any publically available version or
54ebfedea0SLionel Sambuc  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55ebfedea0SLionel Sambuc  * copied and put under another distribution licence
56ebfedea0SLionel Sambuc  * [including the GNU Public Licence.]
57ebfedea0SLionel Sambuc  */
58ebfedea0SLionel Sambuc 
59ebfedea0SLionel Sambuc #include <stdio.h>
60ebfedea0SLionel Sambuc #include <stdlib.h>
61ebfedea0SLionel Sambuc #include <string.h>
62ebfedea0SLionel Sambuc #include "apps.h"
63ebfedea0SLionel Sambuc #include <openssl/bio.h>
64ebfedea0SLionel Sambuc #include <openssl/err.h>
65ebfedea0SLionel Sambuc #include <openssl/x509.h>
66ebfedea0SLionel Sambuc #include <openssl/x509v3.h>
67ebfedea0SLionel Sambuc #include <openssl/pem.h>
68ebfedea0SLionel Sambuc 
69ebfedea0SLionel Sambuc #undef PROG
70ebfedea0SLionel Sambuc #define PROG    verify_main
71ebfedea0SLionel Sambuc 
72ebfedea0SLionel Sambuc static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx);
73ebfedea0SLionel Sambuc static int check(X509_STORE *ctx, char *file,
74ebfedea0SLionel Sambuc                  STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
75ebfedea0SLionel Sambuc                  STACK_OF(X509_CRL) *crls, ENGINE *e);
76ebfedea0SLionel Sambuc static int v_verbose = 0, vflags = 0;
77ebfedea0SLionel Sambuc 
78ebfedea0SLionel Sambuc int MAIN(int, char **);
79ebfedea0SLionel Sambuc 
MAIN(int argc,char ** argv)80ebfedea0SLionel Sambuc int MAIN(int argc, char **argv)
81ebfedea0SLionel Sambuc {
82ebfedea0SLionel Sambuc     ENGINE *e = NULL;
83ebfedea0SLionel Sambuc     int i, ret = 1, badarg = 0;
84ebfedea0SLionel Sambuc     char *CApath = NULL, *CAfile = NULL;
85ebfedea0SLionel Sambuc     char *untfile = NULL, *trustfile = NULL, *crlfile = NULL;
86ebfedea0SLionel Sambuc     STACK_OF(X509) *untrusted = NULL, *trusted = NULL;
87ebfedea0SLionel Sambuc     STACK_OF(X509_CRL) *crls = NULL;
88ebfedea0SLionel Sambuc     X509_STORE *cert_ctx = NULL;
89ebfedea0SLionel Sambuc     X509_LOOKUP *lookup = NULL;
90ebfedea0SLionel Sambuc     X509_VERIFY_PARAM *vpm = NULL;
91ebfedea0SLionel Sambuc #ifndef OPENSSL_NO_ENGINE
92ebfedea0SLionel Sambuc     char *engine = NULL;
93ebfedea0SLionel Sambuc #endif
94ebfedea0SLionel Sambuc 
95ebfedea0SLionel Sambuc     cert_ctx = X509_STORE_new();
96*0a6a1f1dSLionel Sambuc     if (cert_ctx == NULL)
97*0a6a1f1dSLionel Sambuc         goto end;
98ebfedea0SLionel Sambuc     X509_STORE_set_verify_cb(cert_ctx, cb);
99ebfedea0SLionel Sambuc 
100ebfedea0SLionel Sambuc     ERR_load_crypto_strings();
101ebfedea0SLionel Sambuc 
102ebfedea0SLionel Sambuc     apps_startup();
103ebfedea0SLionel Sambuc 
104ebfedea0SLionel Sambuc     if (bio_err == NULL)
105ebfedea0SLionel Sambuc         if ((bio_err = BIO_new(BIO_s_file())) != NULL)
106ebfedea0SLionel Sambuc             BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
107ebfedea0SLionel Sambuc 
108ebfedea0SLionel Sambuc     if (!load_config(bio_err, NULL))
109ebfedea0SLionel Sambuc         goto end;
110ebfedea0SLionel Sambuc 
111ebfedea0SLionel Sambuc     argc--;
112ebfedea0SLionel Sambuc     argv++;
113*0a6a1f1dSLionel Sambuc     for (;;) {
114*0a6a1f1dSLionel Sambuc         if (argc >= 1) {
115*0a6a1f1dSLionel Sambuc             if (strcmp(*argv, "-CApath") == 0) {
116*0a6a1f1dSLionel Sambuc                 if (argc-- < 1)
117*0a6a1f1dSLionel Sambuc                     goto end;
118ebfedea0SLionel Sambuc                 CApath = *(++argv);
119*0a6a1f1dSLionel Sambuc             } else if (strcmp(*argv, "-CAfile") == 0) {
120*0a6a1f1dSLionel Sambuc                 if (argc-- < 1)
121*0a6a1f1dSLionel Sambuc                     goto end;
122ebfedea0SLionel Sambuc                 CAfile = *(++argv);
123*0a6a1f1dSLionel Sambuc             } else if (args_verify(&argv, &argc, &badarg, bio_err, &vpm)) {
124ebfedea0SLionel Sambuc                 if (badarg)
125ebfedea0SLionel Sambuc                     goto end;
126ebfedea0SLionel Sambuc                 continue;
127*0a6a1f1dSLionel Sambuc             } else if (strcmp(*argv, "-untrusted") == 0) {
128*0a6a1f1dSLionel Sambuc                 if (argc-- < 1)
129*0a6a1f1dSLionel Sambuc                     goto end;
130ebfedea0SLionel Sambuc                 untfile = *(++argv);
131*0a6a1f1dSLionel Sambuc             } else if (strcmp(*argv, "-trusted") == 0) {
132*0a6a1f1dSLionel Sambuc                 if (argc-- < 1)
133*0a6a1f1dSLionel Sambuc                     goto end;
134ebfedea0SLionel Sambuc                 trustfile = *(++argv);
135*0a6a1f1dSLionel Sambuc             } else if (strcmp(*argv, "-CRLfile") == 0) {
136*0a6a1f1dSLionel Sambuc                 if (argc-- < 1)
137*0a6a1f1dSLionel Sambuc                     goto end;
138ebfedea0SLionel Sambuc                 crlfile = *(++argv);
139ebfedea0SLionel Sambuc             }
140ebfedea0SLionel Sambuc #ifndef OPENSSL_NO_ENGINE
141*0a6a1f1dSLionel Sambuc             else if (strcmp(*argv, "-engine") == 0) {
142*0a6a1f1dSLionel Sambuc                 if (--argc < 1)
143*0a6a1f1dSLionel Sambuc                     goto end;
144ebfedea0SLionel Sambuc                 engine = *(++argv);
145ebfedea0SLionel Sambuc             }
146ebfedea0SLionel Sambuc #endif
147ebfedea0SLionel Sambuc             else if (strcmp(*argv, "-help") == 0)
148ebfedea0SLionel Sambuc                 goto end;
149ebfedea0SLionel Sambuc             else if (strcmp(*argv, "-verbose") == 0)
150ebfedea0SLionel Sambuc                 v_verbose = 1;
151ebfedea0SLionel Sambuc             else if (argv[0][0] == '-')
152ebfedea0SLionel Sambuc                 goto end;
153ebfedea0SLionel Sambuc             else
154ebfedea0SLionel Sambuc                 break;
155ebfedea0SLionel Sambuc             argc--;
156ebfedea0SLionel Sambuc             argv++;
157*0a6a1f1dSLionel Sambuc         } else
158ebfedea0SLionel Sambuc             break;
159ebfedea0SLionel Sambuc     }
160ebfedea0SLionel Sambuc 
161ebfedea0SLionel Sambuc #ifndef OPENSSL_NO_ENGINE
162ebfedea0SLionel Sambuc     e = setup_engine(bio_err, engine, 0);
163ebfedea0SLionel Sambuc #endif
164ebfedea0SLionel Sambuc 
165ebfedea0SLionel Sambuc     if (vpm)
166ebfedea0SLionel Sambuc         X509_STORE_set1_param(cert_ctx, vpm);
167ebfedea0SLionel Sambuc 
168ebfedea0SLionel Sambuc     lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
169*0a6a1f1dSLionel Sambuc     if (lookup == NULL)
170*0a6a1f1dSLionel Sambuc         abort();
171ebfedea0SLionel Sambuc     if (CAfile) {
172ebfedea0SLionel Sambuc         i = X509_LOOKUP_load_file(lookup, CAfile, X509_FILETYPE_PEM);
173ebfedea0SLionel Sambuc         if (!i) {
174ebfedea0SLionel Sambuc             BIO_printf(bio_err, "Error loading file %s\n", CAfile);
175ebfedea0SLionel Sambuc             ERR_print_errors(bio_err);
176ebfedea0SLionel Sambuc             goto end;
177ebfedea0SLionel Sambuc         }
178*0a6a1f1dSLionel Sambuc     } else
179*0a6a1f1dSLionel Sambuc         X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT);
180ebfedea0SLionel Sambuc 
181ebfedea0SLionel Sambuc     lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_hash_dir());
182*0a6a1f1dSLionel Sambuc     if (lookup == NULL)
183*0a6a1f1dSLionel Sambuc         abort();
184ebfedea0SLionel Sambuc     if (CApath) {
185ebfedea0SLionel Sambuc         i = X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM);
186ebfedea0SLionel Sambuc         if (!i) {
187ebfedea0SLionel Sambuc             BIO_printf(bio_err, "Error loading directory %s\n", CApath);
188ebfedea0SLionel Sambuc             ERR_print_errors(bio_err);
189ebfedea0SLionel Sambuc             goto end;
190ebfedea0SLionel Sambuc         }
191*0a6a1f1dSLionel Sambuc     } else
192*0a6a1f1dSLionel Sambuc         X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
193ebfedea0SLionel Sambuc 
194ebfedea0SLionel Sambuc     ERR_clear_error();
195ebfedea0SLionel Sambuc 
196*0a6a1f1dSLionel Sambuc     if (untfile) {
197ebfedea0SLionel Sambuc         untrusted = load_certs(bio_err, untfile, FORMAT_PEM,
198ebfedea0SLionel Sambuc                                NULL, e, "untrusted certificates");
199ebfedea0SLionel Sambuc         if (!untrusted)
200ebfedea0SLionel Sambuc             goto end;
201ebfedea0SLionel Sambuc     }
202ebfedea0SLionel Sambuc 
203*0a6a1f1dSLionel Sambuc     if (trustfile) {
204ebfedea0SLionel Sambuc         trusted = load_certs(bio_err, trustfile, FORMAT_PEM,
205ebfedea0SLionel Sambuc                              NULL, e, "trusted certificates");
206ebfedea0SLionel Sambuc         if (!trusted)
207ebfedea0SLionel Sambuc             goto end;
208ebfedea0SLionel Sambuc     }
209ebfedea0SLionel Sambuc 
210*0a6a1f1dSLionel Sambuc     if (crlfile) {
211*0a6a1f1dSLionel Sambuc         crls = load_crls(bio_err, crlfile, FORMAT_PEM, NULL, e, "other CRLs");
212ebfedea0SLionel Sambuc         if (!crls)
213ebfedea0SLionel Sambuc             goto end;
214ebfedea0SLionel Sambuc     }
215ebfedea0SLionel Sambuc 
216ebfedea0SLionel Sambuc     ret = 0;
217*0a6a1f1dSLionel Sambuc     if (argc < 1) {
218ebfedea0SLionel Sambuc         if (1 != check(cert_ctx, NULL, untrusted, trusted, crls, e))
219ebfedea0SLionel Sambuc             ret = -1;
220*0a6a1f1dSLionel Sambuc     } else {
221ebfedea0SLionel Sambuc         for (i = 0; i < argc; i++)
222ebfedea0SLionel Sambuc             if (1 != check(cert_ctx, argv[i], untrusted, trusted, crls, e))
223ebfedea0SLionel Sambuc                 ret = -1;
224ebfedea0SLionel Sambuc     }
225ebfedea0SLionel Sambuc 
226ebfedea0SLionel Sambuc  end:
227ebfedea0SLionel Sambuc     if (ret == 1) {
228*0a6a1f1dSLionel Sambuc         BIO_printf(bio_err,
229*0a6a1f1dSLionel Sambuc                    "usage: verify [-verbose] [-CApath path] [-CAfile file] [-purpose purpose] [-crl_check]");
230*0a6a1f1dSLionel Sambuc         BIO_printf(bio_err, " [-no_alt_chains] [-attime timestamp]");
231ebfedea0SLionel Sambuc #ifndef OPENSSL_NO_ENGINE
232ebfedea0SLionel Sambuc         BIO_printf(bio_err, " [-engine e]");
233ebfedea0SLionel Sambuc #endif
234ebfedea0SLionel Sambuc         BIO_printf(bio_err, " cert1 cert2 ...\n");
235ebfedea0SLionel Sambuc 
236ebfedea0SLionel Sambuc         BIO_printf(bio_err, "recognized usages:\n");
237*0a6a1f1dSLionel Sambuc         for (i = 0; i < X509_PURPOSE_get_count(); i++) {
238ebfedea0SLionel Sambuc             X509_PURPOSE *ptmp;
239ebfedea0SLionel Sambuc             ptmp = X509_PURPOSE_get0(i);
240ebfedea0SLionel Sambuc             BIO_printf(bio_err, "\t%-10s\t%s\n",
241ebfedea0SLionel Sambuc                        X509_PURPOSE_get0_sname(ptmp),
242ebfedea0SLionel Sambuc                        X509_PURPOSE_get0_name(ptmp));
243ebfedea0SLionel Sambuc         }
244ebfedea0SLionel Sambuc     }
245*0a6a1f1dSLionel Sambuc     if (vpm)
246*0a6a1f1dSLionel Sambuc         X509_VERIFY_PARAM_free(vpm);
247*0a6a1f1dSLionel Sambuc     if (cert_ctx != NULL)
248*0a6a1f1dSLionel Sambuc         X509_STORE_free(cert_ctx);
249ebfedea0SLionel Sambuc     sk_X509_pop_free(untrusted, X509_free);
250ebfedea0SLionel Sambuc     sk_X509_pop_free(trusted, X509_free);
251ebfedea0SLionel Sambuc     sk_X509_CRL_pop_free(crls, X509_CRL_free);
252ebfedea0SLionel Sambuc     apps_shutdown();
253ebfedea0SLionel Sambuc     OPENSSL_EXIT(ret < 0 ? 2 : ret);
254ebfedea0SLionel Sambuc }
255ebfedea0SLionel Sambuc 
check(X509_STORE * ctx,char * file,STACK_OF (X509)* uchain,STACK_OF (X509)* tchain,STACK_OF (X509_CRL)* crls,ENGINE * e)256ebfedea0SLionel Sambuc static int check(X509_STORE *ctx, char *file,
257ebfedea0SLionel Sambuc                  STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
258ebfedea0SLionel Sambuc                  STACK_OF(X509_CRL) *crls, ENGINE *e)
259ebfedea0SLionel Sambuc {
260ebfedea0SLionel Sambuc     X509 *x = NULL;
261ebfedea0SLionel Sambuc     int i = 0, ret = 0;
262ebfedea0SLionel Sambuc     X509_STORE_CTX *csc;
263ebfedea0SLionel Sambuc 
264ebfedea0SLionel Sambuc     x = load_cert(bio_err, file, FORMAT_PEM, NULL, e, "certificate file");
265ebfedea0SLionel Sambuc     if (x == NULL)
266ebfedea0SLionel Sambuc         goto end;
267ebfedea0SLionel Sambuc     fprintf(stdout, "%s: ", (file == NULL) ? "stdin" : file);
268ebfedea0SLionel Sambuc 
269ebfedea0SLionel Sambuc     csc = X509_STORE_CTX_new();
270*0a6a1f1dSLionel Sambuc     if (csc == NULL) {
271ebfedea0SLionel Sambuc         ERR_print_errors(bio_err);
272ebfedea0SLionel Sambuc         goto end;
273ebfedea0SLionel Sambuc     }
274ebfedea0SLionel Sambuc     X509_STORE_set_flags(ctx, vflags);
275*0a6a1f1dSLionel Sambuc     if (!X509_STORE_CTX_init(csc, ctx, x, uchain)) {
276ebfedea0SLionel Sambuc         ERR_print_errors(bio_err);
277ebfedea0SLionel Sambuc         goto end;
278ebfedea0SLionel Sambuc     }
279*0a6a1f1dSLionel Sambuc     if (tchain)
280*0a6a1f1dSLionel Sambuc         X509_STORE_CTX_trusted_stack(csc, tchain);
281ebfedea0SLionel Sambuc     if (crls)
282ebfedea0SLionel Sambuc         X509_STORE_CTX_set0_crls(csc, crls);
283ebfedea0SLionel Sambuc     i = X509_verify_cert(csc);
284ebfedea0SLionel Sambuc     X509_STORE_CTX_free(csc);
285ebfedea0SLionel Sambuc 
286ebfedea0SLionel Sambuc     ret = 0;
287ebfedea0SLionel Sambuc  end:
288*0a6a1f1dSLionel Sambuc     if (i > 0) {
289ebfedea0SLionel Sambuc         fprintf(stdout, "OK\n");
290ebfedea0SLionel Sambuc         ret = 1;
291*0a6a1f1dSLionel Sambuc     } else
292ebfedea0SLionel Sambuc         ERR_print_errors(bio_err);
293*0a6a1f1dSLionel Sambuc     if (x != NULL)
294*0a6a1f1dSLionel Sambuc         X509_free(x);
295ebfedea0SLionel Sambuc 
296ebfedea0SLionel Sambuc     return (ret);
297ebfedea0SLionel Sambuc }
298ebfedea0SLionel Sambuc 
cb(int ok,X509_STORE_CTX * ctx)299ebfedea0SLionel Sambuc static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx)
300ebfedea0SLionel Sambuc {
301ebfedea0SLionel Sambuc     int cert_error = X509_STORE_CTX_get_error(ctx);
302ebfedea0SLionel Sambuc     X509 *current_cert = X509_STORE_CTX_get_current_cert(ctx);
303ebfedea0SLionel Sambuc 
304*0a6a1f1dSLionel Sambuc     if (!ok) {
305*0a6a1f1dSLionel Sambuc         if (current_cert) {
306ebfedea0SLionel Sambuc             X509_NAME_print_ex_fp(stdout,
307ebfedea0SLionel Sambuc                                   X509_get_subject_name(current_cert),
308ebfedea0SLionel Sambuc                                   0, XN_FLAG_ONELINE);
309ebfedea0SLionel Sambuc             printf("\n");
310ebfedea0SLionel Sambuc         }
311ebfedea0SLionel Sambuc         printf("%serror %d at %d depth lookup:%s\n",
312ebfedea0SLionel Sambuc                X509_STORE_CTX_get0_parent_ctx(ctx) ? "[CRL path]" : "",
313ebfedea0SLionel Sambuc                cert_error,
314ebfedea0SLionel Sambuc                X509_STORE_CTX_get_error_depth(ctx),
315ebfedea0SLionel Sambuc                X509_verify_cert_error_string(cert_error));
316*0a6a1f1dSLionel Sambuc         switch (cert_error) {
317ebfedea0SLionel Sambuc         case X509_V_ERR_NO_EXPLICIT_POLICY:
318ebfedea0SLionel Sambuc             policies_print(NULL, ctx);
319ebfedea0SLionel Sambuc         case X509_V_ERR_CERT_HAS_EXPIRED:
320ebfedea0SLionel Sambuc 
321*0a6a1f1dSLionel Sambuc             /*
322*0a6a1f1dSLionel Sambuc              * since we are just checking the certificates, it is ok if they
323*0a6a1f1dSLionel Sambuc              * are self signed. But we should still warn the user.
324ebfedea0SLionel Sambuc              */
325ebfedea0SLionel Sambuc 
326ebfedea0SLionel Sambuc         case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
327ebfedea0SLionel Sambuc             /* Continue after extension errors too */
328ebfedea0SLionel Sambuc         case X509_V_ERR_INVALID_CA:
329ebfedea0SLionel Sambuc         case X509_V_ERR_INVALID_NON_CA:
330ebfedea0SLionel Sambuc         case X509_V_ERR_PATH_LENGTH_EXCEEDED:
331ebfedea0SLionel Sambuc         case X509_V_ERR_INVALID_PURPOSE:
332ebfedea0SLionel Sambuc         case X509_V_ERR_CRL_HAS_EXPIRED:
333ebfedea0SLionel Sambuc         case X509_V_ERR_CRL_NOT_YET_VALID:
334ebfedea0SLionel Sambuc         case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
335ebfedea0SLionel Sambuc             ok = 1;
336ebfedea0SLionel Sambuc 
337ebfedea0SLionel Sambuc         }
338ebfedea0SLionel Sambuc 
339ebfedea0SLionel Sambuc         return ok;
340ebfedea0SLionel Sambuc 
341ebfedea0SLionel Sambuc     }
342ebfedea0SLionel Sambuc     if (cert_error == X509_V_OK && ok == 2)
343ebfedea0SLionel Sambuc         policies_print(NULL, ctx);
344ebfedea0SLionel Sambuc     if (!v_verbose)
345ebfedea0SLionel Sambuc         ERR_clear_error();
346ebfedea0SLionel Sambuc     return (ok);
347ebfedea0SLionel Sambuc }
348