Skip to content

Commit 9dd88a7

Browse files
committed
keystore: Block key attestation for Google Play Services
In order to enforce SafetyNet security, Google Play Services is now using hardware attestation for ctsProfile validation in all cases, even when basic attestation is selected. The SafetyNet API response from GMS will report that basic attestation was used, but under the hood, hardware attestation is always used regardless of the reported state. This results in SafetyNet failing to pass due to TrustZone reporting an unlocked bootloader (and a partially invalidated root of trust) in the key attestation result. We can still take advantage of the fact that this usage of hardware attestation is opportunistic - that is, it falls back to basic attestation if key attestation fails to run - and prevent GMS from using key attestation at the framework level. This causes it to gracefully fall back to basic attestation and pass SafetyNet with an unlocked bootloader. Key attestation is still available for other apps, as there are valid uses for it that do not involve SafetyNet. The "not implemented" error code from keymaster is used to simulate the most realistic failure condition to evade detection, i.e. an old device that lacks support for key attestation. Change-Id: Iba5fe0791622839e1bad4730593a319ea03661f2
1 parent f681280 commit 9dd88a7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

keystore/key_store_service.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <keystore/keystore_return_types.h>
4949

5050
#include <hardware/hw_auth_token.h>
51+
#include <hardware/keymaster_defs.h>
5152

5253
namespace keystore {
5354

@@ -122,8 +123,12 @@ KeyStoreServiceReturnCode updateParamsForAttestation(uid_t callingUid, Authoriza
122123

123124
auto asn1_attestation_id_result = security::gather_attestation_application_id(callingUid);
124125
if (!asn1_attestation_id_result.isOk()) {
125-
ALOGE("failed to gather attestation_id");
126-
return ErrorCode::ATTESTATION_APPLICATION_ID_MISSING;
126+
if (asn1_attestation_id_result.status() == KM_ERROR_UNIMPLEMENTED) {
127+
return KeyStoreServiceReturnCode(KM_ERROR_UNIMPLEMENTED);
128+
} else {
129+
ALOGE("failed to gather attestation_id");
130+
return ErrorCode::ATTESTATION_APPLICATION_ID_MISSING;
131+
}
127132
}
128133
std::vector<uint8_t>& asn1_attestation_id = asn1_attestation_id_result;
129134

keystore/keystore_attestation_id.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <keystore/KeyAttestationPackageInfo.h>
3535
#include <keystore/Signature.h>
3636

37+
#include <hardware/keymaster_defs.h>
38+
3739
#include <private/android_filesystem_config.h> /* for AID_SYSTEM */
3840

3941
#include <openssl/asn1t.h>
@@ -209,6 +211,10 @@ build_attestation_application_id(const KeyAttestationApplicationId& key_attestat
209211
return BAD_VALUE;
210212
}
211213
std::string package_name(String8(*pinfo->package_name()).string());
214+
// Prevent Google Play Services from using key attestation for SafetyNet
215+
if (package_name == "com.google.android.gms") {
216+
return KM_ERROR_UNIMPLEMENTED;
217+
}
212218
std::unique_ptr<KM_ATTESTATION_PACKAGE_INFO> attestation_package_info;
213219
auto rc = build_attestation_package_info(*pinfo, &attestation_package_info);
214220
if (rc != NO_ERROR) {

0 commit comments

Comments
 (0)