Skip to content

[OpenWrt] Fix HostID and HostID2 creation exceptions #1604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions include/functions
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@
done
fi

if [ ! "${SHA1SUMBINARY}" = "" -o ! "${OPENSSLBINARY}" = "" -o ! "${CSUMBINARY}" = "" ]; then
if [ ! "${SHA1SUMBINARY}" = "" -o ! "${SHA256SUMBINARY}" = "" -o ! "${OPENSSLBINARY}" = "" -o ! "${CSUMBINARY}" = "" ]; then
LogText "Info: found hashing tool, start generation of HostID"
case "${OS}" in

Expand Down Expand Up @@ -1068,7 +1068,12 @@
# Check if we found a MAC address to generate the HostID
if HasData "${FIND}"; then
LogText "Info: using hardware address '${FIND}' to create HostID"
HOSTID=$(echo ${FIND} | ${SHA1SUMBINARY} | awk '{ print $1 }')
if [ -n "${SHA1SUMBINARY}" ]; then
HOSTID=$(echo ${FIND} | ${SHA1SUMBINARY} | awk '{ print $1 }')
elif [ -n "${SHA256SUMBINARY}" ]; then
# Truncate hash to match SHA1 length
HOSTID=$(echo ${FIND} | ${SHA256SUMBINARY} | awk '{ print $1 }' | head -c 40)
fi
LogText "Result: Found HostID: ${HOSTID}"
else
ReportException "GetHostID" "HostID could not be generated"
Expand Down Expand Up @@ -1155,7 +1160,7 @@
fi

else
ReportException "GetHostID" "Can't create HOSTID as there is no SHA1 hash tool available (sha1, sha1sum, openssl)"
ReportException "GetHostID" "Can't create HOSTID as there is no hash tool available (sha1, sha1sum, openssl, truncated sha256sum)"
fi

# Search machine ID
Expand Down Expand Up @@ -1198,10 +1203,9 @@
LogText "Info: start generation of HostID (version 2)"
FOUND=0
DATA_SSH=""
# Use public keys
SSH_KEY_FILES="ssh_host_ed25519_key.pub ssh_host_ecdsa_key.pub ssh_host_dsa_key.pub ssh_host_rsa_key.pub"
if [ -d /etc/ssh ]; then
for I in ${SSH_KEY_FILES}; do
SSH_PUBKEY_FILES="ssh_host_ed25519_key.pub ssh_host_ecdsa_key.pub ssh_host_dsa_key.pub ssh_host_rsa_key.pub"
for I in ${SSH_PUBKEY_FILES}; do
if [ ${FOUND} -eq 0 ]; then
if [ -f /etc/ssh/${I} ]; then
LogText "Result: found file ${I} in /etc/ssh, using that as candidate to create hostid2"
Expand All @@ -1210,8 +1214,20 @@
fi
fi
done
elif [ -d /etc/dropbear ]; then
SSH_KEY_FILES="dropbear_ed25519_host_key dropbear_rsa_host_key"
for I in ${SSH_KEY_FILES}; do
if [ ${FOUND} -eq 0 ]; then
if [ -f "/etc/dropbear/${I}" ]; then
LogText "Result: found file ${I} in /etc/dropbear, using that as candidate to create hostid2"
# Dropbear stores both keys in one binary file
DATA_SSH=$(dropbearkey -y -f "/etc/dropbear/${I}" | grep '^ssh')
FOUND=1
fi
fi
done
else
LogText "Result: no /etc/ssh directory found, skipping"
LogText "Result: no /etc/ssh nor /etc/dropbear directory found, skipping"
fi

STRING_TO_HASH=""
Expand Down