use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class AuthenticatorSelectionCriteriaTest method equals_hashCode_with_serialization_test.
@Test
void equals_hashCode_with_serialization_test() {
AuthenticatorSelectionCriteria instanceA = new AuthenticatorSelectionCriteria(AuthenticatorAttachment.CROSS_PLATFORM, true, UserVerificationRequirement.REQUIRED);
byte[] serializedInstanceA;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(instanceA);
serializedInstanceA = baos.toByteArray();
} catch (IOException e) {
throw new UnexpectedCheckedException(e);
}
AuthenticatorSelectionCriteria instanceB;
try (ByteArrayInputStream bais = new ByteArrayInputStream(serializedInstanceA);
ObjectInputStream ois = new ObjectInputStream(bais)) {
instanceB = (AuthenticatorSelectionCriteria) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
throw new UnexpectedCheckedException(e);
}
assertAll(() -> assertThat(instanceA).isEqualTo(instanceB), () -> assertThat(instanceA).hasSameHashCodeAs(instanceB));
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class AttestationCertificateBuilder method build.
public X509Certificate build(PrivateKey issuerPrivateKey) {
try {
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256withECDSA").build(issuerPrivateKey);
X509CertificateHolder certificateHolder = certificateBuilder.build(contentSigner);
return new JcaX509CertificateConverter().getCertificate(certificateHolder);
} catch (CertificateException e) {
throw new com.webauthn4j.validator.exception.CertificateException(e);
} catch (OperatorCreationException e) {
throw new UnexpectedCheckedException(e);
}
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class CipherUtil method encrypt.
public static byte[] encrypt(byte[] data, byte[] encryptionKey) {
try {
final byte[] iv = new byte[IV_SIZE / 8];
secureRandom.nextBytes(iv);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptionKey, "AES"), new GCMParameterSpec(TAG_SIZE, iv));
byte[] cipherBytes = cipher.doFinal(data);
byte[] output = new byte[iv.length + cipherBytes.length];
System.arraycopy(iv, 0, output, 0, iv.length);
System.arraycopy(cipherBytes, 0, output, iv.length, cipherBytes.length);
return output;
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e) {
throw new UnexpectedCheckedException(e);
}
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class CipherUtil method decrypt.
public static byte[] decrypt(byte[] encrypted, byte[] encryptionKey) {
try {
byte[] iv = new byte[IV_SIZE / 8];
byte[] cipherBytes = new byte[encrypted.length - iv.length];
System.arraycopy(encrypted, 0, iv, 0, iv.length);
System.arraycopy(encrypted, iv.length, cipherBytes, 0, cipherBytes.length);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(encryptionKey, "AES"), new GCMParameterSpec(TAG_SIZE, iv));
return cipher.doFinal(cipherBytes);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e) {
throw new UnexpectedCheckedException(e);
}
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class TestAttestationUtil method createV1DummyCertificate.
public static X509Certificate createV1DummyCertificate() {
try {
X509v1CertificateBuilder certificateBuilder = new X509v1CertificateBuilder(new X500Name("O=SharpLab., C=US"), BigInteger.valueOf(1), Date.from(Instant.parse("2000-01-01T00:00:00Z")), Date.from(Instant.parse("2999-12-31T23:59:59Z")), new X500Name("O=SharpLab., C=US"), new SubjectPublicKeyInfo(new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256WITHRSA"), new byte[0]));
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256withRSA").build(RSAUtil.createKeyPair().getPrivate());
X509CertificateHolder certificateHolder = certificateBuilder.build(contentSigner);
try {
return new JcaX509CertificateConverter().getCertificate(certificateHolder);
} catch (CertificateException e) {
throw new com.webauthn4j.validator.exception.CertificateException(e);
}
} catch (OperatorCreationException e) {
throw new UnexpectedCheckedException(e);
}
}
Aggregations