Android SafetyNetClient.Attest(…) Returns ApiException

南笙酒味 提交于 2019-12-06 14:12:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!