Expose setPrivateKey instead of setRecoveryKey as curveKey shouldn't not be used (let valere continue on the privatekey generation)

This commit is contained in:
ganfra 2022-08-22 17:47:20 +02:00 committed by Valere
parent 03272a9c8f
commit 1db5c662d2
5 changed files with 14 additions and 8 deletions

View File

@ -322,7 +322,9 @@ class KeysBackupTest : InstrumentedTest {
put(cryptoTestData.roomId, roomKeysBackupData)
}
)
algorithm.setRecoveryKey(keyBackupCreationInfo.recoveryKey)
extractCurveKeyFromRecoveryKey(keyBackupCreationInfo.recoveryKey)?.also {
algorithm.setPrivateKey(it)
}
val sessionsData = algorithm.decryptSessions(keysBackupData)
val sessionData = sessionsData.firstOrNull()
assertNotNull(sessionData)

View File

@ -632,7 +632,9 @@ internal class DefaultKeysBackupService @Inject constructor(
// Get backed up keys from the homeserver
val data = getKeys(sessionId, roomId, keysVersionResult.version)
algorithm?.setRecoveryKey(recoveryKey)
extractCurveKeyFromRecoveryKey(recoveryKey)?.also { privateKey ->
algorithm?.setPrivateKey(privateKey)
}
val sessionsData = withContext(coroutineDispatchers.computation) {
algorithm?.decryptSessions(data)
}.orEmpty()
@ -1138,7 +1140,9 @@ internal class DefaultKeysBackupService @Inject constructor(
// roomId -> sessionId -> MXKeyBackupData
val keysBackupData = KeysBackupData()
val recoveryKey = cryptoStore.getKeyBackupRecoveryKeyInfo()?.recoveryKey
algorithm?.setRecoveryKey(recoveryKey)
extractCurveKeyFromRecoveryKey(recoveryKey)?.also { privateKey ->
algorithm?.setPrivateKey(privateKey)
}
olmInboundGroupSessionWrappers.forEach { olmInboundGroupSessionWrapper ->
val roomId = olmInboundGroupSessionWrapper.roomId ?: return@forEach
val olmInboundGroupSession = olmInboundGroupSessionWrapper.session

View File

@ -46,8 +46,8 @@ internal class KeysBackupAes256Algorithm(keysVersions: KeysVersionResult) : Keys
aesAuthData = keysVersions.getAuthDataAsMegolmBackupAuthData() as MegolmBackupAes256AuthData
}
override fun setRecoveryKey(recoveryKey: String?) {
privateKey = extractCurveKeyFromRecoveryKey(recoveryKey)
override fun setPrivateKey(privateKey: ByteArray) {
this.privateKey = privateKey
}
override fun encryptSession(sessionData: MegolmSessionData): JsonDict? {

View File

@ -27,7 +27,7 @@ internal interface KeysBackupAlgorithm {
val authData: MegolmBackupAuthData
val untrusted: Boolean
fun setRecoveryKey(recoveryKey: String?)
fun setPrivateKey(privateKey: ByteArray)
fun encryptSession(sessionData: MegolmSessionData): JsonDict?
fun decryptSessions(data: KeysBackupData): List<MegolmSessionData>
fun keyMatches(privateKey: ByteArray): Boolean

View File

@ -52,8 +52,8 @@ internal class KeysBackupCurve25519Algorithm(keysVersions: KeysVersionResult) :
}
}
override fun setRecoveryKey(recoveryKey: String?) {
privateKey = extractCurveKeyFromRecoveryKey(recoveryKey)
override fun setPrivateKey(privateKey: ByteArray) {
this.privateKey = privateKey
}
override fun encryptSession(sessionData: MegolmSessionData): JsonDict? {