annotate make_verify.py @ 24:6fdde90420ff

Add more strings to pubkey dict. Use for fuzzer-verify too
author Matt Johnston <matt@ucc.asn.au>
date Sun, 23 Jan 2022 17:24:21 +0800
parents e5383cd558e5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #!/usr/bin/env python3
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 """ takes a pubkey, turns it into fuzzer-verify input """
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 import sys
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 import struct
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 import re
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 import binascii
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 BLOB_RE=re.compile(r'(?:ssh-rsa|ecdsa-\S+|ssh-dss) ([a-zA-Z0-9/+=]+)')
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 inp = sys.stdin.read()
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 b64blob = BLOB_RE.search(inp).groups(1)[0]
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 blob = binascii.a2b_base64(b64blob)
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 sigtypelen = struct.unpack('>I', blob[:4])[0]
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 sigtype = blob[4:4+sigtypelen]
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 print("Type is %s" % sigtype, file=sys.stderr)
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 # a bodgy key followed by signature
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 # eg rfc4253
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 # string "ssh-rsa"
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 # string rsa_signature_blob
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 sys.stdout.buffer.write(blob)
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 sys.stdout.buffer.write(struct.pack('>I', sigtypelen))
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 sys.stdout.buffer.write(sigtype)
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 sys.stdout.buffer.write(struct.pack('>II', 4, 20))
e5383cd558e5 fuzzer-verify corpus
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29