【发布时间】:2021-10-24 22:13:44
【问题描述】:
是否有人设法将 java 程序连接到 AWS DocumentDB,其中 java 程序在 AWS 之外运行并且 DocumentDB 启用了 tls?提供的任何示例或指导将不胜感激。
这是我目前所做的 =>
我一直在关注 AWS 的开发人员指南,并且我知道要做到这一点,我需要一个 SSH 隧道设置到跳转盒(EC2 实例),然后设置到数据库集群。我已经这样做了,并通过我的笔记本电脑进行了连接。
然后,我从 AWS 的 rds-combined-ca-bundle.pem 文件创建了所需的 .jks 文件,并在基本的 java 主类中引用了它。在 java 主类中,我将集群引用为 localhost:27017,因为这是我设置 SSH 隧道的地方。
我的测试代码遵循 Java 的 AWS 示例,运行程序时出现以下错误 =>
原因:javax.net.ssl.SSLHandshakeException:找不到与 localhost 匹配的主题备用 DNS 名称。
公共类 CertsTestMain {
public static void main(String[] args) {
String template = "mongodb://%s:%s@%s/test?ssl=true&replicaSet=rs0&readpreference=%s";
String username = "dummy";
String password = "dummy";
String clusterEndpoint = "localhost:27017";
String readPreference = "secondaryPreferred";
String connectionString = String.format(template, username, password, clusterEndpoint, readPreference);
String truststore = "C:/Users/eclipse-workspace/certs/certs/rds-truststore.jks";
String truststorePassword = "test!";
System.setProperty("javax.net.ssl.trustStore", truststore);
System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);
MongoClient mongoClient = MongoClients.create(connectionString);
MongoDatabase testDB = mongoClient.getDatabase("test");
MongoCollection<Document> bookingCollection = testDB.getCollection("booking");
MongoCursor<Document> cursor = bookingCollection.find().iterator();
try {
while (cursor.hasNext()) {
System.out.println(cursor.next().toJson());
}
} finally {
cursor.close();
}
}
}
【问题讨论】:
-
您熟悉握手中使用的证书中的 SAN 整体,如果没有看到这里的定义 en.wikipedia.org/wiki/Subject_Alternative_Name 和这里可能的解决方案 stackoverflow.com/questions/8443081/…
标签: java ssh-tunnel aws-documentdb