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 2e5e665b5..cbc95d462 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 @@ -234,9 +234,10 @@ public class HuaweiCrypto { return CryptoUtils.encryptAES_CBC_Pad(data, encryptionKey, iv); } - public byte[] decryptBondingKey(byte[] data, String mac, byte[] iv) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, IllegalArgumentException { - byte[] encryptionKey = createSecretKey(mac); - return CryptoUtils.decryptAES_CBC_Pad(data, encryptionKey, iv); + public byte[] decryptBondingKey(byte encryptMethod, byte[] data, byte[] key, byte[] iv) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, IllegalArgumentException { + if (encryptMethod == 0x1) + return CryptoUtils.decryptAES_GCM_NoPad(data, key, iv, null); + return CryptoUtils.decryptAES_CBC_Pad(data, key, iv); } public byte[] decryptPinCode(byte encryptMethod, byte[] message, byte[] iv) throws CryptoException { 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 d0b1c1b38..bd83395e4 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 @@ -606,6 +606,8 @@ public class HuaweiPacket { return new DeviceConfig.Bond.OutgoingRequest(paramsProvider).fromPacket(this); case DeviceConfig.HiChain.id: return new DeviceConfig.HiChain.OutgoingRequest(paramsProvider).fromPacket(this); + case DeviceConfig.Auth.id: + return new DeviceConfig.Auth.OutgoingRequest(paramsProvider).fromPacket(this); default: return this; } 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 8aed69f6c..e614a959d 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 @@ -610,6 +610,23 @@ public class DeviceConfig { this.isEncrypted = false; this.complete = true; } + + } + + public static class OutgoingRequest extends HuaweiPacket { + public byte[] challenge; + public byte[] nonce; + + public OutgoingRequest(ParamsProvider paramsProvider) { + super(paramsProvider); + this.complete = false; + } + + @Override + public void parseTlv() throws ParseException { + this.challenge = this.tlv.getBytes(0x01); + this.nonce = this.tlv.getBytes(0x02); + } } public static class Response extends HuaweiPacket {