6

我们已经关注Scottyab Safetynet Library

我们正面临“<strong>Status{statusCode=NETWORK_ERROR, resolution=null}”事件的错误,尽管我们的 android 设备中的 4G 互联网连接可用,包名称为com.safetynet.sample,其中示例项目使用包名称com 可以正常工作。 scottyab.safetynet.sample。我们已经检查了这个解决方案,但不起作用。

下面的代码我们遇到了这个问题

private void runSafetyNetTest() {
    Log.v(TAG, "running SafetyNet.API Test");
    requestNonce = generateOneTimeRequestNonce();
    requestTimestamp = System.currentTimeMillis();
    writeLog("running SafetyNet.API Test");
    SafetyNet.SafetyNetApi.attest(googleApiClient, requestNonce)
            .setResultCallback(new ResultCallback<SafetyNetApi.AttestationResult>() {
                                   @Override
                                   public void onResult(final SafetyNetApi.AttestationResult result) {
                                       writeLog("running SafetyNet.API Result");
                                   //result = Status{statusCode=NETWORK_ERROR, resolution=null} 
                                       if (!validateResultStatus(result)) {
                                           return;
                                       }

                                       final String jwsResult = result.getJwsResult();
                                       final SafetyNetResponse response = parseJsonWebSignature(jwsResult);
                                       lastResponse = response;
                                       writeLog("Res :: " + response);

                                       //validate payload of the response
                                       if (validateSafetyNetResponsePayload(response)) {
                                           if (!TextUtils.isEmpty(googleDeviceVerificationApiKey)) {
                                               //if the api key is set, run the AndroidDeviceVerifier
                                               AndroidDeviceVerifier androidDeviceVerifier = new AndroidDeviceVerifier(googleDeviceVerificationApiKey, jwsResult);
                                               androidDeviceVerifier.verify(new AndroidDeviceVerifier.AndroidDeviceVerifierCallback() {
                                                   @Override
                                                   public void error(String errorMsg) {
                                                       callback.error(RESPONSE_ERROR_VALIDATING_SIGNATURE, "Response signature validation error: " + errorMsg);
                                                   }

                                                   @Override
                                                   public void success(boolean isValidSignature) {
                                                       if (isValidSignature) {
                                                           callback.success(response.isCtsProfileMatch(), response.isBasicIntegrity());
                                                       } else {
                                                           callback.error(RESPONSE_FAILED_SIGNATURE_VALIDATION, "Response signature invalid");

                                                       }
                                                   }
                                               });
                                           } else {
                                               Log.w(TAG, "No google Device Verification ApiKey defined");
                                               callback.error(RESPONSE_FAILED_SIGNATURE_VALIDATION_NO_API_KEY, "No Google Device Verification ApiKey defined. Marking as failed. SafetyNet CtsProfileMatch: " + response.isCtsProfileMatch());
                                           }
                                       } else {
                                           callback.error(RESPONSE_VALIDATION_FAILED, "Response payload validation failed");
                                       }
                                   }
                               }

            );
}
4

2 回答 2

4

这可能与证明 API 已被标记为已弃用的事实有关。新的不依赖于谷歌客户端 API,你应该检查这个。Google 还发布了一个使用新 api 的示例应用程序,您可以在此处查看

于 2018-05-04T12:54:51.087 回答
0

根据这个讨论,错误API_KEY可能是错误的原因。

于 2019-07-09T12:13:11.987 回答