diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2021-03-22 14:16:56 +0100 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2021-04-08 15:18:58 +0200 |
commit | c1fd710297a21336ec0410fe86784c322945b805 (patch) | |
tree | a03b44f007e132f873630fab2bb36d153d92a8d2 /test/x509_check_cert_pkey_test.c | |
parent | 321ac1f2973c01f4a4a2719e4400c26ff01c3231 (diff) | |
download | openssl-c1fd710297a21336ec0410fe86784c322945b805.zip openssl-c1fd710297a21336ec0410fe86784c322945b805.tar.gz openssl-c1fd710297a21336ec0410fe86784c322945b805.tar.bz2 |
d2i_PrivateKey{,_ex}() and PEM_X509_INFO_read_bio_ex(): Fix handling of RSA/DSA/EC private key
This is needed to correct d2i_PrivateKey() after it was changed by commit 576892d78f80cf9a.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14647)
Diffstat (limited to 'test/x509_check_cert_pkey_test.c')
-rw-r--r-- | test/x509_check_cert_pkey_test.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/test/x509_check_cert_pkey_test.c b/test/x509_check_cert_pkey_test.c index cf26ed9..3e075e9 100644 --- a/test/x509_check_cert_pkey_test.c +++ b/test/x509_check_cert_pkey_test.c @@ -106,15 +106,47 @@ failed: return ret; } +static const char *file; /* path of a cert/CRL/key file in PEM format */ +static const char *num; /* expected number of certs/CRLs/keys included */ + +static int test_PEM_X509_INFO_read_bio(void) +{ + BIO *in; + STACK_OF(X509_INFO) *sk; + X509_INFO *it; + int i, count = 0; + int expected = 0; + + if (!TEST_ptr((in = BIO_new_file(file, "r")))) + return 0; + sk = PEM_X509_INFO_read_bio(in, NULL, NULL, ""); + BIO_free(in); + sscanf(num, "%d", &expected); + for (i = 0; i < sk_X509_INFO_num(sk); i++) { + it = sk_X509_INFO_value(sk, i); + if (it->x509 != NULL) + count++; + if (it->crl != NULL) + count++; + if (it->x_pkey != NULL) + count++; + } + sk_X509_INFO_pop_free(sk, X509_INFO_free); + return TEST_int_eq(count, expected); +} + const OPTIONS *test_get_options(void) { enum { OPT_TEST_ENUM }; static const OPTIONS test_options[] = { - OPT_TEST_OPTIONS_WITH_EXTRA_USAGE("cert key type expected\n"), + OPT_TEST_OPTIONS_WITH_EXTRA_USAGE("cert key type expected\n" + " or [options] file num\n"), { OPT_HELP_STR, 1, '-', "cert\tcertificate or CSR filename in PEM\n" }, { OPT_HELP_STR, 1, '-', "key\tprivate key filename in PEM\n" }, { OPT_HELP_STR, 1, '-', "type\t\tvalue must be 'cert' or 'req'\n" }, { OPT_HELP_STR, 1, '-', "expected\tthe expected return value, either 'ok' or 'failed'\n" }, + { OPT_HELP_STR, 1, '-', "file\tPEM format file containing certs, keys, and/OR CRLs\n" }, + { OPT_HELP_STR, 1, '-', "num\texpected number of credentials to be loaded from file\n" }, { NULL } }; return test_options; @@ -127,6 +159,14 @@ int setup_tests(void) return 0; } + if (test_get_argument_count() == 2) { + if (!TEST_ptr(file = test_get_argument(0)) + || !TEST_ptr(num = test_get_argument(1))) + return 0; + ADD_TEST(test_PEM_X509_INFO_read_bio); + return 1; + } + if (!TEST_ptr(c = test_get_argument(0)) || !TEST_ptr(k = test_get_argument(1)) || !TEST_ptr(t = test_get_argument(2)) |