【问题标题】:Is it possible to do not provide public certificate to client?是否可以不向客户提供公共证书?
【发布时间】:2019-01-11 22:33:48
【问题描述】:

我正在尝试使用码头创建一个 ssl 网络服务器,但如果任何客户端尝试连接,我不想提供服务器证书。在正常情况下,任何人都可以下载服务器证书、信任并连接到服务器。但我想在我的客户端上手动安装服务器证书,以确保只有我的客户端拥有该证书并且可以连接到我的服务器。

这可能吗?我在网上没有找到任何与 Jetty 相关的内容。

我正在使用一些示例代码和我的信任库。没什么特别的。

        final Server server = new Server();
        server.setHandler(new HelloWorld());

        final HttpConfiguration httpConfiguration = new HttpConfiguration();
        httpConfiguration.setSecureScheme("https");
        httpConfiguration.setSecurePort(8085);

        final ServerConnector http = new ServerConnector(server,
                new HttpConnectionFactory(httpConfiguration));
        http.setPort(8081);
        server.addConnector(http);

        final SslContextFactory sslContextFactory = new SslContextFactory("mykey.jks");
        sslContextFactory.setKeyStorePassword("tester");
        sslContextFactory.setNeedClientAuth(true);

        final HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
        httpsConfiguration.addCustomizer(new SecureRequestCustomizer());
        final ServerConnector httpsConnector = new ServerConnector(server,
                new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
                new HttpConnectionFactory(httpsConfiguration));
        httpsConnector.setPort(8085);
        server.addConnector(httpsConnector);

        server.start();
        server.join();

我知道,这是一个特殊的用例。如果有更好的解决方案,请告诉我(不,登录会话不适合我)。它必须尽可能简单。

【问题讨论】:

  • 听起来双向认证 SSL 是一个更好的选择;为服务器创建一个密钥对为客户端创建一个密钥对。 codeproject.com/Articles/326574/…
  • 通常在 HTTPS 世界中,重要的不仅仅是证书本身,而是由证书接收者信任的特定(或任何)CA 签署。 “只有我的客户拥有该证书并且可以连接到我的服务器。”如果您想对您的客户进行身份验证,那么他们是否在本地拥有服务器证书并不重要。相反,您通过客户端证书对它们进行身份验证,他们将拥有服务器将验证的证书(仅由其自身或再次因为它由受信任的 CA 或您自己的 CA 签名),或者您稍后在 HTTP 或应用程序中对它们进行身份验证

标签: java ssl jetty truststore


【解决方案1】:

您应该实现Two Way SSL,而不是尝试security though obscurity。你可以看看2-Way SSL with Java: The Keystore Strikes Back的文章。

客户端总是可以盲目信任或忽略服务器提供的任何证书。只要有人知道服务器地址,他们就可以提出请求。

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2018-04-30
    • 2014-06-01
    • 2018-12-05
    • 1970-01-01
    • 2012-02-09
    • 2016-08-02
    相关资源
    最近更新 更多