Skip to content

Better explanation of using custom/self-signed certificates #1237

@Kilo59

Description

@Kilo59

Feature Request

I'm trying to understand how to properly use Custom Certificates (or Self Signed Certificates).
The documentation and related error messages are confusing.

The documentation here says that if I want to use a custom/self-signed certificate I need to use the neo4j+ssc scheme.
https://neo4j.com/docs/api/python-driver/5.28/api.html#uri

However when I do that I get an error.

neo4j.exceptions.ConfigurationError: The config settings "encrypted", "trust", "trusted_certificates", and "ssl_context" can only be used with the URI schemes ['bolt', 'neo4j']. Use the other URI schemes ['bolt+ssc', 'bolt+s', 'neo4j+ssc', 'neo4j+s'] for setting encryption settings.

I've tried using both SSL ssl_context and trusted_certificates, they both throw the same error.

MRE(ish) below 👇

import pathlib
import ssl

import neo4j
from neo4j import GraphDatabase

from my_app import CUSTOM_CERT_PATH # pathlib.Path object

def get_config() -> dict:
   return {"user_name": "username", "password": "pw", "uri": "neo4j+ssc://12345.databases.neo4j.io"}

def get_neo4j_driver_ssl_context(config: dict[str, str]) -> neo4j.Driver:
    return GraphDatabase.driver(
        config["uri"],
        auth=(config["username"], config["password"]),
        ssl_context=ssl.create_default_context(cafile=CUSTOM_CERT_PATH),
    )

def get_neo4j_driver_custom_ca(config: dict[str, str]) -> neo4j.Driver:
    return GraphDatabase.driver(
        config["uri"],
        auth=(config["username"], config["password"]),
        trusted_certificates=neo4j.TrustCustomCAs(str(CUSTOM_CERT_PATH))
    )

if __name__ == "__main__":
  config = get_config()
  ssl_ctx_driver = get_neo4j_driver_ssl_context(config)
  ssl_ctx_driver.verify_connectivity()

  custom_ca_driver = get_neo4j_driver_custom_ca(config)
  custom_ca_driver.verify_connectivity()

I should note I've used this exact cert file with multiple other (non Aura/Neo4J) services without issue.

The DB in question is on/in Aura if the uri didn't make that clear.

I can of course connect when I drop the the +ssc scheme (example: neo4j+ssc://12345.databases.neo4j.io) but it goes without saying I don't want to to use the driver without encryption.

Version Info

neo4j v5.28.2
Python 3.13.5

Pitch

Please update or expand your documentation around using custom certificates along with examples, or fix the underlying issue that prevents using self signed certs in the manor that is described.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions