尝试在最新的 Play-Services v11.0.1 中使用SafetyNetClient.attest(...)进行证明时,客户端出错并返回 ApiException。
代码片段:
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();
}
日志输出:
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)
我在这里想念什么?