/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: 2024-09-09 04:24:39 UTC
  • Revision ID: teddy@recompile.se-20240909042439-j85mr20uli2hnyis
Eliminate compiler warnings

Many programs use nested functions, which now result in a linker
warning about executable stack.  Hide this warning.  Also, rewrite a
loop in the plymouth plugin to avoid warning about signed overflow.
This change also makes the plugin pick the alphabetically first
process entry instead of the last, in case many plymouth processes are
found (which should be unlikely).

* Makefile (plugin-runner, dracut-module/password-agent,
  plugins.d/password-prompt, plugins.d/mandos-client,
  plugins.d/plymouth): New target; set LDFLAGS to add "-Xlinker
  --no-warn-execstack".
* plugins.d/plymouth.c (get_pid): When no pid files are found, and we
  are looking through the process list, go though it from the start
  instead of from the end, i.e. in normal alphabetical order and not
  in reverse order.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# Contact the authors at <mandos@recompile.se>.
24
24
25
25
 
26
 
VERSION="1.8.8"
 
26
VERSION="1.8.16"
27
27
 
28
28
KEYDIR="/etc/keys/mandos"
29
29
KEYTYPE=RSA
147
147
        echo "Empty key type" >&2
148
148
        exit 1
149
149
    fi
150
 
    
 
150
 
151
151
    if [ -z "$KEYNAME" ]; then
152
152
        echo "Empty key name" >&2
153
153
        exit 1
154
154
    fi
155
 
    
 
155
 
156
156
    if [ -z "$KEYLENGTH" ] || [ "$KEYLENGTH" -lt 512 ]; then
157
157
        echo "Invalid key length" >&2
158
158
        exit 1
159
159
    fi
160
 
    
 
160
 
161
161
    if [ -z "$KEYEXPIRE" ]; then
162
162
        echo "Empty key expiration" >&2
163
163
        exit 1
164
164
    fi
165
 
    
 
165
 
166
166
    # Make FORCE be 0 or 1
167
167
    case "$FORCE" in
168
168
        [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) FORCE=1;;
169
169
        [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|*) FORCE=0;;
170
170
    esac
171
 
    
 
171
 
172
172
    if { [ -e "$SECKEYFILE" ] || [ -e "$PUBKEYFILE" ] \
173
173
             || [ -e "$TLS_PRIVKEYFILE" ] \
174
174
             || [ -e "$TLS_PUBKEYFILE" ]; } \
176
176
        echo "Refusing to overwrite old key files; use --force" >&2
177
177
        exit 1
178
178
    fi
179
 
    
 
179
 
180
180
    # Set lines for GnuPG batch file
181
181
    if [ -n "$KEYCOMMENT" ]; then
182
182
        KEYCOMMENTLINE="Name-Comment: $KEYCOMMENT"
184
184
    if [ -n "$KEYEMAIL" ]; then
185
185
        KEYEMAILLINE="Name-Email: $KEYEMAIL"
186
186
    fi
187
 
    
 
187
 
188
188
    # Create temporary gpg batch file
189
189
    BATCHFILE="`mktemp -t mandos-keygen-batch.XXXXXXXXXX`"
190
190
    TLS_PRIVKEYTMP="`mktemp -t mandos-keygen-privkey.XXXXXXXXXX`"
233
233
        %no-protection
234
234
        %commit
235
235
        EOF
236
 
    
 
236
 
237
237
    if tty --quiet; then
238
238
        cat <<-EOF
239
239
        Note: Due to entropy requirements, key generation could take
276
276
            fi
277
277
        fi
278
278
    fi
279
 
    
 
279
 
280
280
    # Make sure trustdb.gpg exists;
281
281
    # this is a workaround for Debian bug #737128
282
282
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
287
287
        --homedir "$RINGDIR" --trust-model always \
288
288
        --gen-key "$BATCHFILE"
289
289
    rm --force "$BATCHFILE"
290
 
    
 
290
 
291
291
    if tty --quiet; then
292
292
        echo -n "Finished: "
293
293
        date
294
294
    fi
295
 
    
 
295
 
296
296
    # Backup any old key files
297
297
    if cp --backup=numbered --force "$SECKEYFILE" "$SECKEYFILE" \
298
298
        2>/dev/null; then
302
302
        2>/dev/null; then
303
303
        rm --force "$PUBKEYFILE"
304
304
    fi
305
 
    
 
305
 
306
306
    FILECOMMENT="Mandos client key for $KEYNAME"
307
307
    if [ "$KEYCOMMENT" != "$KEYCOMMENT_ORIG" ]; then
308
308
        FILECOMMENT="$FILECOMMENT ($KEYCOMMENT)"
309
309
    fi
310
 
    
 
310
 
311
311
    if [ -n "$KEYEMAIL" ]; then
312
312
        FILECOMMENT="$FILECOMMENT <$KEYEMAIL>"
313
313
    fi
314
 
    
 
314
 
315
315
    # Export key from key rings to key files
316
316
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
317
317
        --homedir "$RINGDIR" --armor --export-options export-minimal \
323
323
fi
324
324
 
325
325
if [ "$mode" = password ]; then
326
 
    
 
326
 
327
327
    # Make SSH be 0 or 1
328
328
    case "$SSH" in
329
329
        [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) SSH=1;;
330
330
        [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|*) SSH=0;;
331
331
    esac
332
 
    
 
332
 
333
333
    if [ $SSH -eq 1 ]; then
334
334
        for ssh_keytype in ecdsa-sha2-nistp256 ed25519 rsa; do
335
335
            set +e
346
346
            fi
347
347
        done
348
348
    fi
349
 
    
 
349
 
350
350
    # Import key into temporary key rings
351
351
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
352
352
        --homedir "$RINGDIR" --trust-model always --armor \
354
354
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
355
355
        --homedir "$RINGDIR" --trust-model always --armor \
356
356
        --import "$PUBKEYFILE"
357
 
    
 
357
 
358
358
    # Get fingerprint of key
359
359
    FINGERPRINT="`gpg --quiet --batch --no-tty --no-options \
360
360
        --enable-dsa2 --homedir "$RINGDIR" --trust-model always \
361
361
        --fingerprint --with-colons \
362
362
        | sed --quiet \
363
363
        --expression='/^fpr:/{s/^fpr:.*:\\([0-9A-Z]*\\):\$/\\1/p;q}'`"
364
 
    
 
364
 
365
365
    test -n "$FINGERPRINT"
366
 
    
 
366
 
367
367
    if [ -r "$TLS_PUBKEYFILE" ]; then
368
368
       KEY_ID="$(certtool --key-id --hash=sha256 \
369
369
                       --infile="$TLS_PUBKEYFILE" 2>/dev/null || :)"
376
376
       fi
377
377
       test -n "$KEY_ID"
378
378
    fi
379
 
    
 
379
 
380
380
    FILECOMMENT="Encrypted password for a Mandos client"
381
 
    
 
381
 
382
382
    while [ ! -s "$SECFILE" ]; do
383
383
        if [ -n "$PASSFILE" ]; then
384
384
            cat -- "$PASSFILE"
397
397
                echo "Passphrase mismatch" >&2
398
398
                touch "$RINGDIR"/mismatch
399
399
            else
400
 
                echo -n "$first"
 
400
                printf "%s" "$first"
401
401
            fi
402
402
        fi | gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
403
403
            --homedir "$RINGDIR" --trust-model always --armor \
412
412
            fi
413
413
        fi
414
414
    done
415
 
    
 
415
 
416
416
    cat <<-EOF
417
417
        [$KEYNAME]
418
418
        host = $KEYNAME