Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: RestTemplate去除对SSLv2Hello与SSLv3协议的支持 #1915 #1918

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.tencent.bk.job.gateway.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
Expand All @@ -47,6 +48,7 @@
import java.security.cert.X509Certificate;
import java.util.List;

@Slf4j
@Configuration
public class RestConfig {
@Bean
Expand All @@ -61,8 +63,12 @@ public RestTemplate restTemplate() {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, (X509Certificate[] x509Certificates, String s) -> true);
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), new String[]{
"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.2"}, null, NoopHostnameVerifier.INSTANCE);
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
builder.build(),
null,
null,
NoopHostnameVerifier.INSTANCE
);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", new PlainConnectionSocketFactory())
.register("https", socketFactory).build();
Expand All @@ -72,9 +78,8 @@ public RestTemplate restTemplate() {
HttpClients.custom().setSSLSocketFactory(socketFactory).setConnectionManager(phccm)
.setConnectionManagerShared(true).build();
factory.setHttpClient(httpClient);

} catch (Exception e) {

log.error("Fail to init httpClient", e);
}

RestTemplate restTemplate = new RestTemplate(factory);
Expand Down