use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class PackedAttestationStatementValidatorTest method generateCertPath.
private static AttestationCertificatePath generateCertPath(KeyPair pair, String signAlg) {
try {
Provider bcProvider = new BouncyCastleProvider();
// Security.addProvider(bcProvider);
long now = System.currentTimeMillis();
Date from = new Date(now);
Date to = new Date(from.getTime() + TimeUnit.DAYS.toMillis(1));
X500Name dnName = new X500Name("C=ORG, O=Dummy Org, OU=Authenticator Attestation, CN=Dummy");
BigInteger certSerialNumber = BigInteger.ZERO;
Calendar calendar = Calendar.getInstance();
calendar.setTime(from);
calendar.add(Calendar.YEAR, 1);
ContentSigner contentSigner = new JcaContentSignerBuilder(signAlg).build(pair.getPrivate());
JcaX509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(dnName, certSerialNumber, from, to, dnName, pair.getPublic());
BasicConstraints basicConstraints = new BasicConstraints(false);
certBuilder.addExtension(new ASN1ObjectIdentifier("2.5.29.19"), true, basicConstraints);
X509Certificate certificate = new JcaX509CertificateConverter().setProvider(bcProvider).getCertificate(certBuilder.build(contentSigner));
return new AttestationCertificatePath(Collections.singletonList(certificate));
} catch (OperatorCreationException | CertificateException | CertIOException e) {
throw new UnexpectedCheckedException(e);
}
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class ECUtil method createPublicKey.
@NonNull
private static PublicKey createPublicKey(@NonNull byte[] x, @NonNull byte[] y) {
try {
byte[] encodedPublicKey = ByteBuffer.allocate(1 + x.length + y.length).put(new byte[] { 0x04 }).put(x).put(y).array();
ECPoint point = createECPoint(encodedPublicKey);
return KeyFactory.getInstance("ECDSA").generatePublic(new ECPublicKeySpec(point, ECUtil.P_256_SPEC));
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
throw new UnexpectedCheckedException(e);
}
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class HKDFUtil method createMac.
@NonNull
private static Mac createMac(@NonNull byte[] key) {
Mac mac;
try {
mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(key, "HmacSHA256"));
return mac;
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new UnexpectedCheckedException(e);
}
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class CertPathSerializer method serialize.
/**
* {@inheritDoc}
*/
@Override
public void serialize(@NonNull CertPath value, @NonNull JsonGenerator gen, @NonNull SerializerProvider provider) throws IOException {
try {
gen.writeStartArray();
for (Certificate certificate : value.getCertificates()) {
gen.writeBinary(certificate.getEncoded());
}
gen.writeEndArray();
} catch (CertificateEncodingException e) {
throw new UnexpectedCheckedException(e);
}
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class DeviceCheckManagerTest 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);
}
}
Aggregations