Skip to content

Commit

Permalink
raise minimum API level to 31 (Android 12)
Browse files Browse the repository at this point in the history
Android 12 is the oldest release with security support and also the
oldest release supported by our App Store.
  • Loading branch information
thestinger committed Jul 27, 2024
1 parent 2f354e7 commit 024b19f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ android {

defaultConfig {
applicationId = "app.attestation.auditor"
minSdk = 29
minSdk = 31
targetSdk = 34
versionCode = 81
versionName = versionCode.toString()
Expand Down
24 changes: 5 additions & 19 deletions app/src/main/java/app/attestation/auditor/AttestationProtocol.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.attestation.auditor;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
Expand Down Expand Up @@ -1362,11 +1361,6 @@ static class AttestationResult {
}
}

@TargetApi(31)
static void setAttestKeyAlias(final KeyGenParameterSpec.Builder builder, final String alias) {
builder.setAttestKeyAlias(alias);
}

static KeyGenParameterSpec.Builder getKeyBuilder(final String alias, final int purposes,
final boolean useStrongBox, final byte[] challenge, final boolean temporary) {
final Date startTime = new Date(new Date().getTime() - CLOCK_SKEW_MS);
Expand All @@ -1384,7 +1378,6 @@ static KeyGenParameterSpec.Builder getKeyBuilder(final String alias, final int p
return builder;
}

@TargetApi(31)
static void generateAttestKey(final String alias, final byte[] challenge, final boolean useStrongBox) throws
GeneralSecurityException, IOException {
generateKeyPair(getKeyBuilder(alias, KeyProperties.PURPOSE_ATTEST_KEY,
Expand Down Expand Up @@ -1461,17 +1454,10 @@ static AttestationResult generateSerialized(final Context context, final byte[]
keyStore.deleteEntry(freshKeyStoreAlias);
attestationKeystoreAlias = freshKeyStoreAlias;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
final PrivateKey key = (PrivateKey) keyStore.getKey(persistentKeystoreAlias, null);
final KeyFactory factory = KeyFactory.getInstance(key.getAlgorithm(), "AndroidKeyStore");
final KeyInfo keyinfo = factory.getKeySpec(key, KeyInfo.class);
useStrongBox = keyinfo.getSecurityLevel() == KeyProperties.SECURITY_LEVEL_STRONGBOX;
} else {
final X509Certificate persistent =
(X509Certificate) getCertificate(keyStore, persistentKeystoreAlias);
final String dn = persistent.getIssuerX500Principal().getName(X500Principal.RFC1779);
useStrongBox = dn.contains("StrongBox");
}
final PrivateKey key = (PrivateKey) keyStore.getKey(persistentKeystoreAlias, null);
final KeyFactory factory = KeyFactory.getInstance(key.getAlgorithm(), "AndroidKeyStore");
final KeyInfo keyinfo = factory.getKeySpec(key, KeyInfo.class);
useStrongBox = keyinfo.getSecurityLevel() == KeyProperties.SECURITY_LEVEL_STRONGBOX;

final boolean hasAttestKey = keyStore.containsAlias(attestKeystoreAlias);
if (hasAttestKey) {
Expand All @@ -1498,7 +1484,7 @@ static AttestationResult generateSerialized(final Context context, final byte[]
KeyProperties.PURPOSE_SIGN | KeyProperties.PURPOSE_VERIFY, useStrongBox, challenge,
hasPersistentKey);
if (useAttestKey) {
setAttestKeyAlias(builder, attestKeystoreAlias);
builder.setAttestKeyAlias(attestKeystoreAlias);
}
generateKeyPair(builder.build());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.attestation.auditor;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand Down Expand Up @@ -109,9 +108,7 @@ static void schedule(final Context context, int interval) {
.setPersisted(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setEstimatedNetworkBytes(ESTIMATED_DOWNLOAD_BYTES, ESTIMATED_UPLOAD_BYTES);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
builder.setExpedited(true);
}
builder.setExpedited(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
builder.setPriority(JobInfo.PRIORITY_MAX);
}
Expand Down

0 comments on commit 024b19f

Please sign in to comment.