forked from Qortal/qortal
Rework trustless manager
This commit is contained in:
parent
f6e398ec0f
commit
c989e3c413
@ -1,33 +1,33 @@
|
|||||||
package org.qortal.crypto;
|
package org.qortal.crypto;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.*;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
import javax.net.ssl.TrustManager;
|
|
||||||
import javax.net.ssl.X509TrustManager;
|
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
public abstract class TrustlessSSLSocketFactory {
|
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[] {
|
private static final TrustManager[] TRUSTLESS_MANAGER = new TrustManager[] {
|
||||||
new X509TrustManager() {
|
new X509TrustManager() {
|
||||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
return new X509Certificate[0];
|
return null;
|
||||||
}
|
}
|
||||||
|
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||||
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
|
||||||
}
|
}
|
||||||
|
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||||
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Install the all-trusting trust manager
|
/**
|
||||||
|
* Install the all-trusting trust manager.
|
||||||
|
*/
|
||||||
private static final SSLContext sc;
|
private static final SSLContext sc;
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
sc = SSLContext.getInstance("TLSv1.3");
|
sc = SSLContext.getInstance("SSL");
|
||||||
sc.init(null, TRUSTLESS_MANAGER, new java.security.SecureRandom());
|
sc.init(null, TRUSTLESS_MANAGER, new java.security.SecureRandom());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -37,5 +37,4 @@ public abstract class TrustlessSSLSocketFactory {
|
|||||||
public static SSLSocketFactory getSocketFactory() {
|
public static SSLSocketFactory getSocketFactory() {
|
||||||
return sc.getSocketFactory();
|
return sc.getSocketFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user