Mercurial > dropbear
annotate fuzzer-verify.c @ 1682:a53e7d2d60be
rsa-sha256 for ssh-agent
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 25 May 2020 20:23:02 +0800 |
parents | d5cdc60db08e |
children | e01f9ec6d177 |
rev | line source |
---|---|
1380 | 1 #include "fuzz.h" |
2 #include "session.h" | |
3 #include "fuzz-wrapfd.h" | |
4 #include "debug.h" | |
5 | |
6 static void setup_fuzzer(void) { | |
1456
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1380
diff
changeset
|
7 fuzz_common_setup(); |
1380 | 8 } |
9 | |
10 static buffer *verifydata; | |
11 | |
12 /* Tests reading a public key and verifying a signature */ | |
13 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | |
14 static int once = 0; | |
15 if (!once) { | |
16 setup_fuzzer(); | |
17 verifydata = buf_new(30); | |
18 buf_putstring(verifydata, "x", 1); | |
19 once = 1; | |
20 } | |
21 | |
1456
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1380
diff
changeset
|
22 if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) { |
1380 | 23 return 0; |
24 } | |
25 | |
26 m_malloc_set_epoch(1); | |
27 | |
28 if (setjmp(fuzz.jmp) == 0) { | |
29 sign_key *key = new_sign_key(); | |
1675
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
30 enum signkey_type keytype = DROPBEAR_SIGNKEY_ANY; |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
31 if (buf_get_pub_key(fuzz.input, key, &keytype) == DROPBEAR_SUCCESS) { |
1676
d5cdc60db08e
ext-info handling for server-sig-algs
Matt Johnston <matt@ucc.asn.au>
parents:
1675
diff
changeset
|
32 enum signature_type sigtype; |
1675
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
33 if (keytype == DROPBEAR_SIGNKEY_RSA) { |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
34 /* Flip a coin to decide rsa signature type */ |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
35 int flag = buf_getbyte(fuzz_input); |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
36 if (flag & 0x01) { |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
37 sigtype = DROPBEAR_SIGNATURE_RSA_SHA256; |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
38 } else { |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
39 sigtype = DROPBEAR_SIGNATURE_RSA_SHA1; |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
40 } |
1676
d5cdc60db08e
ext-info handling for server-sig-algs
Matt Johnston <matt@ucc.asn.au>
parents:
1675
diff
changeset
|
41 } else { |
d5cdc60db08e
ext-info handling for server-sig-algs
Matt Johnston <matt@ucc.asn.au>
parents:
1675
diff
changeset
|
42 sigtype = signature_type_from_signkey(keytype); |
1675
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
43 } |
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
44 if (buf_verify(fuzz.input, key, sigtype, verifydata) == DROPBEAR_SUCCESS) { |
1529
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
45 /* The fuzzer is capable of generating keys with a signature to match. |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
46 We don't want false positives if the key is bogus, since a client/server |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
47 wouldn't be trusting a bogus key anyway */ |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
48 int boguskey = 0; |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
49 |
1675
ae41624c2198
split signkey_type and signature_type for RSA sha1 vs sha256
Matt Johnston <matt@ucc.asn.au>
parents:
1655
diff
changeset
|
50 if (keytype == DROPBEAR_SIGNKEY_DSS) { |
1529
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
51 /* So far have seen dss keys with bad p/q/g domain parameters */ |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1559
diff
changeset
|
52 int pprime, qprime, trials; |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1559
diff
changeset
|
53 trials = mp_prime_rabin_miller_trials(mp_count_bits(key->dsskey->p)); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1559
diff
changeset
|
54 assert(mp_prime_is_prime(key->dsskey->p, trials, &pprime) == MP_OKAY); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1559
diff
changeset
|
55 trials = mp_prime_rabin_miller_trials(mp_count_bits(key->dsskey->q)); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1559
diff
changeset
|
56 assert(mp_prime_is_prime(key->dsskey->q, trials, &qprime) == MP_OKAY); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1559
diff
changeset
|
57 boguskey = !(pprime && qprime); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1559
diff
changeset
|
58 /* Could also check g**q mod p == 1 */ |
1529
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
59 } |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
60 |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
61 if (!boguskey) { |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
62 printf("Random key/signature managed to verify!\n"); |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
63 abort(); |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
64 } |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
65 |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
66 |
66a1a2547133
The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
67 } |
1380 | 68 } |
69 sign_key_free(key); | |
70 m_malloc_free_epoch(1, 0); | |
71 } else { | |
72 m_malloc_free_epoch(1, 1); | |
73 TRACE(("dropbear_exit longjmped")) | |
1559
92c93b4a3646
Fix to be able to compile normal(ish) binaries with --enable-fuzz
Matt Johnston <matt@ucc.asn.au>
parents:
1529
diff
changeset
|
74 /* dropbear_exit jumped here */ |
1380 | 75 } |
76 | |
77 return 0; | |
78 } |