Java SafetyNet类代码示例

本文整理汇总了Java中com.google.android.gms.safetynet.SafetyNet的典型用法代码示例。如果您正苦于以下问题:Java SafetyNet类的具体用法?Java SafetyNet怎么用?Java SafetyNet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Java SafetyNet类代码示例

SafetyNet类属于com.google.android.gms.safetynet包,在下文中一共展示了SafetyNet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onCreate

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);

    client = new GoogleApiClient.Builder(this)
            .addApi(SafetyNet.API)
            .enableAutoManage(this, this)
            .build();

    binding.root.setText(new RootBeer(this).isRooted() ? "Device is rooted" : "Device isn't rooted");
    binding.installation.setText(InstallationChecker.verifyInstaller(this) ? "Installed from Play Store" : "Installed from unknown source");

    binding.enviroment.setText((EnvironmentChecker.alternativeIsEmulator() ? "Running on an emulator" : "Running on a device")
            + (EnvironmentChecker.isDebuggable(this) ? " with debugger" : ""));

    binding.tampering.setText((InstallationChecker.checkPackage(this) ?
            "The package is consistent" : "The package was modified")
            + (SignatureUtils.checkSignature(this) ? " and the signature is ok" : " and the signature was changed!"));

    binding.setController(this);
} 
开发者ID:rafaeltoledo,项目名称:android-security,代码行数:23,代码来源:MainActivity.java

示例2: getJws

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
public String getJws(Context ctx, byte[] nonce) throws
                                                AttestationFailedException,
                                                GAPIClientFailedException
{
    GoogleApiClient gApiClient = this.prepareGoogleApiClient(ctx);
    ConnectionResult cr = gApiClient.blockingConnect();
    // That does not necessarily work on every version, most common error is outdated
    // version of google play services
    if (!cr.isSuccess()) {
        Log.d("snet", String.valueOf(cr.getErrorCode()));
        throw new GAPIClientFailedException();
    }

    SafetyNetApi.AttestationResult attestationResult =
            SafetyNet.SafetyNetApi.attest(gApiClient, nonce).await();
    Status status = attestationResult.getStatus();
    if (status.isSuccess()) {
        return attestationResult.getJwsResult();
    } else {
        throw new AttestationFailedException();
    }
} 
开发者ID:cigital,项目名称:safetynet-app,代码行数:23,代码来源:SafetyNetWrapper.java

示例3: requestSafetyNetCheck

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
@Override
public void requestSafetyNetCheck() {
    byte[] nonce = getRequestNonce();
    SafetyNet.SafetyNetApi.attest(client, nonce)
            .setResultCallback(result -> {
                if (result.getStatus().isSuccess()) {
                    showSafetyNetResult(result.getJwsResult());
                } else {
                    Log.e(TAG, "Error on SafetyNet request - Code ("
                            + result.getStatus().getStatusCode() + "): " +
                            "" + result.getStatus().getStatusMessage());
                }
            });
} 
开发者ID:rafaeltoledo,项目名称:android-security,代码行数:15,代码来源:MainActivity.java

示例4: SafetyNetUtils

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
public SafetyNetUtils(Context ctx, Callback callback) {
    this.ctx = ctx;
    this.callback = callback;

    GoogleApiClient.OnConnectionFailedListener googleApiConnectionFailedListener = connectionResult -> Log.e(TAG, "onConnectionFailed:" + connectionResult.toString());
    GoogleApiClient.ConnectionCallbacks googleApiConnectionCallbacks = new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            String logs = bundle == null ? "" : bundle.toString();
            callback.onResponse("GoogleApiClient onConnected " + logs);
        }

        @Override
        public void onConnectionSuspended(int i) {
            Log.d(TAG, "onConnectionSuspended" + i);
        }
    };


    Handler handler = new Handler(MyApplication.INSTANCE.safetyNetLooper.getLooper());
    googleApiClient = new GoogleApiClient.Builder(ctx)
            .addApi(SafetyNet.API)
            .addConnectionCallbacks(googleApiConnectionCallbacks)
            .addOnConnectionFailedListener(googleApiConnectionFailedListener)
            .setHandler(handler) //Run on a new thread
            .build();
    googleApiClient.connect();
    secureRandom = new SecureRandom();
} 
开发者ID:Catherine22,项目名称:SecuritySample,代码行数:30,代码来源:SafetyNetUtils.java

示例5: initClient

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
private void initClient() {

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(SafetyNet.API)
                .addConnectionCallbacks(this)
                .build();

        mGoogleApiClient.connect();
    } 
开发者ID:Learn2Crack,项目名称:safetynet,代码行数:10,代码来源:MainActivity.java

示例6: initReCaptcha

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
private void initReCaptcha() {
    mGoogleApiClient = new GoogleApiClient.Builder(context)
            .addApi(SafetyNet.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    mGoogleApiClient.connect();
} 
开发者ID:sumitsahoo,项目名称:reCAPTCHADemo,代码行数:10,代码来源:ReCaptchaVerification.java

示例7: verifyUser

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
private void verifyUser() {
    SafetyNet.SafetyNetApi.verifyWithRecaptcha(mGoogleApiClient, Util.SITE_KEY)
            .setResultCallback(
                    new ResultCallback<SafetyNetApi.RecaptchaTokenResult>() {
                        @Override
                        public void onResult(SafetyNetApi.RecaptchaTokenResult result) {
                            Status status = result.getStatus();
                            if ((status != null) && status.isSuccess()) {
                                handleSuccess(result.getTokenResult());
                            } else {
                                handleError(status);
                            }
                        }
                    });
} 
开发者ID:sumitsahoo,项目名称:reCAPTCHADemo,代码行数:16,代码来源:ReCaptchaVerification.java

示例8: sendSafetyNetRequest

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
private void sendSafetyNetRequest() {
    Log.i(TAG, "Sending SafetyNet API request.");

     /*
    Create a nonce for this request.
    The nonce is returned as part of the response from the
    SafetyNet API. Here we append the string to a number of random bytes to ensure it larger
    than the minimum 16 bytes required.
    Read out this value and verify it against the original request to ensure the
    response is correct and genuine.
    NOTE: A nonce must only be used once and a different nonce should be used for each request.
    As a more secure option, you can obtain a nonce from your own server using a secure
    connection. Here in this sample, we generate a String and append random bytes, which is not
    very secure. Follow the tips on the Security Tips page for more information:
    https://developer.android.com/training/articles/security-tips.html#Crypto
     */
    // TODO(developer): Change the nonce generation to include your own, used once value,
    // ideally from your remote server.
    String nonceData = "Safety Net Sample: " + System.currentTimeMillis();
    byte[] nonce = getRequestNonce(nonceData);

    /*
     Call the SafetyNet API asynchronously.
     The result is returned through the success or failure listeners.
     First, get a SafetyNetClient for the foreground Activity.
     Next, make the call to the attestation API. The API key is specified in the gradle build
     configuration and read from the gradle.properties file.
     */
    SafetyNetClient client = SafetyNet.getClient(getActivity());
    Task<SafetyNetApi.AttestationResponse> task = client.attest(nonce, BuildConfig.API_KEY);

    task.addOnSuccessListener(getActivity(), mSuccessListener)
            .addOnFailureListener(getActivity(), mFailureListener);

} 
开发者ID:googlesamples,项目名称:android-play-safetynet,代码行数:36,代码来源:SafetyNetSampleFragment.java

示例9: requestTest

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
public void requestTest() {
    if (isRunning)
        return;
    // Connect Google Service
    mGoogleApiClient = new GoogleApiClient.Builder(mActivity)
        .enableAutoManage(mActivity, this)
        .addApi(SafetyNet.API)
        .addConnectionCallbacks(this)
        .build();
    mGoogleApiClient.connect();
    isRunning = true;
} 
开发者ID:bhb27,项目名称:isu,代码行数:13,代码来源:SafetyNetHelper.java

示例10: onConnected

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.d(Constants.TAG, "SN: Google API Connected");
    // Create nonce
    byte[] nonce = new byte[24];
    new SecureRandom().nextBytes(nonce);

    Log.d(Constants.TAG, "SN: Check with nonce: " + Base64.encodeToString(nonce, Base64.DEFAULT));

    // Call SafetyNet
    SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
        .setResultCallback(result-> {
            Status status = result.getStatus();
            if (status.isSuccess()) {
                String json = new String(Base64.decode(result.getJwsResult().split("\\.")[1], Base64.DEFAULT));
                Log.d(Constants.TAG, "SN: Response: " + json);
                try {
                    JSONObject decoded = new JSONObject(json);
                    ret.ctsProfile = decoded.getBoolean("ctsProfileMatch");
                    ret.basicIntegrity = decoded.getBoolean("basicIntegrity");
                    ret.failed = false;
                } catch (JSONException e) {
                    Log.d(Constants.TAG, "SN: result JSONException");
                    ret.errmsg = mActivity.getString(R.string.safetyNet_res_invalid);
                }
            } else {
                Log.d(Constants.TAG, "SN: No response");
                ret.errmsg = mActivity.getString(R.string.safetyNet_no_response);
            }
            // Disconnect
            mGoogleApiClient.stopAutoManage(mActivity);
            mGoogleApiClient.disconnect();
            isRunning = false;
            handleResults(ret);
        });
} 
开发者ID:bhb27,项目名称:isu,代码行数:37,代码来源:SafetyNetHelper.java

示例11: sendSafetyNetRequest

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
public void sendSafetyNetRequest(String nonceData, ResultCallback result) {
    Log.d(TAG, "Sending SafetyNet API request.");

    byte[] nonce = getRequestNonce(nonceData);

    // Call the SafetyNet API asynchronously. The result is returned through the result callback.
    SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
            .setResultCallback(result);
} 
开发者ID:guardianproject,项目名称:proofmode,代码行数:10,代码来源:SafetyNetCheck.java

示例12: buildGoogleApiClient

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
/**
 * Constructs an automanaged {@link GoogleApiClient} for the {@link SafetyNet#API}.
 */
public static synchronized void buildGoogleApiClient(Context context) {
    mGoogleApiClient = new GoogleApiClient.Builder(context)
            .addApi(SafetyNet.API)
            .build();
    mGoogleApiClient.connect();
} 
开发者ID:guardianproject,项目名称:proofmode,代码行数:10,代码来源:SafetyNetCheck.java

示例13: run

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
@Override public void run() {
  running = true;
  googleApiClient = new GoogleApiClient.Builder(context)
      .addOnConnectionFailedListener(this)
      .addConnectionCallbacks(this)
      .addApi(SafetyNet.API)
      .build();
  googleApiClient.connect();
} 
开发者ID:jrummyapps,项目名称:SafetyNetHelper,代码行数:10,代码来源:SafetyNetHelper.java

示例14: buildGoogleApiClient

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
private GoogleApiClient buildGoogleApiClient() {
    return new GoogleApiClient.Builder(getActivity())
            .addApi(SafetyNet.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
} 
开发者ID:googlesamples,项目名称:android-testdpc,代码行数:8,代码来源:SafetyNetFragment.java

示例15: runSaftyNetTest

import com.google.android.gms.safetynet.SafetyNet; //导入依赖的package包/类
private void runSaftyNetTest() {
    final byte[] nonce = generateNonce();
    SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
            .setResultCallback(new ResultCallbacks<AttestationResult>() {
                @Override
                public void onSuccess(@NonNull AttestationResult attestationResult) {
                    if (isDetached()) {
                        return;
                    }
                    final String jws = attestationResult.getJwsResult();
                    try {
                        final JSONObject jsonObject = retrievePayloadFromJws(jws);
                        final String jsonString = jsonObject.toString(4);
                        final String verifyOnServerString
                                = getString(R.string.safetynet_verify_on_server);
                        updateMessageView(verifyOnServerString + "\n" + jsonString, false);
                    } catch (JSONException ex) {
                        updateMessageView(R.string.safetynet_fail_reason_invalid_jws, true);
                    }
                }

                @Override
                public void onFailure(@NonNull Status status) {
                    if (isDetached()) {
                        return;
                    }
                    updateMessageView(R.string.safetynet_fail_to_run_api, true);
                }
            });
} 
开发者ID:googlesamples,项目名称:android-testdpc,代码行数:31,代码来源:SafetyNetFragment.java

本文标签属性:

示例:示例的拼音

代码:代码编程

java:java面试题

SafetyNet:telegram官网

上一篇:Java Region类代码示例
下一篇:网红景点建完封3年

为您推荐