Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safety environment check in android using SafetyNet Attestation API is not working as it not getting callback on success or failure callback

For saftey environment check in android I was using

https://developer.android.com/training/safetynet/attestation.html

SafetyNet.getClient(this).attest(nonce, API_KEY)
   .addOnSuccessListener(this,successListner)
   .addOnFailureListener(this,failureListener)

for which I am getting failure callback with network error null. Can anybody please throw some light on this ?

but https://medium.com/@hargoyal/secure-android-app-with-safetynet-8e367a1c8ad0

SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
                .setResultCallback(new ResultCallback<SafetyNetApi.AttestationResult>() {
                    @Override
                    public void onResult(SafetyNetApi.AttestationResult result) {
                        Status status = result.getStatus();
                        if (status.isSuccess()) {
                            decodeJws(result.getJwsResult());
                            // Indicates communication with the service was successful.
                            // Use result.getJwsResult() to get the result data.
                        } else {
                            // An error occurred while communicating with the service.
                        }
                    }
                });

this approach is working but SafetyNet.SafetyNetApi is deprecated.

like image 361
Syamkrishnan Ck Avatar asked Feb 02 '26 08:02

Syamkrishnan Ck


1 Answers

Recheck the API key or create a new one like here. I was having the same issue and the problem was that I was restricting the key to the wrong package name.

  • Go to the Library page in the Google APIs Console.
  • Search for the Android Device Verification API. When you've found the API, click on it. The Android Device Verification API dashboard screen appears.
  • If the API isn't already enabled, click Enable.
  • If the Create credentials button appears, click on it to generate an API key. Otherwise, click the All API credentials drop-down list and select the API key that is associated with the project for which the Android Device Verification API is enabled.
  • In the sidebar on the left, click Credentials. Copy the API key that appears.
like image 87
Bobstring Avatar answered Feb 04 '26 01:02

Bobstring