我正在尝试使用SSL加密设置MongoDB的最新版本,我能够从mongo shell连接,但是当我从Java客户端连接时出现错误.
作品
mongo admin --host mongo1.xxxx.com --ssl --sslPEMKeyFile mongoClient.pem --sslCAFile mongoCA.crt
不行
public static void main(String args[]){
System.setProperty("javax.net.ssl.trustStore","/home/gasparms/truststore.ts");
System.setProperty("javax.net.ssl.trustStorePassword", "mypasswd");
System.setProperty("javax.net.ssl.keyStore", "/home/gasparms/truststore.ts");
System.setProperty("javax.net.ssl.keyStorePassword", "mypasswd");
System.setProperty("javax.security.auth.useSubjectCredsOnly","false");
MongoClientOptions options = MongoClientOptions.builder().sslEnabled(true)
.build();
MongoClient mongoClient = new MongoClient("mongo1.xxxx.com",options);
System.out.println(mongoClient.getDatabaseNames());
}
Run Code Online (Sandbox Code Playgroud)
我从Mongo方面得到这个错误:
2015-06-09T15:08:14.431ZI NETWORK [initandlisten]连接从192.168.33.1:38944#585接受(现已打开3个连接)2015-06-09T15:08:14.445ZE NETWORK [conn585]没有由同行提供的SSL证书; 连接被拒绝2015-06-09T15:08:14.445ZI NETWORK [conn585] end connection 192.168.33.1:38944(2个连接现已开放)2015-06-09T15:08:14.828ZI NETWORK [conn580] end connection 192.168.33.13:39240 (1个连接现已开启)
并在java客户端程序中
INFORMACIÓN:连接到服务器时监视器线程中的异常mongo1.xxxx.com:27017 com.mongodb.MongoSocketReadException:在com.mongodb的com.mongodb.connection.SocketStream.read(SocketStream.java:88)中过早地到达流的末尾. com.mongodb的com.mongodb.connection.InmandStreamConnection.receiveMessage(InternalStreamConnection.java:221)中com.mongodb的com.mongodb.connection.CommandHelper.receiveReply(CommandHelper.java:134)中的connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:491) com中的com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32)中的.connection.CommandHelper.receiveCommandResult(CommandHelper.java:121)com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:83). com.mongodb.connection.InternalStreamConnection.open中的mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:43)StreamConnection.java:115)在java.lang.Thread.run(Thread.java:745)的com.mongodb.connection.DefaultServerMonitor $ ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
创建证书
我有与mongo shell一起使用的mongoCA.crt和mongoClient.pem.然后,我想将.pem和.crt导入java密钥库
openssl x509 -outform der -in certificate.pem -out certificate.der
keytool -import -alias MongoDB-Client -file …Run Code Online (Sandbox Code Playgroud) 我在这里可能是一个简单的问题,但我不明白为什么它不起作用,我有研究并尝试了很多例子,我发布你的我当前的例子,我从教程中得到这个,他们已经解释了这是解决方案,但在我的情况下,它不起作用,我收到的电子邮件中的主题没有正确显示字母"ÄÖÜßüü".
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf-8";
$headers[] = "From: {$emailfrom}";
$to = "myemail@yahoo.de";
$subject = 'Betreff mit Ä, Ö und Ü ß ü';
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
$txt = "Hallo Sie haben das gewählt, am ä ";
mail($to,$subject,$txt,implode("\r\n",$headers));
Run Code Online (Sandbox Code Playgroud)
通常他们在不同的教程中随处写,这是解决方案,但在我的情况下它不起作用,为什么?在我的情况下,也许与月亮有关?大声笑 ;)