Skip to content

Commit

Permalink
Disable cert validation for JNDI https connector
Browse files Browse the repository at this point in the history
  • Loading branch information
qtc-de committed Sep 28, 2023
1 parent c6ecd62 commit 22ae273
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertPathValidatorException;
import java.util.Map;

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.net.ssl.SSLContext;
import javax.net.ssl.X509TrustManager;
import javax.security.auth.callback.UnsupportedCallbackException;

import de.qtc.beanshooter.cli.ArgumentHandler;
import de.qtc.beanshooter.exceptions.AuthenticationException;
import de.qtc.beanshooter.exceptions.ExceptionHandler;
import de.qtc.beanshooter.exceptions.GlassFishException;
import de.qtc.beanshooter.io.Logger;
import de.qtc.beanshooter.networking.DummyTrustManager;
import de.qtc.beanshooter.operation.BeanshooterOperation;
import de.qtc.beanshooter.operation.BeanshooterOption;
import de.qtc.beanshooter.plugin.IMBeanServerProvider;
Expand All @@ -42,6 +47,20 @@ public MBeanServerConnection getMBeanServerConnection(String host, int port, Map
MBeanServerConnection mBeanServerConnection = null;
String connString = ArgumentHandler.require(BeanshooterOption.CONN_JNDI);

try
{
SSLContext trustAllContext = SSLContext.getInstance("TLS");
trustAllContext.init(null, new X509TrustManager[] {new DummyTrustManager()}, null);
SSLContext.setDefault(trustAllContext);
}

catch (NoSuchAlgorithmException | KeyManagementException e)
{
Logger.eprintlnMixedBlue("Unable to set", "trust-all SSLContext", "- Cert validation might cause problems.");
ExceptionHandler.showStackTrace(e);
Logger.lineBreak();
}

if (!connString.contains("://"))
{
if (connString.startsWith("service:jmx:rmi"))
Expand Down

0 comments on commit 22ae273

Please sign in to comment.