Skip to content

Commit

Permalink
Merge pull request #388 from Yubico/fido-mds-new-alg
Browse files Browse the repository at this point in the history
Fix crash on unknown COSEAlgorithmIdentifier in FIDO MDS
  • Loading branch information
emlun authored Nov 25, 2024
2 parents 5d510c5 + 160e0e2 commit e562c01
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());
}
}
}

1 comment on commit e562c01

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutation test results

Package Coverage Stats Prev Prev
Overall 81 % 🔻 1290 🔻 / 1589 🔻 81 % 1411 / 1726
com.yubico.fido.metadata 69 % 🟢 228 🔺 / 329 🔺 68 % 222 / 324
com.yubico.internal.util 47 % 🟢 57 🔺 / 120 🔻 45 % 56 / 123
com.yubico.webauthn 86 % 🔻 570 🔻 / 656 🔻 88 % 673 / 761
com.yubico.webauthn.attestation 92 % 🔹 13 🔹 / 14 🔹 92 % 13 / 14
com.yubico.webauthn.data 93 % 🟢 397 🔻 / 423 🔻 92 % 422 / 457
com.yubico.webauthn.extension.appid 100 % 🏆 13 🔹 / 13 🔹 100 % 13 / 13
com.yubico.webauthn.extension.uvm 50 % 🔹 12 🔹 / 24 🔹 50 % 12 / 24
com.yubico.webauthn.meta 0 % 🔹 0 🔹 / 10 🔹 0 % 0 / 10

Previous run: 80c52de - Diff

Detailed reports: workflow run #284

Please sign in to comment.