Skip to content

Commit 92faf3b

Browse files
ganfraBillCarsonFr
authored andcommitted
Backup: introduce Aes256 algorithm
1 parent c055f40 commit 92faf3b

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.internal.crypto.keysbackup.algorithm
18+
19+
import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_AES_256_BACKUP
20+
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysVersionResult
21+
import org.matrix.android.sdk.api.session.crypto.keysbackup.MegolmBackupAes256AuthData
22+
import org.matrix.android.sdk.api.session.crypto.keysbackup.MegolmBackupAuthData
23+
import org.matrix.android.sdk.api.util.JsonDict
24+
import org.matrix.android.sdk.internal.crypto.MegolmSessionData
25+
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysBackupData
26+
27+
internal class KeysBackupAes256Algorithm(keysVersions: KeysVersionResult) : KeysBackupAlgorithm {
28+
29+
override val untrusted: Boolean = true
30+
31+
private val aesAuthData: MegolmBackupAes256AuthData
32+
33+
init {
34+
if (keysVersions.algorithm != MXCRYPTO_ALGORITHM_AES_256_BACKUP) {
35+
throw IllegalStateException("Algorithm doesn't match")
36+
}
37+
aesAuthData = keysVersions.getAuthDataAsMegolmBackupAuthData() as MegolmBackupAes256AuthData
38+
}
39+
40+
override fun encryptSession(sessionData: MegolmSessionData): JsonDict? {
41+
TODO("Not yet implemented")
42+
}
43+
44+
override fun decryptSessions(recoveryKey: String, data: KeysBackupData): List<MegolmSessionData> {
45+
TODO("Not yet implemented")
46+
}
47+
48+
override fun release() {
49+
TODO("Not yet implemented")
50+
}
51+
52+
override val authData: MegolmBackupAuthData = aesAuthData
53+
54+
override fun keyMatches(key: String): Boolean {
55+
TODO("Not yet implemented")
56+
}
57+
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/algorithm/KeysBackupAlgorithmFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal class KeysBackupAlgorithmFactory @Inject constructor() {
2929
KeysBackupCurve25519Algorithm(keysVersion)
3030
}
3131
MXCRYPTO_ALGORITHM_AES_256_BACKUP -> {
32-
throw IllegalStateException("AES_256 is not yet handled")
32+
KeysBackupAes256Algorithm(keysVersion)
3333
}
3434
else -> {
3535
throw IllegalStateException("Unknown algorithm")

0 commit comments

Comments
 (0)