1#!/bin/sh 2# $OpenBSD: mktestdata.sh,v 1.7 2018/09/12 01:36:45 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 131# Make a few RSA variant signature too. 132cp rsa_1 rsa_1_sha1 133cp rsa_1 rsa_1_sha512 134cp rsa_1.pub rsa_1_sha1.pub 135cp rsa_1.pub rsa_1_sha512.pub 136ssh-keygen -s rsa_2 -I hugo -n user1,user2 -t ssh-rsa \ 137 -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \ 138 -V 19990101:20110101 -z 1 rsa_1_sha1.pub 139ssh-keygen -s rsa_2 -I hugo -n user1,user2 -t rsa-sha2-512 \ 140 -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \ 141 -V 19990101:20110101 -z 1 rsa_1_sha512.pub 142 143ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \ 144 -V 19990101:20110101 -z 5 rsa_1.pub 145ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \ 146 -V 19990101:20110101 -z 6 dsa_1.pub 147ssh-keygen -s ecdsa_1 -I julius -n host1,host2 -h \ 148 -V 19990101:20110101 -z 7 ecdsa_1.pub 149ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \ 150 -V 19990101:20110101 -z 8 ed25519_1.pub 151 152ssh-keygen -lf rsa_1 | awk '{print $2}' > rsa_1.fp 153ssh-keygen -lf dsa_1 | awk '{print $2}' > dsa_1.fp 154ssh-keygen -lf ecdsa_1 | awk '{print $2}' > ecdsa_1.fp 155ssh-keygen -lf ed25519_1 | awk '{print $2}' > ed25519_1.fp 156ssh-keygen -lf rsa_2 | awk '{print $2}' > rsa_2.fp 157ssh-keygen -lf dsa_2 | awk '{print $2}' > dsa_2.fp 158ssh-keygen -lf ecdsa_2 | awk '{print $2}' > ecdsa_2.fp 159ssh-keygen -lf ed25519_2 | awk '{print $2}' > ed25519_2.fp 160 161ssh-keygen -lf dsa_1-cert.pub | awk '{print $2}' > dsa_1-cert.fp 162ssh-keygen -lf ecdsa_1-cert.pub | awk '{print $2}' > ecdsa_1-cert.fp 163ssh-keygen -lf ed25519_1-cert.pub | awk '{print $2}' > ed25519_1-cert.fp 164ssh-keygen -lf rsa_1-cert.pub | awk '{print $2}' > rsa_1-cert.fp 165 166ssh-keygen -Bf rsa_1 | awk '{print $2}' > rsa_1.fp.bb 167ssh-keygen -Bf dsa_1 | awk '{print $2}' > dsa_1.fp.bb 168ssh-keygen -Bf ecdsa_1 | awk '{print $2}' > ecdsa_1.fp.bb 169ssh-keygen -Bf ed25519_1 | awk '{print $2}' > ed25519_1.fp.bb 170ssh-keygen -Bf rsa_2 | awk '{print $2}' > rsa_2.fp.bb 171ssh-keygen -Bf dsa_2 | awk '{print $2}' > dsa_2.fp.bb 172ssh-keygen -Bf ecdsa_2 | awk '{print $2}' > ecdsa_2.fp.bb 173ssh-keygen -Bf ed25519_2 | awk '{print $2}' > ed25519_2.fp.bb 174 175# XXX Extend ssh-keygen to do detached signatures (better to test/fuzz against) 176 177echo "$PW" > pw 178