问题
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?
来源:https://stackoverflow.com/questions/44664980/android-safetynetclient-attest-returns-apiexception