use of com.yubico.webauthn.data.exception.HexException in project java-webauthn-server by Yubico.
the class PublicKeyCredentialCreationOptionsTest method logsWarningIfAlgorithmNotAvailable.
@Test
public void logsWarningIfAlgorithmNotAvailable() throws HexException {
for (Provider prov : Security.getProviders()) {
if (prov.getName().contains("EC")) {
Security.removeProvider(prov.getName());
}
}
PublicKeyCredentialCreationOptions.builder().rp(RelyingPartyIdentity.builder().id("localhost").name("Test").build()).user(UserIdentity.builder().name("foo").displayName("Foo User").id(ByteArray.fromHex("00010203")).build()).challenge(ByteArray.fromHex("04050607")).pubKeyCredParams(Collections.singletonList(PublicKeyCredentialParameters.ES256)).build();
assertTrue("Expected warning log containing \"ES256\" and (case-insensitive) \"unsupported algorithm\".", testLog.getLoggingEvents().stream().anyMatch(event -> event.getLevel().compareTo(Level.WARN) >= 0 && event.getArguments().stream().anyMatch(arg -> "ES256".equals(arg.toString())) && event.getMessage().toLowerCase().contains("unsupported algorithm")));
}
use of com.yubico.webauthn.data.exception.HexException in project cas by apereo.
the class ExtensionMatcher method matchHex.
private boolean matchHex(String matchKey, JsonNode matchValue, ASN1Primitive value) {
final String matchValueString = matchValue.get(EXTENSION_VALUE_VALUE).textValue();
final ByteArray matchBytes;
try {
matchBytes = ByteArray.fromHex(matchValueString);
} catch (HexException e) {
throw new IllegalArgumentException(String.format("Bad hex value in extension %s: %s", matchKey, matchValueString));
}
final ASN1Primitive innerValue;
if (value instanceof DEROctetString) {
try {
innerValue = ASN1Primitive.fromByteArray(((DEROctetString) value).getOctets());
} catch (IOException e) {
LOGGER.debug("Failed to parse {} extension value as ASN1: {}", matchKey, value);
return false;
}
} else {
LOGGER.debug("Expected nested bit string value for extension {}, was: {}", matchKey, value);
return false;
}
if (innerValue instanceof DEROctetString) {
final ByteArray readBytes = new ByteArray(((DEROctetString) innerValue).getOctets());
return matchBytes.equals(readBytes);
} else {
LOGGER.debug("Expected nested bit string value for extension {}, was: {}", matchKey, value);
return false;
}
}
use of com.yubico.webauthn.data.exception.HexException in project java-webauthn-server by Yubico.
the class ExtensionMatcher method matchHex.
private boolean matchHex(String matchKey, JsonNode matchValue, ASN1Primitive value) {
final String matchValueString = matchValue.get(EXTENSION_VALUE_VALUE).textValue();
final ByteArray matchBytes;
try {
matchBytes = ByteArray.fromHex(matchValueString);
} catch (HexException e) {
throw new IllegalArgumentException(String.format("Bad hex value in extension %s: %s", matchKey, matchValueString));
}
final ASN1Primitive innerValue;
if (value instanceof DEROctetString) {
try {
innerValue = ASN1Primitive.fromByteArray(((DEROctetString) value).getOctets());
} catch (IOException e) {
log.debug("Failed to parse {} extension value as ASN1: {}", matchKey, value);
return false;
}
} else {
log.debug("Expected nested bit string value for extension {}, was: {}", matchKey, value);
return false;
}
if (innerValue instanceof DEROctetString) {
final ByteArray readBytes = new ByteArray(((DEROctetString) innerValue).getOctets());
return matchBytes.equals(readBytes);
} else {
log.debug("Expected nested bit string value for extension {}, was: {}", matchKey, value);
return false;
}
}
Aggregations