### -*-sh-*- ### ### Key type for OpenSSL ### ### (c) 2015 Mark Wooding ### ###----- Licensing notice --------------------------------------------------- ### ### This file is part of the distorted.org.uk key management suite. ### ### distorted-keys is free software; you can redistribute it and/or modify ### it under the terms of the GNU General Public License as published by ### the Free Software Foundation; either version 2 of the License, or ### (at your option) any later version. ### ### distorted-keys is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU General Public License for more details. ### ### You should have received a copy of the GNU General Public License ### along with distorted-keys; if not, write to the Free Software Foundation, ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. R_OPT="$R_IDENT:$R_IDENT" R_OPTSEQ="$R_OPT\([[:space:]][[:space:]]*$R_OPT\)*" R_TYPE="[$R_IDENTCHARS[:space:]][$R_IDENTCHARS[:space:]]*" R_BASE64="[a-zA-Z0-9+/]*=*" R_PARAMS="$R_TYPE:$R_BASE64" defprops k_props <$TMP/param args="-paramfile $TMP/param" ;; nil,t,t,*) openssl genpkey -genparam -algorithm $kprop_algorithm $opts >$TMP/param args="-paramfile $TMP/param" ;; nil,t,nil,*) args="-algorithm $kprop_algorithm $opts" ;; *) echo >&2 "$quis: invalid combination of properties" exit 1 ;; esac ## Generate the private key. openssl -cipher $kprop_cipher -pass file:"$nub" -out "$base/priv" ## Extract the public key. openssl -passin file:"$nub" -in "$base/priv" -pubout "$base/pub" } k_encrypt () { base=$1 openssl pkeyutl -encrypt -pubin -inkey "$base/pub" \ $(intersperse_opts -pkeyopt "$kprop_enc_opts") } k_decrypt () { base=$1 nub=$2 openssl pkeyutl -decrypt -passin file:"$nub" -inkey "$base/priv" } k_sign () { base=$1 nub=$2 openssl pkeyutl -sign -passin file:"$nub" -inkey "$base/priv" \ $(intersperse_opts -pkeyopt "$kprop_sig_opts") >$TMP/sig pem_to_line <$TMP/sig } k_verify () { base=$1 sig=$3 line_to_pem "$3" >$TMP/sig openssl pkeyutl -verify -pubin -inkey "$base/pub" -sigfile $TMP/sig } ###----- That's all, folks --------------------------------------------------