【发布时间】:2015-11-20 16:26:45
【问题描述】:
我正在尝试启动并运行一个非常基本的 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
【问题讨论】:
-
您只需要服务器信任库中的客户端证书即可进行双向(双向)ssl。如果服务器证书是自签名的,您需要做的是将服务器证书添加到客户端信任库
-
@peetskillet - 这是我开始的例子。唯一的区别是我没有使用 jersey-container-grizzly2-servlet 设置。只需使用常规 jersey-container-grizzly2-http 版本作为依赖项。我认为这不会有什么不同。
-
您使用的是 Jersey 客户端还是其他客户端?您是否按照说明创建商店和导入?该示例适用于我(也可以根据说明创建新商店)。您可以看到在测试用例中设置的 Jersey 客户端。我不认为从 servlet 更改为 http 配置应该有所不同,尽管我没有测试
-
现在我只是在使用网络浏览器(Safari、Firefox、Chrome)来尝试访问资源。他们没有运气。它应该设置为允许使用浏览器进行简单的单向 SSL。我没有使用特殊的客户端。