summaryrefslogtreecommitdiff
path: root/regress/unittests/sshkey/test_fuzz.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2015-10-06 01:20:59 +0000
committerDamien Miller <djm@mindrot.org>2015-10-06 12:29:03 +1100
commitfdd020e86439afa7f537e2429d29d4b744c94331 (patch)
tree9973a76defa8a656d104d23e1ced8103ae938a22 /regress/unittests/sshkey/test_fuzz.c
parent21ae8ee3b630b0925f973db647a1b9aa5fcdd4c5 (diff)
upstream commit
adapt to recent sshkey_parse_private_fileblob() API change Upstream-Regress-ID: 5c0d818da511e33e0abf6a92a31bd7163b7ad988
Diffstat (limited to 'regress/unittests/sshkey/test_fuzz.c')
-rw-r--r--regress/unittests/sshkey/test_fuzz.c74
1 files changed, 25 insertions, 49 deletions
diff --git a/regress/unittests/sshkey/test_fuzz.c b/regress/unittests/sshkey/test_fuzz.c
index 1f08a2e43..cb7924de1 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.4 2015/03/04 23:22:35 djm Exp $ */ 1/* $OpenBSD: test_fuzz.c,v 1.5 2015/10/06 01:20:59 djm Exp $ */
2/* 2/*
3 * Fuzz tests for key parsing 3 * Fuzz tests for key parsing
4 * 4 *
@@ -110,8 +110,7 @@ sshkey_fuzz_tests(void)
110 fuzz = fuzz_begin(FUZZ_1_BIT_FLIP | FUZZ_1_BYTE_FLIP | 110 fuzz = fuzz_begin(FUZZ_1_BIT_FLIP | FUZZ_1_BYTE_FLIP |
111 FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END, 111 FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END,
112 sshbuf_mutable_ptr(buf), sshbuf_len(buf)); 112 sshbuf_mutable_ptr(buf), sshbuf_len(buf));
113 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 113 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
114 &k1, NULL), 0);
115 sshkey_free(k1); 114 sshkey_free(k1);
116 sshbuf_free(buf); 115 sshbuf_free(buf);
117 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); 116 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL);
@@ -119,8 +118,7 @@ sshkey_fuzz_tests(void)
119 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { 118 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
120 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); 119 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz));
121 ASSERT_INT_EQ(r, 0); 120 ASSERT_INT_EQ(r, 0);
122 if (sshkey_parse_private_fileblob(fuzzed, "", "key", 121 if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0)
123 &k1, NULL) == 0)
124 sshkey_free(k1); 122 sshkey_free(k1);
125 sshbuf_reset(fuzzed); 123 sshbuf_reset(fuzzed);
126 } 124 }
@@ -154,8 +152,7 @@ sshkey_fuzz_tests(void)
154 buf = load_file("rsa_1"); 152 buf = load_file("rsa_1");
155 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), 153 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
156 sshbuf_len(buf)); 154 sshbuf_len(buf));
157 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 155 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
158 &k1, NULL), 0);
159 sshkey_free(k1); 156 sshkey_free(k1);
160 sshbuf_free(buf); 157 sshbuf_free(buf);
161 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); 158 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL);
@@ -163,8 +160,7 @@ sshkey_fuzz_tests(void)
163 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { 160 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
164 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); 161 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz));
165 ASSERT_INT_EQ(r, 0); 162 ASSERT_INT_EQ(r, 0);
166 if (sshkey_parse_private_fileblob(fuzzed, "", "key", 163 if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0)
167 &k1, NULL) == 0)
168 sshkey_free(k1); 164 sshkey_free(k1);
169 sshbuf_reset(fuzzed); 165 sshbuf_reset(fuzzed);
170 } 166 }
@@ -176,8 +172,7 @@ sshkey_fuzz_tests(void)
176 buf = load_file("rsa_n"); 172 buf = load_file("rsa_n");
177 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), 173 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
178 sshbuf_len(buf)); 174 sshbuf_len(buf));
179 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 175 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
180 &k1, NULL), 0);
181 sshkey_free(k1); 176 sshkey_free(k1);
182 sshbuf_free(buf); 177 sshbuf_free(buf);
183 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); 178 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL);
@@ -185,8 +180,7 @@ sshkey_fuzz_tests(void)
185 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { 180 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
186 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); 181 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz));
187 ASSERT_INT_EQ(r, 0); 182 ASSERT_INT_EQ(r, 0);
188 if (sshkey_parse_private_fileblob(fuzzed, "", "key", 183 if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0)
189 &k1, NULL) == 0)
190 sshkey_free(k1); 184 sshkey_free(k1);
191 sshbuf_reset(fuzzed); 185 sshbuf_reset(fuzzed);
192 } 186 }
@@ -198,8 +192,7 @@ sshkey_fuzz_tests(void)
198 buf = load_file("dsa_1"); 192 buf = load_file("dsa_1");
199 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), 193 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
200 sshbuf_len(buf)); 194 sshbuf_len(buf));
201 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 195 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
202 &k1, NULL), 0);
203 sshkey_free(k1); 196 sshkey_free(k1);
204 sshbuf_free(buf); 197 sshbuf_free(buf);
205 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); 198 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL);
@@ -207,8 +200,7 @@ sshkey_fuzz_tests(void)
207 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { 200 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
208 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); 201 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz));
209 ASSERT_INT_EQ(r, 0); 202 ASSERT_INT_EQ(r, 0);
210 if (sshkey_parse_private_fileblob(fuzzed, "", "key", 203 if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0)
211 &k1, NULL) == 0)
212 sshkey_free(k1); 204 sshkey_free(k1);
213 sshbuf_reset(fuzzed); 205 sshbuf_reset(fuzzed);
214 } 206 }
@@ -220,8 +212,7 @@ sshkey_fuzz_tests(void)
220 buf = load_file("dsa_n"); 212 buf = load_file("dsa_n");
221 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), 213 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
222 sshbuf_len(buf)); 214 sshbuf_len(buf));
223 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 215 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
224 &k1, NULL), 0);
225 sshkey_free(k1); 216 sshkey_free(k1);
226 sshbuf_free(buf); 217 sshbuf_free(buf);
227 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); 218 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL);
@@ -229,8 +220,7 @@ sshkey_fuzz_tests(void)
229 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { 220 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
230 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); 221 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz));
231 ASSERT_INT_EQ(r, 0); 222 ASSERT_INT_EQ(r, 0);
232 if (sshkey_parse_private_fileblob(fuzzed, "", "key", 223 if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0)
233 &k1, NULL) == 0)
234 sshkey_free(k1); 224 sshkey_free(k1);
235 sshbuf_reset(fuzzed); 225 sshbuf_reset(fuzzed);
236 } 226 }
@@ -243,8 +233,7 @@ sshkey_fuzz_tests(void)
243 buf = load_file("ecdsa_1"); 233 buf = load_file("ecdsa_1");
244 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), 234 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
245 sshbuf_len(buf)); 235 sshbuf_len(buf));
246 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 236 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
247 &k1, NULL), 0);
248 sshkey_free(k1); 237 sshkey_free(k1);
249 sshbuf_free(buf); 238 sshbuf_free(buf);
250 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); 239 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL);
@@ -252,8 +241,7 @@ sshkey_fuzz_tests(void)
252 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { 241 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
253 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); 242 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz));
254 ASSERT_INT_EQ(r, 0); 243 ASSERT_INT_EQ(r, 0);
255 if (sshkey_parse_private_fileblob(fuzzed, "", "key", 244 if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0)
256 &k1, NULL) == 0)
257 sshkey_free(k1); 245 sshkey_free(k1);
258 sshbuf_reset(fuzzed); 246 sshbuf_reset(fuzzed);
259 } 247 }
@@ -265,8 +253,7 @@ sshkey_fuzz_tests(void)
265 buf = load_file("ecdsa_n"); 253 buf = load_file("ecdsa_n");
266 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), 254 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
267 sshbuf_len(buf)); 255 sshbuf_len(buf));
268 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 256 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
269 &k1, NULL), 0);
270 sshkey_free(k1); 257 sshkey_free(k1);
271 sshbuf_free(buf); 258 sshbuf_free(buf);
272 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); 259 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL);
@@ -274,8 +261,7 @@ sshkey_fuzz_tests(void)
274 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { 261 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
275 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); 262 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz));
276 ASSERT_INT_EQ(r, 0); 263 ASSERT_INT_EQ(r, 0);
277 if (sshkey_parse_private_fileblob(fuzzed, "", "key", 264 if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0)
278 &k1, NULL) == 0)
279 sshkey_free(k1); 265 sshkey_free(k1);
280 sshbuf_reset(fuzzed); 266 sshbuf_reset(fuzzed);
281 } 267 }
@@ -288,8 +274,7 @@ sshkey_fuzz_tests(void)
288 buf = load_file("ed25519_1"); 274 buf = load_file("ed25519_1");
289 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), 275 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
290 sshbuf_len(buf)); 276 sshbuf_len(buf));
291 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 277 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
292 &k1, NULL), 0);
293 sshkey_free(k1); 278 sshkey_free(k1);
294 sshbuf_free(buf); 279 sshbuf_free(buf);
295 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL); 280 ASSERT_PTR_NE(fuzzed = sshbuf_new(), NULL);
@@ -297,8 +282,7 @@ sshkey_fuzz_tests(void)
297 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) { 282 for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
298 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz)); 283 r = sshbuf_put(fuzzed, fuzz_ptr(fuzz), fuzz_len(fuzz));
299 ASSERT_INT_EQ(r, 0); 284 ASSERT_INT_EQ(r, 0);
300 if (sshkey_parse_private_fileblob(fuzzed, "", "key", 285 if (sshkey_parse_private_fileblob(fuzzed, "", &k1, NULL) == 0)
301 &k1, NULL) == 0)
302 sshkey_free(k1); 286 sshkey_free(k1);
303 sshbuf_reset(fuzzed); 287 sshbuf_reset(fuzzed);
304 } 288 }
@@ -308,8 +292,7 @@ sshkey_fuzz_tests(void)
308 292
309 TEST_START("fuzz RSA public"); 293 TEST_START("fuzz RSA public");
310 buf = load_file("rsa_1"); 294 buf = load_file("rsa_1");
311 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 295 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
312 &k1, NULL), 0);
313 sshbuf_free(buf); 296 sshbuf_free(buf);
314 public_fuzz(k1); 297 public_fuzz(k1);
315 sshkey_free(k1); 298 sshkey_free(k1);
@@ -323,8 +306,7 @@ sshkey_fuzz_tests(void)
323 306
324 TEST_START("fuzz DSA public"); 307 TEST_START("fuzz DSA public");
325 buf = load_file("dsa_1"); 308 buf = load_file("dsa_1");
326 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 309 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
327 &k1, NULL), 0);
328 sshbuf_free(buf); 310 sshbuf_free(buf);
329 public_fuzz(k1); 311 public_fuzz(k1);
330 sshkey_free(k1); 312 sshkey_free(k1);
@@ -339,8 +321,7 @@ sshkey_fuzz_tests(void)
339#ifdef OPENSSL_HAS_ECC 321#ifdef OPENSSL_HAS_ECC
340 TEST_START("fuzz ECDSA public"); 322 TEST_START("fuzz ECDSA public");
341 buf = load_file("ecdsa_1"); 323 buf = load_file("ecdsa_1");
342 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 324 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
343 &k1, NULL), 0);
344 sshbuf_free(buf); 325 sshbuf_free(buf);
345 public_fuzz(k1); 326 public_fuzz(k1);
346 sshkey_free(k1); 327 sshkey_free(k1);
@@ -355,8 +336,7 @@ sshkey_fuzz_tests(void)
355 336
356 TEST_START("fuzz Ed25519 public"); 337 TEST_START("fuzz Ed25519 public");
357 buf = load_file("ed25519_1"); 338 buf = load_file("ed25519_1");
358 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 339 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
359 &k1, NULL), 0);
360 sshbuf_free(buf); 340 sshbuf_free(buf);
361 public_fuzz(k1); 341 public_fuzz(k1);
362 sshkey_free(k1); 342 sshkey_free(k1);
@@ -370,8 +350,7 @@ sshkey_fuzz_tests(void)
370 350
371 TEST_START("fuzz RSA sig"); 351 TEST_START("fuzz RSA sig");
372 buf = load_file("rsa_1"); 352 buf = load_file("rsa_1");
373 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 353 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
374 &k1, NULL), 0);
375 sshbuf_free(buf); 354 sshbuf_free(buf);
376 sig_fuzz(k1); 355 sig_fuzz(k1);
377 sshkey_free(k1); 356 sshkey_free(k1);
@@ -379,8 +358,7 @@ sshkey_fuzz_tests(void)
379 358
380 TEST_START("fuzz DSA sig"); 359 TEST_START("fuzz DSA sig");
381 buf = load_file("dsa_1"); 360 buf = load_file("dsa_1");
382 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 361 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
383 &k1, NULL), 0);
384 sshbuf_free(buf); 362 sshbuf_free(buf);
385 sig_fuzz(k1); 363 sig_fuzz(k1);
386 sshkey_free(k1); 364 sshkey_free(k1);
@@ -389,8 +367,7 @@ sshkey_fuzz_tests(void)
389#ifdef OPENSSL_HAS_ECC 367#ifdef OPENSSL_HAS_ECC
390 TEST_START("fuzz ECDSA sig"); 368 TEST_START("fuzz ECDSA sig");
391 buf = load_file("ecdsa_1"); 369 buf = load_file("ecdsa_1");
392 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 370 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
393 &k1, NULL), 0);
394 sshbuf_free(buf); 371 sshbuf_free(buf);
395 sig_fuzz(k1); 372 sig_fuzz(k1);
396 sshkey_free(k1); 373 sshkey_free(k1);
@@ -399,8 +376,7 @@ sshkey_fuzz_tests(void)
399 376
400 TEST_START("fuzz Ed25519 sig"); 377 TEST_START("fuzz Ed25519 sig");
401 buf = load_file("ed25519_1"); 378 buf = load_file("ed25519_1");
402 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "key", 379 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
403 &k1, NULL), 0);
404 sshbuf_free(buf); 380 sshbuf_free(buf);
405 sig_fuzz(k1); 381 sig_fuzz(k1);
406 sshkey_free(k1); 382 sshkey_free(k1);