Skip to content

Commit

Permalink
fix: certificate mismatch with private key
Browse files Browse the repository at this point in the history
  • Loading branch information
NiccoMlt committed Oct 18, 2024
1 parent 6135ee2 commit 69071d2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main/java/com/diennea/carapace/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ public static void main(final String... args) throws Exception {
saveCertificateToFile(rootCa, "rootCA.crt");

// ... and generate an HTTPS certificate signed by the CA
final KeyPair keyPair = generateKeyPair();
final X509Certificate httpsCertificate1 = buildHttpsCertificate(keyPair, rootCa, contentSigner);
final X509Certificate httpsCertificate2 = buildHttpsCertificate(keyPair, rootCa, contentSigner);
final X509Certificate httpsCertificate1 = buildHttpsCertificate(rootCa, contentSigner);
final X509Certificate httpsCertificate2 = buildHttpsCertificate(rootCa, contentSigner);

// Save the HTTPS certificate to a file
saveCertificateToFile(httpsCertificate1, "httpsCertificate1.crt");
Expand All @@ -147,7 +146,7 @@ public static void main(final String... args) throws Exception {

// ocspResponder.onDispose().block();

final DisposableServer server = setupHttpServer(rootCa, keyPair.getPrivate(), httpsCertificate1, httpsCertificate2);
final DisposableServer server = setupHttpServer(rootCa, rootKeyPair.getPrivate(), httpsCertificate1, httpsCertificate2);

// server.onDispose().block();

Expand Down Expand Up @@ -228,7 +227,7 @@ private static void saveCertificateToFile(X509Certificate certificate, String fi
System.out.println("Saved certificate to " + filename);
}

private static X509Certificate buildHttpsCertificate(final KeyPair keyPair, final X509Certificate rootCa, final ContentSigner contentSigner) throws CertificateException, IOException {
private static X509Certificate buildHttpsCertificate(final X509Certificate rootCa, final ContentSigner contentSigner) throws CertificateException, IOException {
final var subject = new X500NameBuilder()
.addRDN(BCStyle.CN, new DERUTF8String(HOST))
.addRDN(BCStyle.OU, new DERUTF8String("Italy"))
Expand All @@ -243,7 +242,7 @@ private static X509Certificate buildHttpsCertificate(final KeyPair keyPair, fina
rootCa.getNotBefore(),
rootCa.getNotAfter(),
subject,
keyPair.getPublic()
rootCa.getPublicKey()
);

// Add the AIA extension with the OCSP responder URI
Expand Down

0 comments on commit 69071d2

Please sign in to comment.