2 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
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
13 #include <openssl/x509.h>
14 #include <openssl/pem.h>
16 #include "../testutil.h"
18 X509 *load_cert_pem(const char *file, OSSL_LIB_CTX *libctx)
23 if (!TEST_ptr(bio = BIO_new(BIO_s_file())))
25 if (TEST_int_gt(BIO_read_filename(bio, file), 0)
26 && TEST_ptr(cert = X509_new_ex(libctx, NULL)))
27 (void)TEST_ptr(cert = PEM_read_bio_X509(bio, &cert, NULL, NULL));
33 STACK_OF(X509) *load_certs_pem(const char *filename)
35 STACK_OF(X509) *certs;
39 bio = BIO_new_file(filename, "r");
45 certs = sk_X509_new_null();
53 x = PEM_read_bio_X509(bio, NULL, 0, NULL);
54 if (x != NULL && !sk_X509_push(certs, x)) {
55 sk_X509_pop_free(certs, X509_free);
58 } else if (x == NULL) {
60 * We probably just ran out of certs, so ignore any errors
72 EVP_PKEY *load_pkey_pem(const char *file, OSSL_LIB_CTX *libctx)
77 if (!TEST_ptr(bio = BIO_new(BIO_s_file())))
79 if (TEST_int_gt(BIO_read_filename(bio, file), 0))
80 (void)TEST_ptr(key = PEM_read_bio_PrivateKey_ex(bio, NULL, NULL, NULL,
87 X509_REQ *load_csr_der(const char *file)
92 if (!TEST_ptr(file) || !TEST_ptr(bio = BIO_new_file(file, "rb")))
94 (void)TEST_ptr(csr = d2i_X509_REQ_bio(bio, NULL));