Coverage Report

Created: 2023-06-08 06:40

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