gpt4 book ai didi

java - 要使用的 SSL-Config 或 SSLContext?在 Akka Http SSL Java 中

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:50:42 26 4
gpt4 key购买 nike

我正在使用来自第三方的 SSL 证书 - 我使用以下命令创建了一个 .p12 keystore

openssl pkcs12 -export -CAfile Geotrust_EV_Intermediate_Bundle.crt -in www_domainName_in.crt -inkey domainName.in.key -out wtkeystore1.p12 -name CompanyName -passout pass:SomePassWord

我引用了 Akka HTTPS 支持文档并编码如下

public HttpsConnectionContext useHttps(ActorSystem system) {
HttpsConnectionContext https = null;
try {
final char[] password = properties.keystorePassword().toCharArray();

final KeyStore ks = KeyStore.getInstance("PKCS12");
final InputStream keystore = WDService.class.getClassLoader().getResourceAsStream("wtkeystore.p12");
if (keystore == null) {
throw new RuntimeException("Keystore required!");
}
ks.load(keystore, password);
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(ks, password);

final TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(ks);

final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());
final AkkaSSLConfig sslConfig = AkkaSSLConfig.get(system);
https = ConnectionContext.https(sslContext);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
system.log().error(e.getCause() + " while configuring HTTPS.", e);
} catch (CertificateException | KeyStoreException | UnrecoverableKeyException | IOException e) {
system.log().error(e.getCause() + " while ", e);
}

return https;

我的主文件代码如下

final Http http = Http.get(system);

log.info("Starting on " + properties.url() + ":" + properties.port());
final ConnectHttp host = ConnectHttp.toHost(properties.url(), properties.port());

Http.get(system).bindAndHandle(appRoute().flow(system, materializer), host, materializer);
log.info("Started on " + properties.url() + ":" + properties.port());

if (properties.useSSL()) {

HttpsConnectionContext https = useHttps(system);
http.setDefaultServerHttpContext(https);

Http.get(system).bindAndHandle(appRoute().flow(system, materializer),
ConnectHttp.toHost(properties.urlSSL(), properties.portSSL()), materializer);
log.info("Started on " + properties.urlSSL() + ":" + properties.portSSL());
}

现在我可以绑定(bind)到 Akka Http,并且根本没有报告错误,但是我的 https 请求在服务器上被拒绝了(它甚至没有到达 akka/http - 所以 akka 系统中没有错误日志)和 http://domainName.in工作正常。

问题:

  1. 我是否遗漏了以上任何步骤??

  2. 我只使用 SSLContext - 可以吗,或者我也应该使用 SSLConfig 吗?如果是 - 那么我该如何使用 SSLConfig,因为似乎没有提供适当的文档

  3. 是否需要通过 key 工具使用 Java 默认 keystore ?因为我相信使用 openssl 生成的 wtkeystore.p12 文件也是一个 keystore 并且足够好可以使用。

更新代码 1:按照建议:

if (properties.useSSL()) {

HttpsConnectionContext https = useHttps(system);
ConnectHttp connect = ConnectHttp.toHostHttps(properties.urlSSL(), properties.portSSL())
.withCustomHttpsContext(https);

Http.get(system).bindAndHandle(appRoute().flow(system, materializer), connect, materializer);
log.info("Started on " + properties.urlSSL() + ":" + properties.portSSL());
}

and also Made sure that Firewall/Network is open for port 443 but netstat is still showing status as 'ESTABLISHED' and i do telnet to it, this port connection is then closed

当我调试时,我得到的 SSLConfig 和其他对象都没有,除了 SSLContext 对象。这是正常的?? enter image description here

最佳答案

尝试这样的事情:

if (properties.useSSL()) {
ConnectHttp connect =
ConnectHttp.toHostHttps(properties.urlSSL(), properties.portSSL())
.withCustomHttpsContext(useHttps(system));

Http.get(system).bindAndHandle(appRoute().flow(system, materializer),
connect, materializer);
log.info("Started on " + properties.urlSSL() + ":" + properties.portSSL());
}

关于java - 要使用的 SSL-Config 或 SSLContext?在 Akka Http SSL Java 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43468803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com