mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 10:05:49 +01:00
Huawei: Fix for encrypted file downloads
Necessary for the Huawei Band 3 Pro GPS download.
This commit is contained in:
parent
5e62bd3cc6
commit
48a6e1aa95
@ -16,6 +16,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets;
|
package nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiCrypto;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiTLV;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiTLV;
|
||||||
|
|
||||||
@ -236,16 +237,28 @@ public class FileDownloadService0A {
|
|||||||
public byte number;
|
public byte number;
|
||||||
public byte[] data;
|
public byte[] data;
|
||||||
|
|
||||||
|
public Exception e = null;
|
||||||
|
|
||||||
public BlockResponse(ParamsProvider paramsProvider) {
|
public BlockResponse(ParamsProvider paramsProvider) {
|
||||||
super(paramsProvider);
|
super(paramsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parseTlv() throws ParseException {
|
public void parseTlv() throws ParseException {
|
||||||
// Note that this packet does not contain TLV data
|
int offset;
|
||||||
this.number = this.payload[2];
|
// Try to decrypt TLV, and otherwise assume the data is not encrypted
|
||||||
this.data = new byte[this.payload.length - 3];
|
try {
|
||||||
System.arraycopy(this.payload, 3, this.data, 0, this.payload.length - 3);
|
HuaweiTLV tlv = new HuaweiTLV().parse(this.payload, 2 ,this.payload.length - 2);
|
||||||
|
this.payload = tlv.decryptRaw(paramsProvider);
|
||||||
|
offset = 0;
|
||||||
|
} catch (ArrayIndexOutOfBoundsException | HuaweiCrypto.CryptoException e) {
|
||||||
|
this.e = e;
|
||||||
|
offset = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.number = this.payload[offset];
|
||||||
|
this.data = new byte[this.payload.length - offset - 1];
|
||||||
|
System.arraycopy(this.payload, offset + 1, this.data, 0, this.payload.length - offset - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,9 +291,14 @@ public class HuaweiFileDownloadManager {
|
|||||||
@Override
|
@Override
|
||||||
protected void processResponse() throws ResponseParseException {
|
protected void processResponse() throws ResponseParseException {
|
||||||
if (this.receivedPacket instanceof FileDownloadService0A.BlockResponse) {
|
if (this.receivedPacket instanceof FileDownloadService0A.BlockResponse) {
|
||||||
|
FileDownloadService0A.BlockResponse response = (FileDownloadService0A.BlockResponse) this.receivedPacket;
|
||||||
this.newSync = false;
|
this.newSync = false;
|
||||||
this.number = ((FileDownloadService0A.BlockResponse) this.receivedPacket).number;
|
this.number = response.number;
|
||||||
this.data = ((FileDownloadService0A.BlockResponse) this.receivedPacket).data;
|
this.data = response.data;
|
||||||
|
|
||||||
|
if (response.e instanceof HuaweiPacket.CryptoException) {
|
||||||
|
LOG.warn("Data could be decoded as TLV, but not decrypted.", response.e);
|
||||||
|
}
|
||||||
} else if (this.receivedPacket instanceof FileDownloadService2C.BlockResponse) {
|
} else if (this.receivedPacket instanceof FileDownloadService2C.BlockResponse) {
|
||||||
this.newSync = true;
|
this.newSync = true;
|
||||||
this.number = ((FileDownloadService2C.BlockResponse) this.receivedPacket).fileId;
|
this.number = ((FileDownloadService2C.BlockResponse) this.receivedPacket).fileId;
|
||||||
@ -629,7 +634,13 @@ public class HuaweiFileDownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle file data
|
// Handle file data
|
||||||
|
try {
|
||||||
currentFileRequest.fileDownloadCallback.downloadComplete(currentFileRequest);
|
currentFileRequest.fileDownloadCallback.downloadComplete(currentFileRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Download complete callback exception.", e);
|
||||||
|
LOG.warn("File contents: {}", GB.hexdump(currentFileRequest.getData()));
|
||||||
|
GB.toast("Workout GPX file could not be parsed.",Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.currentFileRequest.newSync && !this.fileRequests.isEmpty() && !this.fileRequests.get(0).newSync) {
|
if (!this.currentFileRequest.newSync && !this.fileRequests.isEmpty() && !this.fileRequests.get(0).newSync) {
|
||||||
// Old sync can potentially take a shortcut
|
// Old sync can potentially take a shortcut
|
||||||
|
Loading…
Reference in New Issue
Block a user