Search in sources :

Example 11 with UnexpectedCheckedException

use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.

the class DeviceCheckManagerSample method getAppleAppAttestCertFileTrustAnchorsProvider.

private CertFileTrustAnchorsProvider getAppleAppAttestCertFileTrustAnchorsProvider() {
    CertFileTrustAnchorsProvider certFileTrustAnchorsProvider = new CertFileTrustAnchorsProvider();
    try {
        Path path = Paths.get(ClassLoader.getSystemResource("apple-app-attest/Apple_App_Attestation_Root_CA.pem").toURI());
        certFileTrustAnchorsProvider.setCertificates(Collections.singletonList(path));
        return certFileTrustAnchorsProvider;
    } catch (URISyntaxException e) {
        throw new UnexpectedCheckedException(e);
    }
}
Also used : Path(java.nio.file.Path) CertFileTrustAnchorsProvider(com.webauthn4j.anchor.CertFileTrustAnchorsProvider) UnexpectedCheckedException(com.webauthn4j.util.exception.UnexpectedCheckedException) URISyntaxException(java.net.URISyntaxException)

Example 12 with UnexpectedCheckedException

use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.

the class X509CertificateSerializer method serialize.

/**
 * {@inheritDoc}
 */
@Override
public void serialize(@NonNull X509Certificate value, @NonNull JsonGenerator gen, @NonNull SerializerProvider provider) throws IOException {
    try {
        String str = Base64Util.encodeToString(value.getEncoded());
        gen.writeString(str);
    } catch (CertificateEncodingException e) {
        throw new UnexpectedCheckedException(e);
    }
}
Also used : UnexpectedCheckedException(com.webauthn4j.util.exception.UnexpectedCheckedException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 13 with UnexpectedCheckedException

use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.

the class JWSHeaderSerializer method serialize.

@Override
public void serialize(JWSHeader value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    try {
        gen.writeStartObject();
        gen.writeObjectField("alg", value.getAlg());
        gen.writeFieldName("x5c");
        gen.writeStartArray();
        if (value.getX5c() != null) {
            for (Certificate certificate : value.getX5c().getCertificates()) {
                // x5c must be Base64, not Base64Url
                gen.writeString(Base64Util.encodeToString(certificate.getEncoded()));
            }
        }
        gen.writeEndArray();
    } catch (CertificateEncodingException e) {
        throw new UnexpectedCheckedException(e);
    }
}
Also used : UnexpectedCheckedException(com.webauthn4j.util.exception.UnexpectedCheckedException) CertificateEncodingException(java.security.cert.CertificateEncodingException) Certificate(java.security.cert.Certificate)

Example 14 with UnexpectedCheckedException

use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.

the class ECUtil method createECParameterSpec.

@NonNull
private static ECParameterSpec createECParameterSpec(@NonNull String name) {
    try {
        AlgorithmParameters parameters;
        parameters = AlgorithmParameters.getInstance("EC");
        parameters.init(new ECGenParameterSpec(name));
        return parameters.getParameterSpec(ECParameterSpec.class);
    } catch (NoSuchAlgorithmException | InvalidParameterSpecException e) {
        throw new UnexpectedCheckedException(e);
    }
}
Also used : UnexpectedCheckedException(com.webauthn4j.util.exception.UnexpectedCheckedException) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 15 with UnexpectedCheckedException

use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.

the class ECUtil method createKeyPair.

@NonNull
public static KeyPair createKeyPair(@Nullable byte[] seed, @NonNull ECParameterSpec ecParameterSpec) {
    KeyPairGenerator keyPairGenerator = createKeyPairGenerator();
    SecureRandom random;
    try {
        if (seed != null) {
            // to make it deterministic
            random = SecureRandom.getInstance("SHA1PRNG");
            random.setSeed(seed);
        } else {
            random = secureRandom;
        }
        keyPairGenerator.initialize(ecParameterSpec, random);
        return keyPairGenerator.generateKeyPair();
    } catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
        throw new UnexpectedCheckedException(e);
    }
}
Also used : UnexpectedCheckedException(com.webauthn4j.util.exception.UnexpectedCheckedException) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

UnexpectedCheckedException (com.webauthn4j.util.exception.UnexpectedCheckedException)18 NonNull (org.checkerframework.checker.nullness.qual.NonNull)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 InvalidKeyException (java.security.InvalidKeyException)4 SecretKeySpec (javax.crypto.spec.SecretKeySpec)4 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 CertificateException (java.security.cert.CertificateException)3 JcaX509CertificateConverter (org.bouncycastle.cert.jcajce.JcaX509CertificateConverter)3 ContentSigner (org.bouncycastle.operator.ContentSigner)3 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)3 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)3 CertFileTrustAnchorsProvider (com.webauthn4j.anchor.CertFileTrustAnchorsProvider)2 URISyntaxException (java.net.URISyntaxException)2 Path (java.nio.file.Path)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 Certificate (java.security.cert.Certificate)2 BadPaddingException (javax.crypto.BadPaddingException)2 Cipher (javax.crypto.Cipher)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 Mac (javax.crypto.Mac)2