summaryrefslogtreecommitdiff
path: root/main/src/ui/java/de/blinkt/openvpn/core/ProfileEncryption.kt
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui/java/de/blinkt/openvpn/core/ProfileEncryption.kt')
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/core/ProfileEncryption.kt20
1 files changed, 11 insertions, 9 deletions
diff --git a/main/src/ui/java/de/blinkt/openvpn/core/ProfileEncryption.kt b/main/src/ui/java/de/blinkt/openvpn/core/ProfileEncryption.kt
index ad22460f..fa61e733 100644
--- a/main/src/ui/java/de/blinkt/openvpn/core/ProfileEncryption.kt
+++ b/main/src/ui/java/de/blinkt/openvpn/core/ProfileEncryption.kt
@@ -7,7 +7,7 @@ package de.blinkt.openvpn.core
import android.content.Context
import android.os.Build
import androidx.security.crypto.EncryptedFile
-import androidx.security.crypto.MasterKeys
+import androidx.security.crypto.MasterKey
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
@@ -19,16 +19,18 @@ internal class ProfileEncryption {
companion object {
@JvmStatic
fun encryptionEnabled(): Boolean {
- return mMasterKeyAlias != null
+ return mMasterKey != null
}
- private var mMasterKeyAlias: String? = null
+ private var mMasterKey: MasterKey? = null
@JvmStatic
- fun initMasterCryptAlias() {
+ fun initMasterCryptAlias(context:Context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return
try {
- mMasterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
+ mMasterKey = MasterKey.Builder(context)
+ .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
+ .build()
} catch (e: GeneralSecurityException) {
VpnStatus.logException("Could not initialise file encryption key.", e)
} catch (e: IOException) {
@@ -40,9 +42,9 @@ internal class ProfileEncryption {
@Throws(GeneralSecurityException::class, IOException::class)
fun getEncryptedVpInput(context: Context, file: File): FileInputStream {
val encryptedFile = EncryptedFile.Builder(
- file,
context,
- mMasterKeyAlias!!,
+ file,
+ mMasterKey!!,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build()
return encryptedFile.openFileInput()
@@ -52,9 +54,9 @@ internal class ProfileEncryption {
@Throws(GeneralSecurityException::class, IOException::class)
fun getEncryptedVpOutput(context: Context, file: File): FileOutputStream {
val encryptedFile = EncryptedFile.Builder(
- file,
context,
- mMasterKeyAlias!!,
+ file,
+ mMasterKey!!,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build()
return encryptedFile.openFileOutput()