Rework trustless manager

This commit is contained in:
AlphaX-Projects 2023-12-12 10:05:24 +01:00 committed by GitHub
parent f6e398ec0f
commit c989e3c413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,33 +1,33 @@
package org.qortal.crypto;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.net.ssl.*;
import java.security.cert.X509Certificate;
public abstract class TrustlessSSLSocketFactory {
// Create a trust manager that does not validate certificate chains
/**
* Creates a SSLSocketFactory that ignore certificate chain validation because ElectrumX servers use mostly
* self signed certificates.
*/
private static final TrustManager[] TRUSTLESS_MANAGER = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
/**
* Install the all-trusting trust manager.
*/
private static final SSLContext sc;
static {
try {
sc = SSLContext.getInstance("TLSv1.3");
sc = SSLContext.getInstance("SSL");
sc.init(null, TRUSTLESS_MANAGER, new java.security.SecureRandom());
} catch (Exception e) {
throw new RuntimeException(e);
@ -37,5 +37,4 @@ public abstract class TrustlessSSLSocketFactory {
public static SSLSocketFactory getSocketFactory() {
return sc.getSocketFactory();
}
}