Class VerificationHelper
- java.lang.Object
-
- com.android.identity.VerificationHelper
-
public class VerificationHelper extends java.lang.Object
Helper used for engaging with and receiving documents from a remote mdoc verifier device.This class implements the interface between an mdoc and mdoc verifier using the connection setup and device retrieval interfaces defined in ISO/IEC 18013-5:2021.
Reverse engagement as per drafts of 18013-7 and 23220-4 is supported. These protocols are not finalized so should only be used for testing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VerificationHelper.Builder
Builder forVerificationHelper
.static interface
VerificationHelper.Listener
Interface for listening to messages from the remote mdoc device.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect(ConnectionMethod connectionMethod)
Establishes connection to remote mdoc using the givenConnectionMethod
.void
disconnect()
Ends the session with the remote device.java.security.PrivateKey
getEphemeralReaderKey()
Gets the ephemeral key used by the reader for session encryption.byte[]
getSessionTranscript()
Gets the session transcript.boolean
isTransportSpecificTerminationSupported()
Returns whether transport specific termination is available for the current connection.void
nfcProcessOnTagDiscovered(android.nfc.Tag tag)
Processes aTag
received when in NFC reader mode.void
sendRequest(byte[] deviceRequestBytes)
Sends a request to the remote mdoc device.void
setDeviceEngagementFromQrCode(java.lang.String qrDeviceEngagement)
Set device engagement received via QR code.void
setSendSessionTerminationMessage(boolean sendSessionTerminationMessage)
Sets whether to send session termination message.void
setUseTransportSpecificSessionTermination(boolean useTransportSpecificSessionTermination)
Sets whether to use transport-specific session termination.
-
-
-
Method Detail
-
nfcProcessOnTagDiscovered
public void nfcProcessOnTagDiscovered(@NonNull android.nfc.Tag tag)
Processes aTag
received when in NFC reader mode.Applications should call this method in their
NfcAdapter.ReaderCallback.onTagDiscovered(Tag)
callback.- Parameters:
tag
- the tag.- Throws:
java.lang.IllegalStateException
- if called while not listening.
-
setDeviceEngagementFromQrCode
public void setDeviceEngagementFromQrCode(@NonNull java.lang.String qrDeviceEngagement)
Set device engagement received via QR code.This method parses the textual form of QR code device engagement as specified in ISO/IEC 18013-5 section 8.2 Device Engagement.
If a valid device engagement is received the
VerificationHelper.Listener.onDeviceEngagementReceived(List)
will be called. If an error occurred it is reported using theVerificationHelper.Listener.onError(Throwable)
callback.This method must be called before
connect(ConnectionMethod)
.- Parameters:
qrDeviceEngagement
- textual form of QR device engagement.- Throws:
java.lang.IllegalStateException
- if called afterconnect(ConnectionMethod)
.
-
connect
public void connect(@NonNull ConnectionMethod connectionMethod)
Establishes connection to remote mdoc using the givenConnectionMethod
.This method should be called after receiving the
VerificationHelper.Listener.onDeviceEngagementReceived(List)
callback with one of the addresses from said callback.- Parameters:
connectionMethod
- the address/method to connect to.
-
disconnect
public void disconnect()
Ends the session with the remote device.By default, ending a session involves sending a message to the remote device with empty data and the status code set to 20, meaning session termination as per ISO/IEC 18013-5. This can be configured using
setSendSessionTerminationMessage(boolean)
andsetUseTransportSpecificSessionTermination(boolean)
.Some transports - such as BLE - supports a transport-specific session termination message instead of the generic one. By default this is not used but it can be enabled using
setUseTransportSpecificSessionTermination(boolean)
.After calling this the current object can no longer be used to send requests.
This method is idempotent so it is safe to call multiple times.
-
sendRequest
public void sendRequest(@NonNull byte[] deviceRequestBytes)
Sends a request to the remote mdoc device.The
deviceRequestBytes
parameter must beDeviceRequest
CBOR as specified in ISO/IEC 18013-5 section 8.3 Device Retrieval. TheDeviceRequestGenerator
class can be used to generate this.If a response to the request is received from the remote mdoc device, the
VerificationHelper.Listener.onResponseReceived(byte[])
method is invoked. This will usually take several seconds as it typically involves authenticating the holder and asking for their consent to release identity data.This is usually called in response to
VerificationHelper.Listener.onDeviceConnected()
callback.- Parameters:
deviceRequestBytes
- request message to the remote device
-
getSessionTranscript
@NonNull public byte[] getSessionTranscript()
Gets the session transcript.This must not be called until engagement has been established with the mdoc device.
- Returns:
- the session transcript.
- Throws:
java.lang.IllegalStateException
- if called before engaging with mdoc device.
-
getEphemeralReaderKey
@NonNull public java.security.PrivateKey getEphemeralReaderKey()
Gets the ephemeral key used by the reader for session encryption.This is made available because it's needed for mdoc verification when using the MAC mechanism.
- Returns:
- the ephemeral key used by the reader for session encryption.
-
setUseTransportSpecificSessionTermination
public void setUseTransportSpecificSessionTermination(boolean useTransportSpecificSessionTermination)
Sets whether to use transport-specific session termination.By default this is set to
false
.As per ISO/IEC 18013-5 transport-specific session-termination is currently only supported for BLE. The
isTransportSpecificTerminationSupported()
method can be used to determine whether it's available for the current transport.If
isTransportSpecificTerminationSupported()
indicates that this is not available for the current transport this is a noop.- Parameters:
useTransportSpecificSessionTermination
- Whether to use transport-specific session termination.
-
isTransportSpecificTerminationSupported
public boolean isTransportSpecificTerminationSupported()
Returns whether transport specific termination is available for the current connection. SeesetUseTransportSpecificSessionTermination(boolean)
for more information about what transport specific session termination is.- Returns:
true
if transport specific termination is available,false
if not or if not connected.
-
setSendSessionTerminationMessage
public void setSendSessionTerminationMessage(boolean sendSessionTerminationMessage)
Sets whether to send session termination message.This controls whether a session termination message is sent when
disconnect()
is called. Most applications would want to do this as it is required by ISO/IEC 18013-5.By default this is set to
true
.- Parameters:
sendSessionTerminationMessage
- Whether to send session termination message.
-
-