Skip to content

Commit 2f7d003

Browse files
committed
[android] fix iv for aes key encryption and add compat tests from ts
#4072
1 parent 47e660c commit 2f7d003

File tree

8 files changed

+3886
-9005
lines changed

8 files changed

+3886
-9005
lines changed

Diff for: app-android/app/src/androidTest/assets/CompatibilityTestData.json

-1,957
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../test/tests/api/worker/crypto/CompatibilityTestData.json

Diff for: app-android/app/src/androidTest/java/de/tutao/tutanota/EncryptionCompatTest.kt

+26
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package de.tutao.tutanota
33
import android.content.Context
44
import android.support.test.InstrumentationRegistry
55
import android.support.test.runner.AndroidJUnit4
6+
import de.tutao.tutanota.AndroidNativeCryptoFacade.Companion.bytesToKey
67
import de.tutao.tutanota.ipc.RsaPrivateKey
78
import de.tutao.tutanota.ipc.RsaPublicKey
89
import de.tutao.tutanota.ipc.wrap
@@ -19,6 +20,7 @@ import java.io.IOException
1920
import java.math.BigInteger
2021
import java.security.SecureRandom
2122

23+
2224
@RunWith(AndroidJUnit4::class)
2325
class CompatibilityTest {
2426
@Test
@@ -36,6 +38,30 @@ class CompatibilityTest {
3638
}
3739
}
3840

41+
@Test
42+
@Throws(CryptoError::class, IOException::class)
43+
fun aes128Key128Encryption() {
44+
val crypto = AndroidNativeCryptoFacade(Mockito.mock(Context::class.java))
45+
for (td in testData!!.getAes128Tests()) {
46+
val key = bytesToKey(hexToBytes(td.hexKey))
47+
val keyToEncrypt128 = hexToBytes(td.keyToEncrypt128)
48+
val encryptedKey = crypto.encryptKey(key, keyToEncrypt128)
49+
Assert.assertEquals(td.encryptedKey128, encryptedKey.toBase64())
50+
}
51+
}
52+
53+
@Test
54+
@Throws(CryptoError::class, IOException::class)
55+
fun aes128Key256Encryption() {
56+
val crypto = AndroidNativeCryptoFacade(Mockito.mock(Context::class.java))
57+
for (td in testData!!.getAes128Tests()) {
58+
val key = bytesToKey(hexToBytes(td.hexKey))
59+
val keyToEncrypt256 = hexToBytes(td.keyToEncrypt256)
60+
val encryptedKey = crypto.encryptKey(key, keyToEncrypt256)
61+
Assert.assertEquals(td.encryptedKey256, encryptedKey.toBase64())
62+
}
63+
}
64+
3965
@Test
4066
@Throws(CryptoError::class, IOException::class)
4167
fun aes128Mac() {

0 commit comments

Comments
 (0)