Skip to content

Commit e371103

Browse files
committed
Fix demo registration failure when authenticator extensions are present
1 parent 1e852bd commit e371103

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

webauthn-server-demo/src/main/java/demo/webauthn/WebAuthnServer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,17 @@ public void serialize(
647647
throw new RuntimeException(e);
648648
}
649649
});
650-
gen.writeObjectField("extensions", value.getExtensions());
650+
value
651+
.getExtensions()
652+
.ifPresent(
653+
extensions -> {
654+
try {
655+
gen.writeObjectField(
656+
"extensions", JacksonCodecs.cbor().readTree(extensions.EncodeToBytes()));
657+
} catch (IOException e) {
658+
throw new RuntimeException(e);
659+
}
660+
});
651661
gen.writeEndObject();
652662
}
653663
}

webauthn-server-demo/src/test/scala/demo/webauthn/WebAuthnServerSpec.scala

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.yubico.webauthn.data.Generators.arbitraryAuthenticatorTransport
3838
import com.yubico.webauthn.data.PublicKeyCredentialRequestOptions
3939
import com.yubico.webauthn.data.RelyingPartyIdentity
4040
import com.yubico.webauthn.data.ResidentKeyRequirement
41+
import com.yubico.webauthn.test.RealExamples
4142
import demo.webauthn.data.AssertionRequestWrapper
4243
import demo.webauthn.data.CredentialRegistration
4344
import demo.webauthn.data.RegistrationRequest
@@ -91,23 +92,27 @@ class WebAuthnServerSpec
9192
}
9293

9394
it("has a finish method which accepts and outputs JSON.") {
94-
val requestId = ByteArray.fromBase64Url("request1")
95-
96-
val server = newServerWithRegistrationRequest(
97-
RegistrationTestData.FidoU2f.BasicAttestation
98-
)
95+
for {
96+
testData <- List(
97+
RegistrationTestData.FidoU2f.BasicAttestation, // This test case for no particular reason
98+
RealExamples.LargeBlobWrite.asRegistrationTestData, // This test case because it has authenticator extensions
99+
)
100+
} {
101+
val requestId = ByteArray.fromBase64Url("request1")
102+
val server = newServerWithRegistrationRequest(testData)
99103

100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JSON":"eyJjaGFsbGVuZ2UiOiJBQUVCQWdNRkNBMFZJamRaRUdsNVlscyIsIm9yaWdpbiI6ImxvY2FsaG9zdCIsInR5cGUiOiJ3ZWJhdXRobi5jcmVhdGUiLCJ0b2tlbkJpbmRpbmciOnsic3RhdHVzIjoic3VwcG9ydGVkIn19"}"""
102-
val publicKeyCredentialJson =
103-
s"""{"id":"iOOGPqcfeovZAXe2RSiCKUXKS5peMlPDfk7ib7Q1JfQ","response":${authenticationAttestationResponseJson},"clientExtensionResults":{},"type":"public-key"}"""
104-
val responseJson =
105-
s"""{"requestId":"${requestId.getBase64Url}","credential":${publicKeyCredentialJson}}"""
104+
val authenticationAttestationResponseJson =
105+
s"""{"attestationObject":"${testData.attestationObject.getBase64Url}","clientDataJSON":"${testData.clientDataJsonBytes.getBase64Url}"}"""
106+
val publicKeyCredentialJson =
107+
s"""{"id":"${testData.response.getId.getBase64Url}","response":${authenticationAttestationResponseJson},"clientExtensionResults":{},"type":"public-key"}"""
108+
val responseJson =
109+
s"""{"requestId":"${requestId.getBase64Url}","credential":${publicKeyCredentialJson}}"""
106110

107-
val response = server.finishRegistration(responseJson)
108-
val json = jsonMapper.writeValueAsString(response.right.get)
111+
val response = server.finishRegistration(responseJson)
112+
val json = jsonMapper.writeValueAsString(response.right.get)
109113

110-
json should not be null
114+
json should not be null
115+
}
111116
}
112117

113118
}
@@ -393,8 +398,8 @@ class WebAuthnServerSpec
393398
new InMemoryRegistrationStorage,
394399
registrationRequests,
395400
newCache(),
396-
rpId,
397-
origins,
401+
testData.rpId,
402+
Set(testData.response.getResponse.getClientData.getOrigin).asJava,
398403
)
399404
}
400405

0 commit comments

Comments
 (0)