我正在努力构建一个接受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_nPort = 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
目前我收到以下错误:
错误:javax.net.ssl.SSLHandshakeException:收到致命警报: handshake_failure
当然没有达到处理程序。
密钥库是自签名的。
我已将以下内容添加到SoapUI-5.3.0.vmoptions:
-Dsoapui.https.protocols=TLSv1.2
我哪里出错?
谢谢!
答案 0 :(得分:1)
找到缺失的链接......
我添加了以下内容:
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");
,异常消失了!