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 CredentialDataResultgetCredentialData(java.lang.String credentialName, CredentialDataRequest request)Retrieves data from a named credential in the current presentation session.androidx.biometric.BiometricPrompt.CryptoObjectgetCryptoObject()Gets aBiometricPrompt.CryptoObjectwhich can be used with thisPresentationSession.java.security.KeyPairgetEphemeralKeyPair()Gets the ephemeral key pair to use to establish a secure channel with the verifier.voidsetReaderEphemeralPublicKey(java.security.PublicKey readerEphemeralPublicKey)Set the ephemeral public key provided by the verifier.voidsetSessionTranscript(byte[] sessionTranscript)Set the session transcript.
-
-
-
Method Detail
-
getEphemeralKeyPair
@NonNull public java.security.KeyPair getEphemeralKeyPair()
Description copied from class:PresentationSessionGets 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:
getEphemeralKeyPairin 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.InvalidKeyExceptionDescription copied from class:PresentationSessionSet 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
PresentationSessioninstance.- Specified by:
setReaderEphemeralPublicKeyin 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:PresentationSessionSet 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
PresentationSessioninstance.- Specified by:
setSessionTranscriptin 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:PresentationSessionRetrieves 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_FAILEDis returned the application should callPresentationSession.getCryptoObject()and use the returnedBiometricPrompt.CryptoObjectwith 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_Sign1structure as defined in RFC 8152. For the payloadnilshall be used and the detached payload is theReaderAuthenticationBytesCBOR described below.ReaderAuthentication = [ "ReaderAuthentication", SessionTranscript, ItemsRequestBytes ] ItemsRequestBytes = #6.24(bstr .cbor ItemsRequest) ReaderAuthenticationBytes = #6.24(bstr .cbor ReaderAuthentication)where
ItemsRequestBytesare 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
x5chainunprotected header element of theCOSE_Sign1structure (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,
requestMessageis signed by the top-most certificate in the reader's certificate chain, and the data element is configured with anAccessControlProfileconfigured 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:
getCredentialDatain 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
CredentialDataResultobject 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:PresentationSessionGets aBiometricPrompt.CryptoObjectwhich can be used with thisPresentationSession.If
IdentityCredentialis hardware-backed, the returnedBiometricPrompt.CryptoObjectis 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.CryptoObjectrather than to construct it manually.If no biometrics are enrolled on the device or if the device doesn't support biometrics the value
nullmay be returned. This just means the application won't have aBiometricPrompt.CryptoObjectto pass toBiometricPromptand will have to passnullinstead.- Specified by:
getCryptoObjectin classPresentationSession- Returns:
- A
BiometricPrompt.CryptoObjectwhich can be used withBiometricPrompt.
-
-