Android Protected Confirmation

To help you confirm users' intentions when they initiate a sensitive transaction, such as making a payment, supported devices that run Android 9 (API level 28) or higher let you use Android Protected Confirmation. When using this workflow, your app displays a prompt to the user, asking them to approve a short statement that reaffirms their intent to complete the sensitive transaction.

If the user accepts the statement, your app can use a key from Android Keystore to sign the message shown in the dialog. The signature indicates, with very high confidence, that the user has seen the statement and has agreed to it.

Caution:Android Protected Confirmation doesn't provide a secure information channel for the user. Your app can't assume any confidentiality guarantees beyond those that the Android platform offers. In particular, don't use this workflow to display sensitive information that you wouldn't ordinarily show on the user's device.

After the user confirms the message, the message's integrity is assured, but your app must still use data-in-transit encryption to protect the confidentiality of the signed message.

To provide support for high-assurance user confirmation in your app, complete the following steps:

  1. Generate an asymmetric signing key using the KeyGenParameterSpec.Builder class. When creating the key, passtrueinto setUserConfirmationRequired(). Also, callsetAttestationChallenge(), passing a suitable challenge value provided by the relying party.

  2. Enroll the newly generated key and your key's attestation certificate with the appropriate relying party.

  3. Send transaction details to your server and have it generate and return a binary large object (BLOB) ofextra data.Extra data might include the to-be-confirmed data or parsing hints, such as the locale of the prompt string.

    For a more secure implementation, the BLOB must contain a cryptographic nonce for protection against replay attacks and to disambiguate transactions.

  4. Set up the ConfirmationCallback object that informs your app when the user has accepted the prompt shown in a confirmation dialog:

    Kotlin

    classMyConfirmationCallback:ConfirmationCallback(){
    
    overridefunonConfirmed(dataThatWasConfirmed:ByteArray?){
    super.onConfirmed(dataThatWasConfirmed)
    // Sign dataThatWasConfirmed using your generated signing key.
    // By completing this process, you generate a signed statement.
    }
    
    overridefunonDismissed(){
    super.onDismissed()
    // Handle case where user declined the prompt in the
    // confirmation dialog.
    }
    
    overridefunonCanceled(){
    super.onCanceled()
    // Handle case where your app closed the dialog before the user
    // responded to the prompt.
    }
    
    overridefunonError(e:Exception?){
    super.onError(e)
    // Handle the exception that the callback captured.
    }
    }

    Java

    publicclassMyConfirmationCallbackextendsConfirmationCallback{
    
    @Override
    publicvoidonConfirmed(@NonNullbyte[]dataThatWasConfirmed){
    super.onConfirmed(dataThatWasConfirmed);
    // Sign dataThatWasConfirmed using your generated signing key.
    // By completing this process, you generate a signed statement.
    }
    
    @Override
    publicvoidonDismissed(){
    super.onDismissed();
    // Handle case where user declined the prompt in the
    // confirmation dialog.
    }
    
    @Override
    publicvoidonCanceled(){
    super.onCanceled();
    // Handle case where your app closed the dialog before the user
    // responded to the prompt.
    }
    
    @Override
    publicvoidonError(Throwablee){
    super.onError(e);
    // Handle the exception that the callback captured.
    }
    }

    If the user approves the dialog, theonConfirmed()callback is called. ThedataThatWasConfirmedBLOB is a CBOR data structurethat contains, among other details, the prompt text that the user saw as well as the extra data that you passed into the ConfirmationPrompt builder. Use the previously created key to sign the dataThatWasConfirmedBLOB, then pass this BLOB, along with the signature and transaction details, back to the relying party.

    To make full use of the security assurance that Android Protected Confirmation offers, the relying party must perform the following steps upon receiving a signed message:

    1. Check the signature over the message as well as the attestation certificate chain of the signing key.
    2. Check that the attestation certificate has the TRUSTED_CONFIRMATION_REQUIREDflag set, which indicates that the signing key requires trusted user confirmation. If the signing key is an RSA key, check that it doesn't have the PURPOSE_ENCRYPT orPURPOSE_DECRYPT property.
    3. CheckextraDatato make sure that this confirmation message belongs to a new request and hasn't been processed yet. This step protects against replay attacks.
    4. Parse thepromptTextfor information about the confirmed action or request. Remember that thepromptTextis the only part of the message that the user actually confirmed. The relying party must never assume that to-be confirmed data included inextraDatacorresponds to thepromptText.
  5. Add logic similar to that shown in the following code snippet to display the dialog itself:

    Kotlin

    // This data structure varies by app type. This is an example.
    dataclassConfirmationPromptData(valsender:String,
    valreceiver:String,valamount:String)
    
    valmyExtraData:ByteArray=byteArrayOf()
    valmyDialogData=ConfirmationPromptData("Ashlyn","Jordan","$500")
    valthreadReceivingCallback=Executor{runnable->runnable.run()}
    valcallback=MyConfirmationCallback()
    
    valdialog=ConfirmationPrompt.Builder(context)
    .setPromptText("${myDialogData.sender},send
    ${myDialogData.amount}to
    ${myDialogData.receiver}?")
    .setExtraData(myExtraData)
    .build()
    dialog.presentPrompt(threadReceivingCallback,callback)

    Java

    // This data structure varies by app type. This is an example.
    classConfirmationPromptData{
    Stringsender,receiver,amount;
    ConfirmationPromptData(Stringsender,Stringreceiver,Stringamount){
    this.sender=sender;
    this.receiver=receiver;
    this.amount=amount;
    }
    };
    finalintMY_EXTRA_DATA_LENGTH=100;
    byte[]myExtraData=newbyte[MY_EXTRA_DATA_LENGTH];
    ConfirmationPromptDatamyDialogData=newConfirmationPromptData("Ashlyn","Jordan","$500");
    ExecutorthreadReceivingCallback=Runnable::run;
    MyConfirmationCallbackcallback=newMyConfirmationCallback();
    ConfirmationPromptdialog=(newConfirmationPrompt.Builder(getApplicationContext()))
    .setPromptText("${myDialogData.sender}, send ${myDialogData.amount} to ${myDialogData.receiver}?")
    .setExtraData(myExtraData)
    .build();
    dialog.presentPrompt(threadReceivingCallback,callback);

Additional resources

For more information about Android Protected Confirmation, consult the following resources.

Blogs