From 2538a6e9d3a438fc46b3afcc83a5efc4531fc5e2 Mon Sep 17 00:00:00 2001 From: Vitaliy Tomin Date: Thu, 3 Apr 2025 14:14:39 +0800 Subject: [PATCH] huawei: Handle version 4 digest for Honor Watch 4 * on huawei devices authVersion == 4 means using hichain, but honor still using simple challenge response and actually using V1 digest key --- .../gadgetbridge/devices/huawei/HuaweiCrypto.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCrypto.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCrypto.java index cbc95d4622..a46d48189a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCrypto.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCrypto.java @@ -77,6 +77,7 @@ public class HuaweiCrypto { public static final byte[] MESSAGE_RESPONSE = new byte[]{0x01, 0x10}; public static final byte[] MESSAGE_CHALLENGE = new byte[]{0x01, 0x00}; + public static final byte[] MESSAGE_CHALLENGE_V4 = new byte[]{0x04, 0x00}; public static final long ENCRYPTION_COUNTER_MAX = 0xFFFFFFFF; @@ -105,7 +106,7 @@ public class HuaweiCrypto { private byte[] getDigestSecret() { byte[] digest; - if (authVersion == 1) { + if ((authVersion == 1) || (authVersion == 4)) { //version 4 digest used on honor health devices digest = DIGEST_SECRET_v1.clone(); } else if (authVersion == 2) { digest = DIGEST_SECRET_v2.clone(); @@ -168,7 +169,11 @@ public class HuaweiCrypto { } return computeDigestHiChainLite(MESSAGE_CHALLENGE, secretKey, nonce); } - return computeDigest(MESSAGE_CHALLENGE, nonce); + if (authVersion == 4) { + return computeDigest(MESSAGE_CHALLENGE_V4, nonce); + } else { + return computeDigest(MESSAGE_CHALLENGE, nonce); + } } public byte[] digestResponse(byte[] secretKey, byte[] nonce) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, UnsupportedEncodingException {