是否可以不向客户提供公共证书?

时间:2019-01-11 22:33:49

标签: java ssl jetty truststore

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

有可能吗?我在网上找不到与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();

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

1 个答案:

答案 0 :(得分:0)

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

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

相关问题