/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos-keygen

  • Committer: Teddy Hogeborn
  • Date: 2008-09-17 00:34:09 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080917003409-bxbjsc4o69nx40t6
* .bzr-builddeb/default.conf: New.

* Makefile (install-server): Do not create directories that
                             should already be present in a
                             normal system.
  (install-client-nokey): - '' -  Also specify non-executable
                          mode for "initramfs-tools-hook-conf".

* README: Improved wording.  Use real copyright mark.

* debian/changelog: New.
* debian/compat: - '' -
* debian/control: - '' -
* debian/copyright: - '' -
* debian/mandos-client.README.Debian: - '' -
* debian/mandos-client.dirs: - '' -
* debian/mandos-client.lintian-overrides: - '' -
* debian/mandos-client.postinst: - '' -
* debian/mandos-client.postrm: - '' -
* debian/mandos.dirs: - '' -
* debian/mandos.lintian-overrides: - '' -
* debian/rules: - '' -
* default-mandos: - '' -

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 Teddy Hogeborn & Björn Påhlsson
 
5
# Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
6
6
7
7
# This program is free software: you can redistribute it and/or modify
8
8
# it under the terms of the GNU General Public License as published by
27
27
KEYLENGTH=2048
28
28
SUBKEYTYPE=ELG-E
29
29
SUBKEYLENGTH=2048
30
 
KEYNAME="`hostname --fqdn 2>/dev/null || hostname`"
 
30
KEYNAME="`hostname --fqdn`"
31
31
KEYEMAIL=""
32
32
KEYCOMMENT="Mandos client key"
33
33
KEYEXPIRE=0
40
40
fi
41
41
 
42
42
# Parse options
43
 
TEMP=`getopt --options vhpF:d:t:l:s:L:n:e:c:x:f \
44
 
    --longoptions version,help,password,passfile:,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force \
 
43
TEMP=`getopt --options vhd:t:l:n:e:c:x:f \
 
44
    --longoptions version,help,password,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force \
45
45
    --name "$0" -- "$@"`
46
46
 
47
47
help(){
53
53
       $basename [ OPTIONS ]
54
54
   Encrypted password creation:
55
55
       $basename { -p | --password } [ --name NAME ] [ --dir DIR]
56
 
       $basename { -F | --passfile } FILE [ --name NAME ] [ --dir DIR]
57
56
 
58
57
Key creation options:
59
58
  -v, --version         Show program's version number and exit
75
74
  -x TIME, --expire TIME
76
75
                        Key expire time.  Default is no expiration.
77
76
                        See gpg(1) for syntax.
78
 
  -f, --force           Force overwriting old key files.
 
77
  -f, --force           Force overwriting old keys.
79
78
 
80
79
Password creation options:
81
 
  -p, --password        Create an encrypted password using the key in
82
 
                        the key directory.  All options other than
83
 
                        --dir and --name are ignored.
84
 
  -F FILE, --passfile FILE
85
 
                        Encrypt a password from FILE using the key in
 
80
  -p, --password        Create an encrypted password using the keys in
86
81
                        the key directory.  All options other than
87
82
                        --dir and --name are ignored.
88
83
EOF
92
87
while :; do
93
88
    case "$1" in
94
89
        -p|--password) mode=password; shift;;
95
 
        -F|--passfile) mode=password; PASSFILE="$2"; shift 2;;
96
90
        -d|--dir) KEYDIR="$2"; shift 2;;
97
91
        -t|--type) KEYTYPE="$2"; shift 2;;
98
92
        -s|--subtype) SUBKEYTYPE="$2"; shift 2;;
241
235
        FILECOMMENT="$FILECOMMENT <$KEYEMAIL>"
242
236
    fi
243
237
    
244
 
    # Export key from key rings to key files
 
238
    # Export keys from key rings to key files
245
239
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
246
240
        --homedir "$RINGDIR" --armor --export-options export-minimal \
247
241
        --comment "$FILECOMMENT" --output "$SECKEYFILE" \
252
246
fi
253
247
 
254
248
if [ "$mode" = password ]; then
255
 
    # Import key into temporary key rings
 
249
    # Import keys into temporary key rings
256
250
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
257
251
        --homedir "$RINGDIR" --trust-model always --armor \
258
252
        --import "$SECKEYFILE"
271
265
    
272
266
    FILECOMMENT="Encrypted password for a Mandos client"
273
267
    
274
 
    if [ -n "$PASSFILE" ]; then
275
 
        cat "$PASSFILE"
276
 
    else
277
 
        stty -echo
278
 
        echo -n "Enter passphrase: " >&2
279
 
        first="$(head --lines=1 | tr --delete '\n')"
280
 
        echo -n -e "\nRepeat passphrase: " >&2
281
 
        second="$(head --lines=1 | tr --delete '\n')"
282
 
        echo >&2
283
 
        stty echo
284
 
        if [ "$first" != "$second" ]; then
285
 
            echo -e "Passphrase mismatch" >&2
286
 
            false
287
 
        else
288
 
            echo -n "$first"
289
 
        fi
290
 
    fi | gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
 
268
    stty -echo
 
269
    echo -n "Enter passphrase: " >&2
 
270
    head --lines=1 | tr --delete '\n' \
 
271
        | gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
291
272
        --homedir "$RINGDIR" --trust-model always --armor --encrypt \
292
273
        --recipient "$FINGERPRINT" --comment "$FILECOMMENT" \
293
274
        > "$SECFILE"
294
 
    status="${PIPESTATUS[0]}"
295
 
    if [ "$status" -ne 0 ]; then
296
 
        exit "$status"
297
 
    fi
 
275
    echo >&2
 
276
    stty echo
298
277
    
299
278
    cat <<-EOF
300
279
        [$KEYNAME]
301
280
        host = $KEYNAME
302
281
        fingerprint = $FINGERPRINT
303
282
        secret =
304
 
        EOF
 
283
EOF
305
284
    sed --quiet --expression='
306
285
        /^-----BEGIN PGP MESSAGE-----$/,/^-----END PGP MESSAGE-----$/{
307
286
            /^$/,${