Skip to content

Commit d7c17a1

Browse files
committed
fix first upload
Signed-off-by: alperozturk <[email protected]>
1 parent a251356 commit d7c17a1

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,18 +764,22 @@ private RemoteOperationResult performE2EUpload(E2EClientData data) throws Operat
764764
return result;
765765
}
766766

767-
private E2EData getE2EData(Object object) throws InvalidAlgorithmParameterException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, InvalidParameterSpecException, IOException {
767+
private E2EData getE2EData(Object object) throws InvalidAlgorithmParameterException, IllegalStateException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, InvalidParameterSpecException, IOException {
768768
byte[] key = EncryptionUtils.generateKey();
769769
byte[] iv = EncryptionUtils.randomBytes(EncryptionUtils.ivLength);
770770
Cipher cipher = EncryptionUtils.getCipher(Cipher.ENCRYPT_MODE, key, iv);
771-
File file = new File(mFile.getStoragePath());
772-
EncryptedFile encryptedFile = EncryptionUtils.encryptFile(user.getAccountName(), file, cipher);
771+
File originalFile = new File(mFile.getStoragePath());
772+
EncryptedFile encryptedFile = EncryptionUtils.encryptFile(user.getAccountName(), originalFile, cipher);
773773
String encryptedFileName = getEncryptedFileName(object);
774774

775775
if (key == null) {
776776
throw new NullPointerException("key cannot be null");
777777
}
778778

779+
if (originalFile.getAbsolutePath().equals(encryptedFile.getEncryptedFile().getAbsolutePath())) {
780+
throw new IllegalStateException("The encrypted file path cannot be the same as the original file path.");
781+
}
782+
779783
return new E2EData(key, iv, encryptedFile, encryptedFileName);
780784
}
781785

app/src/main/java/com/owncloud/android/operations/e2e/E2EFiles.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@ data class E2EFiles(
2121
private val tag = "E2EFiles"
2222

2323
fun deleteTemporalFile() {
24+
if (temporalFile == null) {
25+
Log_OC.d(tag, "Could not delete temporal file, temporal file is null")
26+
return
27+
}
28+
2429
if (temporalFile?.exists() == true && temporalFile?.delete() == false) {
2530
Log_OC.e(tag, "Could not delete temporal file " + temporalFile?.absolutePath)
2631
}
2732
}
2833

2934
fun deleteTemporalFileWithOriginalFileComparison() {
35+
if (temporalFile == null) {
36+
Log_OC.d(tag, "Could not delete temporal file, temporal file is null")
37+
return
38+
}
39+
3040
if (originalFile == temporalFile) {
3141
return
3242
}
@@ -38,9 +48,9 @@ data class E2EFiles(
3848
fun deleteEncryptedTempFile() {
3949
if (encryptedTempFile != null) {
4050
val isTempEncryptedFileDeleted = encryptedTempFile?.delete()
41-
Log_OC.e(tag, "isTempEncryptedFileDeleted: $isTempEncryptedFileDeleted")
51+
Log_OC.d(tag, "isTempEncryptedFileDeleted: $isTempEncryptedFileDeleted")
4252
} else {
43-
Log_OC.e(tag, "Encrypted temp file cannot be found")
53+
Log_OC.d(tag, "Encrypted temp file cannot be found")
4454
}
4555
}
4656
}

app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,12 @@ public static byte[] decodeStringToBase64Bytes(String string) {
546546
}
547547

548548
public static EncryptedFile encryptFile(String accountName, File file, Cipher cipher) throws InvalidParameterSpecException, IOException {
549-
File tempEncryptedFolder = FileDataStorageManager.createTempEncryptedFolder(accountName);
550-
File tempEncryptedFile = File.createTempFile(file.getName(), null, tempEncryptedFolder);
549+
final File tempEncryptedFolder = FileDataStorageManager.createTempEncryptedFolder(accountName);
550+
final String randomFileName = UUID.randomUUID().toString();
551+
final String suffix = String.valueOf(System.currentTimeMillis());
552+
final File tempEncryptedFile = File.createTempFile(randomFileName, suffix, tempEncryptedFolder);
551553
encryptFileWithGivenCipher(file, tempEncryptedFile, cipher);
552-
String authenticationTagString = getAuthenticationTag(cipher);
554+
final String authenticationTagString = getAuthenticationTag(cipher);
553555
return new EncryptedFile(tempEncryptedFile, authenticationTagString);
554556
}
555557

0 commit comments

Comments
 (0)