|
20 | 20 |
|
21 | 21 | from .._async_compat.util import AsyncUtil |
22 | 22 | from ..addressing import Address |
23 | | -from ..api import READ_ACCESS |
| 23 | +from ..api import ( |
| 24 | + READ_ACCESS, |
| 25 | + TRUST_ALL_CERTIFICATES, |
| 26 | + TRUST_SYSTEM_CA_SIGNED_CERTIFICATES, |
| 27 | +) |
24 | 28 | from ..conf import ( |
25 | 29 | Config, |
26 | 30 | PoolConfig, |
@@ -71,20 +75,47 @@ def driver(cls, uri, *, auth=None, **config): |
71 | 75 |
|
72 | 76 | driver_type, security_type, parsed = parse_neo4j_uri(uri) |
73 | 77 |
|
74 | | - if security_type in [SECURITY_TYPE_SELF_SIGNED_CERTIFICATE, SECURITY_TYPE_SECURE] and ("encrypted" in config.keys() or "trusted_certificates" in config.keys()): |
| 78 | + # TODO: 6.0 remove "trust" config option |
| 79 | + if "trust" in config.keys(): |
| 80 | + if config["trust"] not in (TRUST_ALL_CERTIFICATES, |
| 81 | + TRUST_SYSTEM_CA_SIGNED_CERTIFICATES): |
| 82 | + from neo4j.exceptions import ConfigurationError |
| 83 | + raise ConfigurationError( |
| 84 | + "The config setting `trust` values are {!r}" |
| 85 | + .format( |
| 86 | + [ |
| 87 | + TRUST_ALL_CERTIFICATES, |
| 88 | + TRUST_SYSTEM_CA_SIGNED_CERTIFICATES, |
| 89 | + ] |
| 90 | + ) |
| 91 | + ) |
| 92 | + |
| 93 | + if (security_type in [SECURITY_TYPE_SELF_SIGNED_CERTIFICATE, SECURITY_TYPE_SECURE] |
| 94 | + and ("encrypted" in config.keys() |
| 95 | + or "trust" in config.keys() |
| 96 | + or "trusted_certificates" in config.keys() |
| 97 | + or "ssl_context" in config.keys())): |
75 | 98 | from neo4j.exceptions import ConfigurationError |
76 | | - raise ConfigurationError("The config settings 'encrypted' and 'trust' can only be used with the URI schemes {!r}. Use the other URI schemes {!r} for setting encryption settings.".format( |
77 | | - [ |
78 | | - URI_SCHEME_BOLT, |
79 | | - URI_SCHEME_NEO4J, |
80 | | - ], |
81 | | - [ |
82 | | - URI_SCHEME_BOLT_SELF_SIGNED_CERTIFICATE, |
83 | | - URI_SCHEME_BOLT_SECURE, |
84 | | - URI_SCHEME_NEO4J_SELF_SIGNED_CERTIFICATE, |
85 | | - URI_SCHEME_NEO4J_SECURE, |
86 | | - ] |
87 | | - )) |
| 99 | + |
| 100 | + # TODO: 6.0 remove "trust" from error message |
| 101 | + raise ConfigurationError( |
| 102 | + 'The config settings "encrypted", "trust", ' |
| 103 | + '"trusted_certificates", and "ssl_context" can only be used ' |
| 104 | + "with the URI schemes {!r}. Use the other URI schemes {!r} " |
| 105 | + "for setting encryption settings." |
| 106 | + .format( |
| 107 | + [ |
| 108 | + URI_SCHEME_BOLT, |
| 109 | + URI_SCHEME_NEO4J, |
| 110 | + ], |
| 111 | + [ |
| 112 | + URI_SCHEME_BOLT_SELF_SIGNED_CERTIFICATE, |
| 113 | + URI_SCHEME_BOLT_SECURE, |
| 114 | + URI_SCHEME_NEO4J_SELF_SIGNED_CERTIFICATE, |
| 115 | + URI_SCHEME_NEO4J_SECURE, |
| 116 | + ] |
| 117 | + ) |
| 118 | + ) |
88 | 119 |
|
89 | 120 | if security_type == SECURITY_TYPE_SECURE: |
90 | 121 | config["encrypted"] = True |
|
0 commit comments