Skip to content

Commit 28c14ca

Browse files
Yaroslav98214alperozturk96
authored andcommitted
fix: enforce E2EE metadata validation
Fail fast when metadata verification detects counter, signature, or checksum issues. Signed-off-by: Yaroslav98214 <diakovichyaroslav30@gmail.com>
1 parent a1a7eb0 commit 28c14ca

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

app/src/main/java/com/owncloud/android/utils/EncryptionUtilsV2.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ class EncryptionUtilsV2 {
250250
)
251251
}
252252

253-
verifyMetadata(metadataFile, decryptedFolderMetadataFile, oldCounter, signature)
253+
if (!verifyMetadata(metadataFile, decryptedFolderMetadataFile, oldCounter, signature)) {
254+
throw IllegalStateException("Metadata is corrupt!")
255+
}
254256

255257
val transferredFiledrop = filesDropCountBefore > 0 &&
256258
decryptedFolderMetadataFile.metadata.files.size == filesBefore + filesDropCountBefore
@@ -953,10 +955,10 @@ class EncryptionUtilsV2 {
953955
decryptedFolderMetadataFile: DecryptedFolderMetadataFile,
954956
oldCounter: Long,
955957
signature: String
956-
) {
958+
): Boolean {
957959
if (decryptedFolderMetadataFile.metadata.counter < oldCounter) {
958960
MainApp.showMessage(R.string.e2e_counter_too_old)
959-
return
961+
return false
960962
}
961963

962964
val message = EncryptionUtils.serializeJSON(encryptedFolderMetadataFile, true)
@@ -965,14 +967,15 @@ class EncryptionUtilsV2 {
965967

966968
if (certs.isNotEmpty() && !verifySignedData(signedData, certs)) {
967969
MainApp.showMessage(R.string.e2e_signature_does_not_match)
968-
return
970+
return false
969971
}
970972

971973
val hashedMetadataKey = hashMetadataKey(decryptedFolderMetadataFile.metadata.metadataKey)
972974
if (!decryptedFolderMetadataFile.metadata.keyChecksums.contains(hashedMetadataKey)) {
973975
MainApp.showMessage(R.string.e2e_hash_not_found)
974-
return
976+
return false
975977
}
978+
return true
976979
}
977980

978981
private fun getSignedData(base64encodedSignature: String, message: String): CMSSignedData {

0 commit comments

Comments
 (0)