Skip to content

Commit

Permalink
Disable cert checking for localhost host servers
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePrez committed Jan 2, 2025
1 parent a5c8c59 commit f5c2333
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/github/ibm/mapepire/MapepireServer.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.github.ibm.mapepire;

import java.io.FileInputStream;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.LinkedList;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.server.Server;
Expand Down Expand Up @@ -125,6 +131,19 @@ public static void main(final String[] _args) {
if (StringUtils.isNonEmpty(remoteServer)) {
DbSocketCreator.setDatabaseHost(remoteServer);
}
if (SystemConnection.isRunningOnIBMi() && (StringUtils.isEmpty(remoteServer) || "localhost".equalsIgnoreCase(remoteServer) || "127.0.0.1".equalsIgnoreCase(remoteServer))) {
SSLContext ctx = SSLContext.getInstance("TLS");
//@formatter:off
ctx.init(null, new TrustManager[] {
new X509TrustManager() {
@Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }
@Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { }
@Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
}
}, null);
//@formatter:on
SSLContext.setDefault(ctx);
}

String remotePort = System.getenv("PORT");
if (StringUtils.isNonEmpty(remotePort)) {
Expand Down

0 comments on commit f5c2333

Please sign in to comment.