Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decrypting redacted event #6148

Merged
merged 4 commits into from
May 25, 2022

Conversation

BillCarsonFr
Copy link
Member

@BillCarsonFr BillCarsonFr commented May 25, 2022

Type of change

  • Bugfix

Content

The SDK was throwing decryption errors (null algorithm) when trying to decrypt a redacted event.
This was not really visible to the user but it could trigger auto rageshakes (if on in settings), and report decryption failure to posthig

Change is as per js-sdk https://github.com/matrix-org/matrix-js-sdk/blob/ad030bfc1f919fecd80e249fc69769ce58bf9201/src/crypto/index.ts#L2873

Motivation and context

Screenshots / GIFs

Before After
image image

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@BillCarsonFr BillCarsonFr requested review from a team, onurays and bmarty and removed request for a team May 25, 2022 10:50
@@ -42,7 +43,7 @@ import javax.inject.Inject

private const val SEND_TO_DEVICE_RETRY_COUNT = 3

private val loggerTag = LoggerTag("CryptoSyncHandler", LoggerTag.CRYPTO)
private val loggerTag = LoggerTag("EventDecryptor", LoggerTag.CRYPTO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@BillCarsonFr BillCarsonFr force-pushed the feature/bca/fix_decrypt_redacted_event branch from 52fc6d8 to 7a739dc Compare May 25, 2022 10:54
@@ -110,6 +111,16 @@ internal class EventDecryptor @Inject constructor(
if (eventContent == null) {
Timber.tag(loggerTag.value).e("decryptEvent : empty event content")
throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ENCRYPTED_MESSAGE, MXCryptoError.BAD_ENCRYPTED_MESSAGE_REASON)
} else if (event.isRedacted()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if returning an empty result is confusing and difficult to back trace, what do you think about having the callers of internalDecryptEvent avoid passing known non-processable events?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to have it in a single place as there could be several callers (and future callers). Also if at some point the redaction reason is encrypted it would have to be processed here I think

val eventBobPov = bobSession.getRoom(e2eRoomID)?.getTimelineEvent(timelineEvent.eventId)!!

testHelper.runBlockingTest {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the try/catch with custom error message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the test.


testHelper.runBlockingTest {
try {
bobSession.cryptoService().decryptEvent(eventBobPov.root, "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test currently doesn't assert any results, only that an exception is not thrown (which all junit tests handle by default), this means the payload of https://github.com/vector-im/element-android/pull/6148/files#diff-090252be59df798b53cf50ae12a6826f79c92565b02d8a557bf589ba52f3d40fR116 could change and the test would potentially still pass

val result = bobSession.cryptoService().decryptEvent(eventBobPov.root, "")

result shouldBeEqualTo MXEventDecryptionResult(clearEvent = mapOf(
  "room_id"  to "roomId",
  ...
  )
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It asserts that it doesn't throw with an understandable message. But yes it could check more

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test

Copy link
Contributor

@ouchadam ouchadam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the updates! 💯

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 small remarks

@github-actions
Copy link

github-actions bot commented May 25, 2022

Unit Test Results

124 files  ±0  124 suites  ±0   2m 9s ⏱️ -13s
220 tests ±0  220 ✔️ ±0  0 💤 ±0  0 ±0 
726 runs  ±0  726 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit d7c8abb. ± Comparison against base commit 52eb48d.

♻️ This comment has been updated with latest results.


// get the event from bob
testHelper.waitWithLatch {
testHelper.retryPeriodicallyWithLatch(it) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this tricky helper function :) I was always trying to listen sync response. Test would loose time ~1 seconds but not a big problem for now.

Copy link
Contributor

@onurays onurays left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@BillCarsonFr BillCarsonFr enabled auto-merge May 25, 2022 13:01
@BillCarsonFr BillCarsonFr force-pushed the feature/bca/fix_decrypt_redacted_event branch from 29e463f to d7c8abb Compare May 25, 2022 14:54
@BillCarsonFr BillCarsonFr merged commit 8b2d6c8 into develop May 25, 2022
@BillCarsonFr BillCarsonFr deleted the feature/bca/fix_decrypt_redacted_event branch May 25, 2022 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants