From e0668eee93fc0015cb65c50f425db4e4d2758840 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Wed, 8 Nov 2023 14:59:48 +0100 Subject: [PATCH] Add public factory functions to LargeBlobAuthenticationOutput --- NEWS | 1 + .../com/yubico/webauthn/data/Extensions.java | 33 ++++++++++++++++++- .../webauthn/RelyingPartyAssertionSpec.scala | 11 +++---- .../RelyingPartyV2AssertionSpec.scala | 11 +++---- .../yubico/webauthn/data/ExtensionsSpec.scala | 7 ++-- .../com/yubico/webauthn/data/Generators.scala | 4 +-- .../webauthn/data/ReexportHelpers.scala | 19 ----------- 7 files changed, 46 insertions(+), 40 deletions(-) delete mode 100644 webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ReexportHelpers.scala diff --git a/NEWS b/NEWS index 5a2df224f..02b98efa9 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ New features: * Added public builder to `CredentialPropertiesOutput`. * Added public factory function `LargeBlobRegistrationOutput.supported(boolean)`. +* Added public factory functions to `LargeBlobAuthenticationOutput`. * (Experimental) Added option `isSecurePaymentConfirmation(boolean)` to `FinishAssertionOptions`. When set, `RelyingParty.finishAssertion()` will adapt the validation logic for a Secure Payment Confirmation (SPC) response diff --git a/webauthn-server-core/src/main/java/com/yubico/webauthn/data/Extensions.java b/webauthn-server-core/src/main/java/com/yubico/webauthn/data/Extensions.java index 1cd3348d0..8a819367f 100644 --- a/webauthn-server-core/src/main/java/com/yubico/webauthn/data/Extensions.java +++ b/webauthn-server-core/src/main/java/com/yubico/webauthn/data/Extensions.java @@ -364,12 +364,43 @@ public static class LargeBlobAuthenticationOutput { @JsonProperty private final Boolean written; @JsonCreator - LargeBlobAuthenticationOutput( + private LargeBlobAuthenticationOutput( @JsonProperty("blob") ByteArray blob, @JsonProperty("written") Boolean written) { this.blob = blob; this.written = written; } + /** + * Create a Large blob storage extension output with the blob output set to the + * given value. + * + *

This corresponds to the extension input {@link LargeBlobAuthenticationInput#read() + * LargeBlobAuthenticationInput.read()}. + * + * @see + * dictionary AuthenticationExtensionsLargeBlobOutputs + */ + public static LargeBlobAuthenticationOutput read(final ByteArray blob) { + return new LargeBlobAuthenticationOutput(blob, null); + } + + /** + * Create a Large blob storage extension output with the written output set to + * the given value. + * + *

This corresponds to the extension input {@link + * LargeBlobAuthenticationInput#write(ByteArray) + * LargeBlobAuthenticationInput.write(ByteArray)}. + * + * @see + * dictionary AuthenticationExtensionsLargeBlobOutputs + */ + public static LargeBlobAuthenticationOutput write(final boolean write) { + return new LargeBlobAuthenticationOutput(null, write); + } + /** * The opaque byte string that was associated with the credential identified by {@link * PublicKeyCredential#getId()}. Only valid if {@link LargeBlobAuthenticationInput#getRead()} diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala index 115b75ee3..6d4c711f2 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala @@ -39,6 +39,7 @@ import com.yubico.webauthn.data.ByteArray import com.yubico.webauthn.data.ClientAssertionExtensionOutputs import com.yubico.webauthn.data.CollectedClientData import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationInput +import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationOutput import com.yubico.webauthn.data.Extensions.Uvm.UvmEntry import com.yubico.webauthn.data.Generators._ import com.yubico.webauthn.data.PublicKeyCredential @@ -46,7 +47,6 @@ import com.yubico.webauthn.data.PublicKeyCredentialCreationOptions import com.yubico.webauthn.data.PublicKeyCredentialDescriptor import com.yubico.webauthn.data.PublicKeyCredentialParameters import com.yubico.webauthn.data.PublicKeyCredentialRequestOptions -import com.yubico.webauthn.data.ReexportHelpers import com.yubico.webauthn.data.RelyingPartyIdentity import com.yubico.webauthn.data.UserIdentity import com.yubico.webauthn.data.UserVerificationRequirement @@ -2517,8 +2517,7 @@ class RelyingPartyAssertionSpec ClientAssertionExtensionOutputs .builder() .largeBlob( - ReexportHelpers - .newLargeBlobAuthenticationOutput(None, Some(true)) + LargeBlobAuthenticationOutput.write(true) ) .build() ) @@ -2559,10 +2558,8 @@ class RelyingPartyAssertionSpec ClientAssertionExtensionOutputs .builder() .largeBlob( - ReexportHelpers.newLargeBlobAuthenticationOutput( - Some(ByteArray.fromHex("00010203")), - None, - ) + LargeBlobAuthenticationOutput + .read(ByteArray.fromHex("00010203")) ) .build() ) diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyV2AssertionSpec.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyV2AssertionSpec.scala index c91be8959..402f2f1d7 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyV2AssertionSpec.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyV2AssertionSpec.scala @@ -39,6 +39,7 @@ import com.yubico.webauthn.data.ByteArray import com.yubico.webauthn.data.ClientAssertionExtensionOutputs import com.yubico.webauthn.data.CollectedClientData import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationInput +import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationOutput import com.yubico.webauthn.data.Extensions.Uvm.UvmEntry import com.yubico.webauthn.data.Generators._ import com.yubico.webauthn.data.PublicKeyCredential @@ -46,7 +47,6 @@ import com.yubico.webauthn.data.PublicKeyCredentialCreationOptions import com.yubico.webauthn.data.PublicKeyCredentialDescriptor import com.yubico.webauthn.data.PublicKeyCredentialParameters import com.yubico.webauthn.data.PublicKeyCredentialRequestOptions -import com.yubico.webauthn.data.ReexportHelpers import com.yubico.webauthn.data.RelyingPartyIdentity import com.yubico.webauthn.data.UserIdentity import com.yubico.webauthn.data.UserVerificationRequirement @@ -2594,8 +2594,7 @@ class RelyingPartyV2AssertionSpec ClientAssertionExtensionOutputs .builder() .largeBlob( - ReexportHelpers - .newLargeBlobAuthenticationOutput(None, Some(true)) + LargeBlobAuthenticationOutput.write(true) ) .build() ) @@ -2637,10 +2636,8 @@ class RelyingPartyV2AssertionSpec ClientAssertionExtensionOutputs .builder() .largeBlob( - ReexportHelpers.newLargeBlobAuthenticationOutput( - Some(ByteArray.fromHex("00010203")), - None, - ) + LargeBlobAuthenticationOutput + .read(ByteArray.fromHex("00010203")) ) .build() ) diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ExtensionsSpec.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ExtensionsSpec.scala index e3989a314..30080c42c 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ExtensionsSpec.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ExtensionsSpec.scala @@ -334,7 +334,7 @@ class ExtensionsSpec Set("appid", "largeBlob") ) assertionCred.getClientExtensionResults.getLargeBlob.toScala should equal( - Some(new LargeBlobAuthenticationOutput(null, true)) + Some(LargeBlobAuthenticationOutput.write(true)) ) } @@ -355,9 +355,8 @@ class ExtensionsSpec ) assertionCred.getClientExtensionResults.getLargeBlob.toScala should equal( Some( - new LargeBlobAuthenticationOutput( - new ByteArray("Hello, World!".getBytes(StandardCharsets.UTF_8)), - null, + LargeBlobAuthenticationOutput.read( + new ByteArray("Hello, World!".getBytes(StandardCharsets.UTF_8)) ) ) ) diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala index 4828fcabc..2a7ce9df3 100644 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala +++ b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala @@ -898,8 +898,8 @@ object Generators { blob <- arbitrary[ByteArray] written <- arbitrary[Boolean] result <- Gen.oneOf( - new LargeBlobAuthenticationOutput(blob, null), - new LargeBlobAuthenticationOutput(null, written), + LargeBlobAuthenticationOutput.read(blob), + LargeBlobAuthenticationOutput.write(written), ) } yield result) } diff --git a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ReexportHelpers.scala b/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ReexportHelpers.scala deleted file mode 100644 index c5d1cb373..000000000 --- a/webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ReexportHelpers.scala +++ /dev/null @@ -1,19 +0,0 @@ -package com.yubico.webauthn.data - -import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationOutput - -/** Public re-exports of things in the com.yubico.webauthn.data package, so that - * tests can access them but dependent projects cannot (unless they do this - * same workaround hack). - */ -object ReexportHelpers { - - def newLargeBlobAuthenticationOutput( - blob: Option[ByteArray], - written: Option[Boolean], - ): LargeBlobAuthenticationOutput = - new LargeBlobAuthenticationOutput( - blob.orNull, - written.map(java.lang.Boolean.valueOf).orNull, - ) -}