mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 20:29:53 +00:00
Merge 7f17f1fafa
into 8f9bb4dc5b
This commit is contained in:
commit
8cfb9bb698
1 changed files with 20 additions and 9 deletions
|
@ -1,8 +1,8 @@
|
||||||
package chat.simplex.common.platform
|
package chat.simplex.common.platform
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.security.keystore.KeyGenParameterSpec
|
import android.os.Build
|
||||||
import android.security.keystore.KeyProperties
|
import android.security.keystore.*
|
||||||
import chat.simplex.common.views.helpers.AlertManager
|
import chat.simplex.common.views.helpers.AlertManager
|
||||||
import chat.simplex.common.views.helpers.generalGetString
|
import chat.simplex.common.views.helpers.generalGetString
|
||||||
import chat.simplex.res.MR
|
import chat.simplex.res.MR
|
||||||
|
@ -71,13 +71,24 @@ internal class Cryptor: CryptorInterface {
|
||||||
private fun createSecretKey(alias: String): SecretKey? {
|
private fun createSecretKey(alias: String): SecretKey? {
|
||||||
if (keyStore.containsAlias(alias)) return getSecretKey(alias)
|
if (keyStore.containsAlias(alias)) return getSecretKey(alias)
|
||||||
val keyGenerator: KeyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM, "AndroidKeyStore")
|
val keyGenerator: KeyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM, "AndroidKeyStore")
|
||||||
keyGenerator.init(
|
val builder = KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
|
||||||
KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
|
.setBlockModes(BLOCK_MODE)
|
||||||
.setBlockModes(BLOCK_MODE)
|
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
||||||
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
.build()
|
try {
|
||||||
)
|
keyGenerator.init(builder.setIsStrongBoxBacked(true).build())
|
||||||
return keyGenerator.generateKey()
|
val key = keyGenerator.generateKey()
|
||||||
|
Log.w(TAG, "StrongBox support is present")
|
||||||
|
key
|
||||||
|
} catch (e: StrongBoxUnavailableException) {
|
||||||
|
Log.w(TAG, "No StrongBox support")
|
||||||
|
keyGenerator.init(builder.setIsStrongBoxBacked(false).build())
|
||||||
|
keyGenerator.generateKey()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
keyGenerator.init(builder.build())
|
||||||
|
keyGenerator.generateKey()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSecretKey(alias: String): SecretKey? {
|
private fun getSecretKey(alias: String): SecretKey? {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue