comparison fuzz-common.c @ 1751:3b9b427925a0

Load password and key for client fuzzer. Add fuzz_dump()
author Matt Johnston <matt@ucc.asn.au>
date Tue, 20 Oct 2020 23:34:38 +0800
parents 6e71440b1e47
children
comparison
equal deleted inserted replaced
1750:7cb8bc5ce8b9 1751:3b9b427925a0
6 #include "runopts.h" 6 #include "runopts.h"
7 #include "crypto_desc.h" 7 #include "crypto_desc.h"
8 #include "session.h" 8 #include "session.h"
9 #include "dbrandom.h" 9 #include "dbrandom.h"
10 #include "bignum.h" 10 #include "bignum.h"
11 #include "atomicio.h"
11 #include "fuzz-wrapfd.h" 12 #include "fuzz-wrapfd.h"
12 13
13 struct dropbear_fuzz_options fuzz; 14 struct dropbear_fuzz_options fuzz;
14 15
15 static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param); 16 static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param);
16 static void load_fixed_hostkeys(void); 17 static void load_fixed_hostkeys(void);
18 static void load_fixed_client_key(void);
17 19
18 void fuzz_common_setup(void) { 20 void fuzz_common_setup(void) {
19 disallow_core(); 21 disallow_core();
20 fuzz.fuzzing = 1; 22 fuzz.fuzzing = 1;
21 fuzz.wrapfds = 1; 23 fuzz.wrapfds = 1;
83 85
84 char *argv[] = { 86 char *argv[] = {
85 "dbclient", 87 "dbclient",
86 "-y", 88 "-y",
87 "localhost", 89 "localhost",
90 "uptime"
88 }; 91 };
89 92
90 int argc = sizeof(argv) / sizeof(*argv); 93 int argc = sizeof(argv) / sizeof(*argv);
91 cli_getopts(argc, argv); 94 cli_getopts(argc, argv);
95
96 load_fixed_client_key();
97 /* Avoid password prompt */
98 setenv(DROPBEAR_PASSWORD_ENV, "password", 1);
99 }
100
101 #include "fuzz-hostkeys.c"
102
103 static void load_fixed_client_key(void) {
104
105 buffer *b = buf_new(3000);
106 sign_key *key;
107 enum signkey_type keytype;
108
109 key = new_sign_key();
110 keytype = DROPBEAR_SIGNKEY_ANY;
111 buf_putbytes(b, keyed25519, keyed25519_len);
112 buf_setpos(b, 0);
113 if (buf_get_priv_key(b, key, &keytype) == DROPBEAR_FAILURE) {
114 dropbear_exit("failed fixed ed25519 hostkey");
115 }
116 list_append(cli_opts.privkeys, key);
117
118 buf_free(b);
92 } 119 }
93 120
94 static void load_fixed_hostkeys(void) { 121 static void load_fixed_hostkeys(void) {
95 #include "fuzz-hostkeys.c"
96 122
97 buffer *b = buf_new(3000); 123 buffer *b = buf_new(3000);
98 enum signkey_type type; 124 enum signkey_type type;
99 125
100 TRACE(("load fixed hostkeys")) 126 TRACE(("load fixed hostkeys"))
274 return t->data; 300 return t->data;
275 } 301 }
276 } 302 }
277 assert(0); 303 assert(0);
278 } 304 }
305
306 void fuzz_dump(const unsigned char* data, size_t len) {
307 TRACE(("dump %zu", len))
308 if (fuzz.dumping) {
309 assert(atomicio(vwrite, fuzz.recv_dumpfd, (void*)data, len) == len);
310 }
311 }