/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: 2008-11-09 06:40:29 UTC
  • mto: (24.1.113 mandos)
  • mto: This revision was merged to the branch mainline in revision 238.
  • Revision ID: teddy@fukt.bsnet.se-20081109064029-df71jpoce308cq3v
First steps of a D-Bus interface to the server.

* mandos: Also import "dbus.service".
  (Client): Inherit from "dbus.service.Object", which is a new-style
            class, so inheriting from "object" is no longer necessary.
  (Client.interface): New temporary variable which only exists during
                     class definition.

  (Client.getName, Client.getFingerprint): New D-Bus getter methods.
  (Client.setSecret): New D-Bus setter method.
  (Client._set_timeout): Emit D-Bus signal "TimeoutChanged".
  (Client.getTimeout): New D-Bus getter method.
  (Client.TimeoutChanged): New D-Bus signal.
  (Client._set_interval): Emit D-Bus signal "IntervalChanged".
  (Client.getInterval): New D-Bus getter method.
  (Client.intervalChanged): New D-Bus signal.
  (Client.__init__): Also call "dbus.service.Object.__init__".
  (Client.started): New boolean attribute.
  (Client.start, Client.stop): Update "self.started", and emit D-Bus
                               signal "StateChanged".
  (Client.StateChanged): New D-Bus signal.
  (Client.stop): Use "self.started" instead of misusing "self.secret".
                 Also simplify code by using "getattr" instead of
                 "hasattr".
  (Client.checker_callback): Emit D-Bus signal "CheckerCompleted".
  (Client.CheckerCompleted): New D-Bus signal.
  (Client.bumpTimeout): D-Bus method name for "bump_timeout".
  (Client.start_checker): Emit D-Bus signal "CheckerStarted".
  (Client.CheckerStarted): New D-Bus signal.
  (Client.checkerIsRunning): New D-Bus method.
  (Client.StopChecker): D-Bus method name for "stop_checker".
  (Client.still_valid): First check "self.started".
  (Client.stillValid): D-Bus method name for "still_valid".

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 © 2007-2008 Teddy Hogeborn & Björn Påhlsson
 
5
# Copyright © 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
20
20
# Contact the authors at <mandos@fukt.bsnet.se>.
21
21
22
22
 
23
 
VERSION="1.0"
 
23
VERSION="1.0.2"
24
24
 
25
25
KEYDIR="/etc/keys/mandos"
26
26
KEYTYPE=DSA
27
27
KEYLENGTH=2048
28
28
SUBKEYTYPE=ELG-E
29
29
SUBKEYLENGTH=2048
30
 
KEYNAME="`hostname --fqdn`"
 
30
KEYNAME="`hostname --fqdn 2>/dev/null || hostname`"
31
31
KEYEMAIL=""
32
32
KEYCOMMENT="Mandos client key"
33
33
KEYEXPIRE=0
35
35
KEYCOMMENT_ORIG="$KEYCOMMENT"
36
36
mode=keygen
37
37
 
 
38
if [ ! -d "$KEYDIR" ]; then
 
39
    KEYDIR="/etc/mandos/keys"
 
40
fi
 
41
 
38
42
# Parse options
39
 
TEMP=`getopt --options vhd:t:l:n:e:c:x:f \
40
 
    --longoptions version,help,password,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force \
 
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 \
41
45
    --name "$0" -- "$@"`
42
46
 
43
47
help(){
49
53
       $basename [ OPTIONS ]
50
54
   Encrypted password creation:
51
55
       $basename { -p | --password } [ --name NAME ] [ --dir DIR]
 
56
       $basename { -F | --passfile } FILE [ --name NAME ] [ --dir DIR]
52
57
 
53
58
Key creation options:
54
59
  -v, --version         Show program's version number and exit
70
75
  -x TIME, --expire TIME
71
76
                        Key expire time.  Default is no expiration.
72
77
                        See gpg(1) for syntax.
73
 
  -f, --force           Force overwriting old keys.
 
78
  -f, --force           Force overwriting old key files.
74
79
 
75
80
Password creation options:
76
 
  -p, --password        Create an encrypted password using the keys in
 
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
77
86
                        the key directory.  All options other than
78
87
                        --dir and --name are ignored.
79
88
EOF
83
92
while :; do
84
93
    case "$1" in
85
94
        -p|--password) mode=password; shift;;
 
95
        -F|--passfile) mode=password; PASSFILE="$2"; shift 2;;
86
96
        -d|--dir) KEYDIR="$2"; shift 2;;
87
97
        -t|--type) KEYTYPE="$2"; shift 2;;
88
98
        -s|--subtype) SUBKEYTYPE="$2"; shift 2;;
231
241
        FILECOMMENT="$FILECOMMENT <$KEYEMAIL>"
232
242
    fi
233
243
    
234
 
    # Export keys from key rings to key files
 
244
    # Export key from key rings to key files
235
245
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
236
246
        --homedir "$RINGDIR" --armor --export-options export-minimal \
237
247
        --comment "$FILECOMMENT" --output "$SECKEYFILE" \
242
252
fi
243
253
 
244
254
if [ "$mode" = password ]; then
245
 
    # Import keys into temporary key rings
 
255
    # Import key into temporary key rings
246
256
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
247
257
        --homedir "$RINGDIR" --trust-model always --armor \
248
258
        --import "$SECKEYFILE"
261
271
    
262
272
    FILECOMMENT="Encrypted password for a Mandos client"
263
273
    
264
 
    stty -echo
265
 
    echo -n "Enter passphrase: " >&2
266
 
    head --lines=1 | tr --delete '\n' \
267
 
        | gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
 
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
291
        --homedir "$RINGDIR" --trust-model always --armor --encrypt \
269
 
        --recipient "$FINGERPRINT" --comment "$FILECOMMENT" \
 
292
        --sign --recipient "$FINGERPRINT" --comment "$FILECOMMENT" \
270
293
        > "$SECFILE"
271
 
    echo >&2
272
 
    stty echo
 
294
    status="${PIPESTATUS[0]}"
 
295
    if [ "$status" -ne 0 ]; then
 
296
        exit "$status"
 
297
    fi
273
298
    
274
299
    cat <<-EOF
275
300
        [$KEYNAME]
276
301
        host = $KEYNAME
277
302
        fingerprint = $FINGERPRINT
278
303
        secret =
279
 
EOF
 
304
        EOF
280
305
    sed --quiet --expression='
281
306
        /^-----BEGIN PGP MESSAGE-----$/,/^-----END PGP MESSAGE-----$/{
282
307
            /^$/,${