gpt4 book ai didi

java - Jetty 支持来自 SoapUI 的 TLS 1.2 请求

转载 作者:行者123 更新时间:2023-12-01 08:58:35 27 4
gpt4 key购买 nike

我正在努力构建一个可接受 TLSv1.2 请求的嵌入式 Jetty 服务器。

这是Java代码:

private void launchHttpsListener() {

Server server = new Server(new InetSocketAddress(m_sAddress, m_nPort));

SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("./keystore.jks");
sslContextFactory.setKeyStorePassword("Aa123456");
sslContextFactory.setKeyManagerPassword("Aa123456");
//sslContextFactory.setProtocol("TLSv1.2");
//sslContextFactory.setIncludeProtocols("TLSv1.2");

// Setup HTTP Configuration
HttpConfiguration httpConf = new HttpConfiguration();
httpConf.setSecurePort(m_nPort);
httpConf.setSecureScheme("https");
httpConf.addCustomizer(new SecureRequestCustomizer());

ContextHandler contextHandler = new ContextHandler();
contextHandler.setContextPath("/Service");
contextHandler.setHandler(new JettyServiceHandler());

ContextHandlerCollection contextHandlers = new ContextHandlerCollection();
contextHandlers.setHandlers(new Handler[] { contextHandler });

ServerConnector serverConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory,"http/1.1"),
new HttpConnectionFactory(httpConf));

serverConnector.setPort(m_nPort);

server.setConnectors(new Connector[] { serverConnector });
server.setHandler(contextHandlers);

try {
server.start();

Log4jWrapper.writeLog(LogLevelEnum.INFO, "[-----------------] <JettyServiceListener> launchHttpsListener",
"HTTPS Listener on " + m_sAddress + ":" + m_nPort);

server.join();
} catch (InterruptedException e) {

Log4jWrapper.writeLog(LogLevelEnum.ERROR, "[-----------------] <JettyServiceListener> launchHttpsListener",
e.getMessage());
} catch (Exception e) {

Log4jWrapper.writeLog(LogLevelEnum.ERROR, "[-----------------] <JettyServiceListener> launchHttpsListener",
e.getMessage());
}

}

m_n端口 = 9520

这是处理程序:

public class JettyServiceHandler extends AbstractHandler {

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

Log4jWrapper.writeLog(LogLevelEnum.DEBUG, "[-----------------] <JettyServiceHandler> handle", "Received a notification...");

String requestStr = convertStreamToString(baseRequest.getReader());

Log4jWrapper.writeLog(LogLevelEnum.DEBUG, "[-----------------] <JettyServiceHandler> handle", "requestStr = " + requestStr);


response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("1.2.1");

}

static String convertStreamToString(BufferedReader bufferedReader) {
Stream<String> lines = bufferedReader.lines();
return lines.collect(Collectors.joining("\n"));
}
}

从 SoapUI 发送一个非常简单的请求到某个 https 地址 135.136.137.138:9520

目前我收到以下错误:

ERROR:javax.net.ssl.SSLHandshakeException: Received fatal alert:handshake_failure

当然没有到达处理程序。

keystore 是自签名的。

我已将以下内容添加到 SoapUI-5.3.0.vmoptions:

-Dsoapui.https.protocols=TLSv1.2

我哪里出错了?

最佳答案

找到缺失的链接...

我添加了以下内容:

    sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_DSS_WITH_DES_CBC_SHA",
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");

异常消失了!

关于java - Jetty 支持来自 SoapUI 的 TLS 1.2 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41876449/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com