Skip to content

Commit 8cfc8d0

Browse files
authored
fix: proteus DuplicateMessage classification to avoid false failedDecryption (#3845)
1 parent c894732 commit 8cfc8d0

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

core/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/ProteusClientCoreCryptoImpl.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ class ProteusClientCoreCryptoImpl private constructor(
156156
private inline fun <T> wrapException(b: () -> T): T {
157157
try {
158158
return b()
159+
} catch (e: ProteusExceptionNative) {
160+
throw ProteusException(
161+
message = e.message,
162+
code = mapProteusExceptionToErrorCode(e),
163+
intCode = mapProteusExceptionToRawIntErrorCode(e),
164+
cause = e
165+
)
159166
} catch (e: CoreCryptoException.Proteus) {
160167
throw ProteusException(
161168
message = e.message,
@@ -197,6 +204,13 @@ class ProteusClientCoreCryptoImpl private constructor(
197204
it.proteusInit()
198205
}
199206
return ProteusClientCoreCryptoImpl(coreCrypto)
207+
} catch (e: ProteusExceptionNative) {
208+
throw ProteusException(
209+
message = e.message,
210+
code = mapProteusExceptionToErrorCode(e),
211+
intCode = mapProteusExceptionToRawIntErrorCode(e),
212+
cause = e
213+
)
200214
} catch (exception: ProteusStorageMigrationException) {
201215
throw exception
202216
} catch (e: CoreCryptoException.Proteus) {

core/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/exceptions/ProteusException.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ open class ProteusException(message: String?, val code: Code, val intCode: Int?,
193193
return when (code) {
194194
501 -> Code.STORAGE_ERROR
195195
3, 301, 302, 303 -> Code.DECODE_ERROR
196+
204 -> Code.REMOTE_IDENTITY_CHANGED
196197
206, 207, 210 -> Code.INVALID_SIGNATURE
197198
200, 201, 202, 205, 213 -> Code.INVALID_MESSAGE
199+
209 -> Code.DUPLICATE_MESSAGE
198200
211, 212 -> Code.TOO_DISTANT_FUTURE
199201
208 -> Code.OUTDATED_MESSAGE
200202
300 -> Code.IDENTITY_ERROR

core/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/ProteusClientTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ class ProteusClientTest : BaseProteusClientTest() {
113113
assertEquals(ProteusException.Code.DUPLICATE_MESSAGE, exception.code)
114114
}
115115

116+
@Test
117+
fun givenProteusRawErrorCode209_whenMapping_thenDuplicateMessage() {
118+
assertEquals(
119+
ProteusException.Code.DUPLICATE_MESSAGE,
120+
ProteusException.fromProteusCode(209)
121+
)
122+
}
123+
124+
@Test
125+
fun givenProteusRawErrorCode204_whenMapping_thenRemoteIdentityChanged() {
126+
assertEquals(
127+
ProteusException.Code.REMOTE_IDENTITY_CHANGED,
128+
ProteusException.fromProteusCode(204)
129+
)
130+
}
131+
116132
@Test
117133
fun givenMissingSession_whenCallingEncryptBatched_thenMissingSessionAreIgnored() = runTest {
118134
val aliceClient = createProteusClient(createProteusStoreRef(alice.id), PROTEUS_DB_SECRET)

0 commit comments

Comments
 (0)