1X509_STORE_CTX_SET_VERIFY_CB(3ossl) OpenSSLX509_STORE_CTX_SET_VERIFY_CB(3ossl)
2
3
4

NAME

6       X509_STORE_CTX_get_cleanup, X509_STORE_CTX_get_lookup_crls,
7       X509_STORE_CTX_get_lookup_certs, X509_STORE_CTX_get_check_policy,
8       X509_STORE_CTX_get_cert_crl, X509_STORE_CTX_get_check_crl,
9       X509_STORE_CTX_get_get_crl, X509_STORE_CTX_get_check_revocation,
10       X509_STORE_CTX_get_check_issued, X509_STORE_CTX_get_get_issuer,
11       X509_STORE_CTX_get_verify_cb, X509_STORE_CTX_set_verify_cb,
12       X509_STORE_CTX_verify_cb, X509_STORE_CTX_print_verify_cb - get and set
13       X509_STORE_CTX components such as verification callback
14

SYNOPSIS

16        #include <openssl/x509_vfy.h>
17
18        typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *);
19        int X509_STORE_CTX_print_verify_cb(int ok, X509_STORE_CTX *ctx);
20
21        X509_STORE_CTX_verify_cb X509_STORE_CTX_get_verify_cb(X509_STORE_CTX *ctx);
22
23        void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
24                                          X509_STORE_CTX_verify_cb verify_cb);
25
26        X509_STORE_CTX_get_issuer_fn X509_STORE_CTX_get_get_issuer(X509_STORE_CTX *ctx);
27        X509_STORE_CTX_check_issued_fn X509_STORE_CTX_get_check_issued(X509_STORE_CTX *ctx);
28        X509_STORE_CTX_check_revocation_fn X509_STORE_CTX_get_check_revocation(X509_STORE_CTX *ctx);
29        X509_STORE_CTX_get_crl_fn X509_STORE_CTX_get_get_crl(X509_STORE_CTX *ctx);
30        X509_STORE_CTX_check_crl_fn X509_STORE_CTX_get_check_crl(X509_STORE_CTX *ctx);
31        X509_STORE_CTX_cert_crl_fn X509_STORE_CTX_get_cert_crl(X509_STORE_CTX *ctx);
32        X509_STORE_CTX_check_policy_fn X509_STORE_CTX_get_check_policy(X509_STORE_CTX *ctx);
33        X509_STORE_CTX_lookup_certs_fn X509_STORE_CTX_get_lookup_certs(X509_STORE_CTX *ctx);
34        X509_STORE_CTX_lookup_crls_fn X509_STORE_CTX_get_lookup_crls(X509_STORE_CTX *ctx);
35        X509_STORE_CTX_cleanup_fn X509_STORE_CTX_get_cleanup(X509_STORE_CTX *ctx);
36

DESCRIPTION

38       X509_STORE_CTX_set_verify_cb() sets the verification callback of ctx to
39       verify_cb overwriting any existing callback.
40
41       The verification callback can be used to customise the operation of
42       certificate verification, for instance by overriding error conditions
43       or logging errors for debugging purposes.
44
45       However, a verification callback is not essential and the default
46       operation is often sufficient.
47
48       The ok parameter to the callback indicates the value the callback
49       should return to retain the default behaviour. If it is zero then an
50       error condition is indicated. If it is 1 then no error occurred. If the
51       flag X509_V_FLAG_NOTIFY_POLICY is set then ok is set to 2 to indicate
52       the policy checking is complete.
53
54       The ctx parameter to the callback is the X509_STORE_CTX structure that
55       is performing the verification operation. A callback can examine this
56       structure and receive additional information about the error, for
57       example by calling X509_STORE_CTX_get_current_cert(). Additional
58       application data can be passed to the callback via the ex_data
59       mechanism.
60
61       X509_STORE_CTX_print_verify_cb() is a verification callback function
62       that, when a certificate verification has failed, adds an entry to the
63       error queue with code X509_R_CERTIFICATE_VERIFICATION_FAILED and with
64       diagnostic details, including the most relevant fields of the target
65       certificate that failed to verify and, if appropriate, of the available
66       untrusted and trusted certificates.
67
68       X509_STORE_CTX_get_verify_cb() returns the value of the current
69       callback for the specific ctx.
70
71       X509_STORE_CTX_get_get_issuer(), X509_STORE_CTX_get_check_issued(),
72       X509_STORE_CTX_get_check_revocation(), X509_STORE_CTX_get_get_crl(),
73       X509_STORE_CTX_get_check_crl(), X509_STORE_CTX_get_cert_crl(),
74       X509_STORE_CTX_get_check_policy(), X509_STORE_CTX_get_lookup_certs(),
75       X509_STORE_CTX_get_lookup_crls() and X509_STORE_CTX_get_cleanup()
76       return the function pointers cached from the corresponding X509_STORE,
77       please see X509_STORE_set_verify(3) for more information.
78

WARNINGS

80       In general a verification callback should NOT unconditionally return 1
81       in all circumstances because this will allow verification to succeed no
82       matter what the error. This effectively removes all security from the
83       application because any certificate (including untrusted generated
84       ones) will be accepted.
85

NOTES

87       The verification callback can be set and inherited from the parent
88       structure performing the operation. In some cases (such as S/MIME
89       verification) the X509_STORE_CTX structure is created and destroyed
90       internally and the only way to set a custom verification callback is by
91       inheriting it from the associated X509_STORE.
92

RETURN VALUES

94       X509_STORE_CTX_set_verify_cb() does not return a value.
95

EXAMPLES

97       Default callback operation:
98
99        int verify_callback(int ok, X509_STORE_CTX *ctx) {
100            return ok;
101        }
102
103       Simple example, suppose a certificate in the chain is expired and we
104       wish to continue after this error:
105
106        int verify_callback(int ok, X509_STORE_CTX *ctx) {
107            /* Tolerate certificate expiration */
108            if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_HAS_EXPIRED)
109                return 1;
110            /* Otherwise don't override */
111            return ok;
112        }
113
114       More complex example, we don't wish to continue after any certificate
115       has expired just one specific case:
116
117        int verify_callback(int ok, X509_STORE_CTX *ctx)
118        {
119            int err = X509_STORE_CTX_get_error(ctx);
120            X509 *err_cert = X509_STORE_CTX_get_current_cert(ctx);
121
122            if (err == X509_V_ERR_CERT_HAS_EXPIRED) {
123                if (check_is_acceptable_expired_cert(err_cert)
124                    return 1;
125            }
126            return ok;
127        }
128
129       Full featured logging callback. In this case the bio_err is assumed to
130       be a global logging BIO, an alternative would to store a BIO in ctx
131       using ex_data.
132
133        int verify_callback(int ok, X509_STORE_CTX *ctx)
134        {
135            X509 *err_cert;
136            int err, depth;
137
138            err_cert = X509_STORE_CTX_get_current_cert(ctx);
139            err = X509_STORE_CTX_get_error(ctx);
140            depth = X509_STORE_CTX_get_error_depth(ctx);
141
142            BIO_printf(bio_err, "depth=%d ", depth);
143            if (err_cert) {
144                X509_NAME_print_ex(bio_err, X509_get_subject_name(err_cert),
145                                   0, XN_FLAG_ONELINE);
146                BIO_puts(bio_err, "\n");
147            }
148            else
149                BIO_puts(bio_err, "<no cert>\n");
150            if (!ok)
151                BIO_printf(bio_err, "verify error:num=%d:%s\n", err,
152                           X509_verify_cert_error_string(err));
153            switch (err) {
154            case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
155                BIO_puts(bio_err, "issuer= ");
156                X509_NAME_print_ex(bio_err, X509_get_issuer_name(err_cert),
157                                   0, XN_FLAG_ONELINE);
158                BIO_puts(bio_err, "\n");
159                break;
160            case X509_V_ERR_CERT_NOT_YET_VALID:
161            case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
162                BIO_printf(bio_err, "notBefore=");
163                ASN1_TIME_print(bio_err, X509_get_notBefore(err_cert));
164                BIO_printf(bio_err, "\n");
165                break;
166            case X509_V_ERR_CERT_HAS_EXPIRED:
167            case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
168                BIO_printf(bio_err, "notAfter=");
169                ASN1_TIME_print(bio_err, X509_get_notAfter(err_cert));
170                BIO_printf(bio_err, "\n");
171                break;
172            case X509_V_ERR_NO_EXPLICIT_POLICY:
173                policies_print(bio_err, ctx);
174                break;
175            }
176            if (err == X509_V_OK && ok == 2)
177                /* print out policies */
178
179            BIO_printf(bio_err, "verify return:%d\n", ok);
180            return(ok);
181        }
182

SEE ALSO

184       X509_STORE_CTX_get_error(3) X509_STORE_set_verify_cb_func(3)
185       X509_STORE_CTX_get_ex_new_index(3)
186

HISTORY

188       The X509_STORE_CTX_get_get_issuer(), X509_STORE_CTX_get_check_issued(),
189       X509_STORE_CTX_get_check_revocation(), X509_STORE_CTX_get_get_crl(),
190       X509_STORE_CTX_get_check_crl(), X509_STORE_CTX_get_cert_crl(),
191       X509_STORE_CTX_get_check_policy(), X509_STORE_CTX_get_lookup_certs(),
192       X509_STORE_CTX_get_lookup_crls() and X509_STORE_CTX_get_cleanup()
193       functions were added in OpenSSL 1.1.0.
194
195       X509_STORE_CTX_print_verify_cb() was added in OpenSSL 3.0.
196
198       Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved.
199
200       Licensed under the Apache License 2.0 (the "License").  You may not use
201       this file except in compliance with the License.  You can obtain a copy
202       in the file LICENSE in the source distribution or at
203       <https://www.openssl.org/source/license.html>.
204
205
206
2073.0.5                             2022-11-01X509_STORE_CTX_SET_VERIFY_CB(3ossl)
Impressum