当使用 apache httpcore5 java 库实现 HTTP 服务器时,我找不到合适的习惯用法来装配套接字以使用 TLS。
在较旧的 httpcore 版本 4.x 下我可以
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(keystoreStream, keystorePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, keyPassword.toCharArray());
SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc. init(kmf.getKeyManagers(), null, new SecureRandom());
ServerSocket sSock = sc.getServerSocketFactory().createServerSocket(port);
然后接受来自该服务器套接字的连接,并在循环中将这些套接字bind()
连接到DefaultHttpServerConnection
和handleRequest()
。
我还没有找到如何使用 httpcore5 框架编写支持 TLS 的服务器的示例。
最佳答案
经过一番翻找,我找到了 H2ServerBootstrap.setTlsStrategy()
并像这样使用它:
SSLContext ctx = buildAppSSLContext();
bootstrap.setTlsStrategy(new BasicServerTlsStrategy(ctx, new FixedPortStrategy(new int[]{port})));
关于java - 您如何配置 Apache httpcore5 java HttpAsyncServer 以在其监听端口上使用 TLS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51065484/