Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions app/src/main/java/com/owncloud/android/utils/EncryptionUtilsV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.annotation.VisibleForTesting
import com.google.gson.reflect.TypeToken
import com.nextcloud.client.account.User
import com.nextcloud.utils.autoRename.AutoRename
import com.nextcloud.utils.extensions.showToast
import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.datamodel.ArbitraryDataProvider
Expand Down Expand Up @@ -171,6 +172,11 @@ class EncryptionUtilsV2 {
context: Context,
arbitraryDataProvider: ArbitraryDataProvider
): DecryptedFolderMetadataFile {
if (signature.isEmpty()) {
context.showToast(R.string.e2e_signature_is_empty)
throw IllegalStateException("Cannot decryptFolderMetadataFile, signature is empty")
}

val parent =
storageManager.getFileById(ocFile.parentId) ?: throw IllegalStateException("Cannot retrieve metadata")

Expand Down Expand Up @@ -945,10 +951,6 @@ class EncryptionUtilsV2 {
oldCounter: Long,
signature: String
) {
if (signature.isEmpty()) {
return
}

if (decryptedFolderMetadataFile.metadata.counter < oldCounter) {
MainApp.showMessage(R.string.e2e_counter_too_old)
return
Expand Down Expand Up @@ -982,20 +984,19 @@ class EncryptionUtilsV2 {
return CMSSignedData(cmsProcessableByteArray, contentInfo)
}

@Suppress("TooGenericExceptionCaught")
fun verifySignedData(data: CMSSignedData, certs: List<X509Certificate>): Boolean {
val signer: SignerInformation = data.signerInfos.signers.iterator().next() as SignerInformation

certs.forEach {
try {
if (signer.verify(JcaSimpleSignerInfoVerifierBuilder().build(it))) {
return true
}
} catch (e: java.lang.Exception) {
Log_OC.e(TAG, "Error caught at verifySignedData: $e")
val signer = data.signerInfos.signers.first() as SignerInformation
val verifierBuilder = JcaSimpleSignerInfoVerifierBuilder()

return certs.any { cert ->
runCatching {
signer.verify(verifierBuilder.build(cert))
}.getOrElse {
Log_OC.e(TAG, "Exception verifySignedData: $it")
false
}
}

return false
}

private fun signMessage(cert: X509Certificate, key: PrivateKey, data: ByteArray): CMSSignedData {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@
<string name="direct_login_text">Login with %1$s to %2$s</string>
<string name="direct_login_failed">Login via direct link failed!</string>

<string name="e2e_signature_is_empty">Could not verify metadata, signature is empty.</string>
<string name="e2e_counter_too_old">Counter is too old</string>
<string name="e2e_hash_not_found">Hash not found</string>
<string name="e2e_signature_does_not_match">Signature does not match</string>
Expand Down
Loading