|
1 | 1 | package org.springframework.security.web.webauthn.jackson; |
2 | 2 |
|
3 | 3 | import org.springframework.security.web.webauthn.api.AttestationConveyancePreference; |
| 4 | +import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInput; |
4 | 5 | import org.springframework.security.web.webauthn.api.AuthenticatorAttachment; |
5 | 6 | import org.springframework.security.web.webauthn.api.AuthenticatorSelectionCriteria; |
6 | 7 | import org.springframework.security.web.webauthn.api.AuthenticatorTransport; |
|
19 | 20 | import org.springframework.security.web.webauthn.api.UserVerificationRequirement; |
20 | 21 |
|
21 | 22 | import java.time.Duration; |
22 | | -import java.util.Collections; |
23 | 23 | import java.util.List; |
24 | 24 | import java.util.Set; |
25 | 25 |
|
|
31 | 31 | */ |
32 | 32 | public final class PublicKeyCredentialCreationOptionsGivens { |
33 | 33 | private PublicKeyCredentialCreationOptionsGivens() {} |
| 34 | + |
34 | 35 | public static PublicKeyCredentialCreationOptions create() { |
35 | 36 | return PublicKeyCredentialCreationOptions.builder() |
36 | | - .rp(PublicKeyCredentialRpEntity.builder().id("example.com").name("Example RP").build()) |
37 | | - .user(ImmutablePublicKeyCredentialUserEntity.builder().name("name").id(Bytes.random()).displayName("displayName").build()) |
| 37 | + .rp( |
| 38 | + PublicKeyCredentialRpEntity.builder() |
| 39 | + .id("example.com") |
| 40 | + .name("Example RP") |
| 41 | + .build() |
| 42 | + ) |
| 43 | + .user( |
| 44 | + ImmutablePublicKeyCredentialUserEntity.builder() |
| 45 | + .name("name") |
| 46 | + .id(Bytes.random()) |
| 47 | + .displayName("displayName") |
| 48 | + .build() |
| 49 | + ) |
38 | 50 | .challenge(Bytes.random()) |
39 | | - .pubKeyCredParams(List.of(PublicKeyCredentialParameters.ES384, PublicKeyCredentialParameters.EdDSA, PublicKeyCredentialParameters.RS512)) |
| 51 | + .pubKeyCredParams( |
| 52 | + List.of( |
| 53 | + PublicKeyCredentialParameters.EdDSA, |
| 54 | + PublicKeyCredentialParameters.ES256, |
| 55 | + PublicKeyCredentialParameters.ES384, |
| 56 | + PublicKeyCredentialParameters.ES512, |
| 57 | + PublicKeyCredentialParameters.RS256, |
| 58 | + PublicKeyCredentialParameters.RS384, |
| 59 | + PublicKeyCredentialParameters.RS512, |
| 60 | + PublicKeyCredentialParameters.RS1 |
| 61 | + ) |
| 62 | + ) |
40 | 63 | .timeout(Duration.ofSeconds(60)) |
41 | | - .excludeCredentials(Collections.singletonList( |
42 | | - PublicKeyCredentialDescriptor.builder() |
43 | | - .id(Bytes.random()) |
44 | | - .type(PublicKeyCredentialType.PUBLIC_KEY) |
45 | | - .transports(Set.of(AuthenticatorTransport.INTERNAL, AuthenticatorTransport.HYBRID)) |
| 64 | + .excludeCredentials( |
| 65 | + List.of( |
| 66 | + PublicKeyCredentialDescriptor.builder() |
| 67 | + .id(Bytes.random()) |
| 68 | + .type(PublicKeyCredentialType.PUBLIC_KEY) |
| 69 | + .transports(Set.of(AuthenticatorTransport.USB)) |
| 70 | + .build(), |
| 71 | + PublicKeyCredentialDescriptor.builder() |
| 72 | + .id(Bytes.random()) |
| 73 | + .type(PublicKeyCredentialType.PUBLIC_KEY) |
| 74 | + .transports(Set.of(AuthenticatorTransport.NFC)) |
| 75 | + .build(), |
| 76 | + PublicKeyCredentialDescriptor.builder() |
| 77 | + .id(Bytes.random()) |
| 78 | + .type(PublicKeyCredentialType.PUBLIC_KEY) |
| 79 | + .transports(Set.of(AuthenticatorTransport.BLE)) |
| 80 | + .build(), |
| 81 | + PublicKeyCredentialDescriptor.builder() |
| 82 | + .id(Bytes.random()) |
| 83 | + .type(PublicKeyCredentialType.PUBLIC_KEY) |
| 84 | + .transports(Set.of(AuthenticatorTransport.SMART_CARD)) |
| 85 | + .build(), |
| 86 | + PublicKeyCredentialDescriptor.builder() |
| 87 | + .id(Bytes.random()) |
| 88 | + .type(PublicKeyCredentialType.PUBLIC_KEY) |
| 89 | + .transports(Set.of(AuthenticatorTransport.HYBRID)) |
| 90 | + .build(), |
| 91 | + PublicKeyCredentialDescriptor.builder() |
| 92 | + .id(Bytes.random()) |
| 93 | + .type(PublicKeyCredentialType.PUBLIC_KEY) |
| 94 | + .transports(Set.of(AuthenticatorTransport.INTERNAL)) |
| 95 | + .build() |
| 96 | + ) |
| 97 | + ) |
| 98 | + .authenticatorSelection( |
| 99 | + AuthenticatorSelectionCriteria.builder() |
| 100 | + .userVerification(UserVerificationRequirement.PREFERRED) |
| 101 | + .residentKey(ResidentKeyRequirement.REQUIRED) |
| 102 | + .authenticatorAttachment(AuthenticatorAttachment.PLATFORM) |
46 | 103 | .build() |
47 | | - )) |
48 | | - .authenticatorSelection(AuthenticatorSelectionCriteria.builder() |
49 | | - .userVerification(UserVerificationRequirement.PREFERRED) |
50 | | - .residentKey(ResidentKeyRequirement.REQUIRED) |
51 | | - .authenticatorAttachment(AuthenticatorAttachment.PLATFORM) |
52 | | - .build() |
53 | 104 | ) |
54 | 105 | .attestation(AttestationConveyancePreference.DIRECT) |
55 | 106 | .extensions( |
56 | | - new ImmutableAuthenticationExtensionsClientInputs(new CredProtectAuthenticationExtensionsClientInput(new CredProtect(ProtectionPolicy.USER_VERIFICATION_REQUIRED, true))) |
| 107 | + new ImmutableAuthenticationExtensionsClientInputs( |
| 108 | + new CredProtectAuthenticationExtensionsClientInput(new CredProtect(ProtectionPolicy.USER_VERIFICATION_REQUIRED, true)), |
| 109 | + new MinPinLengthAuthenticationExtensionsClientInput(true) |
| 110 | + ) |
57 | 111 | ) |
58 | 112 | .build(); |
59 | 113 | } |
| 114 | + |
| 115 | + // ImmutableAuthenticationExtensionsClientInputs wraps a List<AuthenticationExtensionsClientInput<T>>. |
| 116 | + // Since only CredProtectAuthenticationExtensionsClientInput implements AuthenticationExtensionsClientInput<T>, |
| 117 | + // a second class is needed to help test with two extensions. |
| 118 | + /** |
| 119 | + * Implements <a href= |
| 120 | + * "https://fidoalliance.org/specs/fido-v2.2-rd-20230321/fido-client-to-authenticator-protocol-v2.2-rd-20230321.html#sctn-minpinlength-extension"> |
| 121 | + * Minimum PIN Length Extension (minPinLength)</a>. |
| 122 | + * |
| 123 | + * @author Justin Cranford |
| 124 | + * @since 6.5 |
| 125 | + */ |
| 126 | + record MinPinLengthAuthenticationExtensionsClientInput(Boolean getInput) implements AuthenticationExtensionsClientInput<Boolean> { |
| 127 | + @Override |
| 128 | + public String getExtensionId() { |
| 129 | + return "minPinLength"; |
| 130 | + } |
| 131 | + } |
60 | 132 | } |
0 commit comments