mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
[Huawei] Fix transactions encryption
This commit is contained in:
parent
d5cecc4a84
commit
510b8096ed
@ -248,25 +248,21 @@ public class HuaweiCrypto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] encrypt(byte authMode, byte[] message, byte[] key, byte[] iv) throws CryptoException {
|
public static byte[] encrypt(byte encryptMethod, byte[] message, byte[] key, byte[] iv) throws CryptoException {
|
||||||
try {
|
try {
|
||||||
if (authMode == 0x04) {
|
if (encryptMethod == 0x01)
|
||||||
return CryptoUtils.encryptAES_GCM_NoPad(message, key, iv, null);
|
return CryptoUtils.encryptAES_GCM_NoPad(message, key, iv, null);
|
||||||
} else {
|
|
||||||
return CryptoUtils.encryptAES_CBC_Pad(message, key, iv);
|
return CryptoUtils.encryptAES_CBC_Pad(message, key, iv);
|
||||||
}
|
|
||||||
} catch (InvalidAlgorithmParameterException | NoSuchPaddingException | IllegalBlockSizeException | NoSuchAlgorithmException | BadPaddingException | InvalidKeyException | IllegalArgumentException e) {
|
} catch (InvalidAlgorithmParameterException | NoSuchPaddingException | IllegalBlockSizeException | NoSuchAlgorithmException | BadPaddingException | InvalidKeyException | IllegalArgumentException e) {
|
||||||
throw new CryptoException(e);
|
throw new CryptoException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] decrypt(byte authMode, byte[] message, byte[] key, byte[] iv) throws CryptoException {
|
public static byte[] decrypt(byte encryptMethod, byte[] message, byte[] key, byte[] iv) throws CryptoException {
|
||||||
try {
|
try {
|
||||||
if (authMode == 0x04) {
|
if (encryptMethod == 0x01)
|
||||||
return CryptoUtils.decryptAES_GCM_NoPad(message, key, iv, null);
|
return CryptoUtils.decryptAES_GCM_NoPad(message, key, iv, null);
|
||||||
} else {
|
|
||||||
return CryptoUtils.decryptAES_CBC_Pad(message, key, iv);
|
return CryptoUtils.decryptAES_CBC_Pad(message, key, iv);
|
||||||
}
|
|
||||||
} catch (InvalidAlgorithmParameterException | NoSuchPaddingException | IllegalBlockSizeException | NoSuchAlgorithmException | BadPaddingException | InvalidKeyException | IllegalArgumentException e) {
|
} catch (InvalidAlgorithmParameterException | NoSuchPaddingException | IllegalBlockSizeException | NoSuchAlgorithmException | BadPaddingException | InvalidKeyException | IllegalArgumentException e) {
|
||||||
throw new CryptoException(e);
|
throw new CryptoException(e);
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ public class HuaweiTLV {
|
|||||||
byte[] serializedTLV = serialize();
|
byte[] serializedTLV = serialize();
|
||||||
byte[] key = paramsProvider.getSecretKey();
|
byte[] key = paramsProvider.getSecretKey();
|
||||||
byte[] nonce = paramsProvider.getIv();
|
byte[] nonce = paramsProvider.getIv();
|
||||||
byte[] encryptedTLV = HuaweiCrypto.encrypt(paramsProvider.getDeviceSupportType(), serializedTLV, key, nonce);
|
byte[] encryptedTLV = HuaweiCrypto.encrypt(paramsProvider.getEncryptMethod(), serializedTLV, key, nonce);
|
||||||
return new HuaweiTLV()
|
return new HuaweiTLV()
|
||||||
.put(CryptoTags.encryption, (byte) 0x01)
|
.put(CryptoTags.encryption, (byte) 0x01)
|
||||||
.put(CryptoTags.initVector, nonce)
|
.put(CryptoTags.initVector, nonce)
|
||||||
@ -300,7 +300,7 @@ public class HuaweiTLV {
|
|||||||
|
|
||||||
public void decrypt(ParamsProvider paramsProvider) throws CryptoException, HuaweiPacket.MissingTagException {
|
public void decrypt(ParamsProvider paramsProvider) throws CryptoException, HuaweiPacket.MissingTagException {
|
||||||
byte[] key = paramsProvider.getSecretKey();
|
byte[] key = paramsProvider.getSecretKey();
|
||||||
byte[] decryptedTLV = HuaweiCrypto.decrypt(paramsProvider.getDeviceSupportType(), getBytes(CryptoTags.cipherText), key, getBytes(CryptoTags.initVector));
|
byte[] decryptedTLV = HuaweiCrypto.decrypt(paramsProvider.getEncryptMethod(), getBytes(CryptoTags.cipherText), key, getBytes(CryptoTags.initVector));
|
||||||
this.valueMap = new ArrayList<>();
|
this.valueMap = new ArrayList<>();
|
||||||
parse(decryptedTLV);
|
parse(decryptedTLV);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user