Skip to content

Commit f106ca4

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 2d6ff19 commit f106ca4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

keystore/key_store_service.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "keystore_utils.h"
4040
#include <keystore/keystore_hidl_support.h>
4141

42+
#include <hardware/keymaster_defs.h>
43+
4244
namespace keystore {
4345

4446
using namespace android;
@@ -103,8 +105,12 @@ KeyStoreServiceReturnCode updateParamsForAttestation(uid_t callingUid, Authoriza
103105

104106
auto asn1_attestation_id_result = security::gather_attestation_application_id(callingUid);
105107
if (!asn1_attestation_id_result.isOk()) {
106-
ALOGE("failed to gather attestation_id");
107-
return ErrorCode::ATTESTATION_APPLICATION_ID_MISSING;
108+
if (asn1_attestation_id_result.status() == KM_ERROR_UNIMPLEMENTED) {
109+
return KeyStoreServiceReturnCode(ErrorCode(KM_ERROR_UNIMPLEMENTED));
110+
} else {
111+
ALOGE("failed to gather attestation_id");
112+
return ErrorCode::ATTESTATION_APPLICATION_ID_MISSING;
113+
}
108114
}
109115
std::vector<uint8_t>& asn1_attestation_id = asn1_attestation_id_result;
110116

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 <openssl/asn1t.h>
3840
#include <openssl/sha.h>
3941

@@ -165,6 +167,10 @@ build_attestation_application_id(const KeyAttestationApplicationId& key_attestat
165167
return BAD_VALUE;
166168
}
167169
std::string package_name(String8(*pinfo->package_name()).string());
170+
// Prevent Google Play Services from using key attestation for SafetyNet
171+
if (package_name == "com.google.android.gms") {
172+
return KM_ERROR_UNIMPLEMENTED;
173+
}
168174
std::unique_ptr<KM_ATTESTATION_PACKAGE_INFO> attestation_package_info;
169175
auto rc = build_attestation_package_info(*pinfo, &attestation_package_info);
170176
if (rc != NO_ERROR) {

0 commit comments

Comments
 (0)