0

I am trying to connect to mongodb using ssl certificate in julia. What I need is the equivalent of code below wrote in nodejs:

var MongoClient = require('mongodb').MongoClient,
  f = require('util').format,
  fs = require('fs');

// Read the certificate authority
var ca = [fs.readFileSync(__dirname + "/ssl/ca.pem")];
var cert = fs.readFileSync(__dirname + "/ssl/client.pem");
var key = fs.readFileSync(__dirname + "/ssl/client.pem");

// Connect validating the returned certificates from the server
MongoClient.connect("mongodb://localhost:27017/test?ssl=true", {
  server: {
      sslValidate:true
    , sslCA:ca
    , sslKey:key
    , sslCert:cert
    , sslPass:'10gen'
  }
}, function(err, db) {
  db.close();
});

What I found is mongoc.jl tutorial in which described how to connect, but there is nothing about ssl certificates.

https://felipenoris.github.io/Mongoc.jl/stable/tutorial/#Connecting-to-MongoDB-1

could anyone help me how to connect using ssl certificates?

Thank you!

weera
  • 884
  • 1
  • 10
  • 21

2 Answers2

0

This is discussed in the Mongoc.jl package. I tested it and it is working for me.

https://github.com/felipenoris/Mongoc.jl/issues/69

$ brew install openssl
$ ls /usr/local/etc/openssl/cert.pem
$ julia
] add Mongoc
julia> using Mongoc
julia> suffix = "&tlsCAFile=/usr/local/etc/openssl/cert.pem" # or use "?tlsCAFile=" if you don't have any other params already
julia> mongo_uri = "mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017/?authSource=admin"
julia> client = Mongoc.Client(mongo_uri*suffix)
julia> collect(Mongoc.find_databases(client))

ca-certificates Mac OS X

https://pymongo.readthedocs.io/en/3.5.1/examples/tls.html

phyatt
  • 18,472
  • 5
  • 61
  • 80
-1

Perhaps support for SSL certificates is not yet implemented in Mongoc.jl. I think that you have two reasonable options:

  1. Use pymongo via PyCall
using PyCall, Conda
Conda.runconda(`install -c anaconda pymongo -y`)
pymongo = pyimport("pymongo")
  1. Install on your local machine Apache in reverse proxy mode and configure it to transparently handle certificate authorization with the remote host. Thus you can connect to your local Apache with plain HTTP being assured that the connection to the production host is encrypted.
Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62
  • Mongoc.jl is based on libmongoc which support mongodb client SSL. What I need is to combine this: http://mongoc.org/libmongoc/current/mongoc_ssl_opt_t.html#configuration-through-uri-options with src/types.jl in mongoc.jl package. I don't know how! – weera Jun 13 '19 at 16:27
  • I can see you have already raised issue at their project (https://github.com/felipenoris/Mongoc.jl/issues/56) so hopefully they will find solution for the more native connection... – Przemyslaw Szufel Jun 13 '19 at 21:03