-
Notifications
You must be signed in to change notification settings - Fork 6
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
chore: Core crypto 2.0 migration [WPB-14635] #3141
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import io.ktor.util.encodeBase64 | |
import kotlinx.coroutines.sync.Mutex | ||
import kotlinx.coroutines.sync.withLock | ||
import java.io.File | ||
import com.wire.crypto.ProteusException as ProteusExceptionNative | ||
|
||
@Suppress("TooManyFunctions") | ||
class ProteusClientCoreCryptoImpl private constructor( | ||
|
@@ -145,13 +146,12 @@ class ProteusClientCoreCryptoImpl private constructor( | |
private inline fun <T> wrapException(b: () -> T): T { | ||
try { | ||
return b() | ||
} catch (e: CoreCryptoException) { | ||
val proteusLastErrorCode = coreCrypto.proteusLastErrorCode() | ||
} catch (e: CoreCryptoException.Proteus) { | ||
throw ProteusException( | ||
e.message, | ||
ProteusException.fromProteusCode(proteusLastErrorCode.toInt()), | ||
proteusLastErrorCode.toInt(), | ||
e | ||
message = e.message, | ||
code = mapProteusExceptionToErrorCode(e.v1), | ||
intCode = mapProteusExceptionToRawIntErrorCode(e.v1), | ||
cause = e | ||
) | ||
} catch (e: Exception) { | ||
throw ProteusException(e.message, ProteusException.Code.UNKNOWN_ERROR, null, e) | ||
|
@@ -187,11 +187,11 @@ class ProteusClientCoreCryptoImpl private constructor( | |
return ProteusClientCoreCryptoImpl(coreCrypto) | ||
} catch (exception: ProteusStorageMigrationException) { | ||
throw exception | ||
} catch (e: CoreCryptoException) { | ||
} catch (e: CoreCryptoException.Proteus) { | ||
throw ProteusException( | ||
message = e.message, | ||
code = ProteusException.fromProteusCode(coreCrypto.proteusLastErrorCode().toInt()), | ||
intCode = coreCrypto.proteusLastErrorCode().toInt(), | ||
code = mapProteusExceptionToErrorCode(e.v1), | ||
intCode = mapProteusExceptionToRawIntErrorCode(e.v1), | ||
cause = e.cause | ||
) | ||
} catch (e: Exception) { | ||
|
@@ -218,5 +218,24 @@ class ProteusClientCoreCryptoImpl private constructor( | |
throw ProteusStorageMigrationException("Failed to migrate from crypto box at $rootDir", exception) | ||
} | ||
} | ||
|
||
private fun mapProteusExceptionToErrorCode(proteusException: ProteusExceptionNative): ProteusException.Code { | ||
return when (proteusException) { | ||
is ProteusExceptionNative.SessionNotFound -> ProteusException.Code.SESSION_NOT_FOUND | ||
is ProteusExceptionNative.DuplicateMessage -> ProteusException.Code.DUPLICATE_MESSAGE | ||
is ProteusExceptionNative.RemoteIdentityChanged -> ProteusException.Code.REMOTE_IDENTITY_CHANGED | ||
is ProteusExceptionNative.Other -> ProteusException.fromProteusCode(proteusException.v1.toInt()) | ||
} | ||
} | ||
|
||
@Suppress("MagicNumber") | ||
private fun mapProteusExceptionToRawIntErrorCode(proteusException: ProteusExceptionNative): Int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those mappers are here because we've to rely on the native There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going forward I'd suggest aligning Doesn't have to be done right away but maybe create a TODO with a ticket? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to have it in a different task, there is also some corecryptobox mappings to the |
||
return when (proteusException) { | ||
is ProteusExceptionNative.SessionNotFound -> 102 | ||
is ProteusExceptionNative.DuplicateMessage -> 209 | ||
is ProteusExceptionNative.RemoteIdentityChanged -> 204 | ||
is ProteusExceptionNative.Other -> proteusException.v1.toInt() | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would we want to have some other log level for debug builds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can set to the lowest level (
CoreCryptoLogLevel.Trace
), and within theCoreCryptoLoggerImpl
we can map to differentkaliumLogger
functions, which alreadys implement log-level filtering within it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning⚠️ this can have a negative performance impact since a lot of messages will go over the ffi boundary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@typfel should we then make it default to
INFO
? or we should have it disabled for prod at all?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want it enabled in Prod at the
INFO
level which will not generate large amounts of logs.Setting the level
TRACE
will potentially generate a lot of logs so it should not be enabled in Prod.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted to
INFO
there