summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2020-09-04 10:52:20 +0200
committerRichard Levitte <levitte@openssl.org>2020-09-08 06:26:19 +0200
commit08497fc64f688a91d421de74a8498aff33573485 (patch)
treebb21cb1ed600051692b933fa70fe066a97dd33ff /test
parent20d56d6d62d98c3b2649afd2d20e0c2cc39afce1 (diff)
Fix test/evp_extra_test.c
Because EVP_PKEY_CTX_new_from_name() could return a non-NULL context with no value in it, the lack of legacy implementation when OpenSSL was configured with 'no-ec' went through undetected. This adds the necessary guards to skip a test of SM2 in that case. Reviewed-by: Paul Yang <kaishen.yy@antfin.com> (Merged from https://github.com/openssl/openssl/pull/12785)
Diffstat (limited to 'test')
-rw-r--r--test/evp_extra_test.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index f62e26c290..94b95eeac8 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -1803,14 +1803,19 @@ static int test_keygen_with_empty_template(int n)
/*
* Test that we fail if we attempt to use an algorithm that is not available
- * in the current library context (unless we are using an algorithm that should
- * be made available via legacy codepaths).
+ * in the current library context (unless we are using an algorithm that
+ * should be made available via legacy codepaths).
+ *
+ * 0: RSA
+ * 1: SM2
*/
static int test_pkey_ctx_fail_without_provider(int tst)
{
OPENSSL_CTX *tmpctx = OPENSSL_CTX_new();
OSSL_PROVIDER *nullprov = NULL;
EVP_PKEY_CTX *pctx = NULL;
+ const char *keytype = NULL;
+ int expect_null = 0;
int ret = 0;
if (!TEST_ptr(tmpctx))
@@ -1820,21 +1825,42 @@ static int test_pkey_ctx_fail_without_provider(int tst)
if (!TEST_ptr(nullprov))
goto err;
- pctx = EVP_PKEY_CTX_new_from_name(tmpctx, tst == 0 ? "RSA" : "SM2", "");
-
- /* RSA is not available via any provider so we expect this to fail */
- if (tst == 0 && !TEST_ptr_null(pctx))
- goto err;
-
/*
- * SM2 is always available because it is implemented via legacy codepaths
- * and not in a provider at all. We expect this to pass.
- * TODO(3.0): This can be removed once there are no more algorithms
- * available via legacy codepaths
+ * We check for certain algos in the null provider.
+ * If an algo is expected to have a provider keymgmt, contructing an
+ * EVP_PKEY_CTX is expected to fail (return NULL).
+ * Otherwise, if it's expected to have legacy support, contructing an
+ * EVP_PKEY_CTX is expected to succeed (return non-NULL).
*/
- if (tst == 1 && !TEST_ptr(pctx))
+ switch (tst) {
+ case 0:
+ keytype = "RSA";
+ expect_null = 1;
+ break;
+ case 1:
+ keytype = "SM2";
+ expect_null = 0; /* TODO: change to 1 when we have a SM2 keymgmt */
+#ifdef OPENSSL_NO_EC
+ TEST_info("EC disable, skipping SM2 check...");
+ goto end;
+#endif
+#ifdef OPENSSL_NO_SM2
+ TEST_info("SM2 disable, skipping SM2 check...");
+ goto end;
+#endif
+ break;
+ default:
+ TEST_error("No test for case %d", tst);
+ goto err;
+ }
+
+ pctx = EVP_PKEY_CTX_new_from_name(tmpctx, keytype, "");
+ if (expect_null ? !TEST_ptr_null(pctx) : !TEST_ptr(pctx))
goto err;
+#if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_SM2)
+ end:
+#endif
ret = 1;
err: