Skip to content

Commit

Permalink
Simplify option classes (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpassing authored Mar 15, 2024
1 parent d85c2a6 commit 23920da
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void WhenNoPlatformAuthenticatorPresent_ThenCreateCredentialThrowsExcepti
ClientData.FromJson("{}"),
new AttestationOptions()
{
Authenticator = AuthenticatorAttachment.Platform
AuthenticatorAttachment = AuthenticatorAttachment.Platform
},
CancellationToken.None)
.Wait());
Expand Down
59 changes: 41 additions & 18 deletions sources/Jpki.Security.WebAuthn/Security/WebAuthn/IAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

namespace Jpki.Security.WebAuthn
{
/// <summary>
/// WebAuthn authenticator.
/// </summary>
public interface IAuthenticator
{
/// <summary>
Expand All @@ -51,41 +54,61 @@ Task<Assertion> CreateAssertionAsync(
CancellationToken cancellationToken);
}

public abstract class AuthenticatorOptions
{

/// <summary>
/// Types of authenticator the user is allowed to use.
/// </summary>
public AuthenticatorAttachment AuthenticatorAttachment { get; set; }
= AuthenticatorAttachment.Any;

/// <summary>
/// Type of verification the user is expected to perform.
/// </summary>
public UserVerificationRequirement UserVerification { get; set; }
= UserVerificationRequirement.Any;

/// <summary>
/// Timeout allotted for authentication.
/// </summary>
public TimeSpan Timeout { get; set; } = TimeSpan.Zero;
}

/// <summary>
/// Options for creating credential attestations.
/// </summary>
public class AttestationOptions
public class AttestationOptions : AuthenticatorOptions
{
/// <summary>
/// Signature algorithms the authenticator
/// is allowed to use.
/// </summary>
public CoseSignatureAlgorithm[] SignatureAlgorithms { get; set; }
= new[] { CoseSignatureAlgorithm.ES256 };

public AuthenticatorAttachment Authenticator { get; set; }
= AuthenticatorAttachment.CrossPlatform;

public UserVerificationRequirement UserVerification { get; set; }
= UserVerificationRequirement.Preferred;

/// <summary>
/// Determines whether the authenticator is expected to
/// return an attestation.
/// </summary>
public AttestationConveyance Attestation { get; set; }
= AttestationConveyance.None;

/// <summary>
/// Determines whether the authenticator is expected
/// to allocate a resident key or not.
/// </summary>
public ResidentKeyRequirement ResidentKey { get; set; }

public TimeSpan Timeout { get; set; } = TimeSpan.Zero;
}

/// <summary>
/// Options for creating assertions.
/// </summary>
public class AssertionOptions
public class AssertionOptions : AuthenticatorOptions
{
/// <summary>
/// Set of existing credentials the authenticator can use.
/// </summary>
public ICollection<CredentialId>? AllowedCredentials { get; set; }

public AuthenticatorAttachment AuthenticatorAttachment { get; set; }
= AuthenticatorAttachment.Any;

public UserVerificationRequirement UserVerification { get; set; }
= UserVerificationRequirement.Any;

public TimeSpan Timeout { get; set; } = TimeSpan.Zero;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private static Credential CreateCredential(
cExtensions = 0
},

dwAuthenticatorAttachment = (WEBAUTHN_AUTHENTICATOR_ATTACHMENT)options.Authenticator,
dwAuthenticatorAttachment = (WEBAUTHN_AUTHENTICATOR_ATTACHMENT)options.AuthenticatorAttachment,
bRequireResidentKey = options.ResidentKey == ResidentKeyRequirement.Required,
bPreferResidentKey = options.ResidentKey == ResidentKeyRequirement.Preferred,
dwUserVerificationRequirement = (WEBAUTHN_USER_VERIFICATION_REQUIREMENT)options.UserVerification,
Expand Down

0 comments on commit 23920da

Please sign in to comment.