[CXX-323] connect to the mongodb database over SSL using C++ driver and certificate Created: 28/Aug/14  Updated: 11/Sep/19  Resolved: 09/Sep/14

Status: Closed
Project: C++ Driver
Component/s: Documentation
Affects Version/s: legacy-0.0-26compat-2.6.3
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Dharmaraj Narayan Assignee: Unassigned
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

RH linux 64bit, MONGODB Enterpise version.



 Description   

The only example we have so far is

Configuration of the driver is managed through a new class, added in the legacy-0.9.0 release, called Options. This class is hosted in the mongo::client namespace, and is defined in the header mongo/client/options.h.
Passing an instance to mongo::client::initialize
By default, calling mongo::client::initialize() with no parameters is equivalent to calling mongo::client::initialize(mongo::client::Options()) passing a default constructed mongo::client::Options object.
Because the mongo::client::Options class has setters returning a mongo::client::Options& you can chain together options to easily configure them at the call site:
using mongo::client::initialize;
using mongo::client::Options;

// Configure the mongo C++ client driver, enabling SSL and setting
// the SSL Certificate Authority file to "mycafile".
Status status = initialize(
Options().setSSLMode(Options:kSSLModeRequired).setSSLCAFile("mycafile")
);

And this complains that mongo/client/options.h is not found.

Please provide example of how similar thing can be done with mongo-cxx-driver-legacy-0.0-26compat-2.6.3



 Comments   
Comment by Dharmaraj Narayan [ 29/Aug/14 ]

Thanks Tyler.

Comment by Tyler Brock [ 29/Aug/14 ]

Hey Dharmaraj,

You are correct, mongo/client/options.h is only found in the legacy(non 26-compat) versions of the driver greater than v0.9. Here is a simple example of how SSL would work on the 26-compat release stream:

#include "mongo/util/net/ssl_options.h"
#include "mongo/client/init.h"
 
int main() {
    sslGlobalParams.sslMode.store(SSLGlobalParams::SSLMode_requireSSL);
    
    // only really need a PEM on the server side
    mongo::sslGlobalParams.sslPEMKeyFile = "<path/to/keyfile.pem>";
 
    mongo::Status status = mongo::client::initialize();
 
    if (!status.isOK())
        ::abort();
 
    DBClientConnection c;
    c.connect("hostname.whatever.com"); // outgoing connections are SSL
}

Generated at Wed Feb 07 21:58:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.