aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Zhilkin <csharper2005@gmail.com>2022-07-12 14:52:04 +0000
committerChristian Marangi <ansuelsmth@gmail.com>2022-08-19 14:44:35 +0200
commit290ace2fe6ffbbf22c841e10d79267871f4d5748 (patch)
tree7738b0c1cf510f4fb061a35b83a1887704da8853
parentd94a28f7d264ca8286b448a70e0311fa0051603a (diff)
downloadupstream-290ace2fe6ffbbf22c841e10d79267871f4d5748.tar.gz
upstream-290ace2fe6ffbbf22c841e10d79267871f4d5748.tar.bz2
upstream-290ace2fe6ffbbf22c841e10d79267871f4d5748.zip
base-files: add mtd_get_mac_encrypted_arcadyan function
Some Arcadyan devices (e.g. MTS WG430223) keep their config in encrypted mtd. This adds mtd_get_mac_encrypted_arcadyan() function to get the MAC address from the encrypted partition. Function uses uencrypt utility for decryption (and openssl if the uencrypt wasn't found). Signed-off-by: Mikhail Zhilkin <csharper2005@gmail.com> (cherry picked from commit 12c971bc26ac0ff04257bc475fff6fa68068c6c0)
-rw-r--r--package/base-files/files/lib/functions/system.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh
index 0ac2912014..c17354d945 100644
--- a/package/base-files/files/lib/functions/system.sh
+++ b/package/base-files/files/lib/functions/system.sh
@@ -79,6 +79,37 @@ mtd_get_mac_ascii() {
[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
}
+mtd_get_mac_encrypted_arcadyan() {
+ local iv="00000000000000000000000000000000"
+ local key="2A4B303D7644395C3B2B7053553C5200"
+ local mac_dirty
+ local mtdname="$1"
+ local part
+ local size
+
+ part=$(find_mtd_part "$mtdname")
+ if [ -z "$part" ]; then
+ echo "mtd_get_mac_encrypted_arcadyan: partition $mtdname not found!" >&2
+ return
+ fi
+
+ # Config decryption and getting mac. Trying uencrypt and openssl utils.
+ size=$((0x$(dd if=$part skip=9 bs=1 count=4 2>/dev/null | hexdump -v -e '1/4 "%08x"')))
+ if [[ -f "/usr/bin/uencrypt" ]]; then
+ mac_dirty=$(dd if=$part bs=1 count=$size skip=$((0x100)) 2>/dev/null | \
+ uencrypt -d -n -k $key -i $iv | grep mac | cut -c 5-)
+ elif [[ -f "/usr/bin/openssl" ]]; then
+ mac_dirty=$(dd if=$part bs=1 count=$size skip=$((0x100)) 2>/dev/null | \
+ openssl aes-128-cbc -d -nopad -K $key -iv $iv | grep mac | cut -c 5-)
+ else
+ echo "mtd_get_mac_encrypted_arcadyan: Neither uencrypt nor openssl was found!" >&2
+ return
+ fi
+
+ # "canonicalize" mac
+ [ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
+}
+
mtd_get_mac_text() {
local mtdname=$1
local offset=$(($2))