Huawei: Fix encryption logic for files upload

This commit is contained in:
Me7c7 2024-11-26 19:03:01 +02:00
parent c687496cc5
commit fab6a7bc7f
4 changed files with 10 additions and 12 deletions

View File

@ -839,7 +839,7 @@ public class HuaweiPacket {
public List<byte[]> serializeFileChunk(byte[] fileChunk, int uploadPosition, int unitSize, byte fileId, boolean isEncrypted) throws SerializeException {
List<byte[]> retv = new ArrayList<>();
final int sliceHeaderLength = 6;
final int subHeaderLength = 6;
final int packageHeaderAndFooterLength = 6;
int packetCount = (int) Math.ceil(((double) fileChunk.length) / (double) unitSize);
@ -852,14 +852,14 @@ public class HuaweiPacket {
int contentSize = Math.min(unitSize, buffer.remaining());
ByteBuffer payload = ByteBuffer.allocate(contentSize + sliceHeaderLength);
payload.put(fileId); // Slice
payload.put((byte)i); // Flag
ByteBuffer payload = ByteBuffer.allocate(contentSize + subHeaderLength);
payload.put(fileId);
payload.put((byte)i);
payload.putInt(sliceStart);
byte[] packetContent = new byte[contentSize];
buffer.get(packetContent);
payload.put(packetContent); // Packet databyte[] packetContent = new byte[contentSize];
payload.put(packetContent);
byte[] new_payload = null;

View File

@ -52,7 +52,6 @@ public class HuaweiUploadManager {
private String dstPackage = null;
private String srcFingerprint = null;
private String dstFingerprint = null;
private boolean isEncrypted = false;
private int currentUploadPosition = 0;
private int uploadChunkSize = 0;
@ -79,6 +78,10 @@ public class HuaweiUploadManager {
return fileUploadParams.unit_size;
}
public boolean getEncrypt() {
return fileUploadParams.no_encrypt == 0;
}
public void setBytes(byte[] uploadArray) {
this.fileSize = uploadArray.length;
@ -144,10 +147,6 @@ public class HuaweiUploadManager {
public void setDstFingerprint(String dstFingerprint) { this.dstFingerprint = dstFingerprint;}
public boolean isEncrypted() { return isEncrypted; }
public void setEncrypted(boolean encrypted) { isEncrypted = encrypted; }
public byte[] getFileSHA256() {
return fileSHA256;
}

View File

@ -328,7 +328,6 @@ public class HuaweiP2PCalendarService extends HuaweiBaseP2PService {
fileInfo.setDstPackage(this.getPackage());
fileInfo.setSrcFingerprint(this.getLocalFingerprint());
fileInfo.setDstFingerprint(this.getFingerprint());
fileInfo.setEncrypted(true);
fileInfo.setFileUploadCallback(new HuaweiUploadManager.FileUploadCallback() {
@Override

View File

@ -43,7 +43,7 @@ public class SendFileUploadChunk extends Request {
huaweiUploadManager.getFileUploadInfo().getCurrentUploadPosition(),
huaweiUploadManager.getFileUploadInfo().getUnitSize(),
huaweiUploadManager.getFileUploadInfo().getFileId(),
huaweiUploadManager.getFileUploadInfo().isEncrypted()
huaweiUploadManager.getFileUploadInfo().getEncrypt()
);
} catch(HuaweiPacket.SerializeException e) {
throw new RequestCreationException(e.getMessage());