summaryrefslogtreecommitdiff
path: root/src/keygen.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/keygen.sh')
-rwxr-xr-xsrc/keygen.sh122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/keygen.sh b/src/keygen.sh
new file mode 100755
index 0000000..716359b
--- /dev/null
+++ b/src/keygen.sh
@@ -0,0 +1,122 @@
1#!/bin/sh
2
3gpg_set_ultimate_trust()
4{
5 local keygrip
6 keygrip=$(gpg -K --with-colons|sed -ne '/^sec:/{p;q}'|cut -d: -f5) || return
7
8 expect - -- "$keygrip" <<'END'
9
10 set keygrip "[lindex $argv 0]"
11
12 spawn gpg --edit-key "$keygrip" trust
13
14 expect "Your decision?"
15 send -- "5\n"
16 expect "Do you really want to set this key to ultimate trust?"
17 send -- "y\n"
18 expect "gpg>"
19 send -- "save\n"
20 send_tty "\r"
21
22END
23}
24
25add()
26{
27 kiki merge \
28 --flow=sync \
29 --home${2:+="$2"} \
30 --create=rsa:4096 \
31 --flow=spill,match="$1" \
32 --type=pem \
33 --access=secret \
34 nil
35}
36
37init()
38{
39 local root="$1"
40
41 if [ "$root" ]; then
42 mkdir -m0600 -p "$root"/root/.gnupg
43 fi
44
45 kiki init ${root:+--chroot "$root"}
46 add encrypt ${root:+"$root/root/.gnupg"}
47 add sign ${root:+"$root/root/.gnupg"}
48
49 (
50 [ "$root" ] && export GNUPGHOME="$root/root/.gnupg/"
51 gpg_set_ultimate_trust
52 )
53}
54
55sync()
56{
57 local home1="$1"/root/.gnupg home2="$2"/root/.gnupg
58 kiki sync-public \
59 --homedir "$home1" \
60 --passphrase-fd=0 \
61 --import-if-authentic \
62 --autosign \
63 --keyrings "$home2"/pubring.gpg
64 kiki sync-secret \
65 --homedir "$home1" \
66 --autosign --import
67}
68
69doublecheck()
70{
71 gpg2 --clearsign </dev/null | gpg2 --homedir "$1"/root/.gnupg --verify
72 gpg2 --clearsign --homedir "$1"/root/.gnupg </dev/null | gpg2 --verify
73}
74
75silent()
76{
77 exec 3>&1 4>&2
78 exec >/dev/null 2>&1
79}
80
81noisy()
82{
83 exec >&3 2>&1
84}
85
86new_child()
87{
88 local root="$1"
89 init "$root"
90
91 sync "$root" ''
92 sync '' "$root"
93
94 gpg2 --check-trustdb
95 gpg2 --check-trustdb --homedir "$root"/root/.gnupg
96
97 doublecheck "$root"
98}
99
100
101child_dir=$1
102
103set -e
104
105[ "$(id -u)" = 0 ]
106[ "$child_dir" ]
107[ ! -d "$child_dir" ]
108which expect >/dev/null
109
110mkdir "$child_dir"
111trap -- 'umount "$child_dir"; rmdir "$child_dir"' EXIT
112mount -t tmpfs -o mode=0700 tmpfs "$child_dir"
113
114silent
115init
116new_child "$child_dir"
117noisy
118
119trap EXIT
120
121# gpg2 -k
122# gpg2 -k --homedir "$child_dir"/root/.gnupg