Class Ctap2Client
- All Implemented Interfaces:
WebAuthnClient,Closeable,AutoCloseable
Provides the following functionality:
- MakeCredential: Registers a new credential. If a PIN is needed, it is passed to this method.
- GetAssertion: Authenticate an existing credential. If a PIN is needed, it is passed to this method.
- PIN Management: Set or change the PIN code of an Authenticator, or see its state.
- Credential Management: List or delete resident credentials of an Authenticator.
CommandState instance to the call and use its cancel method.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCtap2Client(Ctap2Session session) Create a new Webauthn client.Ctap2Client(Ctap2Session session, @Nullable List<Extension> extensions) Create a new Webauthn client. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangePin(char[] currentPin, char[] newPin) Change the PIN for an Authenticator which already has a PIN configured.voidclose()protected List<com.yubico.yubikit.core.util.Pair<Ctap2Session.AssertionData,ClientExtensionResults>> ctapGetAssertions(byte[] clientDataHash, PublicKeyCredentialRequestOptions options, String effectiveDomain, char @Nullable [] pin, @Nullable com.yubico.yubikit.core.application.CommandState state) Authenticate an existing WebAuthn credential.protected com.yubico.yubikit.core.util.Pair<Ctap2Session.CredentialData,ClientExtensionResults> ctapMakeCredential(byte[] clientDataHash, PublicKeyCredentialCreationOptions options, String effectiveDomain, char @Nullable [] pin, @Nullable Integer enterpriseAttestation, @Nullable com.yubico.yubikit.core.application.CommandState state) Create a new WebAuthn credential.getAssertion(ClientDataProvider clientData, PublicKeyCredentialRequestOptions options, String effectiveDomain, char @Nullable [] pin, @Nullable com.yubico.yubikit.core.application.CommandState state) Authenticate an existing WebAuthn credential.getCredentialManager(char[] pin) Return an object that provides management of resident key type credentials stored on a YubiKeybooleanCheck if the Authenticator supports Enterprise Attestation feature.booleanCheck if the Authenticator has been configured with a PIN.booleanCheck if the Authenticator supports PIN.makeCredential(ClientDataProvider clientData, PublicKeyCredentialCreationOptions options, String effectiveDomain, char @Nullable [] pin, @Nullable Integer enterpriseAttestation, @Nullable com.yubico.yubikit.core.application.CommandState state) Create a new WebAuthn credential.voidsetPin(char[] pin) Set the PIN for an Authenticator which supports PIN, but doesn't have one configured.static voidvalidateExtensionInputs(PublicKeyCredentialCreationOptions options, @Nullable List<Extension> extensions) Validate the device-independent client extension inputs of a registration request, without a key.static voidvalidateExtensionInputs(PublicKeyCredentialRequestOptions options, @Nullable List<Extension> extensions) Validate the device-independent client extension inputs of an authentication request, without a key.
-
Constructor Details
-
Ctap2Client
public Ctap2Client(Ctap2Session session) throws IOException, com.yubico.yubikit.core.application.CommandException Create a new Webauthn client.This client will process all extensions.
- Parameters:
session- CTAP session- Throws:
IOException- A communication error in the transport layercom.yubico.yubikit.core.application.CommandException- A communication in the protocol layer- See Also:
-
Ctap2Client
public Ctap2Client(Ctap2Session session, @Nullable List<Extension> extensions) throws IOException, com.yubico.yubikit.core.application.CommandException Create a new Webauthn client.This client will only process provided extensions.
- Parameters:
session- CTAP2 sessionextensions- List of extensions or null to use default extensions- Throws:
IOException- A communication error in the transport layercom.yubico.yubikit.core.application.CommandException- A communication in the protocol layer- See Also:
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getUserAgentConfiguration
-
getSession
-
makeCredential
public PublicKeyCredential makeCredential(ClientDataProvider clientData, PublicKeyCredentialCreationOptions options, String effectiveDomain, char @Nullable [] pin, @Nullable Integer enterpriseAttestation, @Nullable com.yubico.yubikit.core.application.CommandState state) throws IOException, com.yubico.yubikit.core.application.CommandException, ClientError Create a new WebAuthn credential.- Specified by:
makeCredentialin interfaceWebAuthnClient- Parameters:
clientData- TheClientDataProviderinstance supplying client data for the requestoptions- The options for creating the credentialeffectiveDomain- The effective domain for the request, used to validate the RP IDpin- If needed, the PIN to authorize the credential creation (CTAP2 only)enterpriseAttestation- Enterprise attestation parameter (CTAP2 only)state- If needed, the state to provide control over the ongoing operation- Returns:
- A WebAuthn public key credential.
- Throws:
IOException- A communication error in the transport layercom.yubico.yubikit.core.application.CommandException- A communication in the protocol layerClientError- A higher level error
-
getAssertion
public PublicKeyCredential getAssertion(ClientDataProvider clientData, PublicKeyCredentialRequestOptions options, String effectiveDomain, char @Nullable [] pin, @Nullable com.yubico.yubikit.core.application.CommandState state) throws MultipleAssertionsAvailable, IOException, com.yubico.yubikit.core.application.CommandException, ClientError Authenticate an existing WebAuthn credential. PIN is required if UV is "required", or if UV is "preferred" and a PIN is configured. If no allowCredentials list is provided (which is the case for a passwordless flow) the Authenticator may contain multiple discoverable credentials for the given RP. In such cases MultipleAssertionsAvailable will be thrown, and can be handled to select an assertion.- Specified by:
getAssertionin interfaceWebAuthnClient- Parameters:
clientData- TheClientDataProviderinstance supplying client data for the request. If a provider that only supplies the hash is passed, the resulting credential will contain an empty clientDataJSON in the response.options- The options for authenticating the credential.effectiveDomain- The effective domain for the request, which is used to validate the RP ID against.pin- If needed, the PIN to authorize the credential creation.state- If needed, the state to provide control over the ongoing operation- Returns:
- Webauthn public key credential with assertion response data.
- Throws:
MultipleAssertionsAvailable- In case of multiple assertions, catch this to make a selection and get the result.IOException- A communication error in the transport layercom.yubico.yubikit.core.application.CommandException- A communication in the protocol layerClientError- A higher level error
-
isPinSupported
public boolean isPinSupported()Check if the Authenticator supports PIN.- Returns:
- If PIN is supported.
-
isPinConfigured
public boolean isPinConfigured()Check if the Authenticator has been configured with a PIN.- Returns:
- If a PIN is configured.
-
isEnterpriseAttestationSupported
public boolean isEnterpriseAttestationSupported()Check if the Authenticator supports Enterprise Attestation feature.- Returns:
- true if the authenticator is enterprise attestation capable and enterprise attestation is enabled.
- See Also:
-
setPin
public void setPin(char[] pin) throws IOException, com.yubico.yubikit.core.application.CommandException, ClientError Set the PIN for an Authenticator which supports PIN, but doesn't have one configured.- Parameters:
pin- The PIN to set.- Throws:
IOException- A communication error in the transport layer.com.yubico.yubikit.core.application.CommandException- A communication in the protocol layer.ClientError- A higher level error.
-
changePin
public void changePin(char[] currentPin, char[] newPin) throws IOException, com.yubico.yubikit.core.application.CommandException, ClientError Change the PIN for an Authenticator which already has a PIN configured.- Parameters:
currentPin- The current PIN, to authorize the action.newPin- The new PIN to set.- Throws:
IOException- A communication error in the transport layer.com.yubico.yubikit.core.application.CommandException- A communication in the protocol layer.ClientError- A higher level error.
-
getCredentialManager
public CredentialManager getCredentialManager(char[] pin) throws IOException, com.yubico.yubikit.core.application.CommandException, ClientError Return an object that provides management of resident key type credentials stored on a YubiKey- Parameters:
pin- The configured PIN- Returns:
- Credential manager
- Throws:
IOException- A communication error in the transport layer.com.yubico.yubikit.core.application.CommandException- A communication in the protocol layer.ClientError- A higher level error.
-
ctapMakeCredential
protected com.yubico.yubikit.core.util.Pair<Ctap2Session.CredentialData,ClientExtensionResults> ctapMakeCredential(byte[] clientDataHash, PublicKeyCredentialCreationOptions options, String effectiveDomain, char @Nullable [] pin, @Nullable Integer enterpriseAttestation, @Nullable com.yubico.yubikit.core.application.CommandState state) throws IOException, com.yubico.yubikit.core.application.CommandException, ClientError Create a new WebAuthn credential.This method is used internally in YubiKit and is not part of the public API. It may be changed or removed at any time.
PIN is always required if a PIN is configured.
- Parameters:
clientDataHash- Hash of client data.options- The options for creating the credential.effectiveDomain- The effective domain for the request, which is used to validate the RP ID against.pin- If needed, the PIN to authorize the credential creation.state- If needed, the state to provide control over the ongoing operation- Returns:
- A pair of credential data and client extension results.
- Throws:
IOException- A communication error in the transport layercom.yubico.yubikit.core.application.CommandException- A communication in the protocol layerClientError- A higher level error
-
ctapGetAssertions
protected List<com.yubico.yubikit.core.util.Pair<Ctap2Session.AssertionData,ClientExtensionResults>> ctapGetAssertions(byte[] clientDataHash, PublicKeyCredentialRequestOptions options, String effectiveDomain, char @Nullable [] pin, @Nullable com.yubico.yubikit.core.application.CommandState state) throws IOException, com.yubico.yubikit.core.application.CommandException, ClientError Authenticate an existing WebAuthn credential.This method is used internally in YubiKit and is not part of the public API. It may be changed or removed at any time.
PIN is required if UV is "required", or if UV is "preferred" and a PIN is configured. If no allowCredentials list is provided (which is the case for a passwordless flow) the Authenticator may contain multiple discoverable credentials for the given RP. In such cases MultipleAssertionsAvailable will be thrown, and can be handled to select an assertion.
- Parameters:
clientDataHash- Hash of client data.options- The options for authenticating the credential.effectiveDomain- The effective domain for the request, which is used to validate the RP ID against.pin- If needed, the PIN to authorize the credential creation.state- If needed, the state to provide control over the ongoing operation- Returns:
- List of pairs containing assertion response data and client extension results.
- Throws:
IOException- A communication error in the transport layercom.yubico.yubikit.core.application.CommandException- A communication in the protocol layerClientError- A higher level error
-
validateExtensionInputs
public static void validateExtensionInputs(PublicKeyCredentialCreationOptions options, @Nullable List<Extension> extensions) throws ClientError Validate the device-independent client extension inputs of a registration request, without a key.Runs each extension's
Extension.validateCreateInputs(com.yubico.yubikit.fido.webauthn.PublicKeyCredentialCreationOptions)and surfaces any failure as the sameClientErrormakeCredential(com.yubico.yubikit.fido.client.clientdata.ClientDataProvider, com.yubico.yubikit.fido.webauthn.PublicKeyCredentialCreationOptions, java.lang.String, char[], java.lang.Integer, com.yubico.yubikit.core.application.CommandState)would throw for it. This lets a caller reject a request that can never succeed before connecting to (or prompting for) an authenticator — matching a browser's synchronousNotSupportedError/SyntaxError.This is an optional fast-path: the same checks run inside
makeCredential(com.yubico.yubikit.fido.client.clientdata.ClientDataProvider, com.yubico.yubikit.fido.webauthn.PublicKeyCredentialCreationOptions, java.lang.String, char[], java.lang.Integer, com.yubico.yubikit.core.application.CommandState), so a caller that skips this still gets identical errors, just later. It only covers request-shape checks; capability checks that need the authenticator'sinfo(e.g.largeBlobsupport:"required",credProtectenforce) are not performed here.Coverage is per-extension: only extensions that override
Extension.validateCreateInputs(com.yubico.yubikit.fido.webauthn.PublicKeyCredentialCreationOptions)/Extension.validateGetInputs(com.yubico.yubikit.fido.webauthn.PublicKeyCredentialRequestOptions)participate (currentlylargeBlob). An extension whose hard-failures are only raised once the authenticator's support is known (e.g.prf/hmac-secret, whoseevalByCredentialchecks sit behind a support gate inmakeCredential(com.yubico.yubikit.fido.client.clientdata.ClientDataProvider, com.yubico.yubikit.fido.webauthn.PublicKeyCredentialCreationOptions, java.lang.String, char[], java.lang.Integer, com.yubico.yubikit.core.application.CommandState)/getAssertion(com.yubico.yubikit.fido.client.clientdata.ClientDataProvider, com.yubico.yubikit.fido.webauthn.PublicKeyCredentialRequestOptions, java.lang.String, char[], com.yubico.yubikit.core.application.CommandState)) is intentionally not pre-validated here — doing so would reject a request the device path would accept by ignoring the extension. Such requests still surface their error on the device path.- Parameters:
options- the registration request to validateextensions- the extensions to check, ornullfor the default set- Throws:
ClientError- if a requested extension input cannot be satisfied
-
validateExtensionInputs
public static void validateExtensionInputs(PublicKeyCredentialRequestOptions options, @Nullable List<Extension> extensions) throws ClientError Validate the device-independent client extension inputs of an authentication request, without a key. The authentication counterpart ofvalidateExtensionInputs(PublicKeyCredentialCreationOptions, List); see it for semantics.- Parameters:
options- the authentication request to validateextensions- the extensions to check, ornullfor the default set- Throws:
ClientError- if a requested extension input cannot be satisfied
-