| 1 | #!/bin/sh |
| 2 | # This file is part of cloud-init. See LICENSE file for license information. |
| 3 | |
| 4 | do_syslog() { |
| 5 | log_message=$1 |
| 6 | |
| 7 | # rhels' version of logger_opts does not support long |
| 8 | # form of -s (--stderr), so use short form. |
| 9 | logger_opts="-s" |
| 10 | |
| 11 | # Need to end the options list with "--" to ensure that any minus symbols |
| 12 | # in the text passed to logger are not interpreted as logger options. |
| 13 | logger_opts="$logger_opts -p user.info -t cloud-init --" |
| 14 | |
| 15 | # shellcheck disable=SC2086 # logger give error if $logger_opts quoted |
| 16 | logger $logger_opts "$log_message" |
| 17 | } |
| 18 | |
| 19 | # Redirect stderr to stdout |
| 20 | exec 2>&1 |
| 21 | |
| 22 | fp_blist=",${1}," |
| 23 | key_blist=",${2}," |
| 24 | |
| 25 | fingerprint_header_shown=0 |
| 26 | for f in /etc/ssh/ssh_host_*key.pub; do |
| 27 | [ -f "$f" ] || continue |
| 28 | # shellcheck disable=SC2034 # Unused "line" required for word splitting |
| 29 | read -r ktype line < "$f" |
| 30 | # skip the key if its type is in the blacklist |
| 31 | [ "${fp_blist#*,$ktype,}" = "${fp_blist}" ] || continue |
| 32 | if [ $fingerprint_header_shown -eq 0 ]; then |
| 33 | do_syslog "#############################################################" |
| 34 | do_syslog "-----BEGIN SSH HOST KEY FINGERPRINTS-----" |
| 35 | fingerprint_header_shown=1 |
| 36 | fi |
| 37 | do_syslog "$(ssh-keygen -l -f "$f")" |
| 38 | done |
| 39 | if [ $fingerprint_header_shown -eq 1 ]; then |
| 40 | do_syslog "-----END SSH HOST KEY FINGERPRINTS-----" |
| 41 | do_syslog "#############################################################" |
| 42 | fi |
| 43 | |
| 44 | key_header_shown=0 |
| 45 | for f in /etc/ssh/ssh_host_*key.pub; do |
| 46 | [ -f "$f" ] || continue |
| 47 | # shellcheck disable=SC2034 # Unused "line" required for word splitting |
| 48 | read -r ktype line < "$f" |
| 49 | # skip the key if its type is in the blacklist |
| 50 | [ "${key_blist#*,$ktype,}" = "${key_blist}" ] || continue |
| 51 | if [ $key_header_shown -eq 0 ]; then |
| 52 | echo "-----BEGIN SSH HOST KEY KEYS-----" |
| 53 | key_header_shown=1 |
| 54 | fi |
| 55 | cat "$f" |
| 56 | done |
| 57 | if [ $key_header_shown -eq 1 ]; then |
| 58 | echo "-----END SSH HOST KEY KEYS-----" |
| 59 | fi |