You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
2 years ago
|
package com.fr.plugin.oauth.utils;
|
||
|
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
|
||
|
import javax.net.ssl.*;
|
||
|
import java.security.cert.CertificateException;
|
||
|
import java.security.cert.X509Certificate;
|
||
|
|
||
|
public class HttpsUtils {
|
||
|
final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
|
||
|
public boolean verify(String hostname, SSLSession session) {
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Create a trust manager that does not validate certificate chains
|
||
|
static TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
|
||
|
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||
|
return new java.security.cert.X509Certificate[]{};
|
||
|
}
|
||
|
|
||
|
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||
|
FineLoggerFactory.getLogger().error("checkClientTrusted");
|
||
|
}
|
||
|
|
||
|
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||
|
FineLoggerFactory.getLogger().error("checkServerTrusted");
|
||
|
}
|
||
|
}};
|
||
|
|
||
|
static SSLContext sc;
|
||
|
|
||
|
static {
|
||
|
trustAllHosts();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Trust every server - dont check for any certificate
|
||
|
*/
|
||
|
public static void trustAllHosts() {
|
||
|
// Install the all-trusting trust manager
|
||
|
try {
|
||
|
if (sc == null) {
|
||
|
sc = SSLContext.getInstance("TLS");
|
||
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||
|
}
|
||
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||
|
} catch (Exception e) {
|
||
|
FineLoggerFactory.getLogger().error(e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|