gpt4 book ai didi

android - SafetyNet 证明因内部错误而失败

转载 作者:行者123 更新时间:2023-11-29 02:40:23 24 4
gpt4 key购买 nike

我想使用 SafetyNet Attestation API (请注意,该文档似乎已过时,因为它使用的方法已被弃用)。使用最新版本的 Play Services (11.0.1) 我想出了以下代码:

SecureRandom secureRandom = new SecureRandom();
byte[] nonce = new byte[16];
secureRandom.nextBytes(nonce); // just some random bytes for testing

SafetyNet.getClient(this)
.attest(nonce, API_KEY)
.addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
SafetyNetApi.AttestationResponse result = task.getResult();
String jws = result.getJwsResult();
Log.d(TAG, "JWS: " + jws);
} else {
Exception e = task.getException();

if (e instanceof ApiException) {
Log.e(TAG, "Attestation failure: " + ((ApiException) e).getStatusMessage() + ", code: " + ((ApiException) e).getStatusCode(), e);
} else {
Log.e(TAG, "Attestation failure: " + e, e);
}
}
});

其中 API_KEY 是来自 Google Developer Console 的 API key 。此代码在 ActivityonCreate(...) 中调用。无论我尝试什么,它都会导致失败,并且 eApiException 的一个实例,但它不会提供任何关于出错的有用信息,因为状态消息是 null 状态代码为 8,根据 the documentation - 是一个“内部错误”。我试图延迟 5 秒调用它,但没有成功。测试设备具有 API 24 和 Google Play 服务 11.0.55。

有谁知道出了什么问题,解决方案是什么?


编辑:旧的 SafetyNet.SafetyNetApi.attest(googleApiClient, nonce) 方法似乎工作正常,但它已被弃用,所以我不想使用它。

最佳答案

基于此thread , 如果您收到错误代码 8 (INTERNAL_ERROR),请仔细检查您在开发控制台中的应用注册。请注意,每个已注册的 Android 客户端都由(包名称、Android 签名证书 SHA-1)对唯一标识。如果您的调试和生产环境有多个包名称/签名证书,请确保注册每一对。

To verify:

  1. Open the Credentials page and select your project
  2. Make sure every pair has an Android typed OAuth 2.0 client IDs. To create a new OAuth 2.0 client ID for your Android client, select New Credentials->OAuth2 Client ID from the dropdown, select Android and input your Package name / Signing-certificate fingerprint there.

如果它不起作用,我建议您联系 Google Play 团队寻求帮助。您可以通过此处的链接联系他们:https://support.google.com/googleplay#topic=3364260&contact=1 .

关于android - SafetyNet 证明因内部错误而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44598587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com