Skip to content

Commit

Permalink
Add public factory functions to LargeBlobAuthenticationOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
emlun committed Nov 8, 2023
1 parent e369465 commit e0668ee
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 40 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>blob</code> output set to the
* given value.
*
* <p>This corresponds to the extension input {@link LargeBlobAuthenticationInput#read()
* LargeBlobAuthenticationInput.read()}.
*
* @see <a
* href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dictdef-authenticationextensionslargebloboutputs">
* dictionary AuthenticationExtensionsLargeBlobOutputs</a>
*/
public static LargeBlobAuthenticationOutput read(final ByteArray blob) {
return new LargeBlobAuthenticationOutput(blob, null);
}

/**
* Create a Large blob storage extension output with the <code>written</code> output set to
* the given value.
*
* <p>This corresponds to the extension input {@link
* LargeBlobAuthenticationInput#write(ByteArray)
* LargeBlobAuthenticationInput.write(ByteArray)}.
*
* @see <a
* href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dictdef-authenticationextensionslargebloboutputs">
* dictionary AuthenticationExtensionsLargeBlobOutputs</a>
*/
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()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ 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
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
Expand Down Expand Up @@ -2517,8 +2517,7 @@ class RelyingPartyAssertionSpec
ClientAssertionExtensionOutputs
.builder()
.largeBlob(
ReexportHelpers
.newLargeBlobAuthenticationOutput(None, Some(true))
LargeBlobAuthenticationOutput.write(true)
)
.build()
)
Expand Down Expand Up @@ -2559,10 +2558,8 @@ class RelyingPartyAssertionSpec
ClientAssertionExtensionOutputs
.builder()
.largeBlob(
ReexportHelpers.newLargeBlobAuthenticationOutput(
Some(ByteArray.fromHex("00010203")),
None,
)
LargeBlobAuthenticationOutput
.read(ByteArray.fromHex("00010203"))
)
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ 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
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
Expand Down Expand Up @@ -2594,8 +2594,7 @@ class RelyingPartyV2AssertionSpec
ClientAssertionExtensionOutputs
.builder()
.largeBlob(
ReexportHelpers
.newLargeBlobAuthenticationOutput(None, Some(true))
LargeBlobAuthenticationOutput.write(true)
)
.build()
)
Expand Down Expand Up @@ -2637,10 +2636,8 @@ class RelyingPartyV2AssertionSpec
ClientAssertionExtensionOutputs
.builder()
.largeBlob(
ReexportHelpers.newLargeBlobAuthenticationOutput(
Some(ByteArray.fromHex("00010203")),
None,
)
LargeBlobAuthenticationOutput
.read(ByteArray.fromHex("00010203"))
)
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class ExtensionsSpec
Set("appid", "largeBlob")
)
assertionCred.getClientExtensionResults.getLargeBlob.toScala should equal(
Some(new LargeBlobAuthenticationOutput(null, true))
Some(LargeBlobAuthenticationOutput.write(true))
)
}

Expand All @@ -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))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

This file was deleted.

0 comments on commit e0668ee

Please sign in to comment.