File: dropbear.postinst

package info (click to toggle)
dropbear 2022.83-1%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,216 kB
  • sloc: ansic: 96,944; sh: 4,508; perl: 774; python: 739; makefile: 694; java: 177
file content (45 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
set -e

showpubkey() {
    local keyfile="$1" pubkey
    if ! command -v ssh-keygen >/dev/null; then
        cat
    else
        pubkey="$(mktemp --tmpdir -- "${keyfile##*/}-XXXXXXXXXX.pub")"
        grep -m1 -E '^(ssh-(rsa|ed25519)|ecdsa-sha2-nistp(256|384|521)) ' >"$pubkey"
        ssh-keygen -v -lf "$pubkey" | sed -r "1s@\\S+(\\s+\\([^)]+\\))\$@$keyfile\\1@"
        rm -f -- "$pubkey"
    fi
}

if [ "$1" = 'configure' ]; then
    havehostkey=no
    for keytype in rsa ecdsa ed25519; do
        keyfile="/etc/dropbear/dropbear_${keytype}_host_key"
        if [ -e "$keyfile" ]; then
            havehostkey=yes
            break
        fi
    done
    if [ "$havehostkey" = no ]; then
        # generate host keys (excluding DSS)
        for keytype in rsa ecdsa ed25519; do
            keyfile="/etc/dropbear/dropbear_${keytype}_host_key"
            keyfile_openssh="/etc/ssh/ssh_host_${keytype}_key"
            keytype2="$(echo "$keytype" | tr '[a-z]' '[A-Z]')"

            if [ -f "$keyfile_openssh" ]; then
                echo "Converting existing OpenSSH $keytype2 host key to Dropbear format." >&2
                dropbearconvert openssh dropbear "$keyfile_openssh" "$keyfile"
                dropbearkey -y -f "$keyfile" | showpubkey "$keyfile"
            else
                echo "Generating Dropbear $keytype2 host key.  Please wait." >&2
                dropbearkey -t "$keytype" -f "$keyfile" | showpubkey "$keyfile"
            fi
        done
    fi
fi

#DEBHELPER#
exit 0