bzr branch
http://bzr.recompile.se/loggerhead/mandos/release
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
1 |
#!/bin/sh -e
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
2 |
#
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
3 |
# Mandos key generator - create a new OpenPGP key for a Mandos client
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
4 |
#
|
237.7.355
by Teddy Hogeborn
Update copyright year. |
5 |
# Copyright © 2008-2016 Teddy Hogeborn
|
6 |
# Copyright © 2008-2016 Björn Påhlsson
|
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
7 |
#
|
8 |
# This program is free software: you can redistribute it and/or modify
|
|
9 |
# it under the terms of the GNU General Public License as published by
|
|
10 |
# the Free Software Foundation, either version 3 of the License, or
|
|
11 |
# (at your option) any later version.
|
|
12 |
#
|
|
13 |
# This program is distributed in the hope that it will be useful,
|
|
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
# GNU General Public License for more details.
|
|
17 |
#
|
|
18 |
# You should have received a copy of the GNU General Public License
|
|
19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 |
#
|
|
237.11.2
by Teddy Hogeborn
Change "fukt.bsnet.se" to "recompile.se" throughout. |
21 |
# Contact the authors at <mandos@recompile.se>.
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
22 |
#
|
23 |
||
353
by Teddy Hogeborn
* Makefile (version): Change to 1.7.12. |
24 |
VERSION="1.7.12" |
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
25 |
|
163
by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): Removed. |
26 |
KEYDIR="/etc/keys/mandos" |
237.7.169
by Teddy Hogeborn
* debian/mandos-client.README.Debian: Update Linux documentation link. |
27 |
KEYTYPE=RSA |
28 |
KEYLENGTH=4096 |
|
29 |
SUBKEYTYPE=RSA |
|
30 |
SUBKEYLENGTH=4096 |
|
196
by Teddy Hogeborn
* mandos-keygen (KEYNAME): Fall back to plain "hostname" if the |
31 |
KEYNAME="`hostname --fqdn 2>/dev/null || hostname`" |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
32 |
KEYEMAIL="" |
237.7.179
by Teddy Hogeborn
* mandos (priority): Bug fix: Add even more magic to make the old |
33 |
KEYCOMMENT="" |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
34 |
KEYEXPIRE=0 |
35 |
FORCE=no |
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
36 |
SSH=yes |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
37 |
KEYCOMMENT_ORIG="$KEYCOMMENT" |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
38 |
mode=keygen |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
39 |
|
179
by Teddy Hogeborn
* INSTALL: New file. |
40 |
if [ ! -d "$KEYDIR" ]; then |
41 |
KEYDIR="/etc/mandos/keys" |
|
42 |
fi
|
|
43 |
||
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
44 |
# Parse options
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
45 |
TEMP=`getopt --options vhpF:d:t:l:s:L:n:e:c:x:fS \ |
46 |
--longoptions version,help,password,passfile:,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force,no-ssh \ |
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
47 |
--name "$0" -- "$@"` |
48 |
||
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
49 |
help(){
|
237.7.288
by Teddy Hogeborn
mandos-keygen: Fix some stylistic quoting issues. |
50 |
basename="`basename "$0"`" |
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
51 |
cat <<EOF |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
52 |
Usage: $basename [ -v | --version ]
|
53 |
$basename [ -h | --help ]
|
|
54 |
Key creation:
|
|
55 |
$basename [ OPTIONS ]
|
|
56 |
Encrypted password creation:
|
|
57 |
$basename { -p | --password } [ --name NAME ] [ --dir DIR]
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
58 |
$basename { -F | --passfile } FILE [ --name NAME ] [ --dir DIR]
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
59 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
60 |
Key creation options:
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
61 |
-v, --version Show program's version number and exit
|
62 |
-h, --help Show this help message and exit
|
|
63 |
-d DIR, --dir DIR Target directory for key files
|
|
237.7.169
by Teddy Hogeborn
* debian/mandos-client.README.Debian: Update Linux documentation link. |
64 |
-t TYPE, --type TYPE Key type. Default is RSA.
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
65 |
-l BITS, --length BITS
|
237.7.169
by Teddy Hogeborn
* debian/mandos-client.README.Debian: Update Linux documentation link. |
66 |
Key length in bits. Default is 4096.
|
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
67 |
-s TYPE, --subtype TYPE
|
237.7.175
by Teddy Hogeborn
* mandos-keygen: Bug fix: Specify key usage to avoid creating keys |
68 |
Subkey type. Default is RSA.
|
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
69 |
-L BITS, --sublength BITS
|
237.7.169
by Teddy Hogeborn
* debian/mandos-client.README.Debian: Update Linux documentation link. |
70 |
Subkey length in bits. Default is 4096.
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
71 |
-n NAME, --name NAME Name of key. Default is the FQDN.
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
72 |
-e ADDRESS, --email ADDRESS
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
73 |
Email address of key. Default is empty.
|
123
by Teddy Hogeborn
* mandos-keygen: Minor help text change. |
74 |
-c TEXT, --comment TEXT
|
237.7.179
by Teddy Hogeborn
* mandos (priority): Bug fix: Add even more magic to make the old |
75 |
Comment field for key. The default is empty.
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
76 |
-x TIME, --expire TIME
|
77 |
Key expire time. Default is no expiration.
|
|
78 |
See gpg(1) for syntax.
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
79 |
-f, --force Force overwriting old key files.
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
80 |
|
81 |
Password creation options:
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
82 |
-p, --password Create an encrypted password using the key in
|
83 |
the key directory. All options other than
|
|
84 |
--dir and --name are ignored.
|
|
85 |
-F FILE, --passfile FILE
|
|
86 |
Encrypt a password from FILE using the key in
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
87 |
the key directory. All options other than
|
123
by Teddy Hogeborn
* mandos-keygen: Minor help text change. |
88 |
--dir and --name are ignored.
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
89 |
-S, --no-ssh Don't get SSH key or set "checker" option.
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
90 |
EOF
|
91 |
}
|
|
92 |
||
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
93 |
eval set -- "$TEMP" |
94 |
while :; do |
|
95 |
case "$1" in |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
96 |
-p|--password) mode=password; shift;; |
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
97 |
-F|--passfile) mode=password; PASSFILE="$2"; shift 2;; |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
98 |
-d|--dir) KEYDIR="$2"; shift 2;; |
99 |
-t|--type) KEYTYPE="$2"; shift 2;; |
|
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
100 |
-s|--subtype) SUBKEYTYPE="$2"; shift 2;; |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
101 |
-l|--length) KEYLENGTH="$2"; shift 2;; |
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
102 |
-L|--sublength) SUBKEYLENGTH="$2"; shift 2;; |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
103 |
-n|--name) KEYNAME="$2"; shift 2;; |
104 |
-e|--email) KEYEMAIL="$2"; shift 2;; |
|
105 |
-c|--comment) KEYCOMMENT="$2"; shift 2;; |
|
87
by Teddy Hogeborn
* Makefile: Bug fix: fixed creation of man pages in "plugins.d". |
106 |
-x|--expire) KEYEXPIRE="$2"; shift 2;; |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
107 |
-f|--force) FORCE=yes; shift;; |
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
108 |
-S|--no-ssh) SSH=no; shift;; |
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
109 |
-v|--version) echo "$0 $VERSION"; exit;; |
110 |
-h|--help) help; exit;; |
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
111 |
--) shift; break;; |
112 |
*) echo "Internal error" >&2; exit 1;; |
|
113 |
esac |
|
114 |
done
|
|
115 |
if [ "$#" -gt 0 ]; then |
|
237.7.288
by Teddy Hogeborn
mandos-keygen: Fix some stylistic quoting issues. |
116 |
echo "Unknown arguments: '$*'" >&2 |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
117 |
exit 1 |
118 |
fi
|
|
119 |
||
120 |
SECKEYFILE="$KEYDIR/seckey.txt" |
|
121 |
PUBKEYFILE="$KEYDIR/pubkey.txt" |
|
122 |
||
123 |
# Check for some invalid values
|
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
124 |
if [ ! -d "$KEYDIR" ]; then |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
125 |
echo "$KEYDIR not a directory" >&2 |
126 |
exit 1 |
|
127 |
fi
|
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
128 |
if [ ! -r "$KEYDIR" ]; then |
129 |
echo "Directory $KEYDIR not readable" >&2 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
130 |
exit 1 |
131 |
fi
|
|
132 |
||
133 |
if [ "$mode" = keygen ]; then |
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
134 |
if [ ! -w "$KEYDIR" ]; then |
135 |
echo "Directory $KEYDIR not writeable" >&2 |
|
136 |
exit 1 |
|
137 |
fi |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
138 |
if [ -z "$KEYTYPE" ]; then |
139 |
echo "Empty key type" >&2 |
|
140 |
exit 1 |
|
141 |
fi |
|
142 |
|
|
143 |
if [ -z "$KEYNAME" ]; then |
|
144 |
echo "Empty key name" >&2 |
|
145 |
exit 1 |
|
146 |
fi |
|
147 |
|
|
148 |
if [ -z "$KEYLENGTH" ] || [ "$KEYLENGTH" -lt 512 ]; then |
|
149 |
echo "Invalid key length" >&2 |
|
150 |
exit 1 |
|
151 |
fi |
|
237.2.37
by Teddy Hogeborn
* mandos-keygen (password): Remove bashism "${PIPESTATUS}". |
152 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
153 |
if [ -z "$KEYEXPIRE" ]; then |
154 |
echo "Empty key expiration" >&2 |
|
155 |
exit 1 |
|
156 |
fi |
|
157 |
|
|
158 |
# Make FORCE be 0 or 1 |
|
159 |
case "$FORCE" in |
|
160 |
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) FORCE=1;; |
|
161 |
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|*) FORCE=0;; |
|
162 |
esac |
|
163 |
|
|
168
by Teddy Hogeborn
* initramfs-tools-hook: Use long options where available. Use only |
164 |
if [ \( -e "$SECKEYFILE" -o -e "$PUBKEYFILE" \) \ |
165 |
-a "$FORCE" -eq 0 ]; then |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
166 |
echo "Refusing to overwrite old key files; use --force" >&2 |
167 |
exit 1 |
|
168 |
fi |
|
169 |
|
|
170 |
# Set lines for GnuPG batch file |
|
171 |
if [ -n "$KEYCOMMENT" ]; then |
|
172 |
KEYCOMMENTLINE="Name-Comment: $KEYCOMMENT" |
|
173 |
fi |
|
174 |
if [ -n "$KEYEMAIL" ]; then |
|
175 |
KEYEMAILLINE="Name-Email: $KEYEMAIL" |
|
176 |
fi |
|
237.2.37
by Teddy Hogeborn
* mandos-keygen (password): Remove bashism "${PIPESTATUS}". |
177 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
178 |
# Create temporary gpg batch file |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
179 |
BATCHFILE="`mktemp -t mandos-keygen-batch.XXXXXXXXXX`" |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
180 |
fi
|
181 |
||
182 |
if [ "$mode" = password ]; then |
|
183 |
# Create temporary encrypted password file |
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
184 |
SECFILE="`mktemp -t mandos-keygen-secfile.XXXXXXXXXX`" |
185 |
fi
|
|
186 |
||
187 |
# Create temporary key ring directory
|
|
188 |
RINGDIR="`mktemp -d -t mandos-keygen-keyrings.XXXXXXXXXX`" |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
189 |
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
190 |
# Remove temporary files on exit
|
94
by Teddy Hogeborn
* clients.conf ([DEFAULT]/checker): Update to new default value. |
191 |
trap " |
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
192 |
set +e; \
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
193 |
test -n \"$SECFILE\" && shred --remove \"$SECFILE\"; \ |
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
194 |
shred --remove \"$RINGDIR\"/sec* 2>/dev/null; |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
195 |
test -n \"$BATCHFILE\" && rm --force \"$BATCHFILE\"; \ |
196 |
rm --recursive --force \"$RINGDIR\"; |
|
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
197 |
tty --quiet && stty echo; \
|
94
by Teddy Hogeborn
* clients.conf ([DEFAULT]/checker): Update to new default value. |
198 |
" EXIT |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
199 |
|
237.2.215
by teddy at bsnet
* debian/control (Standards-Version): Updated to "3.9.1". |
200 |
set -e |
201 |
||
166
by Teddy Hogeborn
* Makefile (confdir/clients.conf): Tighten permissions to "u=rw". |
202 |
umask 077 |
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
203 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
204 |
if [ "$mode" = keygen ]; then |
205 |
# Create batch file for GnuPG |
|
206 |
cat >"$BATCHFILE" <<-EOF |
|
207 |
Key-Type: $KEYTYPE
|
|
208 |
Key-Length: $KEYLENGTH
|
|
237.7.175
by Teddy Hogeborn
* mandos-keygen: Bug fix: Specify key usage to avoid creating keys |
209 |
Key-Usage: sign,auth
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
210 |
Subkey-Type: $SUBKEYTYPE
|
211 |
Subkey-Length: $SUBKEYLENGTH
|
|
237.7.175
by Teddy Hogeborn
* mandos-keygen: Bug fix: Specify key usage to avoid creating keys |
212 |
Subkey-Usage: encrypt
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
213 |
Name-Real: $KEYNAME
|
214 |
$KEYCOMMENTLINE
|
|
215 |
$KEYEMAILLINE
|
|
216 |
Expire-Date: $KEYEXPIRE
|
|
217 |
#Preferences: <string>
|
|
218 |
#Handle: <no-spaces>
|
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
219 |
#%pubring pubring.gpg
|
220 |
#%secring secring.gpg
|
|
237.7.427
by Teddy Hogeborn
Fix bug when generating keys in a chroot environment. |
221 |
%no-protection
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
222 |
%commit
|
223 |
EOF
|
|
224 |
|
|
237.2.156
by Teddy Hogeborn
* mandos-keygen (keygen): Warn about long key generation time. |
225 |
if tty --quiet; then |
226 |
cat <<-EOF |
|
227 |
Note: Due to entropy requirements, key generation could take
|
|
228 |
anything from a few minutes to SEVERAL HOURS. Please be
|
|
229 |
patient and/or supply the system with more entropy if needed.
|
|
230 |
EOF
|
|
231 |
echo -n "Started: " |
|
232 |
date
|
|
233 |
fi |
|
234 |
|
|
237.7.211
by Teddy Hogeborn
* mandos-keygen (keygen): Add workaround for Debian bug #737128. |
235 |
# Make sure trustdb.gpg exists; |
236 |
# this is a workaround for Debian bug #737128 |
|
237 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
|
238 |
--homedir "$RINGDIR" \ |
|
239 |
--import-ownertrust < /dev/null |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
240 |
# Generate a new key in the key rings |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
241 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
242 |
--homedir "$RINGDIR" --trust-model always \ |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
243 |
--gen-key "$BATCHFILE" |
244 |
rm --force "$BATCHFILE" |
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
245 |
|
237.2.156
by Teddy Hogeborn
* mandos-keygen (keygen): Warn about long key generation time. |
246 |
if tty --quiet; then |
247 |
echo -n "Finished: " |
|
248 |
date
|
|
249 |
fi |
|
250 |
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
251 |
# Backup any old key files |
252 |
if cp --backup=numbered --force "$SECKEYFILE" "$SECKEYFILE" \ |
|
253 |
2>/dev/null; then |
|
254 |
shred --remove "$SECKEYFILE" |
|
255 |
fi |
|
256 |
if cp --backup=numbered --force "$PUBKEYFILE" "$PUBKEYFILE" \ |
|
257 |
2>/dev/null; then |
|
258 |
rm --force "$PUBKEYFILE" |
|
259 |
fi |
|
260 |
|
|
261 |
FILECOMMENT="Mandos client key for $KEYNAME" |
|
262 |
if [ "$KEYCOMMENT" != "$KEYCOMMENT_ORIG" ]; then |
|
263 |
FILECOMMENT="$FILECOMMENT ($KEYCOMMENT)" |
|
264 |
fi |
|
265 |
|
|
266 |
if [ -n "$KEYEMAIL" ]; then |
|
267 |
FILECOMMENT="$FILECOMMENT <$KEYEMAIL>" |
|
268 |
fi |
|
269 |
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
270 |
# Export key from key rings to key files |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
271 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
272 |
--homedir "$RINGDIR" --armor --export-options export-minimal \ |
|
273 |
--comment "$FILECOMMENT" --output "$SECKEYFILE" \ |
|
274 |
--export-secret-keys
|
|
275 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
|
276 |
--homedir "$RINGDIR" --armor --export-options export-minimal \ |
|
277 |
--comment "$FILECOMMENT" --output "$PUBKEYFILE" --export |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
278 |
fi
|
279 |
||
280 |
if [ "$mode" = password ]; then |
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
281 |
|
282 |
# Make SSH be 0 or 1 |
|
283 |
case "$SSH" in |
|
284 |
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) SSH=1;; |
|
285 |
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|*) SSH=0;; |
|
286 |
esac |
|
287 |
|
|
288 |
if [ $SSH -eq 1 ]; then |
|
237.7.396
by Teddy Hogeborn
mandos-keygen: Try to use ECDSA keys with ssh-keyscan(1) by default. |
289 |
for ssh_keytype in ecdsa-sha2-nistp256 ed25519 rsa; do |
237.7.295
by Teddy Hogeborn
mandos-keygen: Bug fix: Only use one SSH key from ssh-keyscan |
290 |
set +e |
291 |
ssh_fingerprint="`ssh-keyscan -t $ssh_keytype localhost 2>/dev/null`" |
|
292 |
set -e |
|
293 |
if [ $? -ne 0 ]; then |
|
294 |
ssh_fingerprint="" |
|
295 |
continue |
|
296 |
fi |
|
297 |
if [ -n "$ssh_fingerprint" ]; then |
|
298 |
ssh_fingerprint="${ssh_fingerprint#localhost }" |
|
299 |
break |
|
300 |
fi |
|
301 |
done |
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
302 |
fi |
303 |
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
304 |
# Import key into temporary key rings |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
305 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
306 |
--homedir "$RINGDIR" --trust-model always --armor \ |
|
307 |
--import "$SECKEYFILE" |
|
308 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
|
309 |
--homedir "$RINGDIR" --trust-model always --armor \ |
|
310 |
--import "$PUBKEYFILE" |
|
311 |
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
312 |
# Get fingerprint of key |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
313 |
FINGERPRINT="`gpg --quiet --batch --no-tty --no-options \ |
237.7.288
by Teddy Hogeborn
mandos-keygen: Fix some stylistic quoting issues. |
314 |
--enable-dsa2 --homedir "$RINGDIR" --trust-model always \ |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
315 |
--fingerprint --with-colons \
|
168
by Teddy Hogeborn
* initramfs-tools-hook: Use long options where available. Use only |
316 |
| sed --quiet \
|
317 |
--expression='/^fpr:/{s/^fpr:.*:\\([0-9A-Z]*\\):\$/\\1/p;q}'`"
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
318 |
|
319 |
test -n "$FINGERPRINT" |
|
320 |
|
|
321 |
FILECOMMENT="Encrypted password for a Mandos client" |
|
322 |
|
|
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
323 |
while [ ! -s "$SECFILE" ]; do |
324 |
if [ -n "$PASSFILE" ]; then |
|
325 |
cat "$PASSFILE" |
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
326 |
else |
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
327 |
tty --quiet && stty -echo |
237.7.176
by Teddy Hogeborn
* Makefile (install-client-nokey): Install "mandos-change-keytype". |
328 |
echo -n "Enter passphrase: " >&2 |
237.7.162
by Teddy Hogeborn
* mandos: Comment changes. |
329 |
read first |
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
330 |
tty --quiet && echo >&2 |
237.7.176
by Teddy Hogeborn
* Makefile (install-client-nokey): Install "mandos-change-keytype". |
331 |
echo -n "Repeat passphrase: " >&2 |
237.7.162
by Teddy Hogeborn
* mandos: Comment changes. |
332 |
read second |
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
333 |
if tty --quiet; then |
334 |
echo >&2 |
|
335 |
stty echo |
|
336 |
fi |
|
337 |
if [ "$first" != "$second" ]; then |
|
338 |
echo "Passphrase mismatch" >&2 |
|
339 |
touch "$RINGDIR"/mismatch |
|
340 |
else |
|
341 |
echo -n "$first" |
|
342 |
fi |
|
343 |
fi | gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
|
344 |
--homedir "$RINGDIR" --trust-model always --armor \ |
|
345 |
--encrypt --sign --recipient "$FINGERPRINT" --comment \ |
|
346 |
"$FILECOMMENT" > "$SECFILE" |
|
347 |
if [ -e "$RINGDIR"/mismatch ]; then |
|
348 |
rm --force "$RINGDIR"/mismatch |
|
349 |
if tty --quiet; then |
|
350 |
> "$SECFILE" |
|
351 |
else |
|
352 |
exit 1 |
|
353 |
fi |
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
354 |
fi |
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
355 |
done |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
356 |
|
357 |
cat <<-EOF |
|
358 |
[$KEYNAME]
|
|
99
by Teddy Hogeborn
* mandos (fingerprint): Bug fix: Check crtverify.value, not crtverify. |
359 |
host = $KEYNAME
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
360 |
fingerprint = $FINGERPRINT
|
361 |
secret =
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
362 |
EOF
|
168
by Teddy Hogeborn
* initramfs-tools-hook: Use long options where available. Use only |
363 |
sed --quiet --expression=' |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
364 |
/^-----BEGIN PGP MESSAGE-----$/,/^-----END PGP MESSAGE-----$/{
|
365 |
/^$/,${
|
|
103
by Teddy Hogeborn
* mandos-keygen: Strip 24-bit checksum of Radix-64 from output to make |
366 |
# Remove 24-bit Radix-64 checksum
|
367 |
s/=....$//
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
368 |
# Indent four spaces
|
369 |
/^[^-]/s/^/ /p
|
|
370 |
}
|
|
371 |
}' < "$SECFILE" |
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
372 |
if [ -n "$ssh_fingerprint" ]; then |
237.7.295
by Teddy Hogeborn
mandos-keygen: Bug fix: Only use one SSH key from ssh-keyscan |
373 |
echo 'checker = ssh-keyscan -t '"$ssh_keytype"' %%(host)s 2>/dev/null | grep --fixed-strings --line-regexp --quiet --regexp=%%(host)s" %(ssh_fingerprint)s"' |
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
374 |
echo "ssh_fingerprint = ${ssh_fingerprint}" |
375 |
fi |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
376 |
fi
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
377 |
|
378 |
trap - EXIT |
|
379 |
||
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
380 |
set +e |
381 |
# Remove the password file, if any
|
|
382 |
if [ -n "$SECFILE" ]; then |
|
383 |
shred --remove "$SECFILE" |
|
384 |
fi
|
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
385 |
# Remove the key rings
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
386 |
shred --remove "$RINGDIR"/sec* 2>/dev/null |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
387 |
rm --recursive --force "$RINGDIR" |