Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vvb2060 committed Nov 7, 2021
1 parent 9cf72e9 commit 2087e70
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="io.github.vvb2060.keyattestation">

<application
Expand All @@ -8,7 +9,8 @@
android:label="@string/app_name"
android:roundIcon="@drawable/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="AllowBackup">
<activity
android:name=".home.HomeActivity"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import rikka.material.app.DayNightDelegate
class AppApplication : Application() {
companion object {
const val TAG = "KeyAttestation"
lateinit var App: Application
lateinit var App: Application private set
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HomeViewModel(context: Context) : ViewModel() {
var preferIncludeProps = true

@Throws(GeneralSecurityException::class)
private fun generateKey(alias: String, useStrongBox: Boolean, incloudProps: Boolean) {
private fun generateKey(alias: String, useStrongBox: Boolean, includeProps: Boolean) {
val keyPairGenerator = KeyPairGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore")
val now = Date()
Expand All @@ -53,7 +53,7 @@ class HomeViewModel(context: Context) : ViewModel() {
.setKeyValidityForOriginationEnd(originationEnd)
.setKeyValidityForConsumptionEnd(consumptionEnd)
.setAttestationChallenge(now.toString().toByteArray())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && incloudProps) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && includeProps) {
builder.setDevicePropertiesAttestationIncluded(true)
}
if (Build.VERSION.SDK_INT >= 28 && useStrongBox) {
Expand All @@ -65,15 +65,15 @@ class HomeViewModel(context: Context) : ViewModel() {
}

@Throws(AttestationException::class)
private fun doAttestation(alias: String, useStrongBox: Boolean, incloudProps: Boolean
private fun doAttestation(alias: String, useStrongBox: Boolean, includeProps: Boolean
): AttestationResult {
val certs: Array<X509Certificate?>?
val attestation: Attestation
val isGoogleRootCertificate: Boolean
try {
val keyStore = KeyStore.getInstance("AndroidKeyStore")
keyStore.load(null)
generateKey(alias, useStrongBox, incloudProps)
generateKey(alias, useStrongBox, includeProps)
val certificates = keyStore.getCertificateChain(alias)
certs = arrayOfNulls(certificates.size)
for (i in certs.indices) certs[i] = certificates[i] as X509Certificate
Expand Down Expand Up @@ -112,10 +112,10 @@ class HomeViewModel(context: Context) : ViewModel() {

withContext(Dispatchers.IO) {
val useStrongBox = hasStrongBox && preferStrongBox
val incloudProps = hasDeviceIds && preferIncludeProps
val includeProps = hasDeviceIds && preferIncludeProps
val result = try {
val alias = "Key_${useStrongBox}_$incloudProps"
val attestationResult = doAttestation(alias, useStrongBox, incloudProps)
val alias = "Key_${useStrongBox}_$includeProps"
val attestationResult = doAttestation(alias, useStrongBox, includeProps)
Resource.success(attestationResult)
} catch (e: Throwable) {
val cause = if (e is AttestationException) e.cause!! else e
Expand Down

0 comments on commit 2087e70

Please sign in to comment.