1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-10-06 13:20:30 +02:00

[Huawei] Add hichainlite related parsing code

This commit is contained in:
Vitaliy Tomin 2024-07-19 18:16:51 +08:00
parent 676678defb
commit a994603389
3 changed files with 23 additions and 3 deletions

View File

@ -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 {

View File

@ -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;
}

View File

@ -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 {