![](/img/trans.png)
[英]Is it possible to disable ssl certificate download in Weblogic server
[英]Is it possible to disable ssl for https?
在Java上的應用。 使用OkHttp版本2.7.5。 向另一個服務發出請求,並且發生錯誤。
SSLHandshakeException: sun.security.validator.ValidatorException:
PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
我沒有證書。 似乎有okHttp3版本的解決方案。 但是版本不能更改。 如何解決問題?
是否可以為https禁用ssl?
從字面上看,沒有。
SSL的使用是HTTPS協議的基礎。 如果您根本不想使用SSL,請為服務器配置一個HTTP端點,然后使用它代替HTTPS。
此外,使用SSL要求(至少)在語法上格式正確的證書。 這也是HTTPS協議的基礎。
現在,如果問題是您的服務器證書已過期,則可能的解決方案是使用以下方法:
並且如果問題是您無法獲得服務器的正確證書(例如,您負擔不起),那么另一種解決方案是:
但是請注意,執行上述任一操作都存在安全問題。
第三種解決方案更安全。
為什么要使用HTTPS但沒有證書,您應該按照上述Stephen的指示進行操作。 但是,如果您確實想忘記https的含義,則可以考慮覆蓋此行為
private static OkHttpClient getUnprotectedClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
return new okhttp3.OkHttpClient.Builder()
.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0])
.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}).build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.