From 5fb66a7a5402e48337bff755fff16c423196a13d Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 15 Jul 2017 17:52:03 +0100 Subject: [PATCH] @@@ ktype.openssl Missing profile, Makefile hacking. probably float. --- keyfunc.sh.in | 13 ++++++ ktype.openssl | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 ktype.openssl diff --git a/keyfunc.sh.in b/keyfunc.sh.in index dca8dee..c68fec1 100644 --- a/keyfunc.sh.in +++ b/keyfunc.sh.in @@ -187,6 +187,19 @@ checkident () { check "$1" "$R_IDENT" "$2"; } checkword () { check "$1" "$R_WORD" "$2"; } checklabel () { check "$1 label" "$R_LABEL" "$2"; } +## Boolean canonification. +boolify () { + var=$1 what=$2 + + eval v=\$$var + case $v in + 1 | y | yes | on | t | true) v=t ;; + 0 | n | no | off | f | false | nil) v=nil ;; + *) echo >&2 "$quis: bad boolean $what \`$v'"; exit 1 ;; + esac + eval $var=\$v +} + ###-------------------------------------------------------------------------- ### Key storage and properties. diff --git a/ktype.openssl b/ktype.openssl new file mode 100644 index 0000000..b058dbd --- /dev/null +++ b/ktype.openssl @@ -0,0 +1,134 @@ +### -*-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 -------------------------------------------------- -- 2.11.0