Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -13284,6 +13284,24 @@ public AsyncResource<String> requestIntegrityToken(String nonce) {
return result;
}

/// Requests a Google Play Integrity token through the Standard request flow, bound to the given
/// request hash. Only Android implements it; everywhere else the result completes with an error.
///
/// #### Parameters
///
/// - `requestHash`: a digest of the action being protected, bound into the verdict
///
/// #### Returns
///
/// an `AsyncResource` that completes with the opaque integrity token, or with an error
public AsyncResource<String> requestStandardIntegrityToken(String requestHash) {
AsyncResource<String> result = new AsyncResource<String>();
result.error(new UnsupportedOperationException(
"Standard Play Integrity requests are only supported on Android, with the "
+ "android.playIntegrity and android.playIntegrity.cloudProjectNumber build hints."));
return result;
}

/// Returns true if device-attestation (Play Integrity / App Attest) is available on this device and
/// was bundled into the build. False on the base/unsupported implementation.
public boolean isAttestationSupported() {
Expand Down
43 changes: 43 additions & 0 deletions CodenameOne/src/com/codename1/security/DeviceIntegrity.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,49 @@ public static AsyncResource<String> requestIntegrityToken(String serverNonce) {
return Display.getInstance().requestIntegrityToken(serverNonce);
}

/// Requests a Google Play Integrity token through the **Standard** request flow.
///
/// Play Integrity has two request types. [#requestIntegrityToken(String)] makes a *Classic*
/// request: every call goes to Google's servers and takes seconds, so it suits occasional
/// checks such as sign-in. A *Standard* request is what
/// Google recommends for checking individual actions: the token provider is prepared once, ahead
/// of time, and each request then answers in a few hundred milliseconds. Instead of a nonce the
/// verdict carries the `requestHash` you pass, typically a SHA-256 of the action's parameters
/// (the transfer's account, amount and a timestamp); your backend recomputes it and compares it
/// with the `requestDetails.requestHash` of the decoded verdict.
///
/// Enable it with `android.playIntegrity=true` and
/// `android.playIntegrity.cloudProjectNumber=<your Google Cloud project number>`. The provider is
/// prepared in the background when the application starts and prepared again when Google
/// reports it expired, so the first call does not pay for the warm-up.
///
/// ```java
/// String transfer = "IL620108000000099999999|250.00|" + System.currentTimeMillis();
/// String hash = Hash.toHex(Hash.sha256(StringUtil.getBytes(transfer)));
/// DeviceIntegrity.requestStandardIntegrityToken(hash).onResult((token, err) -> {
/// if (err != null) {
/// // attestation unavailable -- treat as untrusted / require step-up
/// return;
/// }
/// // POST token with the transfer; the backend decodes it and checks the hash
/// });
/// ```
///
/// Standard requests exist only on Google Play. On iOS, the simulator and every other platform
/// the result completes with an error; use [#requestIntegrityToken(String)] there.
///
/// #### Parameters
///
/// - `requestHash`: a digest of the action being protected, at most 500 characters
///
/// #### Returns
///
/// an `AsyncResource` that completes with the opaque integrity token, or completes with an error
/// when Standard requests are unsupported, not configured, or the request fails
public static AsyncResource<String> requestStandardIntegrityToken(String requestHash) {
return Display.getInstance().requestStandardIntegrityToken(requestHash);
}

/// Returns true when platform attestation (Play Integrity / App Attest) is available on this device
/// and was bundled into the build via the relevant build hint.
public static boolean isAttestationSupported() {
Expand Down
14 changes: 14 additions & 0 deletions CodenameOne/src/com/codename1/ui/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -9490,6 +9490,20 @@ public AsyncResource<String> requestIntegrityToken(String nonce) {
return impl.requestIntegrityToken(nonce);
}

/// Requests a Play Integrity token through the Standard request flow. See
/// `com.codename1.security.DeviceIntegrity#requestStandardIntegrityToken(String)`.
///
/// #### Parameters
///
/// - `requestHash`: a digest of the action being protected
///
/// #### Returns
///
/// an `AsyncResource` completing with the token or an error
public AsyncResource<String> requestStandardIntegrityToken(String requestHash) {
return impl.requestStandardIntegrityToken(requestHash);
}

/// Returns true if device-attestation (Play Integrity / App Attest) is supported and bundled.
public boolean isAttestationSupported() {
return impl.isAttestationSupported();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,9 @@ public void init(Object m) {
setActivity(null);
setContext((Context)m);
}
// Standard Play Integrity requests answer fast only once the token provider is
// prepared; doing it now keeps the warm-up off the first protected action.
GoogleServices.prewarmStandardIntegrity(getContext());
// The nearby bridge is cached for the life of the process while
// Android recreates the activity freely -- a configuration change,
// or "Don't keep activities". An association chooser opened by the
Expand Down Expand Up @@ -19087,6 +19090,13 @@ public AsyncResource<String> requestIntegrityToken(final String nonce) {
return result;
}

@Override
public AsyncResource<String> requestStandardIntegrityToken(final String requestHash) {
final AsyncResource<String> result = new AsyncResource<String>();
GoogleServices.requestStandardIntegrityToken(getContext(), requestHash, result);
return result;
}

@Override
public boolean isDeviceCompromised() {
// Developer Options and USB debugging are switched on by plenty of ordinary users and
Expand Down
Loading
Loading