本文整理汇总了Java中com.google.android.gms.safetynet.SafetyNetApi类的典型用法代码示例。如果您正苦于以下问题:Java SafetyNetApi类的具体用法?Java SafetyNetApi怎么用?Java SafetyNetApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SafetyNetApi类属于com.google.android.gms.safetynet包,在下文中一共展示了SafetyNetApi类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onSuccess
import com.google.android.gms.safetynet.SafetyNetApi; //导入依赖的package包/类
@Override
public void onSuccess(SafetyNetApi.AttestationResponse attestationResponse) {
/*
Successfully communicated with SafetyNet API.
Use result.getJwsResult() to get the signed result data. See the server
component of this sample for details on how to verify and parse this result.
*/
mResult = attestationResponse.getJwsResult();
Log.d(TAG, "Success! SafetyNet result:\n" + mResult + "\n");
/*
TODO(developer): Forward this result to your server together with
the nonce for verification.
You can also parse the JwsResult locally to confirm that the API
returned a response by checking for an 'error' field first and before
retrying the request with an exponential backoff.
NOTE: Do NOT rely on a local, client-side only check for security, you
must verify the response on a remote server!
*/
}
开发者ID:googlesamples,项目名称:android-play-safetynet,代码行数:22,代码来源:SafetyNetSampleFragment.java
示例2: getJws
import com.google.android.gms.safetynet.SafetyNetApi; //导入依赖的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: verifyUser
import com.google.android.gms.safetynet.SafetyNetApi; //导入依赖的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
示例4: sendSafetyNetRequest
import com.google.android.gms.safetynet.SafetyNetApi; //导入依赖的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
示例5: sendSafetyNetRequest
import com.google.android.gms.safetynet.SafetyNetApi; //导入依赖的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
示例6: requestAttestation
import com.google.android.gms.safetynet.SafetyNetApi; //导入依赖的package包/类
public void requestAttestation(final boolean verifyJWSResponse) {
if (!isGooglePlayServicesAvailable()) return;
Log.v(TAG, "running SafetyNet.API Test");
byte[] requestNonce = generateOneTimeRequestNonce();
Log.d(TAG, "Nonce:" + Base64.encodeToString(requestNonce, Base64.DEFAULT));
SafetyNet.SafetyNetApi.attest(googleApiClient, requestNonce)
.setResultCallback(attestationResult -> {
Status status = attestationResult.getStatus();
boolean isSuccess = status.isSuccess();
if (!isSuccess)
callback.onFail(ErrorMessage.SAFETY_NET_API_NOT_WORK, ErrorMessage.SAFETY_NET_API_NOT_WORK.name());
else {
try {
final String jwsResult = attestationResult.getJwsResult();
final JwsHelper jwsHelper = new JwsHelper(jwsResult);
final AttestationResult response = new AttestationResult(jwsHelper.getDecodedPayload());
if (!verifyJWSResponse) {
callback.onResponse(response.getFormattedString());
//release SafetyNet HandlerThread
MyApplication.INSTANCE.safetyNetLooper.quit();
} else {
AndroidDeviceVerifier androidDeviceVerifier = new AndroidDeviceVerifier(ctx, jwsResult);
androidDeviceVerifier.verify(new AttestationTaskCallback() {
@Override
public void error(String errorMsg) {
callback.onFail(ErrorMessage.FAILED_TO_CALL_GOOGLE_API_SERVICES, errorMsg);
//release SafetyNet HandlerThread
MyApplication.INSTANCE.safetyNetLooper.quit();
}
@Override
public void success(boolean isValidSignature) {
if (isValidSignature)
callback.onResponse("isValidSignature true\n\n" + response.getFormattedString());
else
callback.onFail(ErrorMessage.ERROR_VALID_SIGNATURE, ErrorMessage.ERROR_VALID_SIGNATURE.name());
//release SafetyNet HandlerThread
MyApplication.INSTANCE.safetyNetLooper.quit();
}
});
}
} catch (JSONException e) {
callback.onFail(ErrorMessage.EXCEPTION, e.getMessage());
//release SafetyNet HandlerThread
MyApplication.INSTANCE.safetyNetLooper.quit();
}
}
});
}
开发者ID:Catherine22,项目名称:SecuritySample,代码行数:55,代码来源:SafetyNetUtils.java
示例7: startVerification
import com.google.android.gms.safetynet.SafetyNetApi; //导入依赖的package包/类
private void startVerification() {
final byte[] nonce = getRequestNonce();
SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
.setResultCallback(new ResultCallback<SafetyNetApi.AttestationResult>() {
@Override
public void onResult(@NonNull SafetyNetApi.AttestationResult attestationResult) {
Status status = attestationResult.getStatus();
if (status.isSuccess()) {
String jwsResult = attestationResult.getJwsResult();
verifyOnline(jwsResult);
} else {
mProgressBar.setVisibility(View.GONE);
Toast.makeText(MainActivity.this, "Error !", Toast.LENGTH_SHORT).show();
}
}
});
}
开发者ID:Learn2Crack,项目名称:safetynet,代码行数:26,代码来源:MainActivity.java
注:本文中的com.google.android.gms.safetynet.SafetyNetApi类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论