Coverage Report

Created: 2025-06-13 06:58

/src/openssl32/crypto/x509/t_x509.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2023 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
1.63M
{
22
1.63M
    sk_X509_pop_free(certs, X509_free);
23
1.63M
}
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
29.3k
{
50
29.3k
    return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
51
29.3k
}
52
53
int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
54
                  unsigned long cflag)
55
27.5k
{
56
27.5k
    long l;
57
27.5k
    int ret = 0, i;
58
27.5k
    char mlch = ' ';
59
27.5k
    int nmindent = 0, printok = 0;
60
27.5k
    EVP_PKEY *pkey = NULL;
61
27.5k
    const char *neg;
62
63
27.5k
    if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
64
0
        mlch = '\n';
65
0
        nmindent = 12;
66
0
    }
67
68
27.5k
    if (nmflags == XN_FLAG_COMPAT)
69
21.9k
        printok = 1;
70
71
27.5k
    if (!(cflag & X509_FLAG_NO_HEADER)) {
72
21.9k
        if (BIO_write(bp, "Certificate:\n", 13) <= 0)
73
0
            goto err;
74
21.9k
        if (BIO_write(bp, "    Data:\n", 10) <= 0)
75
0
            goto err;
76
21.9k
    }
77
27.5k
    if (!(cflag & X509_FLAG_NO_VERSION)) {
78
21.9k
        l = X509_get_version(x);
79
21.9k
        if (l >= X509_VERSION_1 && l <= X509_VERSION_3) {
80
20.7k
            if (BIO_printf(bp, "%8sVersion: %ld (0x%lx)\n", "", l + 1, (unsigned long)l) <= 0)
81
0
                goto err;
82
20.7k
        } else {
83
1.21k
            if (BIO_printf(bp, "%8sVersion: Unknown (%ld)\n", "", l) <= 0)
84
0
                goto err;
85
1.21k
        }
86
21.9k
    }
87
27.5k
    if (!(cflag & X509_FLAG_NO_SERIAL)) {
88
23.3k
        const ASN1_INTEGER *bs = X509_get0_serialNumber(x);
89
90
23.3k
        if (BIO_write(bp, "        Serial Number:", 22) <= 0)
91
0
            goto err;
92
93
23.3k
        if (bs->length <= (int)sizeof(long)) {
94
22.6k
                ERR_set_mark();
95
22.6k
                l = ASN1_INTEGER_get(bs);
96
22.6k
                ERR_pop_to_mark();
97
22.6k
        } else {
98
713
            l = -1;
99
713
        }
100
23.3k
        if (l != -1) {
101
20.4k
            unsigned long ul;
102
20.4k
            if (bs->type == V_ASN1_NEG_INTEGER) {
103
7.21k
                ul = 0 - (unsigned long)l;
104
7.21k
                neg = "-";
105
13.2k
            } else {
106
13.2k
                ul = l;
107
13.2k
                neg = "";
108
13.2k
            }
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.92k
            neg = (bs->type == V_ASN1_NEG_INTEGER) ? " (Negative)" : "";
113
2.92k
            if (BIO_printf(bp, "\n%12s%s", "", neg) <= 0)
114
0
                goto err;
115
116
79.2k
            for (i = 0; i < bs->length; i++) {
117
76.2k
                if (BIO_printf(bp, "%02x%c", bs->data[i],
118
76.2k
                               ((i + 1 == bs->length) ? '\n' : ':')) <= 0)
119
0
                    goto err;
120
76.2k
            }
121
2.92k
        }
122
123
23.3k
    }
124
125
27.5k
    if (!(cflag & X509_FLAG_NO_SIGNAME)) {
126
21.9k
        const X509_ALGOR *tsig_alg = X509_get0_tbs_sigalg(x);
127
128
21.9k
        if (BIO_puts(bp, "    ") <= 0)
129
0
            goto err;
130
21.9k
        if (X509_signature_print(bp, tsig_alg, NULL) <= 0)
131
0
            goto err;
132
21.9k
    }
133
134
27.5k
    if (!(cflag & X509_FLAG_NO_ISSUER)) {
135
23.3k
        if (BIO_printf(bp, "        Issuer:%c", mlch) <= 0)
136
0
            goto err;
137
23.3k
        if (X509_NAME_print_ex(bp, X509_get_issuer_name(x), nmindent, nmflags)
138
23.3k
            < printok)
139
71
            goto err;
140
23.2k
        if (BIO_write(bp, "\n", 1) <= 0)
141
0
            goto err;
142
23.2k
    }
143
27.5k
    if (!(cflag & X509_FLAG_NO_VALIDITY)) {
144
23.2k
        if (BIO_write(bp, "        Validity\n", 17) <= 0)
145
0
            goto err;
146
23.2k
        if (BIO_write(bp, "            Not Before: ", 24) <= 0)
147
0
            goto err;
148
23.2k
        if (ossl_asn1_time_print_ex(bp, X509_get0_notBefore(x), ASN1_DTFLGS_RFC822) == 0)
149
0
            goto err;
150
23.2k
        if (BIO_write(bp, "\n            Not After : ", 25) <= 0)
151
0
            goto err;
152
23.2k
        if (ossl_asn1_time_print_ex(bp, X509_get0_notAfter(x), ASN1_DTFLGS_RFC822) == 0)
153
0
            goto err;
154
23.2k
        if (BIO_write(bp, "\n", 1) <= 0)
155
0
            goto err;
156
23.2k
    }
157
27.5k
    if (!(cflag & X509_FLAG_NO_SUBJECT)) {
158
23.2k
        if (BIO_printf(bp, "        Subject:%c", mlch) <= 0)
159
0
            goto err;
160
23.2k
        if (X509_NAME_print_ex
161
23.2k
            (bp, X509_get_subject_name(x), nmindent, nmflags) < printok)
162
7
            goto err;
163
23.2k
        if (BIO_write(bp, "\n", 1) <= 0)
164
0
            goto err;
165
23.2k
    }
166
27.5k
    if (!(cflag & X509_FLAG_NO_PUBKEY)) {
167
21.8k
        X509_PUBKEY *xpkey = X509_get_X509_PUBKEY(x);
168
21.8k
        ASN1_OBJECT *xpoid;
169
21.8k
        X509_PUBKEY_get0_param(&xpoid, NULL, NULL, NULL, xpkey);
170
21.8k
        if (BIO_write(bp, "        Subject Public Key Info:\n", 33) <= 0)
171
0
            goto err;
172
21.8k
        if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
173
0
            goto err;
174
21.8k
        if (i2a_ASN1_OBJECT(bp, xpoid) <= 0)
175
0
            goto err;
176
21.8k
        if (BIO_puts(bp, "\n") <= 0)
177
0
            goto err;
178
179
21.8k
        pkey = X509_get0_pubkey(x);
180
21.8k
        if (pkey == NULL) {
181
16.7k
            BIO_printf(bp, "%12sUnable to load Public Key\n", "");
182
16.7k
            ERR_print_errors(bp);
183
16.7k
        } else {
184
5.13k
            EVP_PKEY_print_public(bp, pkey, 16, NULL);
185
5.13k
        }
186
21.8k
    }
187
188
27.5k
    if (!(cflag & X509_FLAG_NO_IDS)) {
189
21.8k
        const ASN1_BIT_STRING *iuid, *suid;
190
21.8k
        X509_get0_uids(x, &iuid, &suid);
191
21.8k
        if (iuid != NULL) {
192
26
            if (BIO_printf(bp, "%8sIssuer Unique ID: ", "") <= 0)
193
0
                goto err;
194
26
            if (!X509_signature_dump(bp, iuid, 12))
195
0
                goto err;
196
26
        }
197
21.8k
        if (suid != NULL) {
198
43
            if (BIO_printf(bp, "%8sSubject Unique ID: ", "") <= 0)
199
0
                goto err;
200
43
            if (!X509_signature_dump(bp, suid, 12))
201
0
                goto err;
202
43
        }
203
21.8k
    }
204
205
27.5k
    if (!(cflag & X509_FLAG_NO_EXTENSIONS)
206
27.5k
        && !X509V3_extensions_print(bp, "X509v3 extensions",
207
23.2k
                                    X509_get0_extensions(x), cflag, 8))
208
0
        goto err;
209
210
27.5k
    if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
211
21.8k
        const X509_ALGOR *sig_alg;
212
21.8k
        const ASN1_BIT_STRING *sig;
213
21.8k
        X509_get0_signature(&sig, &sig_alg, x);
214
21.8k
        if (X509_signature_print(bp, sig_alg, sig) <= 0)
215
0
            goto err;
216
21.8k
    }
217
27.5k
    if (!(cflag & X509_FLAG_NO_AUX)) {
218
21.8k
        if (!X509_aux_print(bp, x, 0))
219
0
            goto err;
220
21.8k
    }
221
27.5k
    ret = 1;
222
27.5k
 err:
223
27.5k
    return ret;
224
27.5k
}
225
226
int X509_ocspid_print(BIO *bp, X509 *x)
227
0
{
228
0
    unsigned char *der = NULL;
229
0
    unsigned char *dertmp;
230
0
    int derlen;
231
0
    int i;
232
0
    unsigned char SHA1md[SHA_DIGEST_LENGTH];
233
0
    ASN1_BIT_STRING *keybstr;
234
0
    const X509_NAME *subj;
235
0
    EVP_MD *md = NULL;
236
237
0
    if (x == NULL || bp == NULL)
238
0
        return 0;
239
    /*
240
     * display the hash of the subject as it would appear in OCSP requests
241
     */
242
0
    if (BIO_printf(bp, "        Subject OCSP hash: ") <= 0)
243
0
        goto err;
244
0
    subj = X509_get_subject_name(x);
245
0
    derlen = i2d_X509_NAME(subj, NULL);
246
0
    if (derlen <= 0)
247
0
        goto err;
248
0
    if ((der = dertmp = OPENSSL_malloc(derlen)) == NULL)
249
0
        goto err;
250
0
    i2d_X509_NAME(subj, &dertmp);
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
60.5k
{
294
60.5k
    const unsigned char *s;
295
60.5k
    int i, n;
296
297
60.5k
    n = sig->length;
298
60.5k
    s = sig->data;
299
81.5M
    for (i = 0; i < n; i++) {
300
81.5M
        if ((i % 18) == 0) {
301
4.53M
            if (i > 0 && BIO_write(bp, "\n", 1) <= 0)
302
0
                return 0;
303
4.53M
            if (BIO_indent(bp, indent, indent) <= 0)
304
0
                return 0;
305
4.53M
        }
306
81.5M
        if (BIO_printf(bp, "%02x%s", s[i], ((i + 1) == n) ? "" : ":") <= 0)
307
0
            return 0;
308
81.5M
    }
309
60.5k
    if (BIO_write(bp, "\n", 1) != 1)
310
0
        return 0;
311
312
60.5k
    return 1;
313
60.5k
}
314
315
int X509_signature_print(BIO *bp, const X509_ALGOR *sigalg,
316
                         const ASN1_STRING *sig)
317
119k
{
318
119k
    int sig_nid;
319
119k
    int indent = 4;
320
119k
    if (BIO_printf(bp, "%*sSignature Algorithm: ", indent, "") <= 0)
321
0
        return 0;
322
119k
    if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0)
323
0
        return 0;
324
325
119k
    if (sig && BIO_printf(bp, "\n%*sSignature Value:", indent, "") <= 0)
326
0
        return 0;
327
119k
    sig_nid = OBJ_obj2nid(sigalg->algorithm);
328
119k
    if (sig_nid != NID_undef) {
329
31.6k
        int pkey_nid, dig_nid;
330
31.6k
        const EVP_PKEY_ASN1_METHOD *ameth;
331
31.6k
        if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) {
332
13.5k
            ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
333
13.5k
            if (ameth && ameth->sig_print)
334
12.8k
                return ameth->sig_print(bp, sigalg, sig, indent + 4, 0);
335
13.5k
        }
336
31.6k
    }
337
106k
    if (BIO_write(bp, "\n", 1) != 1)
338
0
        return 0;
339
106k
    if (sig)
340
54.2k
        return X509_signature_dump(bp, sig, indent + 4);
341
51.9k
    return 1;
342
106k
}
343
344
int X509_aux_print(BIO *out, X509 *x, int indent)
345
29.2k
{
346
29.2k
    char oidstr[80], first;
347
29.2k
    STACK_OF(ASN1_OBJECT) *trust, *reject;
348
29.2k
    const unsigned char *alias, *keyid;
349
29.2k
    int keyidlen;
350
29.2k
    int i;
351
29.2k
    if (X509_trusted(x) == 0)
352
29.2k
        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
29.2k
}
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
2.17k
{
404
2.17k
    unsigned long flags = ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE |
405
2.17k
        XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN;
406
407
2.17k
    if (cert == NULL)
408
0
        return BIO_printf(bio, "    (no certificate)\n") > 0;
409
2.17k
    if (BIO_printf(bio, "    certificate\n") <= 0
410
2.17k
            || !X509_print_ex(bio, cert, flags, ~X509_FLAG_NO_SUBJECT))
411
0
        return 0;
412
2.17k
    if (X509_check_issued((X509 *)cert, cert) == X509_V_OK) {
413
91
        if (BIO_printf(bio, "        self-issued\n") <= 0)
414
0
            return 0;
415
2.08k
    } else {
416
2.08k
        if (BIO_printf(bio, " ") <= 0
417
2.08k
            || !X509_print_ex(bio, cert, flags, ~X509_FLAG_NO_ISSUER))
418
0
            return 0;
419
2.08k
    }
420
2.17k
    if (!X509_print_ex(bio, cert, flags,
421
2.17k
                       ~(X509_FLAG_NO_SERIAL | X509_FLAG_NO_VALIDITY)))
422
0
        return 0;
423
2.17k
    if (X509_cmp_current_time(X509_get0_notBefore(cert)) > 0)
424
73
        if (BIO_printf(bio, "        not yet valid\n") <= 0)
425
0
            return 0;
426
2.17k
    if (X509_cmp_current_time(X509_get0_notAfter(cert)) < 0)
427
159
        if (BIO_printf(bio, "        no more valid\n") <= 0)
428
0
            return 0;
429
2.17k
    return X509_print_ex(bio, cert, flags,
430
2.17k
                         ~neg_cflags & ~X509_FLAG_EXTENSIONS_ONLY_KID);
431
2.17k
}
432
433
static int print_certs(BIO *bio, const STACK_OF(X509) *certs)
434
0
{
435
0
    int i;
436
437
0
    if (certs == NULL || sk_X509_num(certs) <= 0)
438
0
        return BIO_printf(bio, "    (no certificates)\n") >= 0;
439
440
0
    for (i = 0; i < sk_X509_num(certs); i++) {
441
0
        X509 *cert = sk_X509_value(certs, i);
442
443
0
        if (cert != NULL) {
444
0
            if (!ossl_x509_print_ex_brief(bio, cert, 0))
445
0
                return 0;
446
0
            if (!X509V3_extensions_print(bio, NULL,
447
0
                                         X509_get0_extensions(cert),
448
0
                                         X509_FLAG_EXTENSIONS_ONLY_KID, 8))
449
0
                return 0;
450
0
            }
451
0
    }
452
0
    return 1;
453
0
}
454
455
static int print_store_certs(BIO *bio, X509_STORE *store)
456
0
{
457
0
    if (store != NULL) {
458
0
        STACK_OF(X509) *certs = X509_STORE_get1_all_certs(store);
459
0
        int ret = print_certs(bio, certs);
460
461
0
        OSSL_STACK_OF_X509_free(certs);
462
0
        return ret;
463
0
    } else {
464
0
        return BIO_printf(bio, "    (no trusted store)\n") >= 0;
465
0
    }
466
0
}
467
468
/* Extend the error queue with details on a failed cert verification */
469
int X509_STORE_CTX_print_verify_cb(int ok, X509_STORE_CTX *ctx)
470
0
{
471
0
    if (ok == 0 && ctx != NULL) {
472
0
        int cert_error = X509_STORE_CTX_get_error(ctx);
473
0
        BIO *bio = BIO_new(BIO_s_mem()); /* may be NULL */
474
475
0
        if (bio == NULL)
476
0
            return 0;
477
0
        BIO_printf(bio, "%s at depth = %d error = %d (%s)\n",
478
0
                   X509_STORE_CTX_get0_parent_ctx(ctx) != NULL
479
0
                   ? "CRL path validation"
480
0
                   : "Certificate verification",
481
0
                   X509_STORE_CTX_get_error_depth(ctx),
482
0
                   cert_error, X509_verify_cert_error_string(cert_error));
483
0
        {
484
0
            X509_STORE *ts = X509_STORE_CTX_get0_store(ctx);
485
0
            X509_VERIFY_PARAM *vpm = X509_STORE_get0_param(ts);
486
0
            char *str;
487
0
            int idx = 0;
488
489
0
            switch (cert_error) {
490
0
            case X509_V_ERR_HOSTNAME_MISMATCH:
491
0
                BIO_printf(bio, "Expected hostname(s) = ");
492
0
                while ((str = X509_VERIFY_PARAM_get0_host(vpm, idx++)) != NULL)
493
0
                    BIO_printf(bio, "%s%s", idx == 1 ? "" : ", ", str);
494
0
                BIO_printf(bio, "\n");
495
0
                break;
496
0
            case X509_V_ERR_EMAIL_MISMATCH:
497
0
                str = X509_VERIFY_PARAM_get0_email(vpm);
498
0
                if (str != NULL)
499
0
                    BIO_printf(bio, "Expected email address = %s\n", str);
500
0
                break;
501
0
            case X509_V_ERR_IP_ADDRESS_MISMATCH:
502
0
                str = X509_VERIFY_PARAM_get1_ip_asc(vpm);
503
0
                if (str != NULL)
504
0
                    BIO_printf(bio, "Expected IP address = %s\n", str);
505
0
                OPENSSL_free(str);
506
0
                break;
507
0
            default:
508
0
                break;
509
0
            }
510
0
        }
511
512
0
        BIO_printf(bio, "Failure for:\n");
513
0
        ossl_x509_print_ex_brief(bio, X509_STORE_CTX_get_current_cert(ctx),
514
0
                                 X509_FLAG_NO_EXTENSIONS);
515
0
        if (cert_error == X509_V_ERR_CERT_UNTRUSTED
516
0
                || cert_error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT
517
0
                || cert_error == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN
518
0
                || cert_error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT
519
0
                || cert_error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
520
0
                || cert_error == X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER
521
0
                || cert_error == X509_V_ERR_STORE_LOOKUP) {
522
0
            BIO_printf(bio, "Non-trusted certs:\n");
523
0
            print_certs(bio, X509_STORE_CTX_get0_untrusted(ctx));
524
0
            BIO_printf(bio, "Certs in trust store:\n");
525
0
            print_store_certs(bio, X509_STORE_CTX_get0_store(ctx));
526
0
        }
527
0
        ERR_raise(ERR_LIB_X509, X509_R_CERTIFICATE_VERIFICATION_FAILED);
528
0
        ERR_add_error_mem_bio("\n", bio);
529
0
        BIO_free(bio);
530
0
    }
531
532
0
    return ok;
533
0
}