Search in sources :

Example 1 with HexException

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")));
}
Also used : Level(uk.org.lidalia.slf4jext.Level) TestLoggerFactory(uk.org.lidalia.slf4jtest.TestLoggerFactory) HexException(com.yubico.webauthn.data.exception.HexException) Assert.assertTrue(org.junit.Assert.assertTrue) Security(java.security.Security) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Provider(java.security.Provider) List(java.util.List) Stream(java.util.stream.Stream) TestLogger(uk.org.lidalia.slf4jtest.TestLogger) After(org.junit.After) Optional(java.util.Optional) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Provider(java.security.Provider) Test(org.junit.Test)

Example 2 with HexException

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;
    }
}
Also used : ByteArray(com.yubico.webauthn.data.ByteArray) DEROctetString(org.bouncycastle.asn1.DEROctetString) HexException(com.yubico.webauthn.data.exception.HexException) IOException(java.io.IOException) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 3 with HexException

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;
    }
}
Also used : ByteArray(com.yubico.webauthn.data.ByteArray) DEROctetString(org.bouncycastle.asn1.DEROctetString) HexException(com.yubico.webauthn.data.exception.HexException) IOException(java.io.IOException) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Aggregations

HexException (com.yubico.webauthn.data.exception.HexException)3 ByteArray (com.yubico.webauthn.data.ByteArray)2 IOException (java.io.IOException)2 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)2 DEROctetString (org.bouncycastle.asn1.DEROctetString)2 Provider (java.security.Provider)1 Security (java.security.Security)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Level (uk.org.lidalia.slf4jext.Level)1 TestLogger (uk.org.lidalia.slf4jtest.TestLogger)1 TestLoggerFactory (uk.org.lidalia.slf4jtest.TestLoggerFactory)1