Home > Blockchain >  How to connect the Rust MongoDB driver with Invalid Tls Certificates?
How to connect the Rust MongoDB driver with Invalid Tls Certificates?

Time:08-02

I'm unable to connect to the MongoDB with Tls Allow Invalid Certificate option with the Rust driver.

let uri = "MongoDB://user:pwd@host:port/database_name?tls=true&tlsAllowInvalidCertificates=true"
let client_options = ClientOptions::parse(uri)?;
let client = Client::with_options(client_options).expect("");
let db = client.database("database_name");

I can see that the client_options has correctly parsed the uri with:

tls: Some(Enabled(TlsOptions{allow_invalid_certificates: Some(true) ...}))

However I get the following non-recoverable error:

Error: invalid peer certificate contents: invalid peer certificate: UnsupportedCertVersion

Server MongoDB: 4.2.18

Client Mongosh: 1.5.0

Rust Driver: 2.3.0

P.s. I'm able to connect to MongoDB by the mongosh shell with the following command:

mongosh server_dns:server_port/database_name -u username -p --tls --tlsAllowInvalidCertificates

(It's also possible to connect with described options with pymongo)

CodePudding user response:

What solved the issue was to add the feature "openssl-tls" to Cargo.toml

[dependencies.mongodb]
version = "2.3.0"
default-features = false
features = ["openssl-tls"]
  • Related