1# $OpenBSD: keygen-convert.sh,v 1.6 2021/07/24 02:57:28 dtucker Exp $ 2# Placed in the Public Domain. 3 4tid="convert keys" 5 6cat > $OBJ/askpass <<EOD 7#!/bin/sh 8echo hunter2 9EOD 10chmod u+x $OBJ/askpass 11 12if ${SSHKEYGEN} -? 2>&1 | grep "ssh-keygen -e" >/dev/null; then 13 test_import_export=1 14fi 15 16for t in ${SSH_KEYTYPES}; do 17 # generate user key for agent 18 trace "generating $t key" 19 rm -f $OBJ/$t-key 20 ${SSHKEYGEN} -q -N "" -t $t -f $OBJ/$t-key 21 22 if test "x$test_import_export" = "x1"; then 23 trace "export $t private to rfc4716 public" 24 ${SSHKEYGEN} -q -e -f $OBJ/$t-key >$OBJ/$t-key-rfc || \ 25 fail "export $t private to rfc4716 public" 26 27 trace "export $t public to rfc4716 public" 28 ${SSHKEYGEN} -q -e -f $OBJ/$t-key.pub >$OBJ/$t-key-rfc.pub || \ 29 fail "$t public to rfc4716 public" 30 31 cmp $OBJ/$t-key-rfc $OBJ/$t-key-rfc.pub || \ 32 fail "$t rfc4716 exports differ between public and private" 33 34 trace "import $t rfc4716 public" 35 ${SSHKEYGEN} -q -i -f $OBJ/$t-key-rfc >$OBJ/$t-rfc-imported || \ 36 fail "$t import rfc4716 public" 37 38 cut -f1,2 -d " " $OBJ/$t-key.pub >$OBJ/$t-key-nocomment.pub 39 cmp $OBJ/$t-key-nocomment.pub $OBJ/$t-rfc-imported || \ 40 fail "$t imported differs from original" 41 fi 42 43 trace "set passphrase $t" 44 ${SSHKEYGEN} -q -p -P '' -N 'hunter2' -f $OBJ/$t-key >/dev/null || \ 45 fail "$t set passphrase failed" 46 47 trace "export $t to public with passphrase" 48 SSH_ASKPASS=$OBJ/askpass SSH_ASKPASS_REQUIRE=force \ 49 ${SSHKEYGEN} -y -f $OBJ/$t-key >$OBJ/$t-key-nocomment.pub 50 cmp $OBJ/$t-key.pub $OBJ/$t-key-nocomment.pub || \ 51 fail "$t exported pubkey differs from generated" 52 53 rm -f $OBJ/$t-key $OBJ/$t-key.pub $OBJ/$t-key-rfc $OBJ/$t-key-rfc.pub \ 54 $OBJ/$t-rfc-imported $OBJ/$t-key-nocomment.pub 55done 56