chiark / gitweb /
New ktype operation `k_import'.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 15 Feb 2012 00:48:18 +0000 (00:48 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 23 Feb 2012 03:14:37 +0000 (03:14 +0000)
Given a directory containing `pub', populate it with anything else
necessary.

This is trivial for `seccure'; `gnupg' requires a refactoring of key
generation, to split out the directory setup stuff.

keyfunc.sh.in
ktype.gnupg

index 952a09560b3e1de9d4ddb44688d22650ff4a4bc7..dda8a2eea0327f41ceb9c758faca6afb57308991 100644 (file)
@@ -461,6 +461,7 @@ c_verify () { k_verify "$@"; }
 ## Stub implementations.
 notsupp () { op=$1; echo >&2 "$quis: operation \`$op' not supported"; }
 k_info () { :; }
+k_import () { :; }
 k_encrypt () { notsupp encrypt; }
 k_decrypt () { notsupp decrypt; }
 k_sign () { notsupp sign; }
index 8a8e764da7911e734da670d3571277cfb574f84b..18a17a9ec84ea2edeaea842e27617efe16732fad 100644 (file)
@@ -56,10 +56,9 @@ EOF
 : ${kprop_realname=%{realname\}} ${kprop_email=%{email\}}
 : ${kprop_comment=%{comment-nil\}}
 
-k_generate () {
-  base=$1 nub=$2
+initdir () {
+  base=$1
 
-  makenub >"$nub"
   prefs="$kprop_cipher_prefs $kprop_digest_prefs $kprop_compress_prefs"
 
   case ${kprop_s2k_cipher+t} in
@@ -87,6 +86,13 @@ personal-digest-preferences $kprop_digest_prefs
 personal-compress-preferences $kprop_compress_prefs
 default-preference-list $prefs
 EOF
+}
+
+k_generate () {
+  base=$1 nub=$2
+
+  makenub >"$nub"
+  initdir "$base"
 
   { cat <<EOF
 Key-Type: $kprop_main_type
@@ -121,6 +127,15 @@ EOF
   run_gnupg "$base" --export --armor --output="$base/pub"
 }
 
+k_import () {
+  base=$1
+
+  initdir "$base"
+  run_gnupg "$base" --import "$base/pub"
+  run_gnupg "$base" --fingerprint --with-colons | \
+    grep '^fpr:' | cut -d: -f10 >"$base/fpr"
+}
+
 k_encrypt () {
   base=$1
   run_gnupg "$base" --encrypt --armor --recipient=$(cat "$base/fpr")