diff options
Diffstat (limited to 'regress/unittests')
-rw-r--r-- | regress/unittests/Makefile.inc | 35 | ||||
-rw-r--r-- | regress/unittests/kex/Makefile | 21 | ||||
-rw-r--r-- | regress/unittests/kex/test_kex.c | 13 | ||||
-rw-r--r-- | regress/unittests/sshbuf/Makefile | 5 | ||||
-rw-r--r-- | regress/unittests/sshbuf/test_sshbuf_fuzz.c | 9 | ||||
-rw-r--r-- | regress/unittests/sshbuf/test_sshbuf_getput_crypto.c | 157 | ||||
-rw-r--r-- | regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c | 23 | ||||
-rw-r--r-- | regress/unittests/sshkey/Makefile | 4 | ||||
-rw-r--r-- | regress/unittests/sshkey/test_fuzz.c | 57 | ||||
-rw-r--r-- | regress/unittests/sshkey/tests.c | 5 | ||||
-rw-r--r-- | regress/unittests/test_helper/test_helper.c | 33 | ||||
-rw-r--r-- | regress/unittests/test_helper/test_helper.h | 4 |
12 files changed, 160 insertions, 206 deletions
diff --git a/regress/unittests/Makefile.inc b/regress/unittests/Makefile.inc index b509f4452..428ef6836 100644 --- a/regress/unittests/Makefile.inc +++ b/regress/unittests/Makefile.inc | |||
@@ -1,8 +1,25 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.12 2017/12/21 00:41:22 djm Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.13 2018/10/17 23:28:05 djm Exp $ |
2 | |||
3 | REGRESS_FAIL_EARLY?= yes | ||
2 | 4 | ||
3 | .include <bsd.own.mk> | 5 | .include <bsd.own.mk> |
4 | .include <bsd.obj.mk> | 6 | .include <bsd.obj.mk> |
5 | 7 | ||
8 | # User-settable options | ||
9 | UNITTEST_FAST?= no # Skip slow tests (e.g. less intensive fuzzing). | ||
10 | UNITTEST_SLOW?= no # Include slower tests (e.g. more intensive fuzzing). | ||
11 | UNITTEST_VERBOSE?= no # Verbose test output (inc. per-test names). | ||
12 | |||
13 | MALLOC_OPTIONS?= CFGJRSUX | ||
14 | TEST_ENV?= MALLOC_OPTIONS=${MALLOC_OPTIONS} | ||
15 | |||
16 | # XXX detect from ssh binary? | ||
17 | OPENSSL?= yes | ||
18 | |||
19 | .if (${OPENSSL:L} == "yes") | ||
20 | CFLAGS+= -DWITH_OPENSSL | ||
21 | .endif | ||
22 | |||
6 | # enable warnings | 23 | # enable warnings |
7 | WARNINGS=Yes | 24 | WARNINGS=Yes |
8 | 25 | ||
@@ -49,5 +66,21 @@ DPADD+=${.CURDIR}/../test_helper/libtest_helper.a | |||
49 | 66 | ||
50 | .PATH: ${.CURDIR}/${SSHREL} | 67 | .PATH: ${.CURDIR}/${SSHREL} |
51 | 68 | ||
69 | LDADD+= -lutil | ||
70 | DPADD+= ${LIBUTIL} | ||
71 | |||
72 | .if (${OPENSSL:L} == "yes") | ||
52 | LDADD+= -lcrypto | 73 | LDADD+= -lcrypto |
53 | DPADD+= ${LIBCRYPTO} | 74 | DPADD+= ${LIBCRYPTO} |
75 | .endif | ||
76 | |||
77 | UNITTEST_ARGS?= | ||
78 | |||
79 | .if (${UNITTEST_VERBOSE:L} != "no") | ||
80 | UNITTEST_ARGS+= -v | ||
81 | .endif | ||
82 | .if (${UNITTEST_FAST:L} != "no") | ||
83 | UNITTEST_ARGS+= -f | ||
84 | .elif (${UNITTEST_SLOW:L} != "no") | ||
85 | UNITTEST_ARGS+= -F | ||
86 | .endif | ||
diff --git a/regress/unittests/kex/Makefile b/regress/unittests/kex/Makefile index 5c61307a3..7b4c644e5 100644 --- a/regress/unittests/kex/Makefile +++ b/regress/unittests/kex/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2017/12/21 00:41:22 djm Exp $ | 1 | # $OpenBSD: Makefile,v 1.6 2019/01/21 12:35:20 djm Exp $ |
2 | 2 | ||
3 | PROG=test_kex | 3 | PROG=test_kex |
4 | SRCS=tests.c test_kex.c | 4 | SRCS=tests.c test_kex.c |
@@ -9,12 +9,21 @@ SRCS+=atomicio.c sshkey.c authfile.c cipher.c log.c ssh-rsa.c ssh-dss.c | |||
9 | SRCS+=ssh-ecdsa.c ssh-ed25519.c mac.c umac.c umac128.c hmac.c misc.c | 9 | SRCS+=ssh-ecdsa.c ssh-ed25519.c mac.c umac.c umac128.c hmac.c misc.c |
10 | SRCS+=ssherr.c uidswap.c cleanup.c xmalloc.c match.c krl.c fatal.c | 10 | SRCS+=ssherr.c uidswap.c cleanup.c xmalloc.c match.c krl.c fatal.c |
11 | SRCS+=addrmatch.c bitmap.c packet.c dispatch.c canohost.c ssh_api.c | 11 | SRCS+=addrmatch.c bitmap.c packet.c dispatch.c canohost.c ssh_api.c |
12 | SRCS+=kex.c kexc25519.c kexc25519c.c kexc25519s.c kexdh.c kexdhc.c kexdhs.c | 12 | SRCS+=compat.c ed25519.c hash.c ge25519.c fe25519.c sc25519.c verify.c |
13 | SRCS+=kexecdh.c kexecdhc.c kexecdhs.c kexgex.c kexgexc.c kexgexs.c | ||
14 | SRCS+=dh.c compat.c | ||
15 | SRCS+=ed25519.c hash.c ge25519.c fe25519.c sc25519.c verify.c | ||
16 | SRCS+=cipher-chachapoly.c chacha.c poly1305.c | 13 | SRCS+=cipher-chachapoly.c chacha.c poly1305.c |
17 | SRCS+=smult_curve25519_ref.c | 14 | |
15 | SRCS+= kex.c | ||
16 | SRCS+= dh.c | ||
17 | SRCS+= kexdh.c | ||
18 | SRCS+= kexecdh.c | ||
19 | SRCS+= kexgex.c | ||
20 | SRCS+= kexgexc.c | ||
21 | SRCS+= kexgexs.c | ||
22 | SRCS+= kexc25519.c | ||
23 | SRCS+= smult_curve25519_ref.c | ||
24 | SRCS+= kexgen.c | ||
25 | SRCS+= kexsntrup4591761x25519.c | ||
26 | SRCS+= sntrup4591761.c | ||
18 | 27 | ||
19 | SRCS+=digest-openssl.c | 28 | SRCS+=digest-openssl.c |
20 | #SRCS+=digest-libc.c | 29 | #SRCS+=digest-libc.c |
diff --git a/regress/unittests/kex/test_kex.c b/regress/unittests/kex/test_kex.c index 6e5999bb9..a860efc02 100644 --- a/regress/unittests/kex/test_kex.c +++ b/regress/unittests/kex/test_kex.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_kex.c,v 1.2 2015/07/10 06:23:25 markus Exp $ */ | 1 | /* $OpenBSD: test_kex.c,v 1.4 2019/01/21 12:35:20 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Regress test KEX | 3 | * Regress test KEX |
4 | * | 4 | * |
@@ -24,8 +24,6 @@ | |||
24 | #include "packet.h" | 24 | #include "packet.h" |
25 | #include "myproposal.h" | 25 | #include "myproposal.h" |
26 | 26 | ||
27 | struct ssh *active_state = NULL; /* XXX - needed for linking */ | ||
28 | |||
29 | void kex_tests(void); | 27 | void kex_tests(void); |
30 | static int do_debug = 0; | 28 | static int do_debug = 0; |
31 | 29 | ||
@@ -139,20 +137,19 @@ do_kex_with_key(char *kex, int keytype, int bits) | |||
139 | ASSERT_INT_EQ(ssh_init(&server2, 1, NULL), 0); | 137 | ASSERT_INT_EQ(ssh_init(&server2, 1, NULL), 0); |
140 | ASSERT_PTR_NE(server2, NULL); | 138 | ASSERT_PTR_NE(server2, NULL); |
141 | ASSERT_INT_EQ(ssh_add_hostkey(server2, private), 0); | 139 | ASSERT_INT_EQ(ssh_add_hostkey(server2, private), 0); |
142 | kex_free(server2->kex); /* XXX or should ssh_packet_set_state()? */ | ||
143 | ASSERT_INT_EQ(ssh_packet_set_state(server2, state), 0); | 140 | ASSERT_INT_EQ(ssh_packet_set_state(server2, state), 0); |
144 | ASSERT_INT_EQ(sshbuf_len(state), 0); | 141 | ASSERT_INT_EQ(sshbuf_len(state), 0); |
145 | sshbuf_free(state); | 142 | sshbuf_free(state); |
146 | ASSERT_PTR_NE(server2->kex, NULL); | 143 | ASSERT_PTR_NE(server2->kex, NULL); |
147 | /* XXX we need to set the callbacks */ | 144 | /* XXX we need to set the callbacks */ |
148 | server2->kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server; | 145 | server2->kex->kex[KEX_DH_GRP1_SHA1] = kex_gen_server; |
149 | server2->kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server; | 146 | server2->kex->kex[KEX_DH_GRP14_SHA1] = kex_gen_server; |
150 | server2->kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; | 147 | server2->kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; |
151 | server2->kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; | 148 | server2->kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; |
152 | #ifdef OPENSSL_HAS_ECC | 149 | #ifdef OPENSSL_HAS_ECC |
153 | server2->kex->kex[KEX_ECDH_SHA2] = kexecdh_server; | 150 | server2->kex->kex[KEX_ECDH_SHA2] = kex_gen_server; |
154 | #endif | 151 | #endif |
155 | server2->kex->kex[KEX_C25519_SHA256] = kexc25519_server; | 152 | server2->kex->kex[KEX_C25519_SHA256] = kex_gen_server; |
156 | server2->kex->load_host_public_key = server->kex->load_host_public_key; | 153 | server2->kex->load_host_public_key = server->kex->load_host_public_key; |
157 | server2->kex->load_host_private_key = server->kex->load_host_private_key; | 154 | server2->kex->load_host_private_key = server->kex->load_host_private_key; |
158 | server2->kex->sign = server->kex->sign; | 155 | server2->kex->sign = server->kex->sign; |
diff --git a/regress/unittests/sshbuf/Makefile b/regress/unittests/sshbuf/Makefile index 81d4f27a6..0e8e9fd10 100644 --- a/regress/unittests/sshbuf/Makefile +++ b/regress/unittests/sshbuf/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.6 2017/12/21 00:41:22 djm Exp $ | 1 | # $OpenBSD: Makefile,v 1.7 2018/10/17 23:28:05 djm Exp $ |
2 | 2 | ||
3 | .include <bsd.regress.mk> | 3 | .include <bsd.regress.mk> |
4 | 4 | ||
@@ -17,6 +17,5 @@ SRCS+=sshbuf-getput-basic.c sshbuf-getput-crypto.c sshbuf-misc.c sshbuf.c | |||
17 | SRCS+=atomicio.c | 17 | SRCS+=atomicio.c |
18 | 18 | ||
19 | run-regress-${PROG}: ${PROG} | 19 | run-regress-${PROG}: ${PROG} |
20 | env ${TEST_ENV} ./${PROG} | 20 | env ${TEST_ENV} ./${PROG} ${UNITTEST_ARGS} |
21 | |||
22 | 21 | ||
diff --git a/regress/unittests/sshbuf/test_sshbuf_fuzz.c b/regress/unittests/sshbuf/test_sshbuf_fuzz.c index c52376b53..e236c82f9 100644 --- a/regress/unittests/sshbuf/test_sshbuf_fuzz.c +++ b/regress/unittests/sshbuf/test_sshbuf_fuzz.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_sshbuf_fuzz.c,v 1.1 2014/04/30 05:32:00 djm Exp $ */ | 1 | /* $OpenBSD: test_sshbuf_fuzz.c,v 1.2 2018/10/17 23:28:05 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Regress test for sshbuf.h buffer API | 3 | * Regress test for sshbuf.h buffer API |
4 | * | 4 | * |
@@ -30,10 +30,15 @@ sshbuf_fuzz_tests(void) | |||
30 | { | 30 | { |
31 | struct sshbuf *p1; | 31 | struct sshbuf *p1; |
32 | u_char *dp; | 32 | u_char *dp; |
33 | size_t sz, sz2, i; | 33 | size_t sz, sz2, i, ntests = NUM_FUZZ_TESTS; |
34 | u_int32_t r; | 34 | u_int32_t r; |
35 | int ret; | 35 | int ret; |
36 | 36 | ||
37 | if (test_is_fast()) | ||
38 | ntests >>= 2; | ||
39 | if (test_is_slow()) | ||
40 | ntests <<= 2; | ||
41 | |||
37 | /* NB. uses sshbuf internals */ | 42 | /* NB. uses sshbuf internals */ |
38 | TEST_START("fuzz alloc/dealloc"); | 43 | TEST_START("fuzz alloc/dealloc"); |
39 | p1 = sshbuf_new(); | 44 | p1 = sshbuf_new(); |
diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c b/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c index a68e1329e..5d39e63e1 100644 --- a/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c +++ b/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_sshbuf_getput_crypto.c,v 1.1 2014/04/30 05:32:00 djm Exp $ */ | 1 | /* $OpenBSD: test_sshbuf_getput_crypto.c,v 1.2 2019/01/21 12:29:35 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Regress test for sshbuf.h buffer API | 3 | * Regress test for sshbuf.h buffer API |
4 | * | 4 | * |
@@ -33,7 +33,6 @@ sshbuf_getput_crypto_tests(void) | |||
33 | { | 33 | { |
34 | struct sshbuf *p1; | 34 | struct sshbuf *p1; |
35 | BIGNUM *bn, *bn2; | 35 | BIGNUM *bn, *bn2; |
36 | /* This one has num_bits != num_bytes * 8 to test bignum1 encoding */ | ||
37 | const char *hexbn1 = "0102030405060708090a0b0c0d0e0f10"; | 36 | const char *hexbn1 = "0102030405060708090a0b0c0d0e0f10"; |
38 | /* This one has MSB set to test bignum2 encoding negative-avoidance */ | 37 | /* This one has MSB set to test bignum2 encoding negative-avoidance */ |
39 | const char *hexbn2 = "f0e0d0c0b0a0908070605040302010007fff11"; | 38 | const char *hexbn2 = "f0e0d0c0b0a0908070605040302010007fff11"; |
@@ -77,54 +76,6 @@ sshbuf_getput_crypto_tests(void) | |||
77 | ASSERT_INT_GT(BN_hex2bn(&bnn, b), 0); \ | 76 | ASSERT_INT_GT(BN_hex2bn(&bnn, b), 0); \ |
78 | } while (0) | 77 | } while (0) |
79 | 78 | ||
80 | TEST_START("sshbuf_put_bignum1"); | ||
81 | MKBN(hexbn1, bn); | ||
82 | p1 = sshbuf_new(); | ||
83 | ASSERT_PTR_NE(p1, NULL); | ||
84 | ASSERT_INT_EQ(sshbuf_put_bignum1(p1, bn), 0); | ||
85 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), sizeof(expbn1) + 2); | ||
86 | ASSERT_U16_EQ(PEEK_U16(sshbuf_ptr(p1)), (u_int16_t)BN_num_bits(bn)); | ||
87 | ASSERT_MEM_EQ(sshbuf_ptr(p1) + 2, expbn1, sizeof(expbn1)); | ||
88 | BN_free(bn); | ||
89 | sshbuf_free(p1); | ||
90 | TEST_DONE(); | ||
91 | |||
92 | TEST_START("sshbuf_put_bignum1 limited"); | ||
93 | MKBN(hexbn1, bn); | ||
94 | p1 = sshbuf_new(); | ||
95 | ASSERT_PTR_NE(p1, NULL); | ||
96 | ASSERT_INT_EQ(sshbuf_set_max_size(p1, sizeof(expbn1) + 1), 0); | ||
97 | r = sshbuf_put_bignum1(p1, bn); | ||
98 | ASSERT_INT_EQ(r, SSH_ERR_NO_BUFFER_SPACE); | ||
99 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 0); | ||
100 | BN_free(bn); | ||
101 | sshbuf_free(p1); | ||
102 | TEST_DONE(); | ||
103 | |||
104 | TEST_START("sshbuf_put_bignum1 bn2"); | ||
105 | MKBN(hexbn2, bn); | ||
106 | p1 = sshbuf_new(); | ||
107 | ASSERT_PTR_NE(p1, NULL); | ||
108 | ASSERT_INT_EQ(sshbuf_put_bignum1(p1, bn), 0); | ||
109 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), sizeof(expbn2) + 2); | ||
110 | ASSERT_U16_EQ(PEEK_U16(sshbuf_ptr(p1)), (u_int16_t)BN_num_bits(bn)); | ||
111 | ASSERT_MEM_EQ(sshbuf_ptr(p1) + 2, expbn2, sizeof(expbn2)); | ||
112 | BN_free(bn); | ||
113 | sshbuf_free(p1); | ||
114 | TEST_DONE(); | ||
115 | |||
116 | TEST_START("sshbuf_put_bignum1 bn2 limited"); | ||
117 | MKBN(hexbn2, bn); | ||
118 | p1 = sshbuf_new(); | ||
119 | ASSERT_PTR_NE(p1, NULL); | ||
120 | ASSERT_INT_EQ(sshbuf_set_max_size(p1, sizeof(expbn1) + 1), 0); | ||
121 | r = sshbuf_put_bignum1(p1, bn); | ||
122 | ASSERT_INT_EQ(r, SSH_ERR_NO_BUFFER_SPACE); | ||
123 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 0); | ||
124 | BN_free(bn); | ||
125 | sshbuf_free(p1); | ||
126 | TEST_DONE(); | ||
127 | |||
128 | TEST_START("sshbuf_put_bignum2"); | 79 | TEST_START("sshbuf_put_bignum2"); |
129 | MKBN(hexbn1, bn); | 80 | MKBN(hexbn1, bn); |
130 | p1 = sshbuf_new(); | 81 | p1 = sshbuf_new(); |
@@ -174,88 +125,6 @@ sshbuf_getput_crypto_tests(void) | |||
174 | sshbuf_free(p1); | 125 | sshbuf_free(p1); |
175 | TEST_DONE(); | 126 | TEST_DONE(); |
176 | 127 | ||
177 | TEST_START("sshbuf_get_bignum1"); | ||
178 | MKBN(hexbn1, bn); | ||
179 | p1 = sshbuf_new(); | ||
180 | ASSERT_PTR_NE(p1, NULL); | ||
181 | ASSERT_INT_EQ(sshbuf_put_u16(p1, BN_num_bits(bn)), 0); | ||
182 | ASSERT_INT_EQ(sshbuf_put(p1, expbn1, sizeof(expbn1)), 0); | ||
183 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2 + sizeof(expbn1)); | ||
184 | ASSERT_INT_EQ(sshbuf_put_u16(p1, 0xd00f), 0); | ||
185 | bn2 = BN_new(); | ||
186 | ASSERT_INT_EQ(sshbuf_get_bignum1(p1, bn2), 0); | ||
187 | ASSERT_BIGNUM_EQ(bn, bn2); | ||
188 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2); | ||
189 | BN_free(bn); | ||
190 | BN_free(bn2); | ||
191 | sshbuf_free(p1); | ||
192 | TEST_DONE(); | ||
193 | |||
194 | TEST_START("sshbuf_get_bignum1 truncated"); | ||
195 | MKBN(hexbn1, bn); | ||
196 | p1 = sshbuf_new(); | ||
197 | ASSERT_PTR_NE(p1, NULL); | ||
198 | ASSERT_INT_EQ(sshbuf_put_u16(p1, BN_num_bits(bn)), 0); | ||
199 | ASSERT_INT_EQ(sshbuf_put(p1, expbn1, sizeof(expbn1) - 1), 0); | ||
200 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2 + sizeof(expbn1) - 1); | ||
201 | bn2 = BN_new(); | ||
202 | r = sshbuf_get_bignum1(p1, bn2); | ||
203 | ASSERT_INT_EQ(r, SSH_ERR_MESSAGE_INCOMPLETE); | ||
204 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2 + sizeof(expbn1) - 1); | ||
205 | BN_free(bn); | ||
206 | BN_free(bn2); | ||
207 | sshbuf_free(p1); | ||
208 | TEST_DONE(); | ||
209 | |||
210 | TEST_START("sshbuf_get_bignum1 giant"); | ||
211 | MKBN(hexbn1, bn); | ||
212 | p1 = sshbuf_new(); | ||
213 | ASSERT_PTR_NE(p1, NULL); | ||
214 | ASSERT_INT_EQ(sshbuf_put_u16(p1, 0xffff), 0); | ||
215 | ASSERT_INT_EQ(sshbuf_reserve(p1, (0xffff + 7) / 8, NULL), 0); | ||
216 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2 + ((0xffff + 7) / 8)); | ||
217 | bn2 = BN_new(); | ||
218 | r = sshbuf_get_bignum1(p1, bn2); | ||
219 | ASSERT_INT_EQ(r, SSH_ERR_BIGNUM_TOO_LARGE); | ||
220 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2 + ((0xffff + 7) / 8)); | ||
221 | BN_free(bn); | ||
222 | BN_free(bn2); | ||
223 | sshbuf_free(p1); | ||
224 | TEST_DONE(); | ||
225 | |||
226 | TEST_START("sshbuf_get_bignum1 bn2"); | ||
227 | MKBN(hexbn2, bn); | ||
228 | p1 = sshbuf_new(); | ||
229 | ASSERT_PTR_NE(p1, NULL); | ||
230 | ASSERT_INT_EQ(sshbuf_put_u16(p1, BN_num_bits(bn)), 0); | ||
231 | ASSERT_INT_EQ(sshbuf_put(p1, expbn2, sizeof(expbn2)), 0); | ||
232 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2 + sizeof(expbn2)); | ||
233 | ASSERT_INT_EQ(sshbuf_put_u16(p1, 0xd00f), 0); | ||
234 | bn2 = BN_new(); | ||
235 | ASSERT_INT_EQ(sshbuf_get_bignum1(p1, bn2), 0); | ||
236 | ASSERT_BIGNUM_EQ(bn, bn2); | ||
237 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2); | ||
238 | BN_free(bn); | ||
239 | BN_free(bn2); | ||
240 | sshbuf_free(p1); | ||
241 | TEST_DONE(); | ||
242 | |||
243 | TEST_START("sshbuf_get_bignum1 bn2 truncated"); | ||
244 | MKBN(hexbn2, bn); | ||
245 | p1 = sshbuf_new(); | ||
246 | ASSERT_PTR_NE(p1, NULL); | ||
247 | ASSERT_INT_EQ(sshbuf_put_u16(p1, BN_num_bits(bn)), 0); | ||
248 | ASSERT_INT_EQ(sshbuf_put(p1, expbn2, sizeof(expbn2) - 1), 0); | ||
249 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2 + sizeof(expbn2) - 1); | ||
250 | bn2 = BN_new(); | ||
251 | r = sshbuf_get_bignum1(p1, bn2); | ||
252 | ASSERT_INT_EQ(r, SSH_ERR_MESSAGE_INCOMPLETE); | ||
253 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2 + sizeof(expbn2) - 1); | ||
254 | BN_free(bn); | ||
255 | BN_free(bn2); | ||
256 | sshbuf_free(p1); | ||
257 | TEST_DONE(); | ||
258 | |||
259 | TEST_START("sshbuf_get_bignum2"); | 128 | TEST_START("sshbuf_get_bignum2"); |
260 | MKBN(hexbn1, bn); | 129 | MKBN(hexbn1, bn); |
261 | p1 = sshbuf_new(); | 130 | p1 = sshbuf_new(); |
@@ -264,8 +133,8 @@ sshbuf_getput_crypto_tests(void) | |||
264 | ASSERT_INT_EQ(sshbuf_put(p1, expbn1, sizeof(expbn1)), 0); | 133 | ASSERT_INT_EQ(sshbuf_put(p1, expbn1, sizeof(expbn1)), 0); |
265 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 4 + sizeof(expbn1)); | 134 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 4 + sizeof(expbn1)); |
266 | ASSERT_INT_EQ(sshbuf_put_u16(p1, 0xd00f), 0); | 135 | ASSERT_INT_EQ(sshbuf_put_u16(p1, 0xd00f), 0); |
267 | bn2 = BN_new(); | 136 | bn2 = NULL; |
268 | ASSERT_INT_EQ(sshbuf_get_bignum2(p1, bn2), 0); | 137 | ASSERT_INT_EQ(sshbuf_get_bignum2(p1, &bn2), 0); |
269 | ASSERT_BIGNUM_EQ(bn, bn2); | 138 | ASSERT_BIGNUM_EQ(bn, bn2); |
270 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2); | 139 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2); |
271 | BN_free(bn); | 140 | BN_free(bn); |
@@ -279,8 +148,8 @@ sshbuf_getput_crypto_tests(void) | |||
279 | ASSERT_PTR_NE(p1, NULL); | 148 | ASSERT_PTR_NE(p1, NULL); |
280 | ASSERT_INT_EQ(sshbuf_put_u32(p1, BN_num_bytes(bn)), 0); | 149 | ASSERT_INT_EQ(sshbuf_put_u32(p1, BN_num_bytes(bn)), 0); |
281 | ASSERT_INT_EQ(sshbuf_put(p1, expbn1, sizeof(expbn1) - 1), 0); | 150 | ASSERT_INT_EQ(sshbuf_put(p1, expbn1, sizeof(expbn1) - 1), 0); |
282 | bn2 = BN_new(); | 151 | bn2 = NULL; |
283 | r = sshbuf_get_bignum2(p1, bn2); | 152 | r = sshbuf_get_bignum2(p1, &bn2); |
284 | ASSERT_INT_EQ(r, SSH_ERR_MESSAGE_INCOMPLETE); | 153 | ASSERT_INT_EQ(r, SSH_ERR_MESSAGE_INCOMPLETE); |
285 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), sizeof(expbn1) + 3); | 154 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), sizeof(expbn1) + 3); |
286 | BN_free(bn); | 155 | BN_free(bn); |
@@ -294,8 +163,8 @@ sshbuf_getput_crypto_tests(void) | |||
294 | ASSERT_PTR_NE(p1, NULL); | 163 | ASSERT_PTR_NE(p1, NULL); |
295 | ASSERT_INT_EQ(sshbuf_put_u32(p1, 65536), 0); | 164 | ASSERT_INT_EQ(sshbuf_put_u32(p1, 65536), 0); |
296 | ASSERT_INT_EQ(sshbuf_reserve(p1, 65536, NULL), 0); | 165 | ASSERT_INT_EQ(sshbuf_reserve(p1, 65536, NULL), 0); |
297 | bn2 = BN_new(); | 166 | bn2 = NULL; |
298 | r = sshbuf_get_bignum2(p1, bn2); | 167 | r = sshbuf_get_bignum2(p1, &bn2); |
299 | ASSERT_INT_EQ(r, SSH_ERR_BIGNUM_TOO_LARGE); | 168 | ASSERT_INT_EQ(r, SSH_ERR_BIGNUM_TOO_LARGE); |
300 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 65536 + 4); | 169 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 65536 + 4); |
301 | BN_free(bn); | 170 | BN_free(bn); |
@@ -312,8 +181,8 @@ sshbuf_getput_crypto_tests(void) | |||
312 | ASSERT_INT_EQ(sshbuf_put(p1, expbn2, sizeof(expbn2)), 0); | 181 | ASSERT_INT_EQ(sshbuf_put(p1, expbn2, sizeof(expbn2)), 0); |
313 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 4 + 1 + sizeof(expbn2)); | 182 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 4 + 1 + sizeof(expbn2)); |
314 | ASSERT_INT_EQ(sshbuf_put_u16(p1, 0xd00f), 0); | 183 | ASSERT_INT_EQ(sshbuf_put_u16(p1, 0xd00f), 0); |
315 | bn2 = BN_new(); | 184 | bn2 = NULL; |
316 | ASSERT_INT_EQ(sshbuf_get_bignum2(p1, bn2), 0); | 185 | ASSERT_INT_EQ(sshbuf_get_bignum2(p1, &bn2), 0); |
317 | ASSERT_BIGNUM_EQ(bn, bn2); | 186 | ASSERT_BIGNUM_EQ(bn, bn2); |
318 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2); | 187 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), 2); |
319 | BN_free(bn); | 188 | BN_free(bn); |
@@ -328,8 +197,8 @@ sshbuf_getput_crypto_tests(void) | |||
328 | ASSERT_INT_EQ(sshbuf_put_u32(p1, BN_num_bytes(bn) + 1), 0); | 197 | ASSERT_INT_EQ(sshbuf_put_u32(p1, BN_num_bytes(bn) + 1), 0); |
329 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x00), 0); | 198 | ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x00), 0); |
330 | ASSERT_INT_EQ(sshbuf_put(p1, expbn2, sizeof(expbn2) - 1), 0); | 199 | ASSERT_INT_EQ(sshbuf_put(p1, expbn2, sizeof(expbn2) - 1), 0); |
331 | bn2 = BN_new(); | 200 | bn2 = NULL; |
332 | r = sshbuf_get_bignum2(p1, bn2); | 201 | r = sshbuf_get_bignum2(p1, &bn2); |
333 | ASSERT_INT_EQ(r, SSH_ERR_MESSAGE_INCOMPLETE); | 202 | ASSERT_INT_EQ(r, SSH_ERR_MESSAGE_INCOMPLETE); |
334 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), sizeof(expbn2) + 1 + 4 - 1); | 203 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), sizeof(expbn2) + 1 + 4 - 1); |
335 | BN_free(bn); | 204 | BN_free(bn); |
@@ -343,8 +212,8 @@ sshbuf_getput_crypto_tests(void) | |||
343 | ASSERT_PTR_NE(p1, NULL); | 212 | ASSERT_PTR_NE(p1, NULL); |
344 | ASSERT_INT_EQ(sshbuf_put_u32(p1, BN_num_bytes(bn)), 0); | 213 | ASSERT_INT_EQ(sshbuf_put_u32(p1, BN_num_bytes(bn)), 0); |
345 | ASSERT_INT_EQ(sshbuf_put(p1, expbn2, sizeof(expbn2)), 0); | 214 | ASSERT_INT_EQ(sshbuf_put(p1, expbn2, sizeof(expbn2)), 0); |
346 | bn2 = BN_new(); | 215 | bn2 = NULL; |
347 | r = sshbuf_get_bignum2(p1, bn2); | 216 | r = sshbuf_get_bignum2(p1, &bn2); |
348 | ASSERT_INT_EQ(r, SSH_ERR_BIGNUM_IS_NEGATIVE); | 217 | ASSERT_INT_EQ(r, SSH_ERR_BIGNUM_IS_NEGATIVE); |
349 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), sizeof(expbn2) + 4); | 218 | ASSERT_SIZE_T_EQ(sshbuf_len(p1), sizeof(expbn2) + 4); |
350 | BN_free(bn); | 219 | BN_free(bn); |
diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c b/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c index c6b5c29d1..ca06bfb00 100644 --- a/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c +++ b/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_sshbuf_getput_fuzz.c,v 1.2 2014/05/02 02:54:00 djm Exp $ */ | 1 | /* $OpenBSD: test_sshbuf_getput_fuzz.c,v 1.4 2019/01/21 12:29:35 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Regress test for sshbuf.h buffer API | 3 | * Regress test for sshbuf.h buffer API |
4 | * | 4 | * |
@@ -54,11 +54,8 @@ attempt_parse_blob(u_char *blob, size_t len) | |||
54 | bzero(s, l); | 54 | bzero(s, l); |
55 | free(s); | 55 | free(s); |
56 | } | 56 | } |
57 | bn = BN_new(); | 57 | bn = NULL; |
58 | sshbuf_get_bignum1(p1, bn); | 58 | sshbuf_get_bignum2(p1, &bn); |
59 | BN_clear_free(bn); | ||
60 | bn = BN_new(); | ||
61 | sshbuf_get_bignum2(p1, bn); | ||
62 | BN_clear_free(bn); | 59 | BN_clear_free(bn); |
63 | #if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) | 60 | #if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) |
64 | eck = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); | 61 | eck = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
@@ -92,10 +89,6 @@ sshbuf_getput_fuzz_tests(void) | |||
92 | /* string */ | 89 | /* string */ |
93 | 0x00, 0x00, 0x00, 0x09, | 90 | 0x00, 0x00, 0x00, 0x09, |
94 | 'O', ' ', 'G', 'o', 'r', 'g', 'o', 'n', '!', | 91 | 'O', ' ', 'G', 'o', 'r', 'g', 'o', 'n', '!', |
95 | /* bignum1 */ | ||
96 | 0x79, | ||
97 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, | ||
98 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, | ||
99 | /* bignum2 */ | 92 | /* bignum2 */ |
100 | 0x00, 0x00, 0x00, 0x14, | 93 | 0x00, 0x00, 0x00, 0x14, |
101 | 0x00, | 94 | 0x00, |
@@ -115,11 +108,15 @@ sshbuf_getput_fuzz_tests(void) | |||
115 | 0x55, 0x0f, 0x69, 0xd8, 0x0e, 0xc2, 0x3c, 0xd4, | 108 | 0x55, 0x0f, 0x69, 0xd8, 0x0e, 0xc2, 0x3c, 0xd4, |
116 | }; | 109 | }; |
117 | struct fuzz *fuzz; | 110 | struct fuzz *fuzz; |
111 | u_int fuzzers = FUZZ_1_BIT_FLIP | FUZZ_2_BIT_FLIP | | ||
112 | FUZZ_1_BYTE_FLIP | FUZZ_2_BYTE_FLIP | | ||
113 | FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END; | ||
114 | |||
115 | if (test_is_fast()) | ||
116 | fuzzers &= ~(FUZZ_2_BYTE_FLIP|FUZZ_2_BIT_FLIP); | ||
118 | 117 | ||
119 | TEST_START("fuzz blob parsing"); | 118 | TEST_START("fuzz blob parsing"); |
120 | fuzz = fuzz_begin(FUZZ_1_BIT_FLIP | FUZZ_2_BIT_FLIP | | 119 | fuzz = fuzz_begin(fuzzers, blob, sizeof(blob)); |
121 | FUZZ_1_BYTE_FLIP | FUZZ_2_BYTE_FLIP | | ||
122 | FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END, blob, sizeof(blob)); | ||
123 | TEST_ONERROR(onerror, fuzz); | 120 | TEST_ONERROR(onerror, fuzz); |
124 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) | 121 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) |
125 | attempt_parse_blob(blob, sizeof(blob)); | 122 | attempt_parse_blob(blob, sizeof(blob)); |
diff --git a/regress/unittests/sshkey/Makefile b/regress/unittests/sshkey/Makefile index 1c940bec6..aa731df1c 100644 --- a/regress/unittests/sshkey/Makefile +++ b/regress/unittests/sshkey/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2017/12/21 00:41:22 djm Exp $ | 1 | # $OpenBSD: Makefile,v 1.6 2018/10/17 23:28:05 djm Exp $ |
2 | 2 | ||
3 | PROG=test_sshkey | 3 | PROG=test_sshkey |
4 | SRCS=tests.c test_sshkey.c test_file.c test_fuzz.c common.c | 4 | SRCS=tests.c test_sshkey.c test_file.c test_fuzz.c common.c |
@@ -18,7 +18,7 @@ SRCS+=digest-openssl.c | |||
18 | REGRESS_TARGETS=run-regress-${PROG} | 18 | REGRESS_TARGETS=run-regress-${PROG} |
19 | 19 | ||
20 | run-regress-${PROG}: ${PROG} | 20 | run-regress-${PROG}: ${PROG} |
21 | env ${TEST_ENV} ./${PROG} -d ${.CURDIR}/testdata | 21 | env ${TEST_ENV} ./${PROG} ${UNITTEST_ARGS} -d ${.CURDIR}/testdata |
22 | 22 | ||
23 | .include <bsd.regress.mk> | 23 | .include <bsd.regress.mk> |
24 | 24 | ||
diff --git a/regress/unittests/sshkey/test_fuzz.c b/regress/unittests/sshkey/test_fuzz.c index d3b0c92b4..5953de595 100644 --- a/regress/unittests/sshkey/test_fuzz.c +++ b/regress/unittests/sshkey/test_fuzz.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_fuzz.c,v 1.8 2017/12/21 00:41:22 djm Exp $ */ | 1 | /* $OpenBSD: test_fuzz.c,v 1.9 2018/10/17 23:28:05 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Fuzz tests for key parsing | 3 | * Fuzz tests for key parsing |
4 | * | 4 | * |
@@ -51,14 +51,16 @@ public_fuzz(struct sshkey *k) | |||
51 | struct sshkey *k1; | 51 | struct sshkey *k1; |
52 | struct sshbuf *buf; | 52 | struct sshbuf *buf; |
53 | struct fuzz *fuzz; | 53 | struct fuzz *fuzz; |
54 | u_int fuzzers = FUZZ_1_BIT_FLIP | FUZZ_1_BYTE_FLIP | | ||
55 | FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END; | ||
54 | 56 | ||
57 | if (test_is_fast()) | ||
58 | fuzzers &= ~FUZZ_1_BIT_FLIP; | ||
59 | if (test_is_slow()) | ||
60 | fuzzers |= FUZZ_2_BIT_FLIP | FUZZ_2_BYTE_FLIP; | ||
55 | ASSERT_PTR_NE(buf = sshbuf_new(), NULL); | 61 | ASSERT_PTR_NE(buf = sshbuf_new(), NULL); |
56 | ASSERT_INT_EQ(sshkey_putb(k, buf), 0); | 62 | ASSERT_INT_EQ(sshkey_putb(k, buf), 0); |
57 | /* XXX need a way to run the tests in "slow, but complete" mode */ | 63 | fuzz = fuzz_begin(fuzzers, sshbuf_mutable_ptr(buf), sshbuf_len(buf)); |
58 | fuzz = fuzz_begin(FUZZ_1_BIT_FLIP | /* XXX too slow FUZZ_2_BIT_FLIP | */ | ||
59 | FUZZ_1_BYTE_FLIP | /* XXX too slow FUZZ_2_BYTE_FLIP | */ | ||
60 | FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END, | ||
61 | sshbuf_mutable_ptr(buf), sshbuf_len(buf)); | ||
62 | ASSERT_INT_EQ(sshkey_from_blob(sshbuf_ptr(buf), sshbuf_len(buf), | 64 | ASSERT_INT_EQ(sshkey_from_blob(sshbuf_ptr(buf), sshbuf_len(buf), |
63 | &k1), 0); | 65 | &k1), 0); |
64 | sshkey_free(k1); | 66 | sshkey_free(k1); |
@@ -77,12 +79,17 @@ sig_fuzz(struct sshkey *k, const char *sig_alg) | |||
77 | struct fuzz *fuzz; | 79 | struct fuzz *fuzz; |
78 | u_char *sig, c[] = "some junk to be signed"; | 80 | u_char *sig, c[] = "some junk to be signed"; |
79 | size_t l; | 81 | size_t l; |
82 | u_int fuzzers = FUZZ_1_BIT_FLIP | FUZZ_1_BYTE_FLIP | FUZZ_2_BYTE_FLIP | | ||
83 | FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END; | ||
84 | |||
85 | if (test_is_fast()) | ||
86 | fuzzers &= ~FUZZ_2_BYTE_FLIP; | ||
87 | if (test_is_slow()) | ||
88 | fuzzers |= FUZZ_2_BIT_FLIP; | ||
80 | 89 | ||
81 | ASSERT_INT_EQ(sshkey_sign(k, &sig, &l, c, sizeof(c), sig_alg, 0), 0); | 90 | ASSERT_INT_EQ(sshkey_sign(k, &sig, &l, c, sizeof(c), sig_alg, 0), 0); |
82 | ASSERT_SIZE_T_GT(l, 0); | 91 | ASSERT_SIZE_T_GT(l, 0); |
83 | fuzz = fuzz_begin(FUZZ_1_BIT_FLIP | /* too slow FUZZ_2_BIT_FLIP | */ | 92 | fuzz = fuzz_begin(fuzzers, sig, l); |
84 | FUZZ_1_BYTE_FLIP | FUZZ_2_BYTE_FLIP | | ||
85 | FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END, sig, l); | ||
86 | ASSERT_INT_EQ(sshkey_verify(k, sig, l, c, sizeof(c), NULL, 0), 0); | 93 | ASSERT_INT_EQ(sshkey_verify(k, sig, l, c, sizeof(c), NULL, 0), 0); |
87 | free(sig); | 94 | free(sig); |
88 | TEST_ONERROR(onerror, fuzz); | 95 | TEST_ONERROR(onerror, fuzz); |
@@ -96,13 +103,15 @@ sig_fuzz(struct sshkey *k, const char *sig_alg) | |||
96 | fuzz_cleanup(fuzz); | 103 | fuzz_cleanup(fuzz); |
97 | } | 104 | } |
98 | 105 | ||
106 | #define NUM_FAST_BASE64_TESTS 1024 | ||
107 | |||
99 | void | 108 | void |
100 | sshkey_fuzz_tests(void) | 109 | sshkey_fuzz_tests(void) |
101 | { | 110 | { |
102 | struct sshkey *k1; | 111 | struct sshkey *k1; |
103 | struct sshbuf *buf, *fuzzed; | 112 | struct sshbuf *buf, *fuzzed; |
104 | struct fuzz *fuzz; | 113 | struct fuzz *fuzz; |
105 | int r; | 114 | int r, i; |
106 | 115 | ||
107 | 116 | ||
108 | TEST_START("fuzz RSA private"); | 117 | TEST_START("fuzz RSA private"); |
@@ -114,12 +123,14 @@ sshkey_fuzz_tests(void) | |||
114 | sshbuf_free(buf); | 123 | sshbuf_free(buf); |
115 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); | 124 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); |
116 | TEST_ONERROR(onerror, fuzz); | 125 | TEST_ONERROR(onerror, fuzz); |
117 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { | 126 | for(i = 0; !fuzz_done(fuzz); i++, fuzz_next(fuzz)) { |
118 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); | 127 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); |
119 | ASSERT_INT_EQ(r, 0); | 128 | ASSERT_INT_EQ(r, 0); |
120 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) | 129 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) |
121 | sshkey_free(k1); | 130 | sshkey_free(k1); |
122 | sshbuf_reset(fuzzed); | 131 | sshbuf_reset(fuzzed); |
132 | if (test_is_fast() && i >= NUM_FAST_BASE64_TESTS) | ||
133 | break; | ||
123 | } | 134 | } |
124 | sshbuf_free(fuzzed); | 135 | sshbuf_free(fuzzed); |
125 | fuzz_cleanup(fuzz); | 136 | fuzz_cleanup(fuzz); |
@@ -134,12 +145,14 @@ sshkey_fuzz_tests(void) | |||
134 | sshbuf_free(buf); | 145 | sshbuf_free(buf); |
135 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); | 146 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); |
136 | TEST_ONERROR(onerror, fuzz); | 147 | TEST_ONERROR(onerror, fuzz); |
137 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { | 148 | for(i = 0; !fuzz_done(fuzz); i++, fuzz_next(fuzz)) { |
138 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); | 149 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); |
139 | ASSERT_INT_EQ(r, 0); | 150 | ASSERT_INT_EQ(r, 0); |
140 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) | 151 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) |
141 | sshkey_free(k1); | 152 | sshkey_free(k1); |
142 | sshbuf_reset(fuzzed); | 153 | sshbuf_reset(fuzzed); |
154 | if (test_is_fast() && i >= NUM_FAST_BASE64_TESTS) | ||
155 | break; | ||
143 | } | 156 | } |
144 | sshbuf_free(fuzzed); | 157 | sshbuf_free(fuzzed); |
145 | fuzz_cleanup(fuzz); | 158 | fuzz_cleanup(fuzz); |
@@ -154,12 +167,14 @@ sshkey_fuzz_tests(void) | |||
154 | sshbuf_free(buf); | 167 | sshbuf_free(buf); |
155 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); | 168 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); |
156 | TEST_ONERROR(onerror, fuzz); | 169 | TEST_ONERROR(onerror, fuzz); |
157 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { | 170 | for(i = 0; !fuzz_done(fuzz); i++, fuzz_next(fuzz)) { |
158 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); | 171 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); |
159 | ASSERT_INT_EQ(r, 0); | 172 | ASSERT_INT_EQ(r, 0); |
160 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) | 173 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) |
161 | sshkey_free(k1); | 174 | sshkey_free(k1); |
162 | sshbuf_reset(fuzzed); | 175 | sshbuf_reset(fuzzed); |
176 | if (test_is_fast() && i >= NUM_FAST_BASE64_TESTS) | ||
177 | break; | ||
163 | } | 178 | } |
164 | sshbuf_free(fuzzed); | 179 | sshbuf_free(fuzzed); |
165 | fuzz_cleanup(fuzz); | 180 | fuzz_cleanup(fuzz); |
@@ -174,12 +189,14 @@ sshkey_fuzz_tests(void) | |||
174 | sshbuf_free(buf); | 189 | sshbuf_free(buf); |
175 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); | 190 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); |
176 | TEST_ONERROR(onerror, fuzz); | 191 | TEST_ONERROR(onerror, fuzz); |
177 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { | 192 | for(i = 0; !fuzz_done(fuzz); i++, fuzz_next(fuzz)) { |
178 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); | 193 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); |
179 | ASSERT_INT_EQ(r, 0); | 194 | ASSERT_INT_EQ(r, 0); |
180 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) | 195 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) |
181 | sshkey_free(k1); | 196 | sshkey_free(k1); |
182 | sshbuf_reset(fuzzed); | 197 | sshbuf_reset(fuzzed); |
198 | if (test_is_fast() && i >= NUM_FAST_BASE64_TESTS) | ||
199 | break; | ||
183 | } | 200 | } |
184 | sshbuf_free(fuzzed); | 201 | sshbuf_free(fuzzed); |
185 | fuzz_cleanup(fuzz); | 202 | fuzz_cleanup(fuzz); |
@@ -195,12 +212,14 @@ sshkey_fuzz_tests(void) | |||
195 | sshbuf_free(buf); | 212 | sshbuf_free(buf); |
196 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); | 213 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); |
197 | TEST_ONERROR(onerror, fuzz); | 214 | TEST_ONERROR(onerror, fuzz); |
198 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { | 215 | for(i = 0; !fuzz_done(fuzz); i++, fuzz_next(fuzz)) { |
199 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); | 216 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); |
200 | ASSERT_INT_EQ(r, 0); | 217 | ASSERT_INT_EQ(r, 0); |
201 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) | 218 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) |
202 | sshkey_free(k1); | 219 | sshkey_free(k1); |
203 | sshbuf_reset(fuzzed); | 220 | sshbuf_reset(fuzzed); |
221 | if (test_is_fast() && i >= NUM_FAST_BASE64_TESTS) | ||
222 | break; | ||
204 | } | 223 | } |
205 | sshbuf_free(fuzzed); | 224 | sshbuf_free(fuzzed); |
206 | fuzz_cleanup(fuzz); | 225 | fuzz_cleanup(fuzz); |
@@ -215,12 +234,14 @@ sshkey_fuzz_tests(void) | |||
215 | sshbuf_free(buf); | 234 | sshbuf_free(buf); |
216 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); | 235 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); |
217 | TEST_ONERROR(onerror, fuzz); | 236 | TEST_ONERROR(onerror, fuzz); |
218 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { | 237 | for(i = 0; !fuzz_done(fuzz); i++, fuzz_next(fuzz)) { |
219 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); | 238 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); |
220 | ASSERT_INT_EQ(r, 0); | 239 | ASSERT_INT_EQ(r, 0); |
221 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) | 240 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) |
222 | sshkey_free(k1); | 241 | sshkey_free(k1); |
223 | sshbuf_reset(fuzzed); | 242 | sshbuf_reset(fuzzed); |
243 | if (test_is_fast() && i >= NUM_FAST_BASE64_TESTS) | ||
244 | break; | ||
224 | } | 245 | } |
225 | sshbuf_free(fuzzed); | 246 | sshbuf_free(fuzzed); |
226 | fuzz_cleanup(fuzz); | 247 | fuzz_cleanup(fuzz); |
@@ -236,12 +257,14 @@ sshkey_fuzz_tests(void) | |||
236 | sshbuf_free(buf); | 257 | sshbuf_free(buf); |
237 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); | 258 | ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); |
238 | TEST_ONERROR(onerror, fuzz); | 259 | TEST_ONERROR(onerror, fuzz); |
239 | for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { | 260 | for(i = 0; !fuzz_done(fuzz); i++, fuzz_next(fuzz)) { |
240 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); | 261 | r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); |
241 | ASSERT_INT_EQ(r, 0); | 262 | ASSERT_INT_EQ(r, 0); |
242 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) | 263 | if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0) |
243 | sshkey_free(k1); | 264 | sshkey_free(k1); |
244 | sshbuf_reset(fuzzed); | 265 | sshbuf_reset(fuzzed); |
266 | if (test_is_fast() && i >= NUM_FAST_BASE64_TESTS) | ||
267 | break; | ||
245 | } | 268 | } |
246 | sshbuf_free(fuzzed); | 269 | sshbuf_free(fuzzed); |
247 | fuzz_cleanup(fuzz); | 270 | fuzz_cleanup(fuzz); |
diff --git a/regress/unittests/sshkey/tests.c b/regress/unittests/sshkey/tests.c index 13f265cdb..78aa9223d 100644 --- a/regress/unittests/sshkey/tests.c +++ b/regress/unittests/sshkey/tests.c | |||
@@ -7,8 +7,6 @@ | |||
7 | 7 | ||
8 | #include "includes.h" | 8 | #include "includes.h" |
9 | 9 | ||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | #include "../test_helper/test_helper.h" | 10 | #include "../test_helper/test_helper.h" |
13 | 11 | ||
14 | void sshkey_tests(void); | 12 | void sshkey_tests(void); |
@@ -18,9 +16,6 @@ void sshkey_fuzz_tests(void); | |||
18 | void | 16 | void |
19 | tests(void) | 17 | tests(void) |
20 | { | 18 | { |
21 | OpenSSL_add_all_algorithms(); | ||
22 | ERR_load_CRYPTO_strings(); | ||
23 | |||
24 | sshkey_tests(); | 19 | sshkey_tests(); |
25 | sshkey_file_tests(); | 20 | sshkey_file_tests(); |
26 | sshkey_fuzz_tests(); | 21 | sshkey_fuzz_tests(); |
diff --git a/regress/unittests/test_helper/test_helper.c b/regress/unittests/test_helper/test_helper.c index 4cc70852c..e7a47b265 100644 --- a/regress/unittests/test_helper/test_helper.c +++ b/regress/unittests/test_helper/test_helper.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_helper.c,v 1.8 2018/02/08 08:46:20 djm Exp $ */ | 1 | /* $OpenBSD: test_helper.c,v 1.11 2018/11/23 02:53:57 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> | 3 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> |
4 | * | 4 | * |
@@ -35,11 +35,13 @@ | |||
35 | #include <signal.h> | 35 | #include <signal.h> |
36 | 36 | ||
37 | #include <openssl/bn.h> | 37 | #include <openssl/bn.h> |
38 | #include <openssl/err.h> | ||
38 | 39 | ||
39 | #if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS) | 40 | #if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS) |
40 | # include <vis.h> | 41 | # include <vis.h> |
41 | #endif | 42 | #endif |
42 | 43 | ||
44 | #include "entropy.h" | ||
43 | #include "test_helper.h" | 45 | #include "test_helper.h" |
44 | #include "atomicio.h" | 46 | #include "atomicio.h" |
45 | 47 | ||
@@ -115,12 +117,17 @@ static test_onerror_func_t *test_onerror = NULL; | |||
115 | static void *onerror_ctx = NULL; | 117 | static void *onerror_ctx = NULL; |
116 | static const char *data_dir = NULL; | 118 | static const char *data_dir = NULL; |
117 | static char subtest_info[512]; | 119 | static char subtest_info[512]; |
120 | static int fast = 0; | ||
121 | static int slow = 0; | ||
118 | 122 | ||
119 | int | 123 | int |
120 | main(int argc, char **argv) | 124 | main(int argc, char **argv) |
121 | { | 125 | { |
122 | int ch; | 126 | int ch; |
123 | 127 | ||
128 | seed_rng(); | ||
129 | ERR_load_CRYPTO_strings(); | ||
130 | |||
124 | /* Handle systems without __progname */ | 131 | /* Handle systems without __progname */ |
125 | if (__progname == NULL) { | 132 | if (__progname == NULL) { |
126 | __progname = strrchr(argv[0], '/'); | 133 | __progname = strrchr(argv[0], '/'); |
@@ -134,8 +141,14 @@ main(int argc, char **argv) | |||
134 | } | 141 | } |
135 | } | 142 | } |
136 | 143 | ||
137 | while ((ch = getopt(argc, argv, "vqd:")) != -1) { | 144 | while ((ch = getopt(argc, argv, "Ffvqd:")) != -1) { |
138 | switch (ch) { | 145 | switch (ch) { |
146 | case 'F': | ||
147 | slow = 1; | ||
148 | break; | ||
149 | case 'f': | ||
150 | fast = 1; | ||
151 | break; | ||
139 | case 'd': | 152 | case 'd': |
140 | data_dir = optarg; | 153 | data_dir = optarg; |
141 | break; | 154 | break; |
@@ -167,17 +180,29 @@ main(int argc, char **argv) | |||
167 | } | 180 | } |
168 | 181 | ||
169 | int | 182 | int |
170 | test_is_verbose() | 183 | test_is_verbose(void) |
171 | { | 184 | { |
172 | return verbose_mode; | 185 | return verbose_mode; |
173 | } | 186 | } |
174 | 187 | ||
175 | int | 188 | int |
176 | test_is_quiet() | 189 | test_is_quiet(void) |
177 | { | 190 | { |
178 | return quiet_mode; | 191 | return quiet_mode; |
179 | } | 192 | } |
180 | 193 | ||
194 | int | ||
195 | test_is_fast(void) | ||
196 | { | ||
197 | return fast; | ||
198 | } | ||
199 | |||
200 | int | ||
201 | test_is_slow(void) | ||
202 | { | ||
203 | return slow; | ||
204 | } | ||
205 | |||
181 | const char * | 206 | const char * |
182 | test_data_file(const char *name) | 207 | test_data_file(const char *name) |
183 | { | 208 | { |
diff --git a/regress/unittests/test_helper/test_helper.h b/regress/unittests/test_helper/test_helper.h index 6da0066e9..1f893c8dd 100644 --- a/regress/unittests/test_helper/test_helper.h +++ b/regress/unittests/test_helper/test_helper.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_helper.h,v 1.8 2018/02/08 08:46:20 djm Exp $ */ | 1 | /* $OpenBSD: test_helper.h,v 1.9 2018/10/17 23:28:05 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> | 3 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> |
4 | * | 4 | * |
@@ -45,6 +45,8 @@ void set_onerror_func(test_onerror_func_t *f, void *ctx); | |||
45 | void test_done(void); | 45 | void test_done(void); |
46 | int test_is_verbose(void); | 46 | int test_is_verbose(void); |
47 | int test_is_quiet(void); | 47 | int test_is_quiet(void); |
48 | int test_is_fast(void); | ||
49 | int test_is_slow(void); | ||
48 | void test_subtest_info(const char *fmt, ...) | 50 | void test_subtest_info(const char *fmt, ...) |
49 | __attribute__((format(printf, 1, 2))); | 51 | __attribute__((format(printf, 1, 2))); |
50 | void ssl_err_check(const char *file, int line); | 52 | void ssl_err_check(const char *file, int line); |