Skip to content

Commit 1dcf430

Browse files
committed
Fix requireResidentKey regression in toCredentialsCreateJson()
1 parent 63d6af1 commit 1dcf430

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Fixes:
2020
handle are both absent unless a user handle was returned by the authenticator.
2121
This was originally released in pre-release `1.12.3-RC3`, but was accidentally
2222
left out of the `1.12.3` release.
23+
* Fixed regression in
24+
`PublicKeyCredentialCreationOptions.toCredentialsCreateJson()`, which has not
25+
been emitting a `requireResidentKey` member since version `2.0.0`. This meant
26+
the JSON output was not backwards compatible with browsers that only support
27+
the Level 1 version of the WebAuthn spec.
2328

2429
New features:
2530

doc/Migrating_from_v1.adoc

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ Here is a high-level outline of what needs to be updated:
2626
- Update `getUserVerification()` and `getResidentKey()` calls
2727
to expect `Optional` values.
2828
29-
This migration guide is written for version `2.0.0` of the
29+
Although the next section references version `2.4.0-RC2` for reasons detailed there,
30+
this migration guide is written for version `2.0.0` of the
3031
`webauthn-server-core` module. Later `2.x` versions may introduce new features
31-
but should remain compatible without further changes; consult the release notes
32-
for a full list of new features.
32+
but should remain compatible without further changes; please consult the
33+
link:https://developers.yubico.com/java-webauthn-server/Release_Notes.html[release notes]
34+
for an up to date list of new features.
3335

3436

3537
== Replace dependency on `webauthn-server-core-minimal`
@@ -46,7 +48,7 @@ Maven example:
4648
- <artifactId>webauthn-server-core-minimal</artifactId>
4749
- <version>1.12.2</version>
4850
+ <artifactId>webauthn-server-core</artifactId>
49-
+ <version>2.0.0</version>
51+
+ <version>2.4.0-RC2</version>
5052
<scope>compile</scope>
5153
</dependency>
5254
----------
@@ -56,10 +58,30 @@ Gradle:
5658
[source,diff]
5759
----------
5860
-compile 'com.yubico:webauthn-server-core-minimal:1.12.2'
59-
+compile 'com.yubico:webauthn-server-core:2.0.0'
61+
+compile 'com.yubico:webauthn-server-core:2.4.0-RC2'
6062
----------
6163

6264

65+
[WARNING]
66+
.*Backwards-incompatible regression in versions 2.0.0 to 2.4.0-RC1*
67+
==========
68+
Versions in the inclusive range `2.0.0` to `2.4.0-RC1` have
69+
a backwards-incompatible regression in
70+
link:https://developers.yubico.com/java-webauthn-server/JavaDoc/webauthn-server-core/latest/com/yubico/webauthn/data/PublicKeyCredentialCreationOptions.html#toCredentialsCreateJson()[`PublicKeyCredentialCreationOptions.toCredentialsCreateJson()`]:
71+
When the
72+
link:https://developers.yubico.com/java-webauthn-server/JavaDoc/webauthn-server-core/2.3.0/com/yubico/webauthn/StartRegistrationOptions.StartRegistrationOptionsBuilder.html#authenticatorSelection(com.yubico.webauthn.data.AuthenticatorSelectionCriteria)[`authenticatorSelection`].link:https://developers.yubico.com/java-webauthn-server/JavaDoc/webauthn-server-core/2.3.0/com/yubico/webauthn/data/AuthenticatorSelectionCriteria.AuthenticatorSelectionCriteriaBuilder.html#residentKey(com.yubico.webauthn.data.ResidentKeyRequirement)[`residentKey`]
73+
parameter is set, a corresponding
74+
link:https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-requireresidentkey[`requireResidentKey`]
75+
member is not emitted in the JSON output.
76+
This is not backwards compatible with browsers that only support the
77+
link:https://www.w3.org/TR/2019/REC-webauthn-1-20190304/#authenticatorSelection[Level 1 version of the WebAuthn spec].
78+
The regression is fixed in version `2.4.0-RC2` and greater.
79+
We therefore urge users to upgrade from versions `1.x` directly to `2.4.0-RC2` or greater to maintain backwards compatibility.
80+
Please consult the link:https://developers.yubico.com/java-webauthn-server/Release_Notes.html[release notes]
81+
for an up to date list of additional changes and new features added since version `2.0.0`.
82+
==========
83+
84+
6385
== Add JCA provider for EdDSA
6486

6587
The library no longer depends explicitly on BouncyCastle for cryptography back-ends.

webauthn-server-core/src/main/java/com/yubico/webauthn/data/AuthenticatorSelectionCriteria.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public Optional<AuthenticatorAttachment> getAuthenticatorAttachment() {
100100
* <p>By default, this is not set. When not set, the default in the browser is {@link
101101
* ResidentKeyRequirement#DISCOURAGED}.
102102
*
103+
* <p>When this is set, {@link PublicKeyCredentialCreationOptions#toCredentialsCreateJson()} will
104+
* also emit a <a
105+
* href="https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-requireresidentkey">
106+
* <code>requireResidentKey</code></a> member for backwards compatibility with WebAuthn Level 1.
107+
* It will be set to <code>true</code> if this is set to {@link ResidentKeyRequirement#REQUIRED
108+
* REQUIRED} and <code>false</code> if this is set to anything else. When this is not set, a
109+
* <code>requireResidentKey</code> will not be emitted.
110+
*
103111
* @see ResidentKeyRequirement
104112
* @see <a
105113
* href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6.
@@ -112,6 +120,19 @@ public Optional<ResidentKeyRequirement> getResidentKey() {
112120
return Optional.ofNullable(residentKey);
113121
}
114122

123+
/**
124+
* For backwards compatibility with <code>requireResidentKey</code>.
125+
*
126+
* @see <a
127+
* href="https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-requireresidentkey">5.4.4.
128+
* Authenticator Selection Criteria (dictionary AuthenticatorSelectionCriteria) member
129+
* requireResidentKey</a>
130+
*/
131+
@JsonProperty
132+
private Boolean isRequireResidentKey() {
133+
return getResidentKey().map(rk -> rk == ResidentKeyRequirement.REQUIRED).orElse(null);
134+
}
135+
115136
/**
116137
* Describes the Relying Party's requirements regarding <a
117138
* href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-verification">user

webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyStartOperationSpec.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package com.yubico.webauthn
2626

27+
import com.yubico.internal.util.JacksonCodecs
2728
import com.yubico.webauthn.Generators._
2829
import com.yubico.webauthn.data.AssertionExtensionInputs
2930
import com.yubico.webauthn.data.AttestationConveyancePreference
@@ -33,6 +34,7 @@ import com.yubico.webauthn.data.AuthenticatorTransport
3334
import com.yubico.webauthn.data.ByteArray
3435
import com.yubico.webauthn.data.Generators.Extensions.registrationExtensionInputs
3536
import com.yubico.webauthn.data.Generators._
37+
import com.yubico.webauthn.data.PublicKeyCredentialCreationOptions
3638
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor
3739
import com.yubico.webauthn.data.PublicKeyCredentialParameters
3840
import com.yubico.webauthn.data.RegistrationExtensionInputs
@@ -454,18 +456,37 @@ class RelyingPartyStartOperationSpec
454456
.build()
455457
)
456458

459+
def jsonRequireResidentKey(
460+
pkcco: PublicKeyCredentialCreationOptions
461+
): Option[Boolean] =
462+
Option(
463+
JacksonCodecs
464+
.json()
465+
.readTree(pkcco.toCredentialsCreateJson)
466+
.get("publicKey")
467+
.get("authenticatorSelection")
468+
.get("requireResidentKey")
469+
).map(_.booleanValue)
470+
457471
pkccoDiscouraged.getAuthenticatorSelection.get.getResidentKey.toScala should be(
458472
Some(ResidentKeyRequirement.DISCOURAGED)
459473
)
474+
jsonRequireResidentKey(pkccoDiscouraged) should be(Some(false))
475+
460476
pkccoPreferred.getAuthenticatorSelection.get.getResidentKey.toScala should be(
461477
Some(ResidentKeyRequirement.PREFERRED)
462478
)
479+
jsonRequireResidentKey(pkccoPreferred) should be(Some(false))
480+
463481
pkccoRequired.getAuthenticatorSelection.get.getResidentKey.toScala should be(
464482
Some(ResidentKeyRequirement.REQUIRED)
465483
)
484+
jsonRequireResidentKey(pkccoRequired) should be(Some(true))
485+
466486
pkccoUnspecified.getAuthenticatorSelection.get.getResidentKey.toScala should be(
467487
None
468488
)
489+
jsonRequireResidentKey(pkccoUnspecified) should be(None)
469490
}
470491

471492
it("respects the authenticatorAttachment parameter.") {

0 commit comments

Comments
 (0)