2727import java .util .Arrays ;
2828import java .util .List ;
2929
30+ import static de .rwth .idsg .steve .utils .CertificateUtils .isECDSAFamily ;
31+ import static de .rwth .idsg .steve .utils .CertificateUtils .isRSAFamily ;
3032import static de .rwth .idsg .steve .utils .CertificateUtils .resolveSignatureAlgorithm ;
33+ import static org .bouncycastle .jce .provider .BouncyCastleProvider .PROVIDER_NAME ;
3134
3235/**
3336 * @author Sevket Goekay <sevketgokay@gmail.com>
@@ -41,6 +44,21 @@ public record CertificateIssuerMaterial(
4144 String certificateSignatureAlgorithm
4245) {
4346
47+ public void validateFamily () {
48+ switch (name ) {
49+ case RSA -> {
50+ if (!isRSAFamily (caCertificate .getPublicKey (), caPrivateKey )) {
51+ throw new IllegalArgumentException ("Configured '" + name + "' entry does not contain '" + name + "' CA certificate and/or private-key" );
52+ }
53+ }
54+ case ECDSA -> {
55+ if (!isECDSAFamily (caCertificate .getPublicKey (), caPrivateKey )) {
56+ throw new IllegalArgumentException ("Configured '" + name + "' entry does not contain '" + name + "' CA certificate and/or private-key" );
57+ }
58+ }
59+ }
60+ }
61+
4462 public void validateCaCertificate () throws Exception {
4563 if (caCertificate .getBasicConstraints () < 0 ) {
4664 throw new IllegalArgumentException ("Configured CA certificate for issuer '" + name + "' is not a CA certificate (basicConstraints CA=true required)" );
@@ -54,12 +72,12 @@ public void validateCaCertificate() throws Exception {
5472 String checkAlgorithm = resolveSignatureAlgorithm (caPrivateKey );
5573 byte [] dummyProbeData = "certificate-key-pair-check" .getBytes (StandardCharsets .UTF_8 );
5674
57- Signature signer = Signature .getInstance (checkAlgorithm );
75+ Signature signer = Signature .getInstance (checkAlgorithm , PROVIDER_NAME );
5876 signer .initSign (caPrivateKey );
5977 signer .update (dummyProbeData );
6078 byte [] signature = signer .sign ();
6179
62- Signature verifier = Signature .getInstance (checkAlgorithm );
80+ Signature verifier = Signature .getInstance (checkAlgorithm , PROVIDER_NAME );
6381 verifier .initVerify (caCertificate .getPublicKey ());
6482 verifier .update (dummyProbeData );
6583
0 commit comments