connect mongo server in scala with ssl authentication
<p>I have established a SSL connection between mongo server and client, the command line i used to connect mongo server is shown below and it works well.
<code>
mongo gs-server:27017 --ssl --sslPEMKeyFile E:\mongodb\ssl\ssl_test\client.pem --sslCAFile E:\mongodb\ssl\ssl_test\root-ca.pem
</code></p>

<p>But when I want to connect mongo in scala code with SSL authentication, I meet some problems. What I do is listed below:</p>

<ol>
<li>Generate the keystore and truststore from client.pem and root-ca.pem I used before.
<code>
keytool -import -keystore client.jks -file client.pem -alias client
keytool -import -keystore root-ca.jks -file root-ca.pem -alias root-ca
</code></li>
</ol>

<p>2.Set the connection settings and system properties in scala:</p>

<pre><code>val clusterSettings = ClusterSettings.builder().hosts(List(new ServerAddress("gs-server")).asJava).description("mongo Server").build()

System.setProperty("javax.net.ssl.trustStore", "E:\\mongodb\\ssl\\ssl_test\\root-ca.jks")
System.setProperty("javax.net.ssl.trustStorePassword", "password")
System.setProperty("javax.net.ssl.keyStore", "E:\\mongodb\\ssl\\ssl_test\\client.jks")
System.setProperty("javax.net.ssl.keyStorePassword", "password")

val setting = MongoClientSettings.builder().clusterSettings(clusterSettings)
  .sslSettings(SslSettings.builder()
    .enabled(true)
    .invalidHostNameAllowed(true)
    .build())
  .streamFactoryFactory(NettyStreamFactoryFactory())
  .build()

val client = MongoClient(setting)
val db = client.getDatabase("test")
val coll = db.getCollection("test1")
val first_res = coll.drop().printHeadResult()
</code></pre>

<p>When I run this program, I found the log on the mongo server:</p>

<pre><code>2016-01-14T15:52:20.433+0800 I NETWORK  [initandlisten] connection accepted from 10.200.200.72:64193 #11812 (1 connection now open)
2016-01-14T15:52:20.501+0800 E NETWORK  [conn11812] no SSL certificate provided by peer; connection rejected 
2016-01-14T15:52:20.502+0800 D NETWORK  [conn11812] SocketException: remote: 10.200.200.72:64193 error: 9001 socket exception [CONNECT_ERROR] server [no SSL certificate provided by peer; connection rejected]
2016-01-14T15:52:20.502+0800 I NETWORK  [conn11812] end connection 10.200.200.72:64193 (0 connections now open)
</code></pre>

<p>It seems there is no valid certificate in the keystore and truststore I generated before. So have I done something wrong or miss something? Any help will be appreciated.</p>

<p>BTW, I am using Mongo 3.2.0 and the mongo scala driver version is :
    
            org.mongodb.scala
            mongo-scala-driver_2.11
            1.1.0
        </p>