首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置基本Jersey/Grizzly 2.21 SSL启动配置

如何设置基本Jersey/Grizzly 2.21 SSL启动配置
EN

Stack Overflow用户
提问于 2015-11-21 00:26:46
回答 2查看 1.7K关注 0票数 2

我正在尝试启动并运行一个非常基本的Grizzly服务器,以允许单向SSL (HTTPS)连接来访问jax-rs REST服务。最终,我想要双向SSL安全性。

我已经看过很多例子了,但我就是不能让任何东西起作用。我总是遇到SSL握手错误。很明显,我一定是做了什么傻事。任何帮助都是非常感谢的。

下面是我使用Jersey包装类启动嵌入式Grizzly服务器的代码:

代码语言:javascript
复制
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,看看这是否有帮助。不是的。

我总是得到以下错误:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2016-05-12 09:17:08

除了JMS评论之外,他的回答也解决了我的问题。下面是我用来生成RSA证书的命令。

代码语言:javascript
复制
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
票数 4
EN

Stack Overflow用户

发布于 2015-11-21 03:11:47

我在其他帖子中看到过这种类型的握手问题,而我试图让这个问题落地。在所有这些握手帖子中,从未讨论过服务器密钥算法--我希望它已经讨论过了。这会节省我几个小时的时间。导致上述错误的问题源于假设作为Jersey示例项目的一部分创建的密钥库可以工作。服务器密钥是问题所在。

示例服务器证书使用DSA算法生成。显然,这是一个问题。

我使用RSA算法和2048位强度重新创建了服务器密钥。我重新启动了服务器,一切都开始像预期的那样工作。

错误是我假设“示例”键可以工作。糟了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33831480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档