Эх сурвалжийг харах

Merge pull request #12668 from nextcloud/bugfix/e2e-folder-file-creation

Bugfix E2E folder file creation
Tobias Kaminsky 1 жил өмнө
parent
commit
4c3069c268

+ 8 - 4
app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -441,6 +441,7 @@ public class UploadFileOperation extends SyncOperation {
         }
     }
 
+    // TODO REFACTOR
     @SuppressLint("AndroidLintUseSparseArrays") // gson cannot handle sparse arrays easily, therefore use hashmap
     private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile parentFile) {
         RemoteOperationResult result = null;
@@ -489,13 +490,14 @@ public class UploadFileOperation extends SyncOperation {
 //                                                   mContext);
 
             Object object = EncryptionUtils.downloadFolderMetadata(parentFile, client, mContext, user);
+            if (object instanceof DecryptedFolderMetadataFileV1 decrypted && decrypted.getMetadata() != null) {
+                metadataExists = true;
+            }
 
             if (CapabilityUtils.getCapability(mContext).getEndToEndEncryptionApiVersion().compareTo(E2EVersion.V2_0) >= 0) {
                 if (object == null) {
                     // TODO return error
                     return new RemoteOperationResult(new IllegalStateException("Metadata does not exist"));
-                } else {
-                    metadataExists = true;
                 }
             } else {
                 // v1 is allowed to be null, thus create it
@@ -507,8 +509,11 @@ public class UploadFileOperation extends SyncOperation {
                 String encryptedMetadataKey = EncryptionUtils.encryptStringAsymmetric(metadataKey, publicKey);
                 metadata.getMetadata().setMetadataKey(encryptedMetadataKey);
 
+                if (object instanceof DecryptedFolderMetadataFileV1) {
+                    metadata = (DecryptedFolderMetadataFileV1) object;
+                }
+
                 object = metadata;
-                metadataExists = false;
             }
 
             // todo fail if no metadata
@@ -669,7 +674,6 @@ public class UploadFileOperation extends SyncOperation {
                     data.setFilename(mFile.getDecryptedFileName());
                     data.setMimetype(mFile.getMimeType());
                     data.setKey(EncryptionUtils.encodeBytesToBase64String(key));
-
                     decryptedFile.setEncrypted(data);
                     decryptedFile.setInitializationVector(EncryptionUtils.encodeBytesToBase64String(iv));
                     decryptedFile.setAuthenticationTag(encryptedFile.getAuthenticationTag());

+ 1 - 0
app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java

@@ -1390,6 +1390,7 @@ public static String decryptStringSymmetricAsString(String string,
             // new metadata
             metadata = new DecryptedFolderMetadataFileV1();
             metadata.setMetadata(new DecryptedMetadata());
+            metadata.getMetadata().setVersion(Double.parseDouble(E2EVersion.V1_2.getValue()));
             metadata.getMetadata().setMetadataKeys(new HashMap<>());
             String metadataKey = EncryptionUtils.encodeBytesToBase64String(EncryptionUtils.generateKey());
             String encryptedMetadataKey = EncryptionUtils.encryptStringAsymmetric(metadataKey, publicKey);