Debian Codegraph @

cryptography_vectors/asymmetric/OpenSSH/gen.sh

raw
1 #! /bin/sh
2
3 rm *.key *.pub
4
5 # avoid having too many files
6 ecbits="ecbits.txt"
7 echo 521 > "$ecbits"
8 getecbits() {
9 last=$(cat $ecbits)
10 case "$last" in
11 256) last=384;;
12 384) last=521;;
13 521) last=256;;
14 esac
15 echo $last > "$ecbits"
16 echo $last
17 }
18
19 genkey() {
20 fn="$1"
21 args="-f $fn -C $fn"
22 sk="-O application=ssh:the-application-string"
23 case "$fn" in
24 sk-ecdsa-*) args="$args -t ecdsa-sk -b $(getecbits) $sk" ;;
25 ecdsa-*) args="$args -t ecdsa -b $(getecbits)" ;;
26 rsa-*) args="$args -t rsa" ;;
27 dsa-*) args="$args -t dsa" ;;
28 sk-ed25519-*) args="$args -t ed25519-sk $sk" ;;
29 ed25519-*) args="$args -t ed25519" ;;
30 esac
31 password=''
32 case "$fn" in
33 *-psw.*) password="password" ;;
34 esac
35 ssh-keygen -q -o $args -N "$password"
36 }
37
38 # generate private key files
39 for ktype in rsa dsa ecdsa sk-ecdsa ed25519 sk-ed25519; do
40 for psw in nopsw psw; do
41 genkey "${ktype}-${psw}.key"
42 done
43 done
44
45
46 # generate public key files
47 for fn in *.key; do
48 ssh-keygen -q -y -f "$fn" > /dev/null
49 done
50
51 rm -f "$ecbits"
52
53 # generate public key files with certificate
54 ssh-keygen -q -s "dsa-nopsw.key" -I "name" \
55 -z 1 -V 20100101123000:21090101123000 \
56 "dsa-nopsw.key.pub"
57 ssh-keygen -q -s "rsa-nopsw.key" -I "name" \
58 -z 2 -n user1,user2 -t rsa-sha2-512 \
59 "rsa-nopsw.key.pub"
60 ssh-keygen -q -s "ecdsa-nopsw.key" -I "name" \
61 -h -n domain1,domain2 \
62 "ecdsa-nopsw.key.pub"
63 ssh-keygen -q -s "ed25519-nopsw.key" -I "name" \
64 -O no-port-forwarding \
65 "ed25519-nopsw.key.pub"
66