Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl33/crypto/x509/t_x509.c
Line
Count
Source
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 "internal/cryptlib.h"
12
#include <openssl/buffer.h>
13
#include <openssl/bn.h>
14
#include <openssl/objects.h>
15
#include <openssl/x509.h>
16
#include <openssl/x509v3.h>
17
#include "crypto/asn1.h"
18
#include "crypto/x509.h"
19
20
void OSSL_STACK_OF_X509_free(STACK_OF(X509) *certs)
21
4.46M
{
22
4.46M
    sk_X509_pop_free(certs, X509_free);
23
4.46M
}
24
25
#ifndef OPENSSL_NO_STDIO
26
int X509_print_fp(FILE *fp, X509 *x)
27
0
{
28
0
    return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
29
0
}
30
31
int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag,
32
    unsigned long cflag)
33
0
{
34
0
    BIO *b;
35
0
    int ret;
36
37
0
    if ((b = BIO_new(BIO_s_file())) == NULL) {
38
0
        ERR_raise(ERR_LIB_X509, ERR_R_BUF_LIB);
39
0
        return 0;
40
0
    }
41
0
    BIO_set_fp(b, fp, BIO_NOCLOSE);
42
0
    ret = X509_print_ex(b, x, nmflag, cflag);
43
0
    BIO_free(b);
44
0
    return ret;
45
0
}
46
#endif
47
48
int X509_print(BIO *bp, X509 *x)
49
39.0k
{
50
39.0k
    return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
51
39.0k
}
52
53
int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
54
    unsigned long cflag)
55
29.6k
{
56
29.6k
    long l;
57
29.6k
    int ret = 0, i;
58
29.6k
    char mlch = ' ';
59
29.6k
    int nmindent = 0, printok = 0;
60
29.6k
    EVP_PKEY *pkey = NULL;
61
29.6k
    const char *neg;
62
63
29.6k
    if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
64
0
        mlch = '\n';
65
0
        nmindent = 12;
66
0
    }
67
68
29.6k
    if (nmflags == XN_FLAG_COMPAT)
69
20.8k
        printok = 1;
70
71
29.6k
    if (!(cflag & X509_FLAG_NO_HEADER)) {
72
20.8k
        if (BIO_write(bp, "Certificate:\n", 13) <= 0)
73
0
            goto err;
74
20.8k
        if (BIO_write(bp, "    Data:\n", 10) <= 0)
75
0
            goto err;
76
20.8k
    }
77
29.6k
    if (!(cflag & X509_FLAG_NO_VERSION)) {
78
20.8k
        l = X509_get_version(x);
79
20.8k
        if (l >= X509_VERSION_1 && l <= X509_VERSION_3) {
80
19.9k
            if (BIO_printf(bp, "%8sVersion: %ld (0x%lx)\n", "", l + 1, (unsigned long)l) <= 0)
81
0
                goto err;
82
19.9k
        } else {
83
850
            if (BIO_printf(bp, "%8sVersion: Unknown (%ld)\n", "", l) <= 0)
84
0
                goto err;
85
850
        }
86
20.8k
    }
87
29.6k
    if (!(cflag & X509_FLAG_NO_SERIAL)) {
88
23.0k
        const ASN1_INTEGER *bs = X509_get0_serialNumber(x);
89
90
23.0k
        if (BIO_write(bp, "        Serial Number:", 22) <= 0)
91
0
            goto err;
92
93
23.0k
        if (bs->length <= (int)sizeof(long)) {
94
22.1k
            ERR_set_mark();
95
22.1k
            l = ASN1_INTEGER_get(bs);
96
22.1k
            ERR_pop_to_mark();
97
22.1k
        } else {
98
857
            l = -1;
99
857
        }
100
23.0k
        if (l != -1) {
101
20.4k
            unsigned long ul;
102
20.4k
            if (bs->type == V_ASN1_NEG_INTEGER) {
103
5.87k
                ul = 0 - (unsigned long)l;
104
5.87k
                neg = "-";
105
14.6k
            } else {
106
14.6k
                ul = l;
107
14.6k
                neg = "";
108
14.6k
            }
109
20.4k
            if (BIO_printf(bp, " %s%lu (%s0x%lx)\n", neg, ul, neg, ul) <= 0)
110
0
                goto err;
111
20.4k
        } else {
112
2.55k
            neg = (bs->type == V_ASN1_NEG_INTEGER) ? " (Negative)" : "";
113
2.55k
            if (BIO_printf(bp, "\n%12s%s", "", neg) <= 0)
114
0
                goto err;
115
116
33.5k
            for (i = 0; i < bs->length; i++) {
117
30.9k
                if (BIO_printf(bp, "%02x%c", bs->data[i],
118
30.9k
                        ((i + 1 == bs->length) ? '\n' : ':'))
119
30.9k
                    <= 0)
120
0
                    goto err;
121
30.9k
            }
122
2.55k
        }
123
23.0k
    }
124
125
29.6k
    if (!(cflag & X509_FLAG_NO_SIGNAME)) {
126
20.8k
        const X509_ALGOR *tsig_alg = X509_get0_tbs_sigalg(x);
127
128
20.8k
        if (BIO_puts(bp, "    ") <= 0)
129
0
            goto err;
130
20.8k
        if (X509_signature_print(bp, tsig_alg, NULL) <= 0)
131
0
            goto err;
132
20.8k
    }
133
134
29.6k
    if (!(cflag & X509_FLAG_NO_ISSUER)) {
135
22.9k
        if (BIO_printf(bp, "        Issuer:%c", mlch) <= 0)
136
0
            goto err;
137
22.9k
        if (X509_NAME_print_ex(bp, X509_get_issuer_name(x), nmindent, nmflags)
138
22.9k
            < printok)
139
53
            goto err;
140
22.8k
        if (BIO_write(bp, "\n", 1) <= 0)
141
0
            goto err;
142
22.8k
    }
143
29.5k
    if (!(cflag & X509_FLAG_NO_VALIDITY)) {
144
23.0k
        if (BIO_write(bp, "        Validity\n", 17) <= 0)
145
0
            goto err;
146
23.0k
        if (BIO_write(bp, "            Not Before: ", 24) <= 0)
147
0
            goto err;
148
23.0k
        if (ossl_asn1_time_print_ex(bp, X509_get0_notBefore(x), ASN1_DTFLGS_RFC822) == 0)
149
0
            goto err;
150
23.0k
        if (BIO_write(bp, "\n            Not After : ", 25) <= 0)
151
0
            goto err;
152
23.0k
        if (ossl_asn1_time_print_ex(bp, X509_get0_notAfter(x), ASN1_DTFLGS_RFC822) == 0)
153
0
            goto err;
154
23.0k
        if (BIO_write(bp, "\n", 1) <= 0)
155
0
            goto err;
156
23.0k
    }
157
29.5k
    if (!(cflag & X509_FLAG_NO_SUBJECT)) {
158
23.0k
        if (BIO_printf(bp, "        Subject:%c", mlch) <= 0)
159
0
            goto err;
160
23.0k
        if (X509_NAME_print_ex(bp, X509_get_subject_name(x), nmindent, nmflags) < printok)
161
26
            goto err;
162
22.9k
        if (BIO_write(bp, "\n", 1) <= 0)
163
0
            goto err;
164
22.9k
    }
165
29.5k
    if (!(cflag & X509_FLAG_NO_PUBKEY)) {
166
20.7k
        X509_PUBKEY *xpkey = X509_get_X509_PUBKEY(x);
167
20.7k
        ASN1_OBJECT *xpoid;
168
20.7k
        X509_PUBKEY_get0_param(&xpoid, NULL, NULL, NULL, xpkey);
169
20.7k
        if (BIO_write(bp, "        Subject Public Key Info:\n", 33) <= 0)
170
0
            goto err;
171
20.7k
        if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
172
0
            goto err;
173
20.7k
        if (i2a_ASN1_OBJECT(bp, xpoid) <= 0)
174
0
            goto err;
175
20.7k
        if (BIO_puts(bp, "\n") <= 0)
176
0
            goto err;
177
178
20.7k
        pkey = X509_get0_pubkey(x);
179
20.7k
        if (pkey == NULL) {
180
15.6k
            BIO_printf(bp, "%12sUnable to load Public Key\n", "");
181
15.6k
            ERR_print_errors(bp);
182
15.6k
        } else {
183
5.08k
            EVP_PKEY_print_public(bp, pkey, 16, NULL);
184
5.08k
        }
185
20.7k
    }
186
187
29.5k
    if (!(cflag & X509_FLAG_NO_IDS)) {
188
20.7k
        const ASN1_BIT_STRING *iuid, *suid;
189
20.7k
        X509_get0_uids(x, &iuid, &suid);
190
20.7k
        if (iuid != NULL) {
191
48
            if (BIO_printf(bp, "%8sIssuer Unique ID: ", "") <= 0)
192
0
                goto err;
193
48
            if (!X509_signature_dump(bp, iuid, 12))
194
0
                goto err;
195
48
        }
196
20.7k
        if (suid != NULL) {
197
57
            if (BIO_printf(bp, "%8sSubject Unique ID: ", "") <= 0)
198
0
                goto err;
199
57
            if (!X509_signature_dump(bp, suid, 12))
200
0
                goto err;
201
57
        }
202
20.7k
    }
203
204
29.5k
    if (!(cflag & X509_FLAG_NO_EXTENSIONS)
205
22.9k
        && !X509V3_extensions_print(bp, "X509v3 extensions",
206
22.9k
            X509_get0_extensions(x), cflag, 8))
207
0
        goto err;
208
209
29.5k
    if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
210
20.7k
        const X509_ALGOR *sig_alg;
211
20.7k
        const ASN1_BIT_STRING *sig;
212
20.7k
        X509_get0_signature(&sig, &sig_alg, x);
213
20.7k
        if (X509_signature_print(bp, sig_alg, sig) <= 0)
214
0
            goto err;
215
20.7k
    }
216
29.5k
    if (!(cflag & X509_FLAG_NO_AUX)) {
217
20.7k
        if (!X509_aux_print(bp, x, 0))
218
0
            goto err;
219
20.7k
    }
220
29.5k
    ret = 1;
221
29.6k
err:
222
29.6k
    return ret;
223
29.5k
}
224
225
int X509_ocspid_print(BIO *bp, X509 *x)
226
0
{
227
0
    unsigned char *der = NULL;
228
0
    unsigned char *dertmp;
229
0
    int derlen;
230
0
    int i;
231
0
    unsigned char SHA1md[SHA_DIGEST_LENGTH];
232
0
    ASN1_BIT_STRING *keybstr;
233
0
    const X509_NAME *subj;
234
0
    EVP_MD *md = NULL;
235
236
0
    if (x == NULL || bp == NULL)
237
0
        return 0;
238
    /*
239
     * display the hash of the subject as it would appear in OCSP requests
240
     */
241
0
    if (BIO_printf(bp, "        Subject OCSP hash: ") <= 0)
242
0
        goto err;
243
0
    subj = X509_get_subject_name(x);
244
0
    derlen = i2d_X509_NAME(subj, NULL);
245
0
    if (derlen <= 0)
246
0
        goto err;
247
0
    if ((der = dertmp = OPENSSL_malloc(derlen)) == NULL)
248
0
        goto err;
249
0
    if (i2d_X509_NAME(subj, &dertmp) < 0)
250
0
        goto err;
251
252
0
    md = EVP_MD_fetch(x->libctx, SN_sha1, x->propq);
253
0
    if (md == NULL)
254
0
        goto err;
255
0
    if (!EVP_Digest(der, derlen, SHA1md, NULL, md, NULL))
256
0
        goto err;
257
0
    for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
258
0
        if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0)
259
0
            goto err;
260
0
    }
261
0
    OPENSSL_free(der);
262
0
    der = NULL;
263
264
    /*
265
     * display the hash of the public key as it would appear in OCSP requests
266
     */
267
0
    if (BIO_printf(bp, "\n        Public key OCSP hash: ") <= 0)
268
0
        goto err;
269
270
0
    keybstr = X509_get0_pubkey_bitstr(x);
271
272
0
    if (keybstr == NULL)
273
0
        goto err;
274
275
0
    if (!EVP_Digest(ASN1_STRING_get0_data(keybstr),
276
0
            ASN1_STRING_length(keybstr), SHA1md, NULL, md, NULL))
277
0
        goto err;
278
0
    for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
279
0
        if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0)
280
0
            goto err;
281
0
    }
282
0
    BIO_printf(bp, "\n");
283
0
    EVP_MD_free(md);
284
285
0
    return 1;
286
0
err:
287
0
    OPENSSL_free(der);
288
0
    EVP_MD_free(md);
289
0
    return 0;
290
0
}
291
292
int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
293
87.6k
{
294
87.6k
    const unsigned char *s;
295
87.6k
    int i, n;
296
297
87.6k
    n = sig->length;
298
87.6k
    s = sig->data;
299
94.1M
    for (i = 0; i < n; i++) {
300
94.0M
        if ((i % 18) == 0) {
301
4.97M
            if (i > 0 && BIO_write(bp, "\n", 1) <= 0)
302
0
                return 0;
303
4.97M
            if (BIO_indent(bp, indent, indent) <= 0)
304
0
                return 0;
305
4.97M
        }
306
94.0M
        if (BIO_printf(bp, "%02x%s", s[i], ((i + 1) == n) ? "" : ":") <= 0)
307
0
            return 0;
308
94.0M
    }
309
87.6k
    if (BIO_write(bp, "\n", 1) != 1)
310
0
        return 0;
311
312
87.6k
    return 1;
313
87.6k
}
314
315
int X509_signature_print(BIO *bp, const X509_ALGOR *sigalg,
316
    const ASN1_STRING *sig)
317
164k
{
318
164k
    int sig_nid;
319
164k
    int indent = 4;
320
164k
    if (BIO_printf(bp, "%*sSignature Algorithm: ", indent, "") <= 0)
321
0
        return 0;
322
164k
    if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0)
323
0
        return 0;
324
325
164k
    if (sig && BIO_printf(bp, "\n%*sSignature Value:", indent, "") <= 0)
326
0
        return 0;
327
164k
    sig_nid = OBJ_obj2nid(sigalg->algorithm);
328
164k
    if (sig_nid != NID_undef) {
329
43.5k
        int pkey_nid, dig_nid;
330
43.5k
        const EVP_PKEY_ASN1_METHOD *ameth;
331
43.5k
        if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) {
332
20.8k
            ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
333
20.8k
            if (ameth && ameth->sig_print)
334
19.8k
                return ameth->sig_print(bp, sigalg, sig, indent + 4, 0);
335
20.8k
        }
336
43.5k
    }
337
145k
    if (BIO_write(bp, "\n", 1) != 1)
338
0
        return 0;
339
145k
    if (sig)
340
77.7k
        return X509_signature_dump(bp, sig, indent + 4);
341
67.3k
    return 1;
342
145k
}
343
344
int X509_aux_print(BIO *out, X509 *x, int indent)
345
38.8k
{
346
38.8k
    char oidstr[80], first;
347
38.8k
    STACK_OF(ASN1_OBJECT) *trust, *reject;
348
38.8k
    const unsigned char *alias, *keyid;
349
38.8k
    int keyidlen;
350
38.8k
    int i;
351
38.8k
    if (X509_trusted(x) == 0)
352
38.8k
        return 1;
353
0
    trust = X509_get0_trust_objects(x);
354
0
    reject = X509_get0_reject_objects(x);
355
0
    if (trust) {
356
0
        first = 1;
357
0
        BIO_printf(out, "%*sTrusted Uses:\n%*s", indent, "", indent + 2, "");
358
0
        for (i = 0; i < sk_ASN1_OBJECT_num(trust); i++) {
359
0
            if (!first)
360
0
                BIO_puts(out, ", ");
361
0
            else
362
0
                first = 0;
363
0
            OBJ_obj2txt(oidstr, sizeof(oidstr),
364
0
                sk_ASN1_OBJECT_value(trust, i), 0);
365
0
            BIO_puts(out, oidstr);
366
0
        }
367
0
        BIO_puts(out, "\n");
368
0
    } else
369
0
        BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
370
0
    if (reject) {
371
0
        first = 1;
372
0
        BIO_printf(out, "%*sRejected Uses:\n%*s", indent, "", indent + 2, "");
373
0
        for (i = 0; i < sk_ASN1_OBJECT_num(reject); i++) {
374
0
            if (!first)
375
0
                BIO_puts(out, ", ");
376
0
            else
377
0
                first = 0;
378
0
            OBJ_obj2txt(oidstr, sizeof(oidstr),
379
0
                sk_ASN1_OBJECT_value(reject, i), 0);
380
0
            BIO_puts(out, oidstr);
381
0
        }
382
0
        BIO_puts(out, "\n");
383
0
    } else
384
0
        BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
385
0
    alias = X509_alias_get0(x, &i);
386
0
    if (alias)
387
0
        BIO_printf(out, "%*sAlias: %.*s\n", indent, "", i, alias);
388
0
    keyid = X509_keyid_get0(x, &keyidlen);
389
0
    if (keyid) {
390
0
        BIO_printf(out, "%*sKey Id: ", indent, "");
391
0
        for (i = 0; i < keyidlen; i++)
392
0
            BIO_printf(out, "%s%02X", i ? ":" : "", keyid[i]);
393
0
        BIO_write(out, "\n", 1);
394
0
    }
395
0
    return 1;
396
38.8k
}
397
398
/*
399
 * Helper functions for improving certificate verification error diagnostics
400
 */
401
402
int ossl_x509_print_ex_brief(BIO *bio, X509 *cert, unsigned long neg_cflags)
403
3.93k
{
404
3.93k
    unsigned long flags = ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE | XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN;
405
406
3.93k
    if (cert == NULL)
407
0
        return BIO_printf(bio, "    (no certificate)\n") > 0;
408
3.93k
    if (BIO_printf(bio, "    certificate\n") <= 0
409
3.93k
        || !X509_print_ex(bio, cert, flags, ~X509_FLAG_NO_SUBJECT))
410
0
        return 0;
411
3.93k
    if (X509_check_issued((X509 *)cert, cert) == X509_V_OK) {
412
193
        if (BIO_printf(bio, "        self-issued\n") <= 0)
413
0
            return 0;
414
3.74k
    } else {
415
3.74k
        if (BIO_printf(bio, " ") <= 0
416
3.74k
            || !X509_print_ex(bio, cert, flags, ~X509_FLAG_NO_ISSUER))
417
0
            return 0;
418
3.74k
    }
419
3.93k
    if (!X509_print_ex(bio, cert, flags,
420
3.93k
            ~(X509_FLAG_NO_SERIAL | X509_FLAG_NO_VALIDITY)))
421
0
        return 0;
422
3.93k
    if (X509_cmp_current_time(X509_get0_notBefore(cert)) > 0)
423
236
        if (BIO_printf(bio, "        not yet valid\n") <= 0)
424
0
            return 0;
425
3.93k
    if (X509_cmp_current_time(X509_get0_notAfter(cert)) < 0)
426
398
        if (BIO_printf(bio, "        no more valid\n") <= 0)
427
0
            return 0;
428
3.93k
    return X509_print_ex(bio, cert, flags,
429
3.93k
        ~neg_cflags & ~X509_FLAG_EXTENSIONS_ONLY_KID);
430
3.93k
}
431
432
static int print_certs(BIO *bio, const STACK_OF(X509) *certs)
433
0
{
434
0
    int i;
435
436
0
    if (certs == NULL || sk_X509_num(certs) <= 0)
437
0
        return BIO_printf(bio, "    (no certificates)\n") >= 0;
438
439
0
    for (i = 0; i < sk_X509_num(certs); i++) {
440
0
        X509 *cert = sk_X509_value(certs, i);
441
442
0
        if (cert != NULL) {
443
0
            if (!ossl_x509_print_ex_brief(bio, cert, 0))
444
0
                return 0;
445
0
            if (!X509V3_extensions_print(bio, NULL,
446
0
                    X509_get0_extensions(cert),
447
0
                    X509_FLAG_EXTENSIONS_ONLY_KID, 8))
448
0
                return 0;
449
0
        }
450
0
    }
451
0
    return 1;
452
0
}
453
454
static int print_store_certs(BIO *bio, X509_STORE *store)
455
0
{
456
0
    if (store != NULL) {
457
0
        STACK_OF(X509) *certs = X509_STORE_get1_all_certs(store);
458
0
        int ret = print_certs(bio, certs);
459
460
0
        OSSL_STACK_OF_X509_free(certs);
461
0
        return ret;
462
0
    } else {
463
0
        return BIO_printf(bio, "    (no trusted store)\n") >= 0;
464
0
    }
465
0
}
466
467
/* Extend the error queue with details on a failed cert verification */
468
int X509_STORE_CTX_print_verify_cb(int ok, X509_STORE_CTX *ctx)
469
0
{
470
0
    if (ok == 0 && ctx != NULL) {
471
0
        int cert_error = X509_STORE_CTX_get_error(ctx);
472
0
        BIO *bio = BIO_new(BIO_s_mem()); /* may be NULL */
473
474
0
        if (bio == NULL)
475
0
            return 0;
476
0
        BIO_printf(bio, "%s at depth = %d error = %d (%s)\n",
477
0
            X509_STORE_CTX_get0_parent_ctx(ctx) != NULL
478
0
                ? "CRL path validation"
479
0
                : "Certificate verification",
480
0
            X509_STORE_CTX_get_error_depth(ctx),
481
0
            cert_error, X509_verify_cert_error_string(cert_error));
482
0
        {
483
0
            X509_STORE *ts = X509_STORE_CTX_get0_store(ctx);
484
0
            X509_VERIFY_PARAM *vpm = X509_STORE_get0_param(ts);
485
0
            char *str;
486
0
            int idx = 0;
487
488
0
            switch (cert_error) {
489
0
            case X509_V_ERR_HOSTNAME_MISMATCH:
490
0
                BIO_printf(bio, "Expected hostname(s) = ");
491
0
                while ((str = X509_VERIFY_PARAM_get0_host(vpm, idx++)) != NULL)
492
0
                    BIO_printf(bio, "%s%s", idx == 1 ? "" : ", ", str);
493
0
                BIO_printf(bio, "\n");
494
0
                break;
495
0
            case X509_V_ERR_EMAIL_MISMATCH:
496
0
                str = X509_VERIFY_PARAM_get0_email(vpm);
497
0
                if (str != NULL)
498
0
                    BIO_printf(bio, "Expected email address = %s\n", str);
499
0
                break;
500
0
            case X509_V_ERR_IP_ADDRESS_MISMATCH:
501
0
                str = X509_VERIFY_PARAM_get1_ip_asc(vpm);
502
0
                if (str != NULL)
503
0
                    BIO_printf(bio, "Expected IP address = %s\n", str);
504
0
                OPENSSL_free(str);
505
0
                break;
506
0
            default:
507
0
                break;
508
0
            }
509
0
        }
510
511
0
        BIO_printf(bio, "Failure for:\n");
512
0
        ossl_x509_print_ex_brief(bio, X509_STORE_CTX_get_current_cert(ctx),
513
0
            X509_FLAG_NO_EXTENSIONS);
514
0
        if (cert_error == X509_V_ERR_CERT_UNTRUSTED
515
0
            || cert_error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT
516
0
            || cert_error == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN
517
0
            || cert_error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT
518
0
            || cert_error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
519
0
            || cert_error == X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER
520
0
            || cert_error == X509_V_ERR_STORE_LOOKUP) {
521
0
            BIO_printf(bio, "Non-trusted certs:\n");
522
0
            print_certs(bio, X509_STORE_CTX_get0_untrusted(ctx));
523
0
            BIO_printf(bio, "Certs in trust store:\n");
524
0
            print_store_certs(bio, X509_STORE_CTX_get0_store(ctx));
525
0
        }
526
0
        ERR_raise(ERR_LIB_X509, X509_R_CERTIFICATE_VERIFICATION_FAILED);
527
0
        ERR_add_error_mem_bio("\n", bio);
528
0
        BIO_free(bio);
529
0
    }
530
531
0
    return ok;
532
0
}