-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_weak_keys.sh
executable file
·58 lines (51 loc) · 1.95 KB
/
generate_weak_keys.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <rsa_key_size_in_bits> [<start_pid>] [<output_directory>] [<end_pid>]"
exit
fi
START_PID=0
if [ -n "$2" ]; then
START_PID=$2
fi
END_PID=32767
if [ -n "$4" ]; then
END_PID=$4
fi
CURRENT_DIR=`pwd`
OUTPUT_DIR=keys
if [ -n "$3" ]; then
OUTPUT_DIR=$3
fi
RANDFILE=`mktemp`
mkdir -p $OUTPUT_DIR/$1
cd $OUTPUT_DIR/$1
for (( i=$START_PID; i<=$END_PID; i++ )); do
echo -n "Generating weak RSA-$1 keys for process ID $i of $END_PID: "
# We must do noreadrnd on the first run, because our RANDFILE will be empty.
echo -n "le64(noreadrnd"
RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-64/key_generator $1 $i noreadrnd
echo -n ",nornd"
RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-64/key_generator $1 $i nornd
echo -n ",rnd) "
RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-64/key_generator $1 $i rnd
echo -n "le32(noreadrnd"
RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-32/key_generator $1 $i noreadrnd
echo -n ",nornd"
RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-32/key_generator $1 $i nornd
echo -n ",rnd) "
RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-32/key_generator $1 $i rnd
echo -n "be32(noreadrnd"
FLIP_ENDIAN=1 RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-32/key_generator $1 $i noreadrnd
echo -n ",nornd"
FLIP_ENDIAN=1 RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-32/key_generator $1 $i nornd
echo ",rnd)"
FLIP_ENDIAN=1 RANDFILE=$RANDFILE $CURRENT_DIR/bin/linux/x86-32/key_generator $1 $i rnd
# RANDFILE has been observed to occasionally not work as expected, resulting in an "rnd" key and its corresponding "nornd" key being identical.
# To guard against this, ensure that no duplicate keys were generated by this loop iteration.
UNIQUE_KEYS=`sha256sum $1_${i}_*.key | sed "s/ .*$//g" | sort | uniq | wc -l`
if [[ $UNIQUE_KEYS != "9" ]]; then
echo "Terminating due to a problem with the OpenSSL random file state. Please try again."
exit
fi
done
rm -f $RANDFILE