mktestdata.sh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/usr/bin/env sh
  2. # $OpenBSD: mktestdata.sh,v 1.11 2020/06/19 03:48:49 djm Exp $
  3. PW=mekmitasdigoat
  4. rsa_params()
  5. {
  6. _in="$1"
  7. _outbase="$2"
  8. set -e
  9. openssl rsa -noout -text -in $_in |
  10. awk '/^modulus:$/,/^publicExponent:/' |
  11. grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.n
  12. openssl rsa -noout -text -in $_in |
  13. awk '/^prime1:$/,/^prime2:/' |
  14. grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.p
  15. openssl rsa -noout -text -in $_in |
  16. awk '/^prime2:$/,/^exponent1:/' |
  17. grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.q
  18. for x in n p q; do
  19. echo "" >> ${_outbase}.$x
  20. echo ============ ${_outbase}.$x
  21. cat ${_outbase}.$x
  22. echo ============
  23. done
  24. }
  25. dsa_params()
  26. {
  27. _in="$1"
  28. _outbase="$2"
  29. set -e
  30. openssl dsa -noout -text -in $_in |
  31. awk '/^priv:$/,/^pub:/' |
  32. grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.priv
  33. openssl dsa -noout -text -in $_in |
  34. awk '/^pub:/,/^P:/' | #\
  35. grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.pub
  36. openssl dsa -noout -text -in $_in |
  37. awk '/^G:/,0' |
  38. grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.g
  39. for x in priv pub g; do
  40. echo "" >> ${_outbase}.$x
  41. echo ============ ${_outbase}.$x
  42. cat ${_outbase}.$x
  43. echo ============
  44. done
  45. }
  46. ecdsa_params()
  47. {
  48. _in="$1"
  49. _outbase="$2"
  50. set -e
  51. openssl ec -noout -text -in $_in |
  52. awk '/^priv:$/,/^pub:/' |
  53. grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.priv
  54. openssl ec -noout -text -in $_in |
  55. awk '/^pub:/,/^ASN1 OID:/' | #\
  56. grep -v '^[a-zA-Z]' | tr -d ' \n:' > ${_outbase}.pub
  57. openssl ec -noout -text -in $_in |
  58. grep "ASN1 OID:" |
  59. sed 's/.*: //;s/ *$//' | tr -d '\n' > ${_outbase}.curve
  60. for x in priv pub curve; do
  61. echo "" >> ${_outbase}.$x
  62. echo ============ ${_outbase}.$x
  63. cat ${_outbase}.$x
  64. echo ============
  65. done
  66. }
  67. set -ex
  68. cd testdata
  69. if [ -f ../../../misc/sk-dummy/sk-dummy.so ]; then
  70. SK_DUMMY=../../../misc/sk-dummy/sk-dummy.so
  71. elif [ -f ../../../misc/sk-dummy/obj/sk-dummy.so ]; then
  72. SK_DUMMY=../../../misc/sk-dummy/obj/sk-dummy.so
  73. else
  74. echo "Can't find sk-dummy.so" 1>&2
  75. exit 1
  76. fi
  77. rm -f rsa_1 dsa_1 ecdsa_1 ed25519_1
  78. rm -f rsa_2 dsa_2 ecdsa_2 ed25519_2
  79. rm -f rsa_n dsa_n ecdsa_n # new-format keys
  80. rm -f rsa_1_pw dsa_1_pw ecdsa_1_pw ed25519_1_pw
  81. rm -f rsa_n_pw dsa_n_pw ecdsa_n_pw
  82. rm -f pw *.pub *.bn.* *.param.* *.fp *.fp.bb
  83. ssh-keygen -t rsa -b 1024 -C "RSA test key #1" -N "" -f rsa_1 -m PEM
  84. ssh-keygen -t dsa -b 1024 -C "DSA test key #1" -N "" -f dsa_1 -m PEM
  85. ssh-keygen -t ecdsa -b 256 -C "ECDSA test key #1" -N "" -f ecdsa_1 -m PEM
  86. ssh-keygen -t ed25519 -C "ED25519 test key #1" -N "" -f ed25519_1
  87. ssh-keygen -w "$SK_DUMMY" -t ecdsa-sk -C "ECDSA-SK test key #1" \
  88. -N "" -f ecdsa_sk1
  89. ssh-keygen -w "$SK_DUMMY" -t ed25519-sk -C "ED25519-SK test key #1" \
  90. -N "" -f ed25519_sk1
  91. ssh-keygen -t rsa -b 2048 -C "RSA test key #2" -N "" -f rsa_2 -m PEM
  92. ssh-keygen -t dsa -b 1024 -C "DSA test key #2" -N "" -f dsa_2 -m PEM
  93. ssh-keygen -t ecdsa -b 521 -C "ECDSA test key #2" -N "" -f ecdsa_2 -m PEM
  94. ssh-keygen -t ed25519 -C "ED25519 test key #2" -N "" -f ed25519_2
  95. ssh-keygen -w "$SK_DUMMY" -t ecdsa-sk -C "ECDSA-SK test key #2" \
  96. -N "" -f ecdsa_sk2
  97. ssh-keygen -w "$SK_DUMMY" -t ed25519-sk -C "ED25519-SK test key #2" \
  98. -N "" -f ed25519_sk2
  99. cp rsa_1 rsa_n
  100. cp dsa_1 dsa_n
  101. cp ecdsa_1 ecdsa_n
  102. ssh-keygen -pf rsa_n -N ""
  103. ssh-keygen -pf dsa_n -N ""
  104. ssh-keygen -pf ecdsa_n -N ""
  105. cp rsa_1 rsa_1_pw
  106. cp dsa_1 dsa_1_pw
  107. cp ecdsa_1 ecdsa_1_pw
  108. cp ed25519_1 ed25519_1_pw
  109. cp ecdsa_sk1 ecdsa_sk1_pw
  110. cp ed25519_sk1 ed25519_sk1_pw
  111. cp rsa_1 rsa_n_pw
  112. cp dsa_1 dsa_n_pw
  113. cp ecdsa_1 ecdsa_n_pw
  114. ssh-keygen -pf rsa_1_pw -m PEM -N "$PW"
  115. ssh-keygen -pf dsa_1_pw -m PEM -N "$PW"
  116. ssh-keygen -pf ecdsa_1_pw -m PEM -N "$PW"
  117. ssh-keygen -pf ed25519_1_pw -N "$PW"
  118. ssh-keygen -pf ecdsa_sk1_pw -m PEM -N "$PW"
  119. ssh-keygen -pf ed25519_sk1_pw -N "$PW"
  120. ssh-keygen -pf rsa_n_pw -N "$PW"
  121. ssh-keygen -pf dsa_n_pw -N "$PW"
  122. ssh-keygen -pf ecdsa_n_pw -N "$PW"
  123. rsa_params rsa_1 rsa_1.param
  124. rsa_params rsa_2 rsa_2.param
  125. dsa_params dsa_1 dsa_1.param
  126. dsa_params dsa_1 dsa_1.param
  127. ecdsa_params ecdsa_1 ecdsa_1.param
  128. ecdsa_params ecdsa_2 ecdsa_2.param
  129. # XXX ed25519, *sk params
  130. ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
  131. -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
  132. -V 19990101:20110101 -z 1 rsa_1.pub
  133. ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
  134. -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
  135. -V 19990101:20110101 -z 2 dsa_1.pub
  136. ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
  137. -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
  138. -V 19990101:20110101 -z 3 ecdsa_1.pub
  139. ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
  140. -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
  141. -V 19990101:20110101 -z 4 ed25519_1.pub
  142. ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
  143. -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
  144. -V 19990101:20110101 -z 4 ecdsa_sk1.pub
  145. ssh-keygen -s rsa_2 -I hugo -n user1,user2 \
  146. -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
  147. -V 19990101:20110101 -z 4 ed25519_sk1.pub
  148. # Make a few RSA variant signature too.
  149. cp rsa_1 rsa_1_sha1
  150. cp rsa_1 rsa_1_sha512
  151. cp rsa_1.pub rsa_1_sha1.pub
  152. cp rsa_1.pub rsa_1_sha512.pub
  153. ssh-keygen -s rsa_2 -I hugo -n user1,user2 -t ssh-rsa \
  154. -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
  155. -V 19990101:20110101 -z 1 rsa_1_sha1.pub
  156. ssh-keygen -s rsa_2 -I hugo -n user1,user2 -t rsa-sha2-512 \
  157. -Oforce-command=/bin/ls -Ono-port-forwarding -Osource-address=10.0.0.0/8 \
  158. -V 19990101:20110101 -z 1 rsa_1_sha512.pub
  159. ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \
  160. -V 19990101:20110101 -z 5 rsa_1.pub
  161. ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \
  162. -V 19990101:20110101 -z 6 dsa_1.pub
  163. ssh-keygen -s ecdsa_1 -I julius -n host1,host2 -h \
  164. -V 19990101:20110101 -z 7 ecdsa_1.pub
  165. ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \
  166. -V 19990101:20110101 -z 8 ed25519_1.pub
  167. ssh-keygen -s ecdsa_1 -I julius -n host1,host2 -h \
  168. -V 19990101:20110101 -z 7 ecdsa_sk1.pub
  169. ssh-keygen -s ed25519_1 -I julius -n host1,host2 -h \
  170. -V 19990101:20110101 -z 8 ed25519_sk1.pub
  171. ssh-keygen -lf rsa_1 | awk '{print $2}' > rsa_1.fp
  172. ssh-keygen -lf dsa_1 | awk '{print $2}' > dsa_1.fp
  173. ssh-keygen -lf ecdsa_1 | awk '{print $2}' > ecdsa_1.fp
  174. ssh-keygen -lf ed25519_1 | awk '{print $2}' > ed25519_1.fp
  175. ssh-keygen -lf ecdsa_sk1 | awk '{print $2}' > ecdsa_sk1.fp
  176. ssh-keygen -lf ed25519_sk1 | awk '{print $2}' > ed25519_sk1.fp
  177. ssh-keygen -lf rsa_2 | awk '{print $2}' > rsa_2.fp
  178. ssh-keygen -lf dsa_2 | awk '{print $2}' > dsa_2.fp
  179. ssh-keygen -lf ecdsa_2 | awk '{print $2}' > ecdsa_2.fp
  180. ssh-keygen -lf ed25519_2 | awk '{print $2}' > ed25519_2.fp
  181. ssh-keygen -lf ecdsa_sk2 | awk '{print $2}' > ecdsa_sk2.fp
  182. ssh-keygen -lf ed25519_sk2 | awk '{print $2}' > ed25519_sk2.fp
  183. ssh-keygen -lf rsa_1-cert.pub | awk '{print $2}' > rsa_1-cert.fp
  184. ssh-keygen -lf dsa_1-cert.pub | awk '{print $2}' > dsa_1-cert.fp
  185. ssh-keygen -lf ecdsa_1-cert.pub | awk '{print $2}' > ecdsa_1-cert.fp
  186. ssh-keygen -lf ed25519_1-cert.pub | awk '{print $2}' > ed25519_1-cert.fp
  187. ssh-keygen -lf ecdsa_sk1-cert.pub | awk '{print $2}' > ecdsa_sk1-cert.fp
  188. ssh-keygen -lf ed25519_sk1-cert.pub | awk '{print $2}' > ed25519_sk1-cert.fp
  189. ssh-keygen -Bf rsa_1 | awk '{print $2}' > rsa_1.fp.bb
  190. ssh-keygen -Bf dsa_1 | awk '{print $2}' > dsa_1.fp.bb
  191. ssh-keygen -Bf ecdsa_1 | awk '{print $2}' > ecdsa_1.fp.bb
  192. ssh-keygen -Bf ed25519_1 | awk '{print $2}' > ed25519_1.fp.bb
  193. ssh-keygen -Bf ecdsa_sk1 | awk '{print $2}' > ecdsa_sk1.fp.bb
  194. ssh-keygen -Bf ed25519_sk1 | awk '{print $2}' > ed25519_sk1.fp.bb
  195. ssh-keygen -Bf rsa_2 | awk '{print $2}' > rsa_2.fp.bb
  196. ssh-keygen -Bf dsa_2 | awk '{print $2}' > dsa_2.fp.bb
  197. ssh-keygen -Bf ecdsa_2 | awk '{print $2}' > ecdsa_2.fp.bb
  198. ssh-keygen -Bf ed25519_2 | awk '{print $2}' > ed25519_2.fp.bb
  199. ssh-keygen -Bf ecdsa_sk2 | awk '{print $2}' > ecdsa_sk2.fp.bb
  200. ssh-keygen -Bf ed25519_sk2 | awk '{print $2}' > ed25519_sk2.fp.bb
  201. echo "$PW" > pw