Skip to content

Always skip ssl validation when using a self-signed certificate #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ impl ConfigBuilder {
self
}

/// A CA certificate to use to validate the server's certificate.
///
/// This is required if the server's certificate is not signed by a known CA.
pub fn with_client_certificate(mut self, client_cert: impl AsRef<Path>) -> Self {
self.tls_config =
ConnectionTLSConfig::ClientCACertificate(ClientCertificate::new(client_cert));
self
}

/// Skip SSL validation. This is not recommended for production use.
/// This is true by default when connecting to the server using `neo4j+ssc` or 'bolt+ssc' schemes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good additions, thanks!

pub fn skip_ssl_validation(mut self) -> Self {
self.tls_config = ConnectionTLSConfig::NoSSLValidation;
self
Expand Down
20 changes: 12 additions & 8 deletions lib/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,22 @@ impl ConnectionInfo {
) -> Result<Self> {
let mut url = NeoUrl::parse(uri)?;

let (routing, encryption) = match url.scheme() {
"bolt" | "" => (false, false),
"bolt+s" => (false, true),
"bolt+ssc" => (false, true),
"neo4j" => (true, false),
"neo4j+s" => (true, true),
"neo4j+ssc" => (true, true),
let (routing, encryption, validation) = match url.scheme() {
"bolt" | "" => (false, false, false),
"bolt+s" => (false, true, true),
"bolt+ssc" => (false, true, false),
"neo4j" => (true, false, false),
"neo4j+s" => (true, true, true),
"neo4j+ssc" => (true, true, false),
otherwise => return Err(Error::UnsupportedScheme(otherwise.to_owned())),
};

let encryption = encryption
.then(|| Self::tls_connector(url.host(), tls_config))
.then(|| {
// do not apply validation if using a self-signed certificate,as the documentation suggests
let config = if !validation { &ConnectionTLSConfig::NoSSLValidation } else { tls_config };
Self::tls_connector(url.host(), config)
})
.transpose()?;

let routing = if routing {
Expand Down
Loading