Skip to content

Commit

Permalink
Switch to ISRG roots
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Nov 19, 2023
1 parent 3c1fe4e commit 22ab085
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
*.[pP][sS]1 text eol=crlf

*[aA][uU][tT][oO][gG][eE][nN][eE][rR][aA][tT][eE][dD]* binary
*.der binary
20 changes: 10 additions & 10 deletions src/main/java/com/dreammaster/coremod/LetsEncryptAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.util.Objects;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -58,21 +57,22 @@ public class LetsEncryptAdder {
private static boolean alreadyAdded = false;
private static final Logger LOGGER = LogManager.getLogger(LetsEncryptAdder.class);

private static void trustLetsEncryptX3() throws Exception {
InputStream cert = Objects.requireNonNull(
LetsEncryptAdder.class.getResourceAsStream("/assets/letsencryptroot/lets-encrypt-x3-cross-signed.der"),
"Embedded let's encrypt certificate not found");
private static void trustLetsEncryptRoots() throws Exception {
final InputStream cert1 = Objects.requireNonNull(
LetsEncryptAdder.class.getResourceAsStream("/assets/letsencryptroot/isrg-root-x1.der"),
"Embedded let's encrypt certificate X1 not found");
final InputStream cert2 = Objects.requireNonNull(
LetsEncryptAdder.class.getResourceAsStream("/assets/letsencryptroot/isrg-root-x2.der"),
"Embedded let's encrypt certificate X2 not found");

KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
Path ksPath = Paths.get(System.getProperty("java.home"), "lib", "security", "cacerts");
keyStore.load(Files.newInputStream(ksPath), "changeit".toCharArray());

CertificateFactory cf = CertificateFactory.getInstance("X.509");

InputStream caInput = new BufferedInputStream(cert);
Certificate crt = cf.generateCertificate(caInput);

keyStore.setCertificateEntry("lets-encrypt-x3-cross-signed", crt);
keyStore.setCertificateEntry("isrg-root-x1", cf.generateCertificate(new BufferedInputStream(cert1)));
keyStore.setCertificateEntry("isrg-root-x2", cf.generateCertificate(new BufferedInputStream(cert2)));

TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
Expand Down Expand Up @@ -120,7 +120,7 @@ public static void addLetsEncryptCertificates() {
String body = "";
try {
LOGGER.info("Adding Let's Encrypt certificate...");
LetsEncryptAdder.trustLetsEncryptX3();
LetsEncryptAdder.trustLetsEncryptRoots();
LOGGER.info("Done, attempting to connect to https://helloworld.letsencrypt.org...");
URL url = new URL("https://helloworld.letsencrypt.org");
URLConnection conn = url.openConnection();
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 22ab085

Please sign in to comment.