/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-09-21 04:22:50 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080921042250-r0qqjsbz2ulfo5le
* Makefile: Bug fix: fix syntax error.

* debian/control: Depend on "po-debconf".
  (mandos, mandos-client): Add "${misc:Depends}", used by
                           dh_installdebconf.

* debian/mandos-client.config: New; show note.
* debian/mandos-client.template: New.

* debian/mandos.README.Debian: New.

* debian/mandos.config: New; show note.
* debian/mandos.prerm: New; stop daemon.
* debian/mandos.template: New.

* debian/po/POTFILES.in: New.
* debian/po/sv.po: New.

* debian/rules (clean): Added "debconf-updatepo" as suggested by
                        po-debconf(7).
  (binary-common): Added "dh_installdebconf" to use "debian/*.config"
                   and "debian/*.template" files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
292
        --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
            /^$/,${