Struct ipworksauth::WebAuthn
Properties Methods Events Config Settings Errors
The WebAuthn struct provides a simple way to implement a WebAuthn Relying Party server in your web application.
Syntax
ipworksauth::WebAuthn
Remarks
The WebAuthn struct provides a simple way to implement a WebAuthn Relying Party server, enabling passwordless authentication in your web application.
A typical Relying Party consists of two entities: the server-side logic and the front-end script. The WebAuthn struct implements the server-side logic. The implementation and communication between these two key entities is up to the application. For a simple example, please refer to the demo in the installation directory.
Setup
Credential Storage
Before utilizing the struct the application should implement some credential repository, storage, or database used to store and retrieve user credentials. The exact implementation of this storage is up to the application. For example, in the included demo, user credential information is stored in a text file on disk. Other implementations could store credentials in memory, a database, etc.
For more information on when to store and retrieve user credentials, and what information is necessary, please refer to the registration and authentication sections below.
Configuring the Relying Party Server
A Relying Party Server has multiple properties that serve as identifiers to WebAuthn clients. These can be configured in the WebAuthn struct by using the following properties:
The origin is a required property and specifies the full web origin, including the protocol (http or https) and domain, of the Relying Party. For example, this property may be set to https://login.example.com:7112. This property, along with relying_party_id, ensures the application's security by restricting requests to valid origins and domains, preventing unauthorized entities from attempting to use credentials.
The relying_party_id is a valid domain string used to identify the Relying Party during registration or authentication. By default, this value is empty, and will be calculated by parsing the default effective domain of the specified origin. Using the previous example, this would mean login.example.com would be used as the relying_party_id.
The relying_party_id can be manually specified, though it should be ensured that a valid effective domain is defined for the given origin. Using the previous example, example.com would suffice, however, m.login.example.com would be an invalid identifier.
The relying_party_name is a user-friendly identifier for the struct, intended only for display. For example, this could be set to a company name, such as ACME Corporation.
Related Origins
If manually specified, the relying_party_id must be equal to an effective domain of the origin. However, singular domains can prove difficult for deployments in larger environments, where multiple country-specific domains are in use.
As such, the origin property may be used to specify a comma-separated list of possible origins, for example, https://example.com:7112,https://example.co.uk:7112. Implementations can allow clients to create and use a credential across this set of origins.
In this case, implementations must manually specify a relying_party_id to use across all operations from related origins. Additionally, a JSON document must be hosted at the webauthn well-known URL for the relying_party_id (e.g., hosted at https://RelyingPartyId/.well-known/webauthn) as described here. This document should contain all origins specified in origin.
Please see below for a simple example of configuring the mentioned properties. Note that at the very least, origin must be set for each step of the registration and authentication processes below.
WebAuthn server = new WebAuthn();
// Automatically set RelyingPartyId to default effective domain
server.Origin = "https://login.example.com:7112";
server.RelyingPartyName = "Example Name";
Console.WriteLine(server.RelyingPartyId); // Prints "login.example.com"
// Manually set RelyingPartyId to a different effective domain
server.Origin = "https://login.example.com:7112";
server.RelyingPartyId = "example.com";
server.RelyingPartyName = "Example Name";
// Specify related origins
server.Origin = "https://login.example.com:7112,https://login.example.co.uk:7112";
server.RelyingPartyId = "example.com";
server.RelyingPArtyName = "Example Name";
Registration
Creating Registration Options
To create a new user credential, a user must first initiate the registration process. Typically, the user initiates a request to the front-end script, which should then communicate with the struct to start this process.
During registration, the struct is first required to build options for creating, or registering, a new user credential by calling create_registration_request. After receiving a request from a front-end, several relevant properties should be set before building these options.
In addition to setting the Relying Party properties, as mentioned in the previous section, the only other required property to set is the user_name. The user_name property should be set to the user-friendly identifier for the user account attempting registration. Typically, the user_name is provided by the client in the front-end request. The client may also provide the user_display_name, specifying a name associated with the user account intended only for display.
The user_id property may be set to some unique identifier for the relevant user_name. By default, the user_id is empty, and will be calculated by the struct as the SHA256 hash of the provided user_name. If manually specified, implementations should ensure that this identifier is unique to the user, and available in future operations related to this user.
Lastly, it may be that the specified user_name has existing credentials previously obtained from various authenticators. Before calling create_registration_request, implementations should query their existing credential database for credentials associated with the specified user_name. Once identified, the user_credentials collection should be populated by calling add_user_credential for each credential. Doing so will ensure that a new credential is not created on an authenticator containing a credential mapped to this user_name. While not explicitly required, this step should be performed.
The following properties may also be set or modified for additional configuration of the produced registration options:
- attestation_type
- authenticator_attachment
- discoverable_credentials
- extensions
- public_key_algorithms
- timeout
- user_verification
Once the struct is configured, create_registration_request should be called, producing a JSON string of the relevant options that should be returned to the client. Implementations should store the created options somewhere for use during verification (see below). For example, these options could be stored in the HTTP session context, which should persist during registration.
The client should pass these options to the JavaScript function navigator.credentials.create(). After doing so, the client will then interact with the authenticator. For example, the client may enter a PIN or touch a security key. Assuming this is successful, navigator.credentials.create() will return the authenticator response, which should then be returned to the struct.
Please see below for an example of configuring the struct in this case, and storing the options in the HTTP context:
server.UserName = "test";
server.UserDisplayName = "Test User";
// Some List of WACredential type, search by UserName
List<WACredential> existingCredentials = QueryCredentialsByUser(server.UserName);
for (int i = 0; i < existingCredentials.Count; i++) {
server.AddUserCredential(existingCredentials[i].IdB, existingCredentials[i].PublicKey, existingCredentials[i].SignCount, existingCredentials[i].SignAlgorithm)
}
// JSON options string that should be returned to the client and passed to navigator.credentials.create()
string ret = server.CreateRegistrationRequest();
// Store the options in the same context for later use during registration.
context.Session.SetString("registrationOptions", ret);
Verifying the Registration Response
Assuming a response has been received from the authenticator, to complete registration, the client must provide this response to the struct. To verify the authenticator response, verify_registration_response should be called, taking the options previously generated with create_registration_request and the recently received response as parameters.
After calling verify_registration_response, the on_registration_info event will fire, providing the Id of the recently created credential. During this event, implementations should search for the provided credential Id in their database. Credential Ids must be unique, i.e., no existing credential in the database may have the provided credential Id. If the provided credential Id exists for any user, verification should fail, and the Cancel parameter of on_registration_info should be set to true to do so.
Assuming the credential Id does not exist for any other user and the additional verification performed by the struct succeeds, on_registration_complete will fire. This event will provide various information about the newly created credential record. During this event, implementations should save this information to their existing credential database for use during future registration or authentication ceremonies. Specifically, implementations should save the following values associated with the credential record.
- The current user_name associated with the credential.
- If manually specified, the associated user_id.
- The CredentialId parameter of on_registration_complete.
- The PublicKey parameter of on_registration_complete.
- The SignCount parameter of on_registration_complete.
- The Algorithm parameter of on_registration_complete.
Additionally, implementations may wish to store the BackupEligible, BackupState, and UvInitialized configs as well.
Once the relevant credential information is saved, registration is officially complete, and the registered credential may be used in future authentication ceremonies.
Please see below for an example of the verification process:
server.OnRegistrationInfo += (o, e) => {
// Some List of WACredential type, search by Credential Id
existingCredentials = QueryCredentialsById(e.CredentialId);
if (existingCredentials.Count != 0) {
// Registration should fail since CredentialId exists
e.Cancel = true;
}
};
server.OnRegistrationComplete += (o, e) => {
// Save credential info for authentication
SaveCredential(server.UserName, e.CredentialIdB, e.PublicKey, e.SignCount, e.Algorithm);
};
string response = StreamReader(context.Request.Body).ReadToEnd();
string cachedOptions = context.Session.GetString("registrationOptions") ?? String.Empty;
server.VerifyRegistrationResponse(response, options);
Console.WriteLine("Registration Successful.");
Authentication
Creating Authentication Options
To log in using an existing credential, a user must first initiate the authentication process. Typically, the user initiates a request to the front end which should communicate directly with the struct to start this process.
During authentication, the struct is first required to build options for logging in using an existing user credential by calling create_authentication_request. After receiving a request from a front-end, several relevant properties should be set before building these options.
In addition to setting the Relying Party properties, as mentioned in the first section, there are no required properties that must be set before calling create_authentication_request.
Typically, the user attempting to log in will provide the username associated with their account, however, this is not a requirement. If the username is provided, implementations should query their existing credential database for any credentials associated with this username. Once identified, the user_credentials collection should be populated by calling add_user_credential for each user credential. When sending the options to the client in a later step, the authenticator will then allow the client to select from these credentials during authentication. Note that the user_name property should not be specified in this case, as it is not included in the options.
If the client does not specify a username, implementations should leave the user_credentials collection empty. When sending the options to the client in a later step, the authenticator will then allow the client to utilize any discoverable credentials that were previously created. Discoverable credentials are made available to the client in this specific case, and the client may choose any of the existing discoverable credentials as presented by the authenticator. A discoverable credential can be created during registration. The struct can indicate its preference regarding whether a discoverable credential is created using the discoverable_credentials property during this step. If no discoverable credentials exist, this will result in an error.
The following properties may also be set or modified for additional configuration of the produced login options:
- extensions
- timeout
Once the struct is configured, create_authentication_request should be called, producing a JSON string of the relevant options that should be returned to the client. Implementations should store the created options somewhere for use during verification (see below). For example, these options could be stored in the HTTP session context, which should persist during authentication.
The client should pass these options to the JavaScript function navigator.credentials.get(). After doing so, the client will then interact with the authenticator. For example, the client may enter a PIN or touch a security key. Assuming this is successful, navigator.credentials.get() will return the authenticator response, which should then be returned to the struct.
Please see below for an example of configuring the struct in this case, and storing the options in the HTTP context:
string userName = "test"; // If provided, optional
List<existingCredentials> = QueryCredentialsByUser(userName);
for (int i = 0; i < existingCredentials.Count; i++) {
server.AddUserCredential(existingCredentials[i].IdB, existingCredentials[i].PublicKey, existingCredentials[i].SignCount, existingCredentials[i].SignAlgorithm)
}
// JSON options string that should be returned to the client and passed to navigator.credentials.create()
string ret = server.CreateAuthenticationRequest();
// Store the options in the same context for later use during login.
context.Session.SetString("loginOptions", ret);
Verifying the Authentication Response
Assuming a response has been received from the authenticator, to complete the login process, the client must provide this response to the struct. To verify the authenticator response, verify_authentication_response should be called, taking the recently received response, and the options previously generated with create_authentication_request (stored in the HTTP context).
After calling verify_authentication_response, the on_authentication_info event will fire, providing the Id of the recently created credential. During this event, implementations should search for the provided credential Id in their database. Since a user is attempting to use an existing credential, it is assumed this credential exists in the database. If the provided credential Id does not exist, the Cancel parameter of on_authentication_info should be set to true, and verification should fail.
Assuming the credential exists in the database, the following properties and event parameters should be set during on_authentication_info:
- The current user_name associated with the credential.
- If manually specified, the associated user_id.
- The PublicKey parameter of on_authentication_info.
- The SignCount parameter of on_authentication_info.
- The Algorithm parameter of on_authentication_info.
Assuming this information is correct, the struct will continue the verification process accordingly, and on_authentication_complete will fire. This event will provide necessary information regarding any updates to the existing credential. During this event, implementations should update the credential in their database for future use. Specifically, implementations should update the signature counter associated with the credential record by utilizing the SignCount parameter of on_authentication_complete.
Implementations may wish to query the values of the BackupState and UvInitialized configs to update the stored credential record accordingly.
Once the relevant credential information is updated, authentication is complete.
Please see below for an example of the verification process:
server.OnAuthenticationInfo += (o, e) => {
// Search for single Credential Id
existingCredential = QueryCredentialById(e.CredentialId);
string user = QueryUserById(e.CredentialId);
if (existingCredential == null) {
// Authentication should fail since CredentialId does not exist
e.Cancel = true;
}
server.UserName = user;
e.PublicKey = existingCredential.PublicKey;
e.SignCount = existingCredential.SignCount;
e.Algorithm = existingCredential.SignAlgorithm;
};
server.OnAuthenticationComplete += (o, e) => {
// Update credential info
SaveCredential(e.CredentialIdB, e.SignCount);
};
string response = new StreamReader(context.Request.Body).ReadToEnd();
string cachedOptions = context.Session.GetString("loginOptions") ?? String.Empty;
server.VerifyAuthenticationResponse(response, options);
Console.WriteLine("Authentication Successful.");
Object Lifetime
The new() method returns a mutable reference to a struct instance. The object itself is kept in the global list maintained by IPWorksAuth. Due to this, the WebAuthn struct cannot be disposed of automatically. Please, call the dispose(&mut self) method of WebAuthn when you have finished using the instance.
Property List
The following is the full list of the properties of the struct with short descriptions. Click on the links for further details.
| attestation_type | Specifies the preference regarding attestation conveyance during registration. |
| authenticator_attachment | Specifies the preference regarding authenticator attachment modality during registration. |
| discoverable_credentials | Specifies whether the Relying Party wishes to create a client-side discoverable credential during registration. |
| wa_extension_count | The number of records in the WAExtension arrays. |
| wa_extension_name | Specifies the name of the extension. |
| wa_extension_value | Specifies the value of the extension. |
| wa_extension_value_type | Specifies the type of the Value of the current extension. |
| origin | Specifies the full web origin, including the protocol (http or https) and domain, of the struct (WebAuthn Relying Party). |
| public_key_algorithms | Specifies an ordered, comma-separated list of acceptable algorithms for the public key during registration. |
| relying_party_id | Specifies the unique identifier of the Relying Party. |
| relying_party_name | Specifies a user-friendly name for the WebAuthn Relying Party. |
| timeout | Specifies a time, in seconds, that the Relying Party is willing to wait for the operation to complete. |
| wa_credential_count | The number of records in the WACredential arrays. |
| wa_credential_id | Specifies the credential Id of the credential. |
| wa_credential_public_key | Specifies the public key of the credential. |
| wa_credential_sign_algorithm | Specifies the signing algorithm of the credential. |
| wa_credential_sign_count | Specifies the signature count of the credential. |
| user_display_name | Specifies a user-friendly name for the associated user account intended only for display. |
| user_id | Specifies the user Id, or user handle, for the associated user account. |
| user_name | Specifies a user-friendly name for the associated user account. |
| user_verification | Specifies the Relying Party's requirements regarding user verification during registration. |
Method List
The following is the full list of the methods of the struct with short descriptions. Click on the links for further details.
| add_extension | Used to add an extension to include when building the options for registration or authentication. |
| add_user_credential | Used to add a user credential to the UserCredentials collection. |
| config | Sets or retrieves a configuration setting. |
| create_authentication_request | Used to build the request options for a user attempting to login, or authenticate, using an existing credential. |
| create_registration_request | Used to build the request options for a user attempting to register a new credential. |
| reset | Resets the struct properties. |
| verify_authentication_response | Used to log in, or authenticate, using an existing credential. |
| verify_registration_response | Used to register a new credential. |
Event List
The following is the full list of the events fired by the struct with short descriptions. Click on the links for further details.
| on_authentication_complete | Fired when a user successfully logs in. |
| on_authentication_info | Fired when the struct requests additional information regarding the existing credential. |
| on_error | Fired when information is available about errors during data delivery. |
| on_extension | Fired when an extension is found while verifying an authenticator response. |
| on_log | Fired once for each log message. |
| on_registration_complete | Fired when a user is successfully registered. |
| on_registration_info | Fired when the struct requests additional information regarding the new credential. |
Config Settings
The following is a list of config settings for the struct with short descriptions. Click on the links for further details.
| BackupEligible | Indicates or specifies the backup eligibility of a credential. |
| BackupState | Indicates the backup state of a credential. |
| Hints | Specifies any hints to communicate to the user-agent about how a request may be completed. |
| ServerChallenge | Specifies the cryptographic challenge associated with the current options, as specified by the struct. |
| UvInitialized | Indicates whether user verification has been performed for a new or existing credential. |
| BuildInfo | Information about the product's build. |
| CodePage | The system code page used for Unicode to Multibyte translations. |
| LicenseInfo | Information about the current license. |
| MaskSensitiveData | Whether sensitive data is masked in log messages. |
| UseInternalSecurityAPI | Whether or not to use the system security libraries or an internal implementation. |
attestation_type property (WebAuthn Struct)
Specifies the preference regarding attestation conveyance during registration.
Syntax
fn attestation_type(&self ) -> Result<i32, IPWorksAuthError>
fn set_attestation_type(&self, value : i32) -> Option<IPWorksAuthError>
Possible Values
0 // None
1 // Indirect
2 // Direct
3 // Enterprise
Default Value
0
Remarks
This property specifies the preference regarding attestation conveyance during registration. This value may be set prior to calling create_registration_request. Possible values include:
| 0 (atNone - default) | Indicates the Relying Party is not interested in an attestation. |
| 1 (atIndirect) | Indicates the Relying Party wants to receive a verifiable attestation, but allows the client to decide how to obtain such an attestation statement. |
| 2 (atDirect) | Indicates the Relying Party wants to receive the attestation statement as generated by the authenticator. |
| 3 (atEnterprise) | Indicates the Relying Party wants to receive an attestation statement that may include uniquely identifying information. |
Data Type
i32
authenticator_attachment property (WebAuthn Struct)
Specifies the preference regarding authenticator attachment modality during registration.
Syntax
fn authenticator_attachment(&self ) -> Result<i32, IPWorksAuthError>
fn set_authenticator_attachment(&self, value : i32) -> Option<IPWorksAuthError>
Possible Values
0 // Any
1 // Platform
2 // CrossPlatform
Default Value
0
Remarks
This property specifies the preference regarding authenticator attachment modality. This value may be set prior to calling create_registration_request. Possible values include:
| 0 (atAny - default) | Indicates the Relying Party does not have a preference between platform and cross-platform authenticators. |
| 1 (atPlatform) | Indicates the Relying Party prefers the use of a platform authenticator, i.e., a non-removable authenticator. |
| 2 (atCrossPlatform) | Indicates the Relying Party prefers the use of a cross-platform attachment, i.e., a roaming authenticator. |
Note that this value may not affect which types of authenticators (platform or cross-platform) are presented to the client, as it only indicates server-side preference.
Data Type
i32
discoverable_credentials property (WebAuthn Struct)
Specifies whether the Relying Party wishes to create a client-side discoverable credential during registration.
Syntax
fn discoverable_credentials(&self ) -> Result<i32, IPWorksAuthError>
fn set_discoverable_credentials(&self, value : i32) -> Option<IPWorksAuthError>
Possible Values
0 // Unspecified
1 // Discouraged
2 // Preferred
3 // Required
Default Value
0
Remarks
This property specifies whether the Relying Party wishes to create a client-side discoverable credential during registration. This value may be set prior to calling create_registration_request. Possible values include:
| 0 (dcUnspecified - default) | The option will not be specified in the returned value of create_registration_request. |
| 1 (dcDiscouraged) | The Relying Party prefers creating a server-side credential, but will accept a client-side discoverable credential. |
| 2 (dcPreferred) | The Relying Party strongly prefers creating a client-side discoverable credential, but will accept a server-side credential. |
| 3 (dcRequired) | The Relying Party requires a client-side discoverable credential. |
As some background, a discoverable credential is a credential that is discoverable and usable during authentication ceremonies where the user_credentials is empty, i.e., when no existing credential Ids are specified. In this case, the Relying Party does not necessarily need to first identify the user. On the client-side, the user will be able to select some appropriate credential to log in with.
Assuming the authentication on the client-side is successful, the authenticator should return a response to the application, which will contain the relevant credential Id used to log in. The associated credential Id will be provided in on_authentication_info, and assuming the credential exists, relevant credential information should be provided.
Data Type
i32
wa_extension_count property (WebAuthn Struct)
The number of records in the WAExtension arrays.
Syntax
fn wa_extension_count(&self ) -> Result<i32, IPWorksAuthError>
Default Value
0
Remarks
This property controls the size of the following arrays:
The array indices start at 0 and end at wa_extension_count - 1.This property is read-only.
Data Type
i32
wa_extension_name property (WebAuthn Struct)
Specifies the name of the extension.
Syntax
fn wa_extension_name(&self , WAExtensionIndex : i32) -> Result<String, IPWorksAuthError>
Default Value
""
Remarks
Specifies the name of the extension.
The WAExtensionIndex parameter specifies the index of the item in the array. The size of the array is controlled by the WAExtensionCount property.
This property is read-only.
Data Type
String
wa_extension_value property (WebAuthn Struct)
Specifies the value of the extension.
Syntax
fn wa_extension_value(&self , WAExtensionIndex : i32) -> Result<String, IPWorksAuthError>
Default Value
""
Remarks
Specifies the value of the extension. See wa_extension_value_type for information regarding this properties type.
The WAExtensionIndex parameter specifies the index of the item in the array. The size of the array is controlled by the WAExtensionCount property.
This property is read-only.
Data Type
String
wa_extension_value_type property (WebAuthn Struct)
Specifies the type of the Value of the current extension.
Syntax
fn wa_extension_value_type(&self , WAExtensionIndex : i32) -> Result<i32, IPWorksAuthError>
Default Value
0
Remarks
Specifies the type of the wa_extension_value of the current extension. Possible values are:
- 0 (Object)
- 1 (Array)
- 2 (String)
- 3 (Number)
- 4 (Bool)
- 5 (Null)
- 6 (Raw)
The WAExtensionIndex parameter specifies the index of the item in the array. The size of the array is controlled by the WAExtensionCount property.
This property is read-only.
Data Type
i32
origin property (WebAuthn Struct)
Specifies the full web origin, including the protocol (http or https) and domain, of the struct (WebAuthn Relying Party).
Syntax
fn origin(&self ) -> Result<String, IPWorksAuthError>
fn set_origin(&self, value : &str) -> Option<IPWorksAuthError> fn set_origin_ref(&self, value : &String) -> Option<IPWorksAuthError>
Default Value
""
Remarks
This property specifies the full web origin, including the protocol (http or https) and domain, of the struct (WebAuthn Relying Party). The origin must be specified before calling create_registration_request, verify_registration_response, create_authentication_request, and verify_authentication_response.
This property ensures the security of the application by restricting requests to valid origins, preventing unauthorized entities from attempting to use credentials. For example, setting the Origin property to https://login.example.com:7112 limits requests to that specific domain.
By default, after setting this property, the relying_party_id will be set to the default effective domain of the origin. In the above example, relying_party_id would be set to login.example.com.
The relying_party_id can be manually specified, though it should be ensured that a valid effective domain is specified for the given origin. Using the previous example, example.com would suffice, however, m.login.example.com would be an invalid identifier.
Related Origins
If manually specified, the relying_party_id must be equal to an effective domain of the origin. However, singular domains can prove difficult for deployments in larger environments, where multiple country-specific domains are in use.
As such, the origin property may be used to specify a comma-separated list of possible origins, for example, https://example.com:7112,https://example.co.uk:7112. Implementations can allow clients to create and use a credential across this set of origins.
In this case, implementations must manually specify a relying_party_id to use across all operations from related origins. Additionally, a JSON document must be hosted at the webauthn well-known URL for the relying_party_id (e.g., hosted at https://RelyingPartyId/.well-known/webauthn) as described here. This document should contain all origins specified in origin.
Data Type
String
public_key_algorithms property (WebAuthn Struct)
Specifies an ordered, comma-separated list of acceptable algorithms for the public key during registration.
Syntax
fn public_key_algorithms(&self ) -> Result<String, IPWorksAuthError>
fn set_public_key_algorithms(&self, value : &str) -> Option<IPWorksAuthError> fn set_public_key_algorithms_ref(&self, value : &String) -> Option<IPWorksAuthError>
Default Value
"ES256,RS256"
Remarks
This property specifies an ordered, comma-separated list of acceptable algorithms for the public key during registration. By default, this value is ES256,RS256, and must be specified before calling create_registration_request.
Though those elements are sorted by preference (the first element being the most preferred), it is up to the client to choose among those elements for building the credential.
Possible values to include in this property are:
- ES256 (default)
- RS256 (default)
- ES384
- ES512
- EdDSA
- PS256
- PS384
- PS512
- RS1
The selected algorithm will be made available in on_registration_complete, after verifying the authenticator response using verify_registration_response.
Data Type
String
relying_party_id property (WebAuthn Struct)
Specifies the unique identifier of the Relying Party.
Syntax
fn relying_party_id(&self ) -> Result<String, IPWorksAuthError>
fn set_relying_party_id(&self, value : &str) -> Option<IPWorksAuthError> fn set_relying_party_id_ref(&self, value : &String) -> Option<IPWorksAuthError>
Default Value
""
Remarks
This property specifies the unique identifier of the WebAuthn Relying Party.
A Relying Party identifier is a valid domain string identifying the WebAuthn Relying Party on whose behalf registration or authentication is being performed.
By default, this value is empty, and will be set as the default effective domain of the origin. For example, if the origin is specified as https://example.com, this property will be set to example.com.
The relying_party_id can be manually specified after setting origin, though it should be ensured that a valid effective domain is specified for the given origin. Using the previous example, example.com would suffice, however, m.login.example.com would be an invalid identifier.
NOTE: If the origin is specified as a comma-separated list of valid origins, this property must be manually specified, otherwise, it will remain empty.
Data Type
String
relying_party_name property (WebAuthn Struct)
Specifies a user-friendly name for the WebAuthn Relying Party.
Syntax
fn relying_party_name(&self ) -> Result<String, IPWorksAuthError>
fn set_relying_party_name(&self, value : &str) -> Option<IPWorksAuthError> fn set_relying_party_name_ref(&self, value : &String) -> Option<IPWorksAuthError>
Default Value
""
Remarks
This property specifies a user-friendly identifier for the Relying Party, intended only for display. For example, "ACME Corporation", "Wonderful Widgets, Inc.".
This property may be specified before calling create_registration_request, verify_registration_response, create_authentication_request, and verify_authentication_response.
Data Type
String
timeout property (WebAuthn Struct)
Specifies a time, in seconds, that the Relying Party is willing to wait for the operation to complete.
Syntax
fn timeout(&self ) -> Result<i32, IPWorksAuthError>
fn set_timeout(&self, value : i32) -> Option<IPWorksAuthError>
Default Value
60
Remarks
This property specifies a time, in seconds, that the Relying Party is willing to wait for the operation to complete. By default, this is set to 60 seconds.
When calling create_registration_request or create_authentication_request, this value simply represents a hint for the time the struct is willing to wait for the completion of the operation. This property is optional and merely is a hint which may be overridden by the browser.
Data Type
i32
wa_credential_count property (WebAuthn Struct)
The number of records in the WACredential arrays.
Syntax
fn wa_credential_count(&self ) -> Result<i32, IPWorksAuthError>
Default Value
0
Remarks
This property controls the size of the following arrays:
The array indices start at 0 and end at wa_credential_count - 1.This property is read-only.
Data Type
i32
wa_credential_id property (WebAuthn Struct)
Specifies the credential Id of the credential.
Syntax
fn wa_credential_id(&self , WACredentialIndex : i32) -> Result<Vec<u8>, IPWorksAuthError>
Default Value
""
Remarks
Specifies the credential Id of the credential.
The WACredentialIndex parameter specifies the index of the item in the array. The size of the array is controlled by the WACredentialCount property.
This property is read-only.
Data Type
Vec
wa_credential_public_key property (WebAuthn Struct)
Specifies the public key of the credential.
Syntax
fn wa_credential_public_key(&self , WACredentialIndex : i32) -> Result<String, IPWorksAuthError>
Default Value
""
Remarks
Specifies the public key of the credential.
The WACredentialIndex parameter specifies the index of the item in the array. The size of the array is controlled by the WACredentialCount property.
This property is read-only.
Data Type
String
wa_credential_sign_algorithm property (WebAuthn Struct)
Specifies the signing algorithm of the credential.
Syntax
fn wa_credential_sign_algorithm(&self , WACredentialIndex : i32) -> Result<String, IPWorksAuthError>
Default Value
"0"
Remarks
Specifies the signing algorithm of the credential.
The WACredentialIndex parameter specifies the index of the item in the array. The size of the array is controlled by the WACredentialCount property.
This property is read-only.
Data Type
String
wa_credential_sign_count property (WebAuthn Struct)
Specifies the signature count of the credential.
Syntax
fn wa_credential_sign_count(&self , WACredentialIndex : i32) -> Result<i32, IPWorksAuthError>
Default Value
0
Remarks
Specifies the signature count of the credential.
The WACredentialIndex parameter specifies the index of the item in the array. The size of the array is controlled by the WACredentialCount property.
This property is read-only.
Data Type
i32
user_display_name property (WebAuthn Struct)
Specifies a user-friendly name for the associated user account intended only for display.
Syntax
fn user_display_name(&self ) -> Result<String, IPWorksAuthError>
fn set_user_display_name(&self, value : &str) -> Option<IPWorksAuthError> fn set_user_display_name_ref(&self, value : &String) -> Option<IPWorksAuthError>
Default Value
""
Remarks
This property specifies a user-friendly name for the associated user account intended only for display.
Data Type
String
user_id property (WebAuthn Struct)
Specifies the user Id, or user handle, for the associated user account.
Syntax
fn user_id(&self ) -> Result<Vec<u8>, IPWorksAuthError>
fn set_user_id(&self, value : Vec<u8>) -> Option<IPWorksAuthError> fn set_user_id_ref(&self, value : &[u8]) -> Option<IPWorksAuthError>
Default Value
""
Remarks
This property specifies the user Id, or user handle, for the associated user account. By default, this value will be empty. If left unspecified, the Id will be calculated as the SHA256 hash of the user_name property for use during registration and authentication.
If manually specified, this property will be used instead. In this case, it should be ensured that the specified Id is an opaque byte sequence with a maximum size of 64 bytes.
Note that this property is not meant to be displayed to the user.
Data Type
Vec
user_name property (WebAuthn Struct)
Specifies a user-friendly name for the associated user account.
Syntax
fn user_name(&self ) -> Result<String, IPWorksAuthError>
fn set_user_name(&self, value : &str) -> Option<IPWorksAuthError> fn set_user_name_ref(&self, value : &String) -> Option<IPWorksAuthError>
Default Value
""
Remarks
This property specifies a user-friendly name or identifier for the associated user account. This property must be set prior to calling create_registration_request.
For example, possible values include: "alexm", "+14255551234", "alex.mueller@example.com", "alex.mueller@example.com (prod-env)".
By default, the user_id will be calculated as the SHA256 hash of this property for use during registration and authentication.
Data Type
String
user_verification property (WebAuthn Struct)
Specifies the Relying Party's requirements regarding user verification during registration.
Syntax
fn user_verification(&self ) -> Result<i32, IPWorksAuthError>
fn set_user_verification(&self, value : i32) -> Option<IPWorksAuthError>
Possible Values
0 // Required
1 // Preferred
2 // Discouraged
Default Value
1
Remarks
This property specifies whether the Relying Party's requirements regarding user verification during registration. Possible values include:
| 0 (uvRequired) | The Relying Party requires user verification during registration or authentication, in that an error should be returned if user verification cannot be performed, or fails. |
| 1 (uvPreferred - default) | The Relying Party prefers user verification during registration or authentication if possible, but will not fail the operation if user verification is not performed. |
| 2 (uvDiscouraged) | The Relying Party discourages user verification during registration or authentication, but will not fail the operation if user verification is performed. |
As some background, an authenticator must support at least one authentication factor. An authenticator that supports one or more additional authentication factors (i.e., 2 or 3 total authentication factors) can support user verification, and is known as a multi-factor capable authenticator. In that regard, an authenticator that is not multi-factor capable is defined as single-factor capable, and do not support user verification. If this property is set to 0 (uvRequired) and the client attempts to utilize a single-factor capable authenticator, registration will fail.
Whether user verification was successful, or even performed, is indicated by the UvInitialized config, which may be queried during on_registration_complete or on_authentication_complete. This config may be stored or updated during these events for future use.
Data Type
i32
add_extension method (WebAuthn Struct)
Used to add an extension to include when building the options for registration or authentication.
Syntax
fn add_extension(&self, name : &str, value : &str, value_type : i32) -> Result<(), IPWorksAuthError>
Remarks
This method is used to add an extension to include when building the options for registration or authentication (i.e., when calling create_registration_request and create_authentication_request, respectively).
The Name parameter specifies the name of the extension.
The Value parameter specifies the value of the extension.
The ValueType parameter specifies the type of the value. Possible values are as follows:
- 0 (Object)
- 1 (Array)
- 2 (String)
- 3 (Number)
- 4 (Bool)
- 5 (Null)
- 6 (Raw)
For example, to include the registered FIDO AppId Extension (appid) when calling create_authentication_request, you can do the following:
webauthn.AddExtension("appid", "some_legacy_rp_id", 2);
Assuming the extensions are supported by the authenticator and client, the extension outputs are reported when verifying the response after calling either verify_registration_response or verify_authentication_response. For each extension, the on_extension event will fire with the relevant response parameters and types.
In the above case, the extension output will report either true or false, depending on whether the provided appid was utilized. If true, the relying_party_id should be updated accordingly to ensure that verification succeeds. For example:
webauthn.OnExtension += (o, e) => {
// Ensure returned value is a boolean, and true, before updating
if (e.Name.Equals("appid") && e.ValueType == 4 && bool.Parse(e.Value)) {
webauthn.RelyingPartyId = "some_legacy_rp_id";
}
};
add_user_credential method (WebAuthn Struct)
Used to add a user credential to the UserCredentials collection.
Syntax
fn add_user_credential(&self, credential_id : &[u8], public_key : &str, sign_count : i32, algorithm : &str) -> Result<(), IPWorksAuthError>
Remarks
This method is used to add a user credential to the user_credentials collection, which can be used to hold existing credentials for a specified user_name prior to calling create_registration_request and create_authentication_request.
Before calling create_registration_request, this method should be called for each credential that exists for the given user_name. Included credentials will be specified in the resulting options. This will ensure that the new credential is not created on an authenticator that already contains a credential mapped to the specific user_name. If a mapped credential for the selected authenticator already exists, this may result in an error.
Before calling create_authentication_request, if a username is provided by the front-end, add_user_credential should be called for each existing credential for the identified user account. The user_name property should not be specified in this case, as it is not included in the options.
If a username is not provided by the front-end, add_user_credential should not called, and only discoverable credentials will be utilized for authentication. In this case, the user will select the relevant credential during authentication, unknown to the struct initially. After receiving a response from the authenticator and calling verify_authentication_response, the utilized credential will be present in on_authentication_info.
config method (WebAuthn Struct)
Sets or retrieves a configuration setting.
Syntax
fn config(&self, configuration_string : &str) -> Result<String, IPWorksAuthError>
Remarks
config is a generic method available in every struct. It is used to set and retrieve configuration settings for the struct.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the struct, access to these internal properties is provided through the config method.
To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.
create_authentication_request method (WebAuthn Struct)
Used to build the request options for a user attempting to login, or authenticate, using an existing credential.
Syntax
fn create_authentication_request(&self) -> Result<String, IPWorksAuthError>
Remarks
This method is used to build the request options for a user attempting to login, or authenticate, an existing credential, and will return a JSON-formatted string of these options. These options should be returned to the front-end and then passed to navigator.credentials.get() after some additional modification.
Before calling this method, origin, relying_party_id, and/or relying_party_name must be set accordingly.
Additionally, if the user account has been identified (i.e., the user has specified their username), add_user_credential should be called to populate user_credentials with existing credentials for the identified user. If the user account has not been specified, user_credentials may remain empty, implying that only discoverable credentials will be utilized for login.
The following properties may also be set or modified for additional configuration of the produced login options:
- extensions
- timeout
Please see below for a simple example of this process:
string userName = "test"; // If provided, optional
List<existingCredentials> = QueryCredentialsByUser(userName);
for (int i = 0; i < existingCredentials.Count; i++) {
server.AddUserCredential(existingCredentials[i].IdB, existingCredentials[i].PublicKey, existingCredentials[i].SignCount, existingCredentials[i].SignAlgorithm)
}
// JSON options string that should be returned to the client and passed to navigator.credentials.create()
string ret = server.CreateAuthenticationRequest();
// Store the options in the same context for later use during login.
context.Session.SetString("loginOptions", ret);
create_registration_request method (WebAuthn Struct)
Used to build the request options for a user attempting to register a new credential.
Syntax
fn create_registration_request(&self) -> Result<String, IPWorksAuthError>
Remarks
This method is used to build the request options for a user attempting to register, and will return a JSON-formatted string of these options. These options should be returned to the front-end and then passed to navigator.credentials.create() after some additional modification.
Before calling this method, origin, relying_party_id, and/or relying_party_name must be set accordingly.
To identify the user performing registration, the user_name, user_display_name, and user_id should be specified. Additionally, add_user_credential should be called to populate user_credentials with existing credentials for the relevant user.
The following properties may also be set or modified for additional configuration of the produced registration options:
- attestation_type
- authenticator_attachment
- discoverable_credentials
- extensions
- public_key_algorithms
- timeout
- user_verification
Please see below for a simple example of this process:
server.UserName = "test";
server.UserDisplayName = "Test User";
// Some List of WACredential type, search by UserName
List<WACredential> existingCredentials = QueryCredentialsByUser(server.UserName);
for (int i = 0; i < existingCredentials.Count; i++) {
server.AddUserCredential(existingCredentials[i].IdB, existingCredentials[i].PublicKey, existingCredentials[i].SignCount, existingCredentials[i].SignAlgorithm)
}
// JSON options string that should be returned to the client and passed to navigator.credentials.create()
string ret = server.CreateRegistrationRequest();
// Store the options in the same context for later use during registration.
context.Session.SetString("registrationOptions", ret);
reset method (WebAuthn Struct)
Resets the struct properties.
Syntax
fn reset(&self) -> Result<(), IPWorksAuthError>
Remarks
This method resets all message and key properties to their default values.
verify_authentication_response method (WebAuthn Struct)
Used to log in, or authenticate, using an existing credential.
Syntax
fn verify_authentication_response(&self, response : &str, options : &str) -> Result<(), IPWorksAuthError>
Remarks
This method is used to log in, or authenticate, using an existing credential.
Before calling this method, origin, relying_party_id, and/or relying_party_name must be set accordingly.
The Response parameter is used to provide the JSON-formatted authenticator response returned from the front-end call to navigator.credentials.get().
The Options parameter is used to provide the options obtained from create_authentication_request during the first step of authentication.
After parsing the Response and Options parameters, the struct will first attempt to verify the Response. During verification, on_authentication_info will fire, requesting additional information regarding the current credential. Within this event, it should be confirmed that the relevant credential used to log in exists. Relevant information about this credential should also be provided to the struct. Please see on_authentication_info for additional information.
Assuming the response is successfully verified, on_authentication_complete will fire containing updated information about the existing credential, which must be stored for future use. Afterwards, this method will return successfully, indicating the authentication process is complete.
Please see below for a simple example of this process:
server.OnAuthenticationInfo += (o, e) => {
// Search for single Credential Id
existingCredential = QueryCredentialById(e.CredentialId);
string user = QueryUserById(e.CredentialId);
if (existingCredential == null) {
// Authentication should fail since CredentialId does not exist
e.Cancel = true;
}
server.UserName = user;
e.PublicKey = existingCredential.PublicKey;
e.SignCount = existingCredential.SignCount;
e.Algorithm = existingCredential.SignAlgorithm;
};
server.OnAuthenticationComplete += (o, e) => {
// Update credential info
SaveCredential(e.CredentialIdB, e.SignCount);
};
string response = new StreamReader(context.Request.Body).ReadToEnd();
string cachedOptions = context.Session.GetString("loginOptions") ?? String.Empty;
server.VerifyAuthenticationResponse(response, options);
Console.WriteLine("Authentication Successful.");
verify_registration_response method (WebAuthn Struct)
Used to register a new credential.
Syntax
fn verify_registration_response(&self, response : &str, options : &str) -> Result<(), IPWorksAuthError>
Remarks
This method is used to register a new credential.
Before calling this method, origin, relying_party_id, and/or relying_party_name must be set accordingly.
The Response parameter is used to provide the JSON-formatted authenticator response returned from the front-end call to navigator.credentials.create().
The Options parameter is used to provide the options obtained from create_registration_request during the first step of registration.
After parsing the Response and Options parameters, the struct will first attempt to verify the Response. During verification, on_registration_info will fire, requesting confirmation regarding the new credential. Within this event, it should be confirmed that the new credential does not already exist for any user. Please see on_registration_info for additional information.
Assuming the response is successfully verified, on_registration_complete will fire containing information about the new credential, which must be stored for future use. Afterwards, this method will return successfully, indicating the registration process is complete.
Please see below for a simple example of this process:
server.OnRegistrationInfo += (o, e) => {
// Some List of WACredential type, search by Credential Id
existingCredentials = QueryCredentialsById(e.CredentialId);
if (existingCredentials.Count != 0) {
// Registration should fail since CredentialId exists
e.Cancel = true;
}
};
server.OnRegistrationComplete += (o, e) => {
// Save credential info for authentication
SaveCredential(server.UserName, e.CredentialIdB, e.PublicKey, e.SignCount, e.Algorithm);
};
string response = StreamReader(context.Request.Body).ReadToEnd();
string cachedOptions = context.Session.GetString("registrationOptions") ?? String.Empty;
server.VerifyRegistrationResponse(response, options);
Console.WriteLine("Registration Successful.");
on_authentication_complete event (WebAuthn Struct)
Fired when a user successfully logs in.
Syntax
// WebAuthnAuthenticationCompleteEventArgs carries the WebAuthn AuthenticationComplete event's parameters.
pub struct WebAuthnAuthenticationCompleteEventArgs {
fn credential_id(&self) -> &[u8]
fn sign_count(&self) -> i32
}
// WebAuthnAuthenticationCompleteEvent defines the signature of the WebAuthn AuthenticationComplete event's handler function.
pub trait WebAuthnAuthenticationCompleteEvent {
fn on_authentication_complete(&self, sender : WebAuthn, e : &mut WebAuthnAuthenticationCompleteEventArgs);
}
impl <'a> WebAuthn<'a> {
pub fn on_authentication_complete(&self) -> &'a dyn WebAuthnAuthenticationCompleteEvent;
pub fn set_on_authentication_complete(&mut self, value : &'a dyn WebAuthnAuthenticationCompleteEvent);
...
}
Remarks
This event is fired when a user successfully logs in, i.e., after verify_authentication_response returns without error.
The CredentialId parameter should be used to identify the locally stored credential that has been used to successfully log in.
Once the stored credential is identified, the signature counter of this credential record should be updated to the value in the SignCount parameter.
If stored previously, implementations may also query the BackupState and UvInitialized configs to update the credential record accordingly.
on_authentication_info event (WebAuthn Struct)
Fired when the struct requests additional information regarding the existing credential.
Syntax
// WebAuthnAuthenticationInfoEventArgs carries the WebAuthn AuthenticationInfo event's parameters.
pub struct WebAuthnAuthenticationInfoEventArgs {
fn credential_id(&self) -> &[u8]
fn cancel(&self) -> bool
fn set_cancel(&self, value : bool)
fn public_key(&self) -> &String
fn set_public_key(&self, value : &str)
fn set_public_key_ref(&self, value : &String)
fn algorithm(&self) -> &String
fn set_algorithm(&self, value : &str)
fn set_algorithm_ref(&self, value : &String)
fn sign_count(&self) -> i32
fn set_sign_count(&self, value : i32)
}
// WebAuthnAuthenticationInfoEvent defines the signature of the WebAuthn AuthenticationInfo event's handler function.
pub trait WebAuthnAuthenticationInfoEvent {
fn on_authentication_info(&self, sender : WebAuthn, e : &mut WebAuthnAuthenticationInfoEventArgs);
}
impl <'a> WebAuthn<'a> {
pub fn on_authentication_info(&self) -> &'a dyn WebAuthnAuthenticationInfoEvent;
pub fn set_on_authentication_info(&mut self, value : &'a dyn WebAuthnAuthenticationInfoEvent);
...
}
Remarks
This event is fired when the struct requests additional information regarding the existing credential after calling verify_authentication_response.
The CredentialId parameter specifies the credential Id of the existing credential.
The Cancel parameter may be utilized to cancel the authentication of the current user or credential.
To handle this event appropriately, the CredentialId parameter should be utilized to check the existing credential database. If the credential does not exist in the database, authentication should fail, and the Cancel parameter should be set to true.
Otherwise, if the credential exists, PublicKey, Algorithm, and SignCount should be set to their relevant values associated with the credential. Additionally, the user_name (and possibly user_id) should be set to their relevant values. The struct will utilize these to complete the verification and authentication process.
If stored previously, implementations may optionally set the BackupEligible config for use during verification.
on_error event (WebAuthn Struct)
Fired when information is available about errors during data delivery.
Syntax
// WebAuthnErrorEventArgs carries the WebAuthn Error event's parameters.
pub struct WebAuthnErrorEventArgs {
fn error_code(&self) -> i32
fn description(&self) -> &String
}
// WebAuthnErrorEvent defines the signature of the WebAuthn Error event's handler function.
pub trait WebAuthnErrorEvent {
fn on_error(&self, sender : WebAuthn, e : &mut WebAuthnErrorEventArgs);
}
impl <'a> WebAuthn<'a> {
pub fn on_error(&self) -> &'a dyn WebAuthnErrorEvent;
pub fn set_on_error(&mut self, value : &'a dyn WebAuthnErrorEvent);
...
}
Remarks
The on_error event is fired in case of exceptional conditions during message processing. Normally the struct fails with an error.
The error_code parameter contains an error code, and the description parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.
on_extension event (WebAuthn Struct)
Fired when an extension is found while verifying an authenticator response.
Syntax
// WebAuthnExtensionEventArgs carries the WebAuthn Extension event's parameters.
pub struct WebAuthnExtensionEventArgs {
fn name(&self) -> &String
fn value(&self) -> &String
fn value_type(&self) -> i32
}
// WebAuthnExtensionEvent defines the signature of the WebAuthn Extension event's handler function.
pub trait WebAuthnExtensionEvent {
fn on_extension(&self, sender : WebAuthn, e : &mut WebAuthnExtensionEventArgs);
}
impl <'a> WebAuthn<'a> {
pub fn on_extension(&self) -> &'a dyn WebAuthnExtensionEvent;
pub fn set_on_extension(&mut self, value : &'a dyn WebAuthnExtensionEvent);
...
}
Remarks
This event is fired when an extension is found while verifying an authenticator response using either verify_registration_response or verify_authentication_response. Any extensions from the parsed response will be added to the extensions collection and may be manually verified in on_registration_info or on_authentication_info.
The Name parameter specifies the name of the extension.
The Value parameter specifies the value of the extension.
The ValueType parameter specifies the type of the value. Possible values are as follows:
- 0 (Object)
- 1 (Array)
- 2 (String)
- 3 (Number)
- 4 (Bool)
- 5 (Null)
- 6 (Raw)
The struct will not interpret the extensions found, and it will be up to the developer to interpret the extensions accordingly. For more information and an example, please see add_extension.
on_log event (WebAuthn Struct)
Fired once for each log message.
Syntax
// WebAuthnLogEventArgs carries the WebAuthn Log event's parameters.
pub struct WebAuthnLogEventArgs {
fn log_level(&self) -> i32
fn message(&self) -> &String
fn log_type(&self) -> &String
}
// WebAuthnLogEvent defines the signature of the WebAuthn Log event's handler function.
pub trait WebAuthnLogEvent {
fn on_log(&self, sender : WebAuthn, e : &mut WebAuthnLogEventArgs);
}
impl <'a> WebAuthn<'a> {
pub fn on_log(&self) -> &'a dyn WebAuthnLogEvent;
pub fn set_on_log(&mut self, value : &'a dyn WebAuthnLogEvent);
...
}
Remarks
This event is fired once for each log message generated by the struct. The verbosity is controlled by the LogLevel setting.
log_level indicates the level of message. Possible values are as follows:
| 0 (None) | No events are logged. |
| 1 (Info - default) | Informational events are logged. |
| 2 (Verbose) | Detailed data are logged. |
| 3 (Debug) | Debug data are logged. |
The value 1 (Info) logs basic information, including the URL, HTTP version, and status details.
The value 2 (Verbose) logs additional information about the request and response.
The value 3 (Debug) logs the headers and body for both the request and response, as well as additional debug information (if any).
message is the log entry.
log_type identifies the type of log entry. Possible values are as follows:
- "Info"
- "RequestHeaders"
- "ResponseHeaders"
- "RequestBody"
- "ResponseBody"
- "ProxyRequest"
- "ProxyResponse"
- "FirewallRequest"
- "FirewallResponse"
on_registration_complete event (WebAuthn Struct)
Fired when a user is successfully registered.
Syntax
// WebAuthnRegistrationCompleteEventArgs carries the WebAuthn RegistrationComplete event's parameters.
pub struct WebAuthnRegistrationCompleteEventArgs {
fn credential_id(&self) -> &[u8]
fn user_name(&self) -> &String
fn public_key(&self) -> &String
fn sign_count(&self) -> i32
fn algorithm(&self) -> &String
}
// WebAuthnRegistrationCompleteEvent defines the signature of the WebAuthn RegistrationComplete event's handler function.
pub trait WebAuthnRegistrationCompleteEvent {
fn on_registration_complete(&self, sender : WebAuthn, e : &mut WebAuthnRegistrationCompleteEventArgs);
}
impl <'a> WebAuthn<'a> {
pub fn on_registration_complete(&self) -> &'a dyn WebAuthnRegistrationCompleteEvent;
pub fn set_on_registration_complete(&mut self, value : &'a dyn WebAuthnRegistrationCompleteEvent);
...
}
Remarks
This event is fired when a user is successfully registered, i.e., after verify_registration_response returns without error.
The CredentialId parameter indicates the credential Id of the new credential associated with the current UserName.
Along with the credential Id, the PublicKey, SignCount, and Algorithm parameters must be stored for future use. Specifically, these parameters will be utilized during authentication, when verify_authentication_response is called. These parameters should be directly associated with the specific user this credential was created for.
Implementations may optionally store the BackupState, BackupEligible, UvInitialized configs for future use. Please refer to the config descriptions for additional details.
on_registration_info event (WebAuthn Struct)
Fired when the struct requests additional information regarding the new credential.
Syntax
// WebAuthnRegistrationInfoEventArgs carries the WebAuthn RegistrationInfo event's parameters.
pub struct WebAuthnRegistrationInfoEventArgs {
fn credential_id(&self) -> &[u8]
fn cancel(&self) -> bool
fn set_cancel(&self, value : bool)
}
// WebAuthnRegistrationInfoEvent defines the signature of the WebAuthn RegistrationInfo event's handler function.
pub trait WebAuthnRegistrationInfoEvent {
fn on_registration_info(&self, sender : WebAuthn, e : &mut WebAuthnRegistrationInfoEventArgs);
}
impl <'a> WebAuthn<'a> {
pub fn on_registration_info(&self) -> &'a dyn WebAuthnRegistrationInfoEvent;
pub fn set_on_registration_info(&mut self, value : &'a dyn WebAuthnRegistrationInfoEvent);
...
}
Remarks
This event is fired when the struct requests additional information regarding the new credential after calling verify_registration_response.
The Cancel parameter may be utilized to cancel the authentication of the current user or credential.
To handle this event appropriately, the CredentialId parameter should be utilized to check the existing credential database. If the credential Id already exists in the database for any user, this implies that registration should fail. In this case, the Cancel parameter should be set to true.
Otherwise, if the credential Id does not exist in the existing credential database, the Cancel parameter should not be modified, and verification will succeed.
Config Settings (WebAuthn Struct)
The struct accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the struct, access to these internal properties is provided through the config method.WebAuthn Config Settings
- 0: The credential is a single-device credential and may never be backed up.
- 1: The credential is a multi-device credential and may be backed up.
During registration, this config may be queried within on_registration_complete (or after verify_registration_response returns) in order to store the backup eligibility of the new credential for future use.
During authentication, this config may first be set during on_authentication_info for use during verification of the existing credential. By default, this config will be set to -1, implying that backup eligibility will not be utilized during verification.
After verification, this config may be queried within on_authentication_complete in order to update the stored backup eligibility of the existing credential.
It is recommended to store the value of this flag along with the relevant credential for future evaluation, though not required.
- 0: The credential is not currently backed up.
- 1: The credential is currently backed up.
During registration, this config may be queried within on_registration_complete (or after verify_registration_response returns) in order to store the backup state of the new credential for future use.
During authentication, this config may be queried within on_authentication_complete (or after verify_authentication_response returns) in order to update the stored backup state of the existing credential.
It is recommended to store the value of this flag along with the relevant credential for future evaluation, though not required.
This config may be specified as a comma-separated list of one or more of the following values in order of decreasing preference:
- security-key: Indicates that the Relying Party believes that users will satisfy this request with a physical security key.
- client-device: Indicates that the Relying Party believes that users will satisfy this request with a platform authenticator attached to the client device.
- hybrid: Indicates that the Relying Party believes that users will satisfy this request with general-purpose authenticators such as smartphones.
For example, this config may be set to the following string: security-key,client-device,hybrid
The cryptographic challenge is some randomly generated data that is sent to the authenticator.
After calling create_registration_request or create_authentication_request, this may be queried to get the challenge specified in the recently created options.
The struct can indicate whether it would like user verification to occur by setting the user_verification property before calling create_registration_request. This config may be queried during on_registration_complete or on_authentication_complete to determine the current user verification status of the relevant credential.
This config may be stored or updated during on_registration_complete or on_authentication_complete for future use.
Base Config Settings
The following is a list of valid code page identifiers:
| Identifier | Name |
| 037 | IBM EBCDIC - U.S./Canada |
| 437 | OEM - United States |
| 500 | IBM EBCDIC - International |
| 708 | Arabic - ASMO 708 |
| 709 | Arabic - ASMO 449+, BCON V4 |
| 710 | Arabic - Transparent Arabic |
| 720 | Arabic - Transparent ASMO |
| 737 | OEM - Greek (formerly 437G) |
| 775 | OEM - Baltic |
| 850 | OEM - Multilingual Latin I |
| 852 | OEM - Latin II |
| 855 | OEM - Cyrillic (primarily Russian) |
| 857 | OEM - Turkish |
| 858 | OEM - Multilingual Latin I + Euro symbol |
| 860 | OEM - Portuguese |
| 861 | OEM - Icelandic |
| 862 | OEM - Hebrew |
| 863 | OEM - Canadian-French |
| 864 | OEM - Arabic |
| 865 | OEM - Nordic |
| 866 | OEM - Russian |
| 869 | OEM - Modern Greek |
| 870 | IBM EBCDIC - Multilingual/ROECE (Latin-2) |
| 874 | ANSI/OEM - Thai (same as 28605, ISO 8859-15) |
| 875 | IBM EBCDIC - Modern Greek |
| 932 | ANSI/OEM - Japanese, Shift-JIS |
| 936 | ANSI/OEM - Simplified Chinese (PRC, Singapore) |
| 949 | ANSI/OEM - Korean (Unified Hangul Code) |
| 950 | ANSI/OEM - Traditional Chinese (Taiwan; Hong Kong SAR, PRC) |
| 1026 | IBM EBCDIC - Turkish (Latin-5) |
| 1047 | IBM EBCDIC - Latin 1/Open System |
| 1140 | IBM EBCDIC - U.S./Canada (037 + Euro symbol) |
| 1141 | IBM EBCDIC - Germany (20273 + Euro symbol) |
| 1142 | IBM EBCDIC - Denmark/Norway (20277 + Euro symbol) |
| 1143 | IBM EBCDIC - Finland/Sweden (20278 + Euro symbol) |
| 1144 | IBM EBCDIC - Italy (20280 + Euro symbol) |
| 1145 | IBM EBCDIC - Latin America/Spain (20284 + Euro symbol) |
| 1146 | IBM EBCDIC - United Kingdom (20285 + Euro symbol) |
| 1147 | IBM EBCDIC - France (20297 + Euro symbol) |
| 1148 | IBM EBCDIC - International (500 + Euro symbol) |
| 1149 | IBM EBCDIC - Icelandic (20871 + Euro symbol) |
| 1200 | Unicode UCS-2 Little-Endian (BMP of ISO 10646) |
| 1201 | Unicode UCS-2 Big-Endian |
| 1250 | ANSI - Central European |
| 1251 | ANSI - Cyrillic |
| 1252 | ANSI - Latin I |
| 1253 | ANSI - Greek |
| 1254 | ANSI - Turkish |
| 1255 | ANSI - Hebrew |
| 1256 | ANSI - Arabic |
| 1257 | ANSI - Baltic |
| 1258 | ANSI/OEM - Vietnamese |
| 1361 | Korean (Johab) |
| 10000 | MAC - Roman |
| 10001 | MAC - Japanese |
| 10002 | MAC - Traditional Chinese (Big5) |
| 10003 | MAC - Korean |
| 10004 | MAC - Arabic |
| 10005 | MAC - Hebrew |
| 10006 | MAC - Greek I |
| 10007 | MAC - Cyrillic |
| 10008 | MAC - Simplified Chinese (GB 2312) |
| 10010 | MAC - Romania |
| 10017 | MAC - Ukraine |
| 10021 | MAC - Thai |
| 10029 | MAC - Latin II |
| 10079 | MAC - Icelandic |
| 10081 | MAC - Turkish |
| 10082 | MAC - Croatia |
| 12000 | Unicode UCS-4 Little-Endian |
| 12001 | Unicode UCS-4 Big-Endian |
| 20000 | CNS - Taiwan |
| 20001 | TCA - Taiwan |
| 20002 | Eten - Taiwan |
| 20003 | IBM5550 - Taiwan |
| 20004 | TeleText - Taiwan |
| 20005 | Wang - Taiwan |
| 20105 | IA5 IRV International Alphabet No. 5 (7-bit) |
| 20106 | IA5 German (7-bit) |
| 20107 | IA5 Swedish (7-bit) |
| 20108 | IA5 Norwegian (7-bit) |
| 20127 | US-ASCII (7-bit) |
| 20261 | T.61 |
| 20269 | ISO 6937 Non-Spacing Accent |
| 20273 | IBM EBCDIC - Germany |
| 20277 | IBM EBCDIC - Denmark/Norway |
| 20278 | IBM EBCDIC - Finland/Sweden |
| 20280 | IBM EBCDIC - Italy |
| 20284 | IBM EBCDIC - Latin America/Spain |
| 20285 | IBM EBCDIC - United Kingdom |
| 20290 | IBM EBCDIC - Japanese Katakana Extended |
| 20297 | IBM EBCDIC - France |
| 20420 | IBM EBCDIC - Arabic |
| 20423 | IBM EBCDIC - Greek |
| 20424 | IBM EBCDIC - Hebrew |
| 20833 | IBM EBCDIC - Korean Extended |
| 20838 | IBM EBCDIC - Thai |
| 20866 | Russian - KOI8-R |
| 20871 | IBM EBCDIC - Icelandic |
| 20880 | IBM EBCDIC - Cyrillic (Russian) |
| 20905 | IBM EBCDIC - Turkish |
| 20924 | IBM EBCDIC - Latin-1/Open System (1047 + Euro symbol) |
| 20932 | JIS X 0208-1990 & 0121-1990 |
| 20936 | Simplified Chinese (GB2312) |
| 21025 | IBM EBCDIC - Cyrillic (Serbian, Bulgarian) |
| 21027 | Extended Alpha Lowercase |
| 21866 | Ukrainian (KOI8-U) |
| 28591 | ISO 8859-1 Latin I |
| 28592 | ISO 8859-2 Central Europe |
| 28593 | ISO 8859-3 Latin 3 |
| 28594 | ISO 8859-4 Baltic |
| 28595 | ISO 8859-5 Cyrillic |
| 28596 | ISO 8859-6 Arabic |
| 28597 | ISO 8859-7 Greek |
| 28598 | ISO 8859-8 Hebrew |
| 28599 | ISO 8859-9 Latin 5 |
| 28605 | ISO 8859-15 Latin 9 |
| 29001 | Europa 3 |
| 38598 | ISO 8859-8 Hebrew |
| 50220 | ISO 2022 Japanese with no halfwidth Katakana |
| 50221 | ISO 2022 Japanese with halfwidth Katakana |
| 50222 | ISO 2022 Japanese JIS X 0201-1989 |
| 50225 | ISO 2022 Korean |
| 50227 | ISO 2022 Simplified Chinese |
| 50229 | ISO 2022 Traditional Chinese |
| 50930 | Japanese (Katakana) Extended |
| 50931 | US/Canada and Japanese |
| 50933 | Korean Extended and Korean |
| 50935 | Simplified Chinese Extended and Simplified Chinese |
| 50936 | Simplified Chinese |
| 50937 | US/Canada and Traditional Chinese |
| 50939 | Japanese (Latin) Extended and Japanese |
| 51932 | EUC - Japanese |
| 51936 | EUC - Simplified Chinese |
| 51949 | EUC - Korean |
| 51950 | EUC - Traditional Chinese |
| 52936 | HZ-GB2312 Simplified Chinese |
| 54936 | Windows XP: GB18030 Simplified Chinese (4 Byte) |
| 57002 | ISCII Devanagari |
| 57003 | ISCII Bengali |
| 57004 | ISCII Tamil |
| 57005 | ISCII Telugu |
| 57006 | ISCII Assamese |
| 57007 | ISCII Oriya |
| 57008 | ISCII Kannada |
| 57009 | ISCII Malayalam |
| 57010 | ISCII Gujarati |
| 57011 | ISCII Punjabi |
| 65000 | Unicode UTF-7 |
| 65001 | Unicode UTF-8 |
| Identifier | Name |
| 1 | ASCII |
| 2 | NEXTSTEP |
| 3 | JapaneseEUC |
| 4 | UTF8 |
| 5 | ISOLatin1 |
| 6 | Symbol |
| 7 | NonLossyASCII |
| 8 | ShiftJIS |
| 9 | ISOLatin2 |
| 10 | Unicode |
| 11 | WindowsCP1251 |
| 12 | WindowsCP1252 |
| 13 | WindowsCP1253 |
| 14 | WindowsCP1254 |
| 15 | WindowsCP1250 |
| 21 | ISO2022JP |
| 30 | MacOSRoman |
| 10 | UTF16String |
| 0x90000100 | UTF16BigEndian |
| 0x94000100 | UTF16LittleEndian |
| 0x8c000100 | UTF32String |
| 0x98000100 | UTF32BigEndian |
| 0x9c000100 | UTF32LittleEndian |
| 65536 | Proprietary |
- Product: The product the license is for.
- Product Key: The key the license was generated from.
- License Source: Where the license was found (e.g., RuntimeLicense, License File).
- License Type: The type of license installed (e.g., Royalty Free, Single Server).
- Last Valid Build: The last valid build number for which the license will work.
Setting this configuration setting to true tells the struct to use the internal implementation instead of using the system security libraries.
On Windows, this setting is set to false by default. On Linux/macOS, this setting is set to true by default.
To use the system security libraries for Linux, OpenSSL support must be enabled. For more information on how to enable OpenSSL, please refer to the OpenSSL Notes section.