summaryrefslogtreecommitdiff
path: root/regress/usr.bin/ssh/unittests/sshkey
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2024-01-11 01:46:00 +0000
committerDamien Miller <djm@cvs.openbsd.org>2024-01-11 01:46:00 +0000
commit2eb153c997f08e2e296505a64ccfa7160245d9aa (patch)
treecff328cec476c4b56a8c22fe0bc96e605b3159cb /regress/usr.bin/ssh/unittests/sshkey
parent2ee72980d0b93226e1ffd31be13d2b8940cc8e00 (diff)
make DSA testing optional, defaulting to on
ok markus
Diffstat (limited to 'regress/usr.bin/ssh/unittests/sshkey')
-rw-r--r--regress/usr.bin/ssh/unittests/sshkey/test_file.c4
-rw-r--r--regress/usr.bin/ssh/unittests/sshkey/test_fuzz.c8
-rw-r--r--regress/usr.bin/ssh/unittests/sshkey/test_sshkey.c20
3 files changed, 24 insertions, 8 deletions
diff --git a/regress/usr.bin/ssh/unittests/sshkey/test_file.c b/regress/usr.bin/ssh/unittests/sshkey/test_file.c
index 6a0fdbad0a2..6c22548d5dc 100644
--- a/regress/usr.bin/ssh/unittests/sshkey/test_file.c
+++ b/regress/usr.bin/ssh/unittests/sshkey/test_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_file.c,v 1.10 2021/12/14 21:25:27 deraadt Exp $ */
+/* $OpenBSD: test_file.c,v 1.11 2024/01/11 01:45:58 djm Exp $ */
/*
* Regress test for sshkey.h key management API
*
@@ -154,6 +154,7 @@ sshkey_file_tests(void)
sshkey_free(k1);
+#ifdef WITH_DSA
TEST_START("parse DSA from private");
buf = load_file("dsa_1");
ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
@@ -244,6 +245,7 @@ sshkey_file_tests(void)
TEST_DONE();
sshkey_free(k1);
+#endif
TEST_START("parse ECDSA from private");
buf = load_file("ecdsa_1");
diff --git a/regress/usr.bin/ssh/unittests/sshkey/test_fuzz.c b/regress/usr.bin/ssh/unittests/sshkey/test_fuzz.c
index 2c3ffc720d2..c839700ac5a 100644
--- a/regress/usr.bin/ssh/unittests/sshkey/test_fuzz.c
+++ b/regress/usr.bin/ssh/unittests/sshkey/test_fuzz.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_fuzz.c,v 1.13 2021/12/14 21:25:27 deraadt Exp $ */
+/* $OpenBSD: test_fuzz.c,v 1.14 2024/01/11 01:45:58 djm Exp $ */
/*
* Fuzz tests for key parsing
*
@@ -152,6 +152,7 @@ sshkey_fuzz_tests(void)
fuzz_cleanup(fuzz);
TEST_DONE();
+#ifdef WITH_DSA
TEST_START("fuzz DSA private");
buf = load_file("dsa_1");
fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
@@ -195,6 +196,7 @@ sshkey_fuzz_tests(void)
sshbuf_free(fuzzed);
fuzz_cleanup(fuzz);
TEST_DONE();
+#endif
TEST_START("fuzz ECDSA private");
buf = load_file("ecdsa_1");
@@ -276,6 +278,7 @@ sshkey_fuzz_tests(void)
sshkey_free(k1);
TEST_DONE();
+#ifdef WITH_DSA
TEST_START("fuzz DSA public");
buf = load_file("dsa_1");
ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
@@ -289,6 +292,7 @@ sshkey_fuzz_tests(void)
public_fuzz(k1);
sshkey_free(k1);
TEST_DONE();
+#endif
TEST_START("fuzz ECDSA public");
buf = load_file("ecdsa_1");
@@ -342,6 +346,7 @@ sshkey_fuzz_tests(void)
sshkey_free(k1);
TEST_DONE();
+#ifdef WITH_DSA
TEST_START("fuzz DSA sig");
buf = load_file("dsa_1");
ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
@@ -349,6 +354,7 @@ sshkey_fuzz_tests(void)
sig_fuzz(k1, NULL);
sshkey_free(k1);
TEST_DONE();
+#endif
TEST_START("fuzz ECDSA sig");
buf = load_file("ecdsa_1");
diff --git a/regress/usr.bin/ssh/unittests/sshkey/test_sshkey.c b/regress/usr.bin/ssh/unittests/sshkey/test_sshkey.c
index 84019a16588..fe331d259b6 100644
--- a/regress/usr.bin/ssh/unittests/sshkey/test_sshkey.c
+++ b/regress/usr.bin/ssh/unittests/sshkey/test_sshkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_sshkey.c,v 1.23 2023/01/04 22:48:57 tb Exp $ */
+/* $OpenBSD: test_sshkey.c,v 1.24 2024/01/11 01:45:58 djm Exp $ */
/*
* Regress test for sshkey.h key management API
*
@@ -170,8 +170,9 @@ get_private(const char *n)
void
sshkey_tests(void)
{
- struct sshkey *k1, *k2, *k3, *k4, *kr, *kd, *ke, *kf;
- struct sshbuf *b;
+ struct sshkey *k1 = NULL, *k2 = NULL, *k3 = NULL, *k4 = NULL;
+ struct sshkey *kr = NULL, *kd = NULL, *ke = NULL, *kf = NULL;
+ struct sshbuf *b = NULL;
TEST_START("new invalid");
k1 = sshkey_new(-42);
@@ -191,12 +192,14 @@ sshkey_tests(void)
sshkey_free(k1);
TEST_DONE();
+#ifdef WiTH_DSA
TEST_START("new/free KEY_DSA");
k1 = sshkey_new(KEY_DSA);
ASSERT_PTR_NE(k1, NULL);
ASSERT_PTR_NE(k1->dsa, NULL);
sshkey_free(k1);
TEST_DONE();
+#endif
TEST_START("new/free KEY_ECDSA");
k1 = sshkey_new(KEY_ECDSA);
@@ -226,12 +229,14 @@ sshkey_tests(void)
ASSERT_PTR_EQ(k1, NULL);
TEST_DONE();
+#ifdef WITH_DSA
TEST_START("generate KEY_DSA wrong bits");
ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 2048, &k1),
SSH_ERR_KEY_LENGTH);
ASSERT_PTR_EQ(k1, NULL);
sshkey_free(k1);
TEST_DONE();
+#endif
TEST_START("generate KEY_ECDSA wrong bits");
ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 42, &k1),
@@ -252,6 +257,7 @@ sshkey_tests(void)
ASSERT_INT_EQ(BN_num_bits(rsa_n(kr)), 1024);
TEST_DONE();
+#ifdef WITH_DSA
TEST_START("generate KEY_DSA");
ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &kd), 0);
ASSERT_PTR_NE(kd, NULL);
@@ -259,6 +265,7 @@ sshkey_tests(void)
ASSERT_PTR_NE(dsa_g(kd), NULL);
ASSERT_PTR_NE(dsa_priv_key(kd), NULL);
TEST_DONE();
+#endif
TEST_START("generate KEY_ECDSA");
ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &ke), 0);
@@ -292,6 +299,7 @@ sshkey_tests(void)
sshkey_free(k1);
TEST_DONE();
+#ifdef WITH_DSA
TEST_START("demote KEY_DSA");
ASSERT_INT_EQ(sshkey_from_private(kd, &k1), 0);
ASSERT_PTR_NE(k1, NULL);
@@ -306,6 +314,7 @@ sshkey_tests(void)
ASSERT_INT_EQ(sshkey_equal(kd, k1), 1);
sshkey_free(k1);
TEST_DONE();
+#endif
TEST_START("demote KEY_ECDSA");
ASSERT_INT_EQ(sshkey_from_private(ke, &k1), 0);
@@ -349,9 +358,6 @@ sshkey_tests(void)
ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &k1), 0);
ASSERT_INT_EQ(sshkey_equal(kr, k1), 0);
sshkey_free(k1);
- ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &k1), 0);
- ASSERT_INT_EQ(sshkey_equal(kd, k1), 0);
- sshkey_free(k1);
ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &k1), 0);
ASSERT_INT_EQ(sshkey_equal(ke, k1), 0);
sshkey_free(k1);
@@ -438,6 +444,7 @@ sshkey_tests(void)
sshkey_free(k2);
TEST_DONE();
+#ifdef WITH_DSA
TEST_START("sign and verify DSA");
k1 = get_private("dsa_1");
ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_2.pub"), &k2,
@@ -446,6 +453,7 @@ sshkey_tests(void)
sshkey_free(k1);
sshkey_free(k2);
TEST_DONE();
+#endif
TEST_START("sign and verify ECDSA");
k1 = get_private("ecdsa_1");