我正在使用Jetty Embedded编写一个用Java编写的Web应用程序。我的经理要我配置SSL。他给了我两个文件:'server.key'和'server.crt'。
'server.key'如下所示:
-----BEGIN RSA PRIVATE KEY-----
[Base64]
-----END RSA PRIVATE KEY-----
'server.crt'
-----BEGIN CERTIFICATE-----
[Base64]
-----END CERTIFICATE-----
我试图在线寻找教程,但我无法让它工作......
我使用以下命令将crt文件转换为jks文件:
keytool -keystore server.jks -import -alias <alias> -file server.crt -trustcacerts
但是,当我启动服务器时,一切都正常加载,它说它在addess 0.0.0.0:443上使用'SSL - HTTP / 1.1'启动了服务器。 但每当我尝试从chrome连接到它时,它会尝试建立安全连接,而不仅仅是说“无法访问此站点”。
这是我的主要服务器代码:
JSONObject config = new JSONObject(FileUtils.read("data/config.json"));
String sslKeystore = config.getString("keystore_file");
String sslPassword = config.getString("keystore_password");
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(500);
Server server = new Server(threadPool);
server.addBean(new ScheduledExecutorScheduler());
ServletContextHandler app = new ServletContextHandler(ServletContextHandler.SESSIONS);
app.setContextPath("/");
app.addServlet(new ServletHolder(new DefaultHandler()), "/*");
HandlerCollection handlers = new HandlerCollection();
RequestLogHandler requestLogHandler = new RequestLogHandler();
handlers.setHandlers(new Handler[] { app, requestLogHandler});
server.setHandler(handlers);
NCSARequestLog requestLog = new NCSARequestLog("data/logs/requests/TicketTracker-yyyy_mm_dd.request.log");
requestLog.setRetainDays(90);
requestLog.setAppend(true);
requestLog.setExtended(false);
requestLog.setLogServer(true);
requestLog.setLogLatency(true);
requestLog.setLogCookies(true);
requestLog.setLogTimeZone("GMT");
requestLogHandler.setRequestLog(requestLog);
requestLogHandler.setServer(server);
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(sslKeystore);
sslContextFactory.setKeyStorePassword(sslPassword);
sslContextFactory.setKeyManagerPassword(sslPassword);
ServerConnector sslConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(https));
sslConnector.setPort(443);
server.setConnectors(new Connector[] { sslConnector });
server.start();
server.join();
密码与别名相同。
主要问题我不知道在哪里看...因为它不会崩溃,它不会给我一个错误,它只是不起作用...