Skip to content

Commit e9a8aeb

Browse files
authored
Merge pull request #1604 from macie/openwrt-hostid
[OpenWrt] Fix HostID and HostID2 creation exceptions
2 parents 4f7a333 + 89383ee commit e9a8aeb

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

include/functions

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@
940940
done
941941
fi
942942

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

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

11571162
else
1158-
ReportException "GetHostID" "Can't create HOSTID as there is no SHA1 hash tool available (sha1, sha1sum, openssl)"
1163+
ReportException "GetHostID" "Can't create HOSTID as there is no hash tool available (sha1, sha1sum, openssl, truncated sha256sum)"
11591164
fi
11601165

11611166
# Search machine ID
@@ -1198,10 +1203,9 @@
11981203
LogText "Info: start generation of HostID (version 2)"
11991204
FOUND=0
12001205
DATA_SSH=""
1201-
# Use public keys
1202-
SSH_KEY_FILES="ssh_host_ed25519_key.pub ssh_host_ecdsa_key.pub ssh_host_dsa_key.pub ssh_host_rsa_key.pub"
12031206
if [ -d /etc/ssh ]; then
1204-
for I in ${SSH_KEY_FILES}; do
1207+
SSH_PUBKEY_FILES="ssh_host_ed25519_key.pub ssh_host_ecdsa_key.pub ssh_host_dsa_key.pub ssh_host_rsa_key.pub"
1208+
for I in ${SSH_PUBKEY_FILES}; do
12051209
if [ ${FOUND} -eq 0 ]; then
12061210
if [ -f /etc/ssh/${I} ]; then
12071211
LogText "Result: found file ${I} in /etc/ssh, using that as candidate to create hostid2"
@@ -1210,8 +1214,20 @@
12101214
fi
12111215
fi
12121216
done
1217+
elif [ -d /etc/dropbear ]; then
1218+
SSH_KEY_FILES="dropbear_ed25519_host_key dropbear_rsa_host_key"
1219+
for I in ${SSH_KEY_FILES}; do
1220+
if [ ${FOUND} -eq 0 ]; then
1221+
if [ -f "/etc/dropbear/${I}" ]; then
1222+
LogText "Result: found file ${I} in /etc/dropbear, using that as candidate to create hostid2"
1223+
# Dropbear stores both keys in one binary file
1224+
DATA_SSH=$(dropbearkey -y -f "/etc/dropbear/${I}" | grep '^ssh')
1225+
FOUND=1
1226+
fi
1227+
fi
1228+
done
12131229
else
1214-
LogText "Result: no /etc/ssh directory found, skipping"
1230+
LogText "Result: no /etc/ssh nor /etc/dropbear directory found, skipping"
12151231
fi
12161232

12171233
STRING_TO_HASH=""

0 commit comments

Comments
 (0)