1

While attempting to attest with SafetyNetClient.attest(...) in the latest Play-Services v11.0.1, the client errors out and returns an ApiException.

code snippet:

byte[] nonce = getRequestNonce();
String apiKey = "<api key>";
mSafetyNetClient.attest(nonce, apiKey)
        .addOnCompleteListener(new OnCompleteListener<SafetyNetApi.AttestationResponse>() {
            @Override
            public void onComplete(@NonNull Task<SafetyNetApi.AttestationResponse> task) {
            ...
            }
        });
...
private byte[] getRequestNonce() {
    String nonceData = "Safety Net Sample: " + System.currentTimeMillis();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    byte[] bytes = new byte[24];
    mRandom.nextBytes(bytes);
    try {
        byteStream.write(bytes);
        byteStream.write(nonceData.getBytes());
    } catch (IOException e) {
        return null;
    }

    return byteStream.toByteArray();
}

Logcat output:

06-20 16:43:57.987 18222-18222/com.example.test W/System.err: com.google.android.gms.common.api.ApiException
06-20 16:43:57.987 18222-18222/com.example.test W/System.err:     at com.google.android.gms.common.internal.zzb.zzx(Unknown Source)
06-20 16:43:57.987 18222-18222/com.example.test W/System.err:     at com.google.android.gms.common.internal.zzbi.zzy(Unknown Source)
06-20 16:43:57.987 18222-18222/com.example.test W/System.err:     at com.google.android.gms.common.internal.zzbj.zzo(Unknown Source)
06-20 16:43:57.987 18222-18222/com.example.test W/System.err:     at com.google.android.gms.internal.zzbbd.zzb(Unknown Source)
06-20 16:43:57.987 18222-18222/com.example.test W/System.err:     at com.google.android.gms.internal.zzbbd.setResult(Unknown Source)
06-20 16:43:57.988 18222-18222/com.example.test W/System.err:     at com.google.android.gms.internal.zzcsh.zza(Unknown Source)
06-20 16:43:57.988 18222-18222/com.example.test W/System.err:     at com.google.android.gms.internal.zzcrw.onTransact(Unknown Source)
06-20 16:43:57.988 18222-18222/com.example.test W/System.err:     at android.os.Binder.execTransact(Binder.java:565)

What am I missing here?

abielita
  • 13,147
  • 2
  • 17
  • 59
Wilson
  • 11
  • 2
  • [`ApiException`](https://developers.google.com/android/reference/com/google/android/gms/common/api/ApiException) is an exception to be returned by a Task when a call to Google Play services has failed. You may refer with this [thread](https://stackoverflow.com/questions/34478757/after-upgrading-to-google-play-services-8-4-0-my-app-crashes-on-startup) for a possible workaround which is to redownload SDK, synced everything and then it ran again. – abielita Jun 21 '17 at 15:51
  • I get the same if I set the `key restriction` to `android apps` in the google api console – Dori Jul 14 '17 at 20:49

0 Answers0