/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-keygen

  • Committer: Teddy Hogeborn
  • Date: 2014-03-28 22:32:21 UTC
  • Revision ID: teddy@recompile.se-20140328223221-w579qlvlex5if3dn
Fix location and format of signing key file.

* debian/upstream/signing-key.asc: Added.
* debian/upstream-signing-key.pgp: Removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
3
3
# Mandos key generator - create a new OpenPGP key for a Mandos client
4
4
5
 
# Copyright © 2008-2016 Teddy Hogeborn
6
 
# Copyright © 2008-2016 Björn Påhlsson
 
5
# Copyright © 2008-2013 Teddy Hogeborn
 
6
# Copyright © 2008-2013 Björn Påhlsson
7
7
8
8
# This program is free software: you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
21
21
# Contact the authors at <mandos@recompile.se>.
22
22
23
23
 
24
 
VERSION="1.7.14"
 
24
VERSION="1.6.4"
25
25
 
26
26
KEYDIR="/etc/keys/mandos"
27
27
KEYTYPE=RSA
33
33
KEYCOMMENT=""
34
34
KEYEXPIRE=0
35
35
FORCE=no
36
 
SSH=yes
37
36
KEYCOMMENT_ORIG="$KEYCOMMENT"
38
37
mode=keygen
39
38
 
42
41
fi
43
42
 
44
43
# Parse options
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 \
 
44
TEMP=`getopt --options vhpF:d:t:l:s:L:n:e:c:x:f \
 
45
    --longoptions version,help,password,passfile:,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force \
47
46
    --name "$0" -- "$@"`
48
47
 
49
48
help(){
50
 
basename="`basename "$0"`"
 
49
basename="`basename $0`"
51
50
cat <<EOF
52
51
Usage: $basename [ -v | --version ]
53
52
       $basename [ -h | --help ]
86
85
                        Encrypt a password from FILE using the key in
87
86
                        the key directory.  All options other than
88
87
                        --dir and --name are ignored.
89
 
  -S, --no-ssh          Don't get SSH key or set "checker" option.
90
88
EOF
91
89
}
92
90
 
105
103
        -c|--comment) KEYCOMMENT="$2"; shift 2;;
106
104
        -x|--expire) KEYEXPIRE="$2"; shift 2;;
107
105
        -f|--force) FORCE=yes; shift;;
108
 
        -S|--no-ssh) SSH=no; shift;;
109
106
        -v|--version) echo "$0 $VERSION"; exit;;
110
107
        -h|--help) help; exit;;
111
108
        --) shift; break;;
113
110
    esac
114
111
done
115
112
if [ "$#" -gt 0 ]; then
116
 
    echo "Unknown arguments: '$*'" >&2
 
113
    echo "Unknown arguments: '$@'" >&2
117
114
    exit 1
118
115
fi
119
116
 
191
188
trap "
192
189
set +e; \
193
190
test -n \"$SECFILE\" && shred --remove \"$SECFILE\"; \
194
 
shred --remove \"$RINGDIR\"/sec* 2>/dev/null;
 
191
shred --remove \"$RINGDIR\"/sec*;
195
192
test -n \"$BATCHFILE\" && rm --force \"$BATCHFILE\"; \
196
193
rm --recursive --force \"$RINGDIR\";
197
194
tty --quiet && stty echo; \
218
215
        #Handle: <no-spaces>
219
216
        #%pubring pubring.gpg
220
217
        #%secring secring.gpg
221
 
        %no-protection
222
218
        %commit
223
219
        EOF
224
220
    
278
274
fi
279
275
 
280
276
if [ "$mode" = password ]; then
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
289
 
        for ssh_keytype in ecdsa-sha2-nistp256 ed25519 rsa; do
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
302
 
    fi
303
 
    
304
277
    # Import key into temporary key rings
305
278
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
306
279
        --homedir "$RINGDIR" --trust-model always --armor \
311
284
    
312
285
    # Get fingerprint of key
313
286
    FINGERPRINT="`gpg --quiet --batch --no-tty --no-options \
314
 
        --enable-dsa2 --homedir "$RINGDIR" --trust-model always \
 
287
        --enable-dsa2 --homedir \"$RINGDIR\" --trust-model always \
315
288
        --fingerprint --with-colons \
316
289
        | sed --quiet \
317
290
        --expression='/^fpr:/{s/^fpr:.*:\\([0-9A-Z]*\\):\$/\\1/p;q}'`"
325
298
            cat "$PASSFILE"
326
299
        else
327
300
            tty --quiet && stty -echo
328
 
            echo -n "Enter passphrase: " >/dev/tty
 
301
            echo -n "Enter passphrase: " >&2
329
302
            read first
330
303
            tty --quiet && echo >&2
331
 
            echo -n "Repeat passphrase: " >/dev/tty
 
304
            echo -n "Repeat passphrase: " >&2
332
305
            read second
333
306
            if tty --quiet; then
334
307
                echo >&2
369
342
                /^[^-]/s/^/    /p
370
343
            }
371
344
        }' < "$SECFILE"
372
 
    if [ -n "$ssh_fingerprint" ]; then
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"'
374
 
        echo "ssh_fingerprint = ${ssh_fingerprint}"
375
 
    fi
376
345
fi
377
346
 
378
347
trap - EXIT
383
352
    shred --remove "$SECFILE"
384
353
fi
385
354
# Remove the key rings
386
 
shred --remove "$RINGDIR"/sec* 2>/dev/null
 
355
shred --remove "$RINGDIR"/sec*
387
356
rm --recursive --force "$RINGDIR"