From 3d1040139aa3872740b0a3d33d86c54d61bb0964 Mon Sep 17 00:00:00 2001 From: BlackMesa123 Date: Tue, 20 Jun 2023 21:24:37 +0200 Subject: [PATCH] app: support SAK from api 29 and above Signed-off-by: BlackMesa123 --- .../vvb2060/keyattestation/home/HomeViewModel.kt | 3 ++- .../security/keystore/AttestParameterSpec.java | 5 ++++- .../android/security/keystore/AttestationUtils.java | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeViewModel.kt b/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeViewModel.kt index 864e1f4..8dca8df 100644 --- a/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeViewModel.kt +++ b/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeViewModel.kt @@ -61,7 +61,8 @@ class HomeViewModel(pm: PackageManager) : ViewModel() { @Throws(GeneralSecurityException::class) private fun generateKey(alias: String, useStrongBox: Boolean, includeProps: Boolean) { - if (SamsungUtils.isSecAttestationSupported()) { + if (Build.VERSION.SDK_INT >= 29 && + SamsungUtils.isSecAttestationSupported()) { val now = Date() val originationEnd = Date(now.time + 1000000) val consumptionEnd = Date(now.time + 2000000) diff --git a/stub/src/main/java/com/samsung/android/security/keystore/AttestParameterSpec.java b/stub/src/main/java/com/samsung/android/security/keystore/AttestParameterSpec.java index ef196e1..09f8a9d 100644 --- a/stub/src/main/java/com/samsung/android/security/keystore/AttestParameterSpec.java +++ b/stub/src/main/java/com/samsung/android/security/keystore/AttestParameterSpec.java @@ -1,9 +1,10 @@ package com.samsung.android.security.keystore; import android.security.keystore.KeyGenParameterSpec; - +import androidx.annotation.RequiresApi; import javax.security.auth.x500.X500Principal; +@RequiresApi(29) public class AttestParameterSpec { public AttestParameterSpec(String algorithm, byte[] challenge, boolean reqAttestDevice, boolean checkIntegrity, boolean devicePropertiesAttestationIncluded, @@ -38,6 +39,7 @@ public boolean isVerifiableIntegrity() { throw new RuntimeException("Stub!"); } + @RequiresApi(33) public boolean isDevicePropertiesAttestationIncluded() { throw new RuntimeException("Stub!"); } @@ -71,6 +73,7 @@ public Builder setVerifiableIntegrity(boolean checked) { throw new RuntimeException("Stub!"); } + @RequiresApi(33) public Builder setDevicePropertiesAttestationIncluded( boolean devicePropertiesAttestationIncluded) { throw new RuntimeException("Stub!"); diff --git a/stub/src/main/java/com/samsung/android/security/keystore/AttestationUtils.java b/stub/src/main/java/com/samsung/android/security/keystore/AttestationUtils.java index 642455c..a831230 100644 --- a/stub/src/main/java/com/samsung/android/security/keystore/AttestationUtils.java +++ b/stub/src/main/java/com/samsung/android/security/keystore/AttestationUtils.java @@ -1,13 +1,14 @@ package com.samsung.android.security.keystore; import android.content.Context; - +import androidx.annotation.RequiresApi; import java.security.Key; import java.security.KeyPair; import java.security.KeyStoreException; import java.security.ProviderException; import java.security.cert.Certificate; +@RequiresApi(28) public class AttestationUtils { public static final String DEFAULT_KEYSTORE = "AndroidKeyStore"; public static final String PUBKEY_DIGEST_ALGORITHM = "SHA-256"; @@ -17,6 +18,7 @@ public Iterable attestKey(String alias, byte[] challenge) throw new RuntimeException("Stub!"); } + @RequiresApi(29) public Iterable attestKey(AttestParameterSpec spec) throws IllegalArgumentException, ProviderException, NullPointerException { throw new RuntimeException("Stub!"); @@ -28,6 +30,7 @@ public Iterable attestDevice(String alias, byte[] challenge) throw new RuntimeException("Stub!"); } + @RequiresApi(29) public Iterable attestDevice(AttestParameterSpec spec) throws IllegalArgumentException, ProviderException, NullPointerException, DeviceIdAttestationException { @@ -39,28 +42,34 @@ public void storeCertificateChain(String alias, Iterable iterable) throw new RuntimeException("Stub!"); } + @RequiresApi(29) public KeyPair generateKeyPair(String alias, byte[] challenge) throws IllegalArgumentException, ProviderException, NullPointerException { throw new RuntimeException("Stub!"); } + @RequiresApi(29) public KeyPair generateKeyPair(AttestParameterSpec spec) throws IllegalArgumentException, ProviderException, NullPointerException { throw new RuntimeException("Stub!"); } + @RequiresApi(29) public Certificate[] getCertificateChain(String alias) { throw new RuntimeException("Stub!"); } + @RequiresApi(29) public Key getKey(String alias) throws KeyStoreException { throw new RuntimeException("Stub!"); } + @RequiresApi(29) public void deleteKey(String alias) throws KeyStoreException { throw new RuntimeException("Stub!"); } + @RequiresApi(33) public boolean isSupportDeviceAttestation(Context context) { throw new RuntimeException("Stub!"); }