xref: /netbsd-src/external/bsd/pam-u2f/dist/fuzz/make_seed.py (revision 3ff1169c71051ece76f531052b2ab22d07f38c9c)
1*3ff1169cSchristos#!/usr/bin/env python3
2*3ff1169cSchristos
3*3ff1169cSchristos# append the 1 byte the fuzzer needs to decide which format to choose,
4*3ff1169cSchristos# 1 byte for debug or not and then 4 bytes for the srandom() seed.
5*3ff1169cSchristos# run this script and then merge the generated seeds to the corpus.
6*3ff1169cSchristos# Note: this has already been done with the existing corpus. This
7*3ff1169cSchristos# script is included in case new credentials tests are added
8*3ff1169cSchristos# ./make_seed.py
9*3ff1169cSchristos# ./fuzz_format_parsers corpus seed -merge=1
10*3ff1169cSchristos
11*3ff1169cSchristosimport os
12*3ff1169cSchristos
13*3ff1169cSchristosif not os.path.exists("./seed"):
14*3ff1169cSchristos    os.mkdir("./seed")
15*3ff1169cSchristos
16*3ff1169cSchristoswith os.scandir("../tests/credentials") as entries:
17*3ff1169cSchristos    for entry in entries:
18*3ff1169cSchristos        if not entry.is_file():
19*3ff1169cSchristos            continue
20*3ff1169cSchristos        print(entry.name)
21*3ff1169cSchristos        with open("./seed/{}".format(entry.name), "wb") as w:
22*3ff1169cSchristos            w.write(bytes([1,1,1,1,1,1]))
23*3ff1169cSchristos            with open("../tests/credentials/{}".format(entry.name), "rb") as r:
24*3ff1169cSchristos                w.write(r.read())
25*3ff1169cSchristos        with open("./seed/{}.ssh".format(entry.name), "wb") as w:
26*3ff1169cSchristos            w.write(bytes([0,1,1,1,1,1]))
27*3ff1169cSchristos            with open("../tests/credentials/{}".format(entry.name), "rb") as r:
28*3ff1169cSchristos                w.write(r.read())
29