Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

AttestationStatement.java getApkDigestSha256() does not properly handle null #19

Open
dphillipsprosper opened this issue Mar 21, 2019 · 0 comments

Comments

@dphillipsprosper
Copy link

dphillipsprosper commented Mar 21, 2019

According to the docs at https://developer.android.com/training/safetynet/attestation:

If the device is tampered—that is, if basicIntegrity is set to false in the response—the verdict might not contain data about the calling app, such as the apkPackageName and apkCertificateDigestSha256. This occurs when our systems cannot reliably determine the calling app.

Sure enough, I've got a test device w/ Magisk right now, that is failing SafetyNet. I get an attestation response like so:

{
  "nonce": "Y2MyOGQ2YWEtNzA5Yi00ODUyLTk2MTItZGU4N2EwMDFlZDRh",
  "timestampMs": 1553123841535,
  "ctsProfileMatch": false,
  "apkCertificateDigestSha256": [],
  "basicIntegrity": false,
  "advice": "RESTORE_TO_FACTORY_ROM"
}

However, the getApkDigestSha256() property in the AttestationStatement.java example file for offline server validation does not take this null into account.

public byte[] getApkDigestSha256() {
    return Base64.decodeBase64(apkDigestSha256);
}

So, if you call this property on a failing device, it explodes.

The fix is simple, we just need a null check:

public byte[] getApkDigestSha256() {
    return apkDigestSha256 != null ? Base64.decodeBase64(apkDigestSha256) : new byte[0];
}

I've fixed this locally, filing this so I can contribute the fix.

@dphillipsprosper dphillipsprosper changed the title AttestationStatement.java getApkDigestSha256() does not properly handle null AttestationStatement.java getApkDigestSha256() does not properly handle null Mar 21, 2019
dphillipsprosper added a commit to dphillipsprosper/android-play-safetynet that referenced this issue Mar 21, 2019
`getApkDigestSha256()` now null checks the backing field, and if is null, returns an empty byte array
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant