Class HardwarePresentationSession
- java.lang.Object
-
- com.android.identity.PresentationSession
-
- com.android.identity.HardwarePresentationSession
-
@RequiresApi(33) public class HardwarePresentationSession extends PresentationSession
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CredentialDataResult
getCredentialData(java.lang.String credentialName, CredentialDataRequest request)
Retrieves data from a named credential in the current presentation session.androidx.biometric.BiometricPrompt.CryptoObject
getCryptoObject()
Gets aBiometricPrompt.CryptoObject
which can be used with thisPresentationSession
.java.security.KeyPair
getEphemeralKeyPair()
Gets the ephemeral key pair to use to establish a secure channel with the verifier.void
setReaderEphemeralPublicKey(java.security.PublicKey readerEphemeralPublicKey)
Set the ephemeral public key provided by the verifier.void
setSessionTranscript(byte[] sessionTranscript)
Set the session transcript.
-
-
-
Method Detail
-
getEphemeralKeyPair
@NonNull public java.security.KeyPair getEphemeralKeyPair()
Description copied from class:PresentationSession
Gets the ephemeral key pair to use to establish a secure channel with the verifier.Applications should use this key-pair for the communications channel with the verifier using a protocol / cipher-suite appropriate for the application. One example of such a protocol is the one used for Mobile Driving Licenses, see ISO 18013-5.
- Specified by:
getEphemeralKeyPair
in classPresentationSession
- Returns:
- ephemeral key pair to use to establish a secure channel with a reader.
-
setReaderEphemeralPublicKey
public void setReaderEphemeralPublicKey(@NonNull java.security.PublicKey readerEphemeralPublicKey) throws java.security.InvalidKeyException
Description copied from class:PresentationSession
Set the ephemeral public key provided by the verifier.If called, this must be called before any calls to
PresentationSession.getCredentialData(String, CredentialDataRequest)
.This method can only be called once per
PresentationSession
instance.- Specified by:
setReaderEphemeralPublicKey
in classPresentationSession
- Parameters:
readerEphemeralPublicKey
- The ephemeral public key provided by the reader to establish a secure session.- Throws:
java.security.InvalidKeyException
- if the given key is invalid.
-
setSessionTranscript
public void setSessionTranscript(@NonNull byte[] sessionTranscript)
Description copied from class:PresentationSession
Set the session transcript.If called, this must be called before any calls to
PresentationSession.getCredentialData(String, CredentialDataRequest)
.The X and Y coordinates of the public part of the key-pair returned by
PresentationSession.getEphemeralKeyPair()
must appear somewhere in the bytes of the passed in CBOR. Each of these coordinates must appear encoded with the most significant bits first and use the exact amount of bits indicated by the key size of the ephemeral keys. For example, if the ephemeral key is using the P-256 curve then the 32 bytes for the X coordinate encoded with the most significant bits first must appear somewhere and ditto for the 32 bytes for the Y coordinate.This method can only be called once per
PresentationSession
instance.- Specified by:
setSessionTranscript
in classPresentationSession
- Parameters:
sessionTranscript
- the session transcript.
-
getCredentialData
@Nullable public CredentialDataResult getCredentialData(@NonNull java.lang.String credentialName, @NonNull CredentialDataRequest request) throws NoAuthenticationKeyAvailableException, InvalidReaderSignatureException, InvalidRequestMessageException, EphemeralPublicKeyNotFoundException
Description copied from class:PresentationSession
Retrieves data from a named credential in the current presentation session.If an access control check fails for one of the requested entries or if the entry doesn't exist, the entry is simply not returned. The application can detect this by using the
CredentialDataResult.Entries.getStatus(String, String)
method on each of the requested entries.The application should not make any assumptions on whether user authentication is needed. Instead, the application should request the data elements values first and then examine the returned
CredentialDataResult
. IfCredentialDataResult.Entries.STATUS_USER_AUTHENTICATION_FAILED
is returned the application should callPresentationSession.getCryptoObject()
and use the returnedBiometricPrompt.CryptoObject
with aBiometricPrompt
. Upon successful authentication the application may callPresentationSession.getCredentialData(String, CredentialDataRequest)
again.It is permissible to call this method multiple times using the same credential name. If this is done the same auth-key will be used.
If the reader signature is set in the request parameter (via the
CredentialDataRequest.Builder.setReaderSignature(byte[])
method) it must contain the bytes of aCOSE_Sign1
structure as defined in RFC 8152. For the payloadnil
shall be used and the detached payload is theReaderAuthenticationBytes
CBOR described below.ReaderAuthentication = [ "ReaderAuthentication", SessionTranscript, ItemsRequestBytes ] ItemsRequestBytes = #6.24(bstr .cbor ItemsRequest) ReaderAuthenticationBytes = #6.24(bstr .cbor ReaderAuthentication)
where
ItemsRequestBytes
are the bytes of the request message set in the request parameter (via theCredentialDataRequest.Builder.setRequestMessage(byte[])
method).The public key corresponding to the key used to make the signature, can be found in the
x5chain
unprotected header element of theCOSE_Sign1
structure (as as described in draft-ietf-cose-x509-08). There will be at least one certificate in said element and there may be more (and if so, each certificate must be signed by its successor).Data elements protected by reader authentication are returned if, and only if,
requestMessage
is signed by the top-most certificate in the reader's certificate chain, and the data element is configured with anAccessControlProfile
configured with an X.509 certificate for a key which appear in the certificate chain.Note that the request message CBOR is used only for enforcing reader authentication, it's not used for determining which entries this API will return. The application is expected to have parsed the request message and filtered it according to user preference and/or consent.
- Specified by:
getCredentialData
in classPresentationSession
- Parameters:
credentialName
- the name of the credential to retrieve.request
- the data to retrieve from the credential- Returns:
- If the credential wasn't found, returns null. Otherwise a
CredentialDataResult
object containing entry data organized by namespace and a cryptographically authenticated representation of the same data, bound to the current session. - Throws:
NoAuthenticationKeyAvailableException
- if authentication keys were never provisioned for the credential or if they are expired or exhausted their use-count.InvalidReaderSignatureException
- if the reader signature is invalid, or it doesn't contain a certificate chain, or if the signature failed to validate.InvalidRequestMessageException
- if the requestMessage is malformed.EphemeralPublicKeyNotFoundException
- if the ephemeral public key was not found in the session transcript.
-
getCryptoObject
@Nullable public androidx.biometric.BiometricPrompt.CryptoObject getCryptoObject()
Description copied from class:PresentationSession
Gets aBiometricPrompt.CryptoObject
which can be used with thisPresentationSession
.If
IdentityCredential
is hardware-backed, the returnedBiometricPrompt.CryptoObject
is associated android.security.identity.PresentationSession object from the Android Framework. If it's not hardware-backed it's not defined which kind of object it's associated with. Because of this, this method is the preferred way to obtain aBiometricPrompt.CryptoObject
rather than to construct it manually.If no biometrics are enrolled on the device or if the device doesn't support biometrics the value
null
may be returned. This just means the application won't have aBiometricPrompt.CryptoObject
to pass toBiometricPrompt
and will have to passnull
instead.- Specified by:
getCryptoObject
in classPresentationSession
- Returns:
- A
BiometricPrompt.CryptoObject
which can be used withBiometricPrompt
.
-
-