From 270212a771b9b7828af266d0757323ec5dc1df6a Mon Sep 17 00:00:00 2001 From: Damien 'Psolyca' Gaignon Date: Sat, 3 Feb 2024 16:22:35 +0100 Subject: [PATCH] [Huawei] Rename authMode to deviceSupportType --- .../gadgetbridge/devices/huawei/HuaweiCrypto.java | 10 +++++----- .../gadgetbridge/devices/huawei/HuaweiPacket.java | 12 ++++++------ .../gadgetbridge/devices/huawei/HuaweiTLV.java | 4 ++-- .../devices/huawei/packets/DeviceConfig.java | 6 +++--- .../devices/huawei/HuaweiSupportProvider.java | 4 ++-- .../devices/huawei/requests/GetAuthRequest.java | 8 ++++---- .../huawei/requests/GetLinkParamsRequest.java | 2 +- .../requests/GetSecurityNegotiationRequest.java | 2 +- .../devices/huawei/TestHuaweiPacket.java | 6 +++--- .../gadgetbridge/devices/huawei/TestHuaweiTLV.java | 2 +- .../devices/huawei/packets/TestAlarms.java | 2 +- .../devices/huawei/packets/TestDeviceConfig.java | 2 +- .../huawei/packets/TestDisconnectNotification.java | 2 +- .../devices/huawei/packets/TestFindPhone.java | 2 +- .../devices/huawei/packets/TestFitnessData.java | 2 +- .../devices/huawei/packets/TestLocaleConfig.java | 2 +- .../devices/huawei/packets/TestMusicControl.java | 2 +- .../devices/huawei/packets/TestNotifications.java | 2 +- .../devices/huawei/packets/TestWorkMode.java | 2 +- .../devices/huawei/packets/TestWorkout.java | 2 +- 20 files changed, 38 insertions(+), 38 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 80a9fb6d2..fbd395cdf 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 @@ -81,16 +81,16 @@ public class HuaweiCrypto { public static final long ENCRYPTION_COUNTER_MAX = 0xFFFFFFFF; protected int authVersion; - protected int authMode; + protected int deviceSupportType; protected byte authAlgo; public HuaweiCrypto(int authVersion) { this.authVersion = authVersion; } - public HuaweiCrypto(int authVersion, byte authAlgo, int authMode) { + public HuaweiCrypto(int authVersion, byte authAlgo, int deviceSupportType) { this(authVersion); - this.authMode = authMode; + this.deviceSupportType = deviceSupportType; this.authAlgo = authAlgo; } @@ -142,7 +142,7 @@ public class HuaweiCrypto { } public byte[] digestChallenge(byte[] secretKey, byte[] nonce) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, UnsupportedEncodingException { - if (authMode == 0x02) { + if (deviceSupportType == 0x02) { if (secretKey == null) return null; if (authVersion == 0x02) { @@ -158,7 +158,7 @@ public class HuaweiCrypto { } public byte[] digestResponse(byte[] secretKey, byte[] nonce) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, UnsupportedEncodingException { - if (authMode == 0x02) { + if (deviceSupportType == 0x02) { if (secretKey == null) return null; if (authVersion == 0x02) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiPacket.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiPacket.java index 314b29760..3c5c56972 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiPacket.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiPacket.java @@ -46,7 +46,7 @@ public class HuaweiPacket { public static class ParamsProvider { protected byte authVersion; - protected byte authMode; + protected byte deviceSupportType; protected byte[] secretKey; protected int slicesize = 0xf4; protected boolean transactionsCrypted = true; @@ -67,12 +67,12 @@ public class HuaweiPacket { return this.authVersion; } - public void setAuthMode(byte authMode) { - this.authMode = authMode; + public void setDeviceSupportType(byte deviceSupportType) { + this.deviceSupportType = deviceSupportType; } - public byte getAuthMode(){ - return this.authMode; + public byte getDeviceSupportType(){ + return this.deviceSupportType; } public void setSecretKey(byte[] secretKey) { @@ -124,7 +124,7 @@ public class HuaweiPacket { public byte[] getIv() { byte[] iv = null; - if (this.authMode == 0x04) { + if (this.deviceSupportType == 0x04) { iv = HuaweiCrypto.generateNonce(); } else { ByteBuffer ivCounter = HuaweiCrypto.initializationVector(this.encryptionCounter); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiTLV.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiTLV.java index 51568de32..80d8f6753 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiTLV.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiTLV.java @@ -291,7 +291,7 @@ public class HuaweiTLV { byte[] serializedTLV = serialize(); byte[] key = paramsProvider.getSecretKey(); byte[] nonce = paramsProvider.getIv(); - byte[] encryptedTLV = HuaweiCrypto.encrypt(paramsProvider.getAuthMode(), serializedTLV, key, nonce); + byte[] encryptedTLV = HuaweiCrypto.encrypt(paramsProvider.getDeviceSupportType(), serializedTLV, key, nonce); return new HuaweiTLV() .put(CryptoTags.encryption, (byte) 0x01) .put(CryptoTags.initVector, nonce) @@ -300,7 +300,7 @@ public class HuaweiTLV { public void decrypt(ParamsProvider paramsProvider) throws CryptoException, HuaweiPacket.MissingTagException { byte[] key = paramsProvider.getSecretKey(); - byte[] decryptedTLV = HuaweiCrypto.decrypt(paramsProvider.getAuthMode(), getBytes(CryptoTags.cipherText), key, getBytes(CryptoTags.initVector)); + byte[] decryptedTLV = HuaweiCrypto.decrypt(paramsProvider.getDeviceSupportType(), getBytes(CryptoTags.cipherText), key, getBytes(CryptoTags.initVector)); this.valueMap = new ArrayList<>(); parse(decryptedTLV); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/DeviceConfig.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/DeviceConfig.java index 3bc32a01e..e470f559d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/DeviceConfig.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/DeviceConfig.java @@ -74,7 +74,7 @@ public class DeviceConfig { public short sliceSize = 0x00f4; public byte authVersion = 0x00; public byte[] serverNonce = new byte[16]; - public byte authMode = 0x00; + public byte deviceSupportType = 0x00; public byte authAlgo = 0x00; public byte bondState = 0x00; public short interval = 0x0; @@ -105,7 +105,7 @@ public class DeviceConfig { this.authVersion = (byte)this.tlv.getBytes(0x05)[1]; if (this.tlv.contains(0x07)) - this.authMode = this.tlv.getByte(0x07); + this.deviceSupportType = this.tlv.getByte(0x07); if (this.tlv.contains(0x08)) this.authAlgo = this.tlv.getByte(0x08); @@ -607,7 +607,7 @@ public class DeviceConfig { this.tlv = new HuaweiTLV() .put(0x01, challenge) .put(0x02, nonce); - if (paramsProvider.getAuthMode() == 0x02) + if (paramsProvider.getDeviceSupportType() == 0x02) this.tlv.put(0x03, paramsProvider.getAuthAlgo()); this.isEncrypted = false; this.complete = true; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java index 477bead17..5f8cb6a27 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java @@ -306,12 +306,12 @@ public class HuaweiSupportProvider { // 1 or 3 : HiChain // 2 or 8 : HiChainLite -> normal mode // 4 : HiChain3 - byte authMode = paramsProvider.getAuthMode(); + byte authMode = paramsProvider.getDeviceSupportType(); return authMode == 0x01 || authMode == 0x03 || authMode == 0x04 || isHiChainLite(); } protected boolean isHiChainLite() { - byte authMode = paramsProvider.getAuthMode(); + byte authMode = paramsProvider.getDeviceSupportType(); return authMode == 0x02; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetAuthRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetAuthRequest.java index 81e070b6f..9c252fe20 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetAuthRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetAuthRequest.java @@ -42,7 +42,7 @@ public class GetAuthRequest extends Request { protected byte authAlgo; protected byte[] doubleNonce; protected byte[] key = null; - protected byte authMode; + protected byte deviceSupportType; public GetAuthRequest(HuaweiSupportProvider support, Request linkParamsReq) { @@ -56,16 +56,16 @@ public class GetAuthRequest extends Request { .array(); this.authVersion = paramsProvider.getAuthVersion(); this.authAlgo = paramsProvider.getAuthAlgo(); - this.authMode = paramsProvider.getAuthMode(); + this.deviceSupportType = paramsProvider.getDeviceSupportType(); } @Override protected List createRequest() throws RequestCreationException { - huaweiCrypto = new HuaweiCrypto(authVersion, authAlgo, authMode); + huaweiCrypto = new HuaweiCrypto(authVersion, authAlgo, deviceSupportType); byte[] nonce; try { - if (authMode == 0x02) { + if (deviceSupportType == 0x02) { key = paramsProvider.getPinCode(); if (authVersion == 0x02) key = paramsProvider.getSecretKey(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetLinkParamsRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetLinkParamsRequest.java index 7ba643f3b..1be952a5b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetLinkParamsRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetLinkParamsRequest.java @@ -73,7 +73,7 @@ public class GetLinkParamsRequest extends Request { throw new ResponseTypeMismatchException(receivedPacket, LinkParams.Response.class); supportProvider.setProtocolVersion(((LinkParams.Response) receivedPacket).protocolVersion); - paramsProvider.setAuthMode(((LinkParams.Response) receivedPacket).authMode); + paramsProvider.setDeviceSupportType(((LinkParams.Response) receivedPacket).deviceSupportType); paramsProvider.setSliceSize(((LinkParams.Response) receivedPacket).sliceSize); paramsProvider.setMtu(((LinkParams.Response) receivedPacket).mtu); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetSecurityNegotiationRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetSecurityNegotiationRequest.java index f4bf41b00..73d6c3c49 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetSecurityNegotiationRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetSecurityNegotiationRequest.java @@ -42,7 +42,7 @@ public class GetSecurityNegotiationRequest extends Request { try { return new DeviceConfig.SecurityNegotiation.Request( paramsProvider, - paramsProvider.getAuthMode(), + paramsProvider.getDeviceSupportType(), supportProvider.getAndroidId(), Build.MODEL ).serialize(); diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/TestHuaweiPacket.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/TestHuaweiPacket.java index ee19ca808..a6b761242 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/TestHuaweiPacket.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/TestHuaweiPacket.java @@ -29,7 +29,7 @@ public class TestHuaweiPacket { HuaweiPacket.ParamsProvider paramsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } @@ -62,7 +62,7 @@ public class TestHuaweiPacket { HuaweiPacket.ParamsProvider paramsProviderEncrypt = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } @@ -95,7 +95,7 @@ public class TestHuaweiPacket { HuaweiPacket.ParamsProvider paramsProviderSmallSlice = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/TestHuaweiTLV.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/TestHuaweiTLV.java index 83c6dfda1..62f9ab3dd 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/TestHuaweiTLV.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/TestHuaweiTLV.java @@ -26,7 +26,7 @@ public class TestHuaweiTLV { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestAlarms.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestAlarms.java index 3f1c5cfbc..0712dd247 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestAlarms.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestAlarms.java @@ -29,7 +29,7 @@ public class TestAlarms { HuaweiPacket.ParamsProvider paramsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestDeviceConfig.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestDeviceConfig.java index 5ade9f698..af9788c1b 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestDeviceConfig.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestDeviceConfig.java @@ -42,7 +42,7 @@ public class TestDeviceConfig { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestDisconnectNotification.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestDisconnectNotification.java index dc28bd370..9db856237 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestDisconnectNotification.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestDisconnectNotification.java @@ -29,7 +29,7 @@ public class TestDisconnectNotification { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestFindPhone.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestFindPhone.java index 495c06fe0..7204f200f 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestFindPhone.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestFindPhone.java @@ -28,7 +28,7 @@ public class TestFindPhone { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestFitnessData.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestFitnessData.java index 04774cde0..717944dc3 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestFitnessData.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestFitnessData.java @@ -30,7 +30,7 @@ public class TestFitnessData { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestLocaleConfig.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestLocaleConfig.java index 168e355f1..a8b288cc3 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestLocaleConfig.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestLocaleConfig.java @@ -29,7 +29,7 @@ public class TestLocaleConfig { HuaweiPacket.ParamsProvider paramsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestMusicControl.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestMusicControl.java index a5eb5dad8..e45bf134e 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestMusicControl.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestMusicControl.java @@ -32,7 +32,7 @@ public class TestMusicControl { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestNotifications.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestNotifications.java index 9911b3552..fb42a7c8e 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestNotifications.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestNotifications.java @@ -30,7 +30,7 @@ public class TestNotifications { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestWorkMode.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestWorkMode.java index b6773f92d..2be8d6cf6 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestWorkMode.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestWorkMode.java @@ -29,7 +29,7 @@ public class TestWorkMode { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestWorkout.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestWorkout.java index 714d4b67f..d29b173de 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestWorkout.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/TestWorkout.java @@ -30,7 +30,7 @@ public class TestWorkout { HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() { @Override - public byte getAuthMode() { + public byte getDeviceSupportType() { return 0; }