xref: /freebsd/crypto/openssh/regress/unittests/sshkey/mktestdata.sh (revision f1951fd745b894fe6586c298874af98544a5e272)
1#!/bin/sh
2# $OpenBSD: mktestdata.sh,v 1.6 2017/04/30 23:33:48 djm Exp $
3
4PW=mekmitasdigoat
5
6rsa_params() {
7	_in="$1"
8	_outbase="$2"
9	set -e
10	openssl rsa -noout -text -in $_in | \
11	    awk '/^modulus:$/,/^publicExponent:/' | \
12	    grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.n
13	openssl rsa -noout -text -in $_in | \
14	    awk '/^prime1:$/,/^prime2:/' | \
15	    grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.p
16	openssl rsa -noout -text -in $_in | \
17	    awk '/^prime2:$/,/^exponent1:/' | \
18	    grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.q
19	for x in n p q ; do
20		echo "" >> ${_outbase}.$x
21		echo ============ ${_outbase}.$x
22		cat ${_outbase}.$x
23		echo ============
24	done
25}
26
27dsa_params() {
28	_in="$1"
29	_outbase="$2"
30	set -e
31	openssl dsa -noout -text -in $_in | \
32	    awk '/^priv:$/,/^pub:/' | \
33	    grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.priv
34	openssl dsa -noout -text -in $_in | \
35	    awk '/^pub:/,/^P:/' | #\
36	    grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.pub
37	openssl dsa -noout -text -in $_in | \
38	    awk '/^G:/,0' | \
39	    grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.g
40	for x in priv pub g ; do
41		echo "" >> ${_outbase}.$x
42		echo ============ ${_outbase}.$x
43		cat ${_outbase}.$x
44		echo ============
45	done
46}
47
48ecdsa_params() {
49	_in="$1"
50	_outbase="$2"
51	set -e
52	openssl ec -noout -text -in $_in | \
53	    awk '/^priv:$/,/^pub:/' | \
54	    grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.priv
55	openssl ec -noout -text -in $_in | \
56	    awk '/^pub:/,/^ASN1 OID:/' | #\
57	    grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.pub
58	openssl ec -noout -text -in $_in | \
59	    grep "ASN1 OID:" | tr -d '\n' | \
60	    sed 's/.*: //;s/ *$//' > ${_outbase}.curve
61	for x in priv pub curve ; do
62		echo "" >> ${_outbase}.$x
63		echo ============ ${_outbase}.$x
64		cat ${_outbase}.$x
65		echo ============
66	done
67}
68
69set -ex
70
71cd testdata
72
73rm -f rsa_1 dsa_1 ecdsa_1 ed25519_1
74rm -f rsa_2 dsa_2 ecdsa_2 ed25519_2
75rm -f rsa_n dsa_n ecdsa_n # new-format keys
76rm -f rsa_1_pw dsa_1_pw ecdsa_1_pw ed25519_1_pw
77rm -f rsa_n_pw dsa_n_pw ecdsa_n_pw
78rm -f pw *.pub *.bn.* *.param.* *.fp *.fp.bb
79
80ssh-keygen -t rsa -b 1024 -C "RSA test key #1" -N "" -f rsa_1
81ssh-keygen -t dsa -b 1024 -C "DSA test key #1" -N "" -f dsa_1
82ssh-keygen -t ecdsa -b 256 -C "ECDSA test key #1" -N "" -f ecdsa_1
83ssh-keygen -t ed25519 -C "ED25519 test key #1" -N "" -f ed25519_1
84
85ssh-keygen -t rsa -b 2048 -C "RSA test key #2" -N "" -f rsa_2
86ssh-keygen -t dsa -b 1024 -C "DSA test key #2" -N "" -f dsa_2
87ssh-keygen -t ecdsa -b 521 -C "ECDSA test key #2" -N "" -f ecdsa_2
88ssh-keygen -t ed25519 -C "ED25519 test key #1" -N "" -f ed25519_2
89
90cp rsa_1 rsa_n
91cp dsa_1 dsa_n
92cp ecdsa_1 ecdsa_n
93
94cp rsa_1 rsa_1_pw
95cp dsa_1 dsa_1_pw
96cp ecdsa_1 ecdsa_1_pw
97cp ed25519_1 ed25519_1_pw
98cp rsa_1 rsa_n_pw
99cp dsa_1 dsa_n_pw
100cp ecdsa_1 ecdsa_n_pw
101
102ssh-keygen -pf rsa_1_pw -N "$PW"
103ssh-keygen -pf dsa_1_pw -N "$PW"
104ssh-keygen -pf ecdsa_1_pw -N "$PW"
105ssh-keygen -pf ed25519_1_pw -N "$PW"
106ssh-keygen -opf rsa_n_pw -N "$PW"
107ssh-keygen -opf dsa_n_pw -N "$PW"
108ssh-keygen -opf ecdsa_n_pw -N "$PW"
109
110rsa_params rsa_1 rsa_1.param
111rsa_params rsa_2 rsa_2.param
112dsa_params dsa_1 dsa_1.param
113dsa_params dsa_1 dsa_1.param
114ecdsa_params ecdsa_1 ecdsa_1.param
115ecdsa_params ecdsa_2 ecdsa_2.param
116# XXX ed25519 params
117
118ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
119    -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
120    -V 19990101:20110101 -z 1 rsa_1.pub
121ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
122    -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
123    -V 19990101:20110101 -z 2 dsa_1.pub
124ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
125    -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
126    -V 19990101:20110101 -z 3 ecdsa_1.pub
127ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
128    -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
129    -V 19990101:20110101 -z 4 ed25519_1.pub
130
131ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \
132    -V 19990101:20110101 -z 5 rsa_1.pub
133ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \
134    -V 19990101:20110101 -z 6 dsa_1.pub
135ssh-keygen -s ecdsa_1 -I julius -n host1,host2 -h \
136    -V 19990101:20110101 -z 7 ecdsa_1.pub
137ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \
138    -V 19990101:20110101 -z 8 ed25519_1.pub
139
140ssh-keygen -lf rsa_1 | awk '{print $2}' > rsa_1.fp
141ssh-keygen -lf dsa_1 | awk '{print $2}' > dsa_1.fp
142ssh-keygen -lf ecdsa_1 | awk '{print $2}' > ecdsa_1.fp
143ssh-keygen -lf ed25519_1 | awk '{print $2}' > ed25519_1.fp
144ssh-keygen -lf rsa_2 | awk '{print $2}' > rsa_2.fp
145ssh-keygen -lf dsa_2 | awk '{print $2}' > dsa_2.fp
146ssh-keygen -lf ecdsa_2 | awk '{print $2}' > ecdsa_2.fp
147ssh-keygen -lf ed25519_2 | awk '{print $2}' > ed25519_2.fp
148
149ssh-keygen -lf dsa_1-cert.pub  | awk '{print $2}' > dsa_1-cert.fp
150ssh-keygen -lf ecdsa_1-cert.pub  | awk '{print $2}' > ecdsa_1-cert.fp
151ssh-keygen -lf ed25519_1-cert.pub  | awk '{print $2}' > ed25519_1-cert.fp
152ssh-keygen -lf rsa_1-cert.pub  | awk '{print $2}' > rsa_1-cert.fp
153
154ssh-keygen -Bf rsa_1 | awk '{print $2}' > rsa_1.fp.bb
155ssh-keygen -Bf dsa_1 | awk '{print $2}' > dsa_1.fp.bb
156ssh-keygen -Bf ecdsa_1 | awk '{print $2}' > ecdsa_1.fp.bb
157ssh-keygen -Bf ed25519_1 | awk '{print $2}' > ed25519_1.fp.bb
158ssh-keygen -Bf rsa_2 | awk '{print $2}' > rsa_2.fp.bb
159ssh-keygen -Bf dsa_2 | awk '{print $2}' > dsa_2.fp.bb
160ssh-keygen -Bf ecdsa_2 | awk '{print $2}' > ecdsa_2.fp.bb
161ssh-keygen -Bf ed25519_2 | awk '{print $2}' > ed25519_2.fp.bb
162
163# XXX Extend ssh-keygen to do detached signatures (better to test/fuzz against)
164
165echo "$PW" > pw
166