Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LoginActivity : AppCompatActivity(), SurelockFingerprintListener {
Surelock.Builder(this)
.withDefaultDialog(R.style.SurelockDemoDialog)
.withKeystoreAlias(KEYSTORE_KEY_ALIAS)
.withFragmentManager(fragmentManager)
.withFragmentManager(supportFragmentManager)
.withSurelockFragmentTag(FINGERPRINT_DIALOG_FRAGMENT_TAG)
.withSurelockStorage(surelockStorage)
.build()
Expand Down Expand Up @@ -288,10 +288,10 @@ class LoginActivity : AppCompatActivity(), SurelockFingerprintListener {
companion object {

private val TAG = LoginActivity::class.java.simpleName
private val FINGERPRINT_DIALOG_FRAGMENT_TAG = "com.smashingboxes.surelockdemo.FINGERPRINT_DIALOG_FRAGMENT_TAG"
private val KEYSTORE_KEY_ALIAS = "com.smashingboxes.surelockdemo.KEYSTORE_KEY_ALIAS"
private val KEY_CRE_DEN_TIALS = "com.smashingboxes.surelockdemo.KEY_CRE_DEN_TIALS"
private val SHARED_PREFS_FILE_NAME = "surelock_demo_prefs"
private val DELIMITER = "%s]%s"
private const val FINGERPRINT_DIALOG_FRAGMENT_TAG = "com.smashingboxes.surelockdemo.FINGERPRINT_DIALOG_FRAGMENT_TAG"
private const val KEYSTORE_KEY_ALIAS = "com.smashingboxes.surelockdemo.KEYSTORE_KEY_ALIAS"
private const val KEY_CRE_DEN_TIALS = "com.smashingboxes.surelockdemo.KEY_CRE_DEN_TIALS"
private const val SHARED_PREFS_FILE_NAME = "surelock_demo_prefs"
private const val DELIMITER = "%s]%s"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.smashingboxes.surelock

import android.annotation.TargetApi
import android.app.FragmentManager
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
Expand All @@ -11,6 +10,7 @@ import android.security.keystore.KeyPermanentlyInvalidatedException
import android.security.keystore.KeyProperties
import android.support.annotation.IntDef
import android.support.annotation.StyleRes
import android.support.v4.app.FragmentManager
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat
import android.util.Log
import android.widget.Toast
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.smashingboxes.surelock

import android.app.Dialog
import android.app.DialogFragment
import android.app.FragmentManager
import android.content.Context
import android.content.res.TypedArray
import android.os.Bundle
import android.support.annotation.StyleRes
import android.support.v4.app.DialogFragment
import android.support.v4.app.FragmentManager
import android.support.v4.content.ContextCompat
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat
import android.view.LayoutInflater
Expand Down Expand Up @@ -45,16 +45,16 @@ class SurelockDefaultDialog : DialogFragment(), SurelockFragment {
private var styleId: Int = 0

// TODO clean up and genericize default dialog - add custom attribute set which can be overridden
private var iconView: SwirlView? = null
private var statusTextView: TextView? = null
private lateinit var iconView: SwirlView
private lateinit var statusTextView: TextView

private val resetErrorTextRunnable = Runnable {
if (isAdded) {
statusTextView?.apply {
setTextColor(ContextCompat.getColor(activity, R.color.hint_grey))
text = resources.getString(R.string.fingerprint_hint)
statusTextView.apply {
setTextColor(ContextCompat.getColor(context, R.color.hint_grey))
text = getString(R.string.fingerprint_hint)
}
iconView?.setState(SwirlView.State.ON)
iconView.setState(SwirlView.State.ON)
}
}

Expand All @@ -80,11 +80,11 @@ class SurelockDefaultDialog : DialogFragment(), SurelockFragment {
cipherOperationMode = savedInstanceState.getInt(KEY_CIPHER_OP_MODE)
styleId = savedInstanceState.getInt(KEY_STYLE_ID)
} else {
cipherOperationMode = arguments.getInt(KEY_CIPHER_OP_MODE)
styleId = arguments.getInt(KEY_STYLE_ID)
cipherOperationMode = arguments!!.getInt(KEY_CIPHER_OP_MODE)
styleId = arguments!!.getInt(KEY_STYLE_ID)
}

val attrs = activity.obtainStyledAttributes(styleId, R.styleable
val attrs = context!!.obtainStyledAttributes(styleId, R.styleable
.SurelockDefaultDialog)
val dialogTheme = attrs.getResourceId(R.styleable.SurelockDefaultDialog_sl_dialog_theme, 0)
attrs.recycle()
Expand All @@ -96,7 +96,7 @@ class SurelockDefaultDialog : DialogFragment(), SurelockFragment {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fingerprint_dialog_container, container, false)
val attrs = activity.obtainStyledAttributes(styleId, R.styleable.SurelockDefaultDialog)
val attrs = activity!!.obtainStyledAttributes(styleId, R.styleable.SurelockDefaultDialog)

setUpViews(view, attrs)

Expand Down Expand Up @@ -160,7 +160,7 @@ class SurelockDefaultDialog : DialogFragment(), SurelockFragment {
override fun onResume() {
super.onResume()
uiHelper?.startListening(cryptoObject!!)
iconView?.setState(SwirlView.State.ON)
iconView.setState(SwirlView.State.ON)
}

override fun show(fragmentManager: FragmentManager, fingerprintDialogFragmentTag: String) {
Expand All @@ -186,35 +186,35 @@ class SurelockDefaultDialog : DialogFragment(), SurelockFragment {
}

override fun onAuthenticationSucceeded(result: FingerprintManagerCompat.AuthenticationResult?) {
iconView?.postDelayed({
iconView.postDelayed({
//TODO figure out a way to not make user have to run encryption/decryption themselves here
if (Cipher.ENCRYPT_MODE == cipherOperationMode) {
try {
val encryptedValue = cryptoObject?.cipher?.doFinal(valueToEncrypt)
keyForDecryption?.let {
if (encryptedValue != null) {
storage?.createOrUpdate(it, encryptedValue)
listener?.onFingerprintEnrolled()
}
storage?.createOrUpdate(it, encryptedValue!!)
listener?.onFingerprintEnrolled()
}
} catch (e: IllegalBlockSizeException) {
listener?.onFingerprintError(e.message)
} catch (e: BadPaddingException) {
listener?.onFingerprintError(e.message)
} catch (e: NullPointerException) {
listener?.onFingerprintError(e.message)
}

} else if (Cipher.DECRYPT_MODE == cipherOperationMode) {
val encryptedValue = storage?.get(keyForDecryption!!)
val decryptedValue: ByteArray
val decryptedValue: ByteArray?
try {
decryptedValue = cryptoObject?.cipher?.doFinal(encryptedValue) ?: ByteArray(0)
listener?.onFingerprintAuthenticated(decryptedValue)
decryptedValue = cryptoObject?.cipher?.doFinal(encryptedValue)
listener?.onFingerprintAuthenticated(decryptedValue!!)
} catch (e: BadPaddingException) {
listener?.onFingerprintError(e.message)
} catch (e: IllegalBlockSizeException) {
listener?.onFingerprintError(e.message)
} catch (e: NullPointerException) {
listener?.onFingerprintError(e.message)
}

}
dismiss()
}, SUCCESS_DELAY_MILLIS)
Expand All @@ -232,27 +232,27 @@ class SurelockDefaultDialog : DialogFragment(), SurelockFragment {
}

override fun onAuthenticationFailed() {
showError(statusTextView!!.resources.getString(R.string.fingerprint_not_recognized))
showError(getString(R.string.fingerprint_not_recognized))
listener?.onFingerprintError(null)
}

private fun showError(error: CharSequence?) {
iconView?.setState(SwirlView.State.ERROR)
statusTextView?.apply {
iconView.setState(SwirlView.State.ERROR)
statusTextView.apply {
text = error
setTextColor(ContextCompat.getColor(activity, R.color.error_red))
setTextColor(ContextCompat.getColor(context, R.color.error_red))
removeCallbacks(resetErrorTextRunnable)
postDelayed(resetErrorTextRunnable, ERROR_TIMEOUT_MILLIS)
}
}

companion object {

private val KEY_CIPHER_OP_MODE = "com.smashingboxes.surelock.SurelockDefaultDialog.KEY_CIPHER_OP_MODE"
private val KEY_STYLE_ID = "com.smashingboxes.surelock.KEY_STYLE_ID"
private const val KEY_CIPHER_OP_MODE = "com.smashingboxes.surelock.SurelockDefaultDialog.KEY_CIPHER_OP_MODE"
private const val KEY_STYLE_ID = "com.smashingboxes.surelock.KEY_STYLE_ID"

private val ERROR_TIMEOUT_MILLIS: Long = 1600
private val SUCCESS_DELAY_MILLIS: Long = 1300 //TODO make these configurable via attrs
private const val ERROR_TIMEOUT_MILLIS: Long = 1600
private const val SUCCESS_DELAY_MILLIS: Long = 1300 //TODO make these configurable via attrs

internal fun newInstance(cipherOperationMode: Int,
@StyleRes styleId: Int): SurelockDefaultDialog {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.smashingboxes.surelock

import android.app.FragmentManager
import android.support.v4.app.FragmentManager
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.smashingboxes.surelock

import android.app.DialogFragment
import android.app.FragmentManager
import android.content.Context
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v4.app.FragmentManager
import android.support.v4.content.ContextCompat
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat
import android.view.LayoutInflater
Expand All @@ -30,8 +30,8 @@ import javax.crypto.IllegalBlockSizeException

class SurelockMaterialDialog : DialogFragment(), SurelockFragment {

private var swirlView: SwirlView? = null
private var messageView: TextView? = null
private lateinit var swirlView: SwirlView
private lateinit var messageView: TextView

private var fingerprintManager: FingerprintManagerCompat? = null
private var cryptoObject: FingerprintManagerCompat.CryptoObject? = null
Expand All @@ -44,11 +44,11 @@ class SurelockMaterialDialog : DialogFragment(), SurelockFragment {

private val resetErrorTextRunnable = Runnable {
if (isAdded) {
messageView?.apply {
setTextColor(ContextCompat.getColor(activity, R.color.hint_grey))
messageView.apply {
setTextColor(ContextCompat.getColor(context, R.color.hint_grey))
text = resources.getString(R.string.fingerprint_hint)
}
swirlView?.apply {
swirlView.apply {
setState(SwirlView.State.ON)
}
}
Expand All @@ -72,8 +72,8 @@ class SurelockMaterialDialog : DialogFragment(), SurelockFragment {
// Do not create a new Fragment when the Activity is re-created such as orientation changes.
retainInstance = true

cipherOperationMode = savedInstanceState?.getInt(KEY_CIPHER_OP_MODE) ?: arguments.getInt(
KEY_CIPHER_OP_MODE)
cipherOperationMode = savedInstanceState?.getInt(KEY_CIPHER_OP_MODE) ?: arguments?.getInt(
KEY_CIPHER_OP_MODE) ?: 0

setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog)
}
Expand All @@ -94,7 +94,7 @@ class SurelockMaterialDialog : DialogFragment(), SurelockFragment {
cryptoObject?.let {
uiHelper?.startListening(it)
}
swirlView?.setState(SwirlView.State.ON)
swirlView.setState(SwirlView.State.ON)
}

override fun show(fragmentManager: FragmentManager, fingerprintDialogFragmentTag: String) {
Expand Down Expand Up @@ -140,62 +140,62 @@ class SurelockMaterialDialog : DialogFragment(), SurelockFragment {
}

override fun onAuthenticationSucceeded(result: FingerprintManagerCompat.AuthenticationResult?) {
swirlView?.postDelayed({
swirlView.postDelayed({
//TODO figure out a way to not make user have to run encryption/decryption
// themselves here
if (Cipher.ENCRYPT_MODE == cipherOperationMode) {
try {
val encryptedValue = cryptoObject?.cipher?.doFinal(valueToEncrypt)
keyForDecryption?.let {
if (encryptedValue != null) {
storage?.createOrUpdate(it, encryptedValue)
listener?.onFingerprintEnrolled()
}
storage?.createOrUpdate(it, encryptedValue!!)
listener?.onFingerprintEnrolled()
}
} catch (e: IllegalBlockSizeException) {
listener?.onFingerprintError(e.message)
} catch (e: BadPaddingException) {
listener?.onFingerprintError(e.message)
} catch (e: NullPointerException) {
listener?.onFingerprintError(e.message)
}

} else if (Cipher.DECRYPT_MODE == cipherOperationMode) {
val encryptedValue = storage?.get(keyForDecryption!!)
val decryptedValue: ByteArray
val decryptedValue: ByteArray?
try {
decryptedValue = cryptoObject?.cipher?.doFinal(encryptedValue) ?: ByteArray(0)
listener?.onFingerprintAuthenticated(decryptedValue)
decryptedValue = cryptoObject?.cipher?.doFinal(encryptedValue)
listener?.onFingerprintAuthenticated(decryptedValue!!)
} catch (e: BadPaddingException) {
listener?.onFingerprintError(e.message)
} catch (e: IllegalBlockSizeException) {
listener?.onFingerprintError(e.message)
} catch (e: NullPointerException) {
listener?.onFingerprintError(e.message)
}

}
dismiss()
}, SUCCESS_DELAY_MILLIS)
}

override fun onAuthenticationFailed() {
showError(messageView?.resources?.getString(R.string.fingerprint_not_recognized) ?: "")
showError(messageView.resources.getString(R.string.fingerprint_not_recognized))
listener?.onFingerprintError(null)
}

private fun showError(error: CharSequence?) {
swirlView?.setState(SwirlView.State.ERROR)
messageView?.apply {
swirlView.setState(SwirlView.State.ERROR)
messageView.apply {
text = error
setTextColor(ContextCompat.getColor(activity, R.color.error_red))
setTextColor(ContextCompat.getColor(context, R.color.error_red))
removeCallbacks(resetErrorTextRunnable)
postDelayed(resetErrorTextRunnable, ERROR_TIMEOUT_MILLIS)
}
}

companion object {

private val KEY_CIPHER_OP_MODE = "com.smashingboxes.surelock" + ".SurelockMaterialDialog.KEY_CIPHER_OP_MODE"
private const val KEY_CIPHER_OP_MODE = "com.smashingboxes.surelock" + ".SurelockMaterialDialog.KEY_CIPHER_OP_MODE"

private val ERROR_TIMEOUT_MILLIS: Long = 1600
private val SUCCESS_DELAY_MILLIS: Long = 1300
private const val ERROR_TIMEOUT_MILLIS: Long = 1600
private const val SUCCESS_DELAY_MILLIS: Long = 1300

internal fun newInstance(cipherOperationMode: Int): SurelockMaterialDialog {

Expand Down