mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
[Huawei] Rename authMode to deviceSupportType
This commit is contained in:
parent
2880297c51
commit
270212a771
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<byte[]> 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();
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class TestHuaweiTLV {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class TestAlarms {
|
||||
|
||||
HuaweiPacket.ParamsProvider paramsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class TestDeviceConfig {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class TestDisconnectNotification {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class TestFindPhone {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class TestFitnessData {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class TestLocaleConfig {
|
||||
|
||||
HuaweiPacket.ParamsProvider paramsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class TestMusicControl {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class TestNotifications {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class TestWorkMode {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class TestWorkout {
|
||||
|
||||
HuaweiPacket.ParamsProvider secretsProvider = new HuaweiPacket.ParamsProvider() {
|
||||
@Override
|
||||
public byte getAuthMode() {
|
||||
public byte getDeviceSupportType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user