Skip to content

Commit

Permalink
Fix crash on unknown COSEAlgorithmIdentifier in FIDO MDS
Browse files Browse the repository at this point in the history
  • Loading branch information
emlun committed Nov 25, 2024
1 parent 5d510c5 commit 160e0e2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
== Version 2.5.4 (unreleased) ==

`webauthn-server-attestation`:

Fixes:

* `AuthenticatorGetInfo.algorithms` now silently ignores unknown
`COSEAlgorithmIdentifier` and `PublicKeyCredentialType` values instead of
rejecting the MDS BLOB.


== Version 2.5.3 ==

`webauthn-server-attestation`:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yubico.fido.metadata;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand All @@ -19,6 +20,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
Expand Down Expand Up @@ -116,6 +118,7 @@ public class AuthenticatorGetInfo {
* href="https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#authenticatorGetInfo">Client
* to Authenticator Protocol (CTAP) §6.4. authenticatorGetInfo (0x04)</a>
*/
@JsonDeserialize(using = ListPublicKeyCredentialParametersIgnoringUnknownValuesDeserializer.class)
List<PublicKeyCredentialParameters> algorithms;

/**
Expand Down Expand Up @@ -377,4 +380,44 @@ public void serialize(
value.stream().reduce(0, (acc, next) -> acc | next.getValue(), (a, b) -> a | b));
}
}

@Value
@JsonDeserialize(using = PublicKeyCredentialParametersIgnoringUnknownValues.Deserializer.class)
private static class PublicKeyCredentialParametersIgnoringUnknownValues {
PublicKeyCredentialParameters value;

private static class Deserializer
extends JsonDeserializer<PublicKeyCredentialParametersIgnoringUnknownValues> {
@Override
public PublicKeyCredentialParametersIgnoringUnknownValues deserialize(
JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
try {
return new PublicKeyCredentialParametersIgnoringUnknownValues(
p.readValueAs(PublicKeyCredentialParameters.class));
} catch (IOException e) {
return null;
}
}
}
}

private static class ListPublicKeyCredentialParametersIgnoringUnknownValuesDeserializer
extends JsonDeserializer<List<PublicKeyCredentialParameters>> {
@Override
public List<PublicKeyCredentialParameters> deserialize(
JsonParser p, DeserializationContext ctxt) throws IOException {
PublicKeyCredentialParametersIgnoringUnknownValues[] pkcpiuvs =
p.readValueAs(PublicKeyCredentialParametersIgnoringUnknownValues[].class);
return Arrays.stream(pkcpiuvs)
.flatMap(
pkcpiuv -> {
if (pkcpiuv != null && pkcpiuv.value != null) {
return Stream.of(pkcpiuv.value);
} else {
return Stream.empty();
}
})
.collect(Collectors.toList());
}
}
}

0 comments on commit 160e0e2

Please sign in to comment.