[英]How to setup basic Jersey/Grizzly 2.21 SSL startup configuration
我正在嘗試啟動並運行一個非常基本的Grizzly服務器,以允許單向SSL(HTTPS)連接訪問jax-rs REST服務。 最終,我需要雙向SSL安全性。
我已經看過很多例子,但我什么都做不了。 我一直遇到SSL握手錯誤。 顯然我一定在做一些愚蠢的事情。 任何幫助表示贊賞。
這是使用Jersey包裝器類啟動嵌入式Grizzly服務器的代碼:
public static HttpServer startHttpsServer(URI listenerURI) throws IOException {
ResourceConfig resourceConfig = new ResourceConfig().packages("ws.argo.experiment.ssl");
// First I tried this configuration using the certs from the Jersey sample code
// Grizzly ssl configuration
SSLContextConfigurator sslContext = new SSLContextConfigurator();
// set up security context
sslContext.setKeyStoreFile("./src/main/resources/keystore_server"); // contains server keypair
sslContext.setKeyStorePass("asdfgh");
sslContext.setTrustStoreFile("./src/main/resources/truststore_server"); // contains client certificate
sslContext.setTrustStorePass("asdfgh");
// Then I tried just using a default config - didn't work either
// sslContext = SSLContextConfigurator.DEFAULT_CONFIG;
if (!sslContext.validateConfiguration(true)) {
LOGGER.severe("Context is not valid");
}
LOGGER.finer("Starting Jersey-Grizzly2 JAX-RS secure server...");
HttpServer httpServer; //= GrizzlyHttpServerFactory.createHttpServer(listenerURI, resourceConfig, false);
httpServer= GrizzlyHttpServerFactory.createHttpServer(
listenerURI,
resourceConfig,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false)
);
httpServer.getServerConfiguration().setName("Test HTTPS Server");
httpServer.start();
LOGGER.info("Started Jersey-Grizzly2 JAX-RS secure server.");
return httpServer;
}
我還嘗試將SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false)替換為null,以查看是否有幫助。 不。
我總是收到以下錯誤:
grizzly-nio-kernel(3) SelectorRunner, fatal error: 40: no cipher suites in common
javax.net.ssl.SSLHandshakeException: no cipher suites in common
%% Invalidated: [Session-2, SSL_NULL_WITH_NULL_NULL]
grizzly-nio-kernel(3) SelectorRunner, SEND TLSv1.2 ALERT: fatal, description = handshake_failure
grizzly-nio-kernel(3) SelectorRunner, WRITE: TLSv1.2 Alert, length = 2
grizzly-nio-kernel(3) SelectorRunner, fatal: engine already closed. Rethrowing javax.net.ssl.SSLHandshakeException: no cipher suites in common
除了JMS注釋之外,他的回答也解決了我的問題。 這是我用來生成RSA證書的命令。
keytool -genkey -keystore ./keystore_client -alias clientKey -keyalg RSA -keypass changeit -storepass changeit -dname "CN=Client, OU=Jersey, O=changeit, L=KL, ST=SEL, C=MY"
keytool -export -alias clientKey -storepass changeit -keystore ./keystore_client -file ./client.cert
keytool -import -alias clientCert -file ./client.cert -storepass changeit -keystore ./truststore_server
keytool -genkey -keystore ./keystore_server -alias serverKey -keyalg RSA -keyalg RSA -keypass changeit -storepass changeit -dname "CN=changeit, OU=Jersey, O=changeit, L=KL, ST=SEL, C=MY"
keytool -export -alias serverKey -storepass changeit -keystore ./keystore_server -file ./server.cert
keytool -import -alias serverCert -file ./server.cert -storepass changeit -keystore ./truststore_client
我曾在嘗試將這一問題付諸實踐時在其他帖子中看到過這種握手問題。 在所有這些握手文章中,從未討論過服務器密鑰算法-我希望是這樣。 這樣可以節省我幾個小時。 導致上述錯誤的問題源於假定作為Jersey示例項目的一部分創建的密鑰庫可以工作的原因。 服務器密鑰是問題所在。
樣本服務器證書是使用DSA算法生成的。 顯然這是一個問題。
我使用RSA算法和2048位強度重新創建了服務器密鑰。 我重新啟動服務器,一切開始按預期運行。
錯誤是我認為“示例”鍵可以工作。 哎呀。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.