Skip to content

Commit

Permalink
Add additional security params for Android P and higher
Browse files Browse the repository at this point in the history
  • Loading branch information
Fi5t committed Jul 3, 2020
1 parent 18f5b25 commit f0feabd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pinkman/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lib_name=pinkman
lib_version=1.0.0
lib_version=1.0.1
lib_description=PINkman is a library to help implementing an authentication by a PIN code in a secure manner
lib_vcs=https://github.com/RedMadRobot/PINkman.git
lib_issue_tracker=https://github.com/RedMadRobot/PINkman/issues
10 changes: 8 additions & 2 deletions pinkman/src/main/java/com/redmadrobot/pinkman/Pinkman.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.redmadrobot.pinkman

import android.content.Context
import android.os.Build
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties.*
import androidx.security.crypto.EncryptedFile
Expand Down Expand Up @@ -33,7 +34,12 @@ class Pinkman(
.setBlockModes(BLOCK_MODE_GCM)
.setEncryptionPaddings(ENCRYPTION_PADDING_NONE)
.setKeySize(KEY_SIZE)
.build()
.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
setUnlockedDeviceRequired(true)
setIsStrongBoxBacked(true)
}
}.build()


private val encryptedStorage by lazy {
Expand Down Expand Up @@ -74,7 +80,7 @@ class Pinkman(
fun isValidPin(inputPin: String): Boolean {
require(storageFile.exists()) { "PIN is not set. Please create PIN before validating." }

val storedKey = loadKeyFromStorage()
val storedKey = loadKeyFromStorage()

val inputKey = Pbkdf2Factory.createKey(
inputPin.toCharArray(),
Expand Down

0 comments on commit f0feabd

Please sign in to comment.