Skip to content

Commit

Permalink
Merge pull request #12668 from nextcloud/bugfix/e2e-folder-file-creation
Browse files Browse the repository at this point in the history
Bugfix E2E folder file creation
  • Loading branch information
tobiasKaminsky committed Mar 15, 2024
2 parents 0819783 + 4dac5d5 commit 4c3069c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
}
}

// TODO REFACTOR
@SuppressLint("AndroidLintUseSparseArrays") // gson cannot handle sparse arrays easily, therefore use hashmap
private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile parentFile) {
RemoteOperationResult result = null;
Expand Down Expand Up @@ -489,13 +490,14 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
// 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
Expand All @@ -507,8 +509,11 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
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
Expand Down Expand Up @@ -669,7 +674,6 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@ public static Pair<Boolean, DecryptedFolderMetadataFileV1> retrieveMetadataV1(OC
// 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);
Expand Down

0 comments on commit 4c3069c

Please sign in to comment.