Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions redis/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def __init__(
ssl_check_hostname: bool = True,
ssl_min_version: Optional[TLSVersion] = None,
ssl_ciphers: Optional[str] = None,
ssl_password: Optional[str] = None,
max_connections: Optional[int] = None,
single_connection_client: bool = False,
health_check_interval: int = 0,
Expand Down Expand Up @@ -357,6 +358,7 @@ def __init__(
"ssl_check_hostname": ssl_check_hostname,
"ssl_min_version": ssl_min_version,
"ssl_ciphers": ssl_ciphers,
"ssl_password": ssl_password,
}
)
# This arg only used if no pool is passed in
Expand Down
13 changes: 11 additions & 2 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ def __init__(
ssl_check_hostname: bool = True,
ssl_min_version: Optional[TLSVersion] = None,
ssl_ciphers: Optional[str] = None,
ssl_password: Optional[str] = None,
**kwargs,
):
if not SSL_AVAILABLE:
Expand All @@ -832,6 +833,7 @@ def __init__(
check_hostname=ssl_check_hostname,
min_version=ssl_min_version,
ciphers=ssl_ciphers,
password=ssl_password,
)
super().__init__(**kwargs)

Expand Down Expand Up @@ -890,6 +892,7 @@ class RedisSSLContext:
"check_hostname",
"min_version",
"ciphers",
"password",
)

def __init__(
Expand All @@ -904,6 +907,7 @@ def __init__(
check_hostname: bool = False,
min_version: Optional[TLSVersion] = None,
ciphers: Optional[str] = None,
password: Optional[str] = None,
):
if not SSL_AVAILABLE:
raise RedisError("Python wasn't built with SSL support")
Expand Down Expand Up @@ -933,6 +937,7 @@ def __init__(
)
self.min_version = min_version
self.ciphers = ciphers
self.password = password
self.context: Optional[SSLContext] = None

def get(self) -> SSLContext:
Expand All @@ -946,8 +951,12 @@ def get(self) -> SSLContext:
if self.exclude_verify_flags:
for flag in self.exclude_verify_flags:
context.verify_flags &= ~flag
if self.certfile and self.keyfile:
context.load_cert_chain(certfile=self.certfile, keyfile=self.keyfile)
if self.certfile or self.keyfile:
context.load_cert_chain(
certfile=self.certfile,
keyfile=self.keyfile,
password=self.password,
)
if self.ca_certs or self.ca_data:
context.load_verify_locations(cafile=self.ca_certs, cadata=self.ca_data)
if self.min_version is not None:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_asyncio/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,29 @@ def capture_context_create_default():

finally:
await r.aclose()

async def test_ssl_password_parameter(self, request):
"""Test that ssl_password parameter is properly passed to SSLConnection"""
ssl_url = request.config.option.redis_ssl_url
parsed_url = urlparse(ssl_url)

# Test with a mock password for encrypted private key
test_password = "test_key_password"

r = redis.Redis(
host=parsed_url.hostname,
port=parsed_url.port,
ssl=True,
ssl_cert_reqs="none",
ssl_password=test_password,
)

try:
# Get the connection to verify ssl_password is passed through
conn = r.connection_pool.make_connection()
assert isinstance(conn, redis.SSLConnection)

# Verify the password is stored in the SSL context
assert conn.ssl_context.password == test_password
finally:
await r.aclose()