Skip to content

Commit

Permalink
add support for sslcrl
Browse files Browse the repository at this point in the history
  • Loading branch information
jdobes committed Jun 8, 2021
1 parent bc856f9 commit f66a4ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions asyncpg/connect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _parse_hostlist(hostlist, port, *, unquote=False):

def _parse_connect_dsn_and_args(*, dsn, host, port, user,
password, passfile, database, ssl,
sslcert, sslkey, sslrootcert,
sslcert, sslkey, sslrootcert, sslcrl,
connect_timeout, server_settings):
# `auth_hosts` is the version of host information for the purposes
# of reading the pgpass file.
Expand Down Expand Up @@ -326,6 +326,11 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
if sslrootcert is None:
sslrootcert = val

if 'sslcrl' in query:
val = query.pop('sslcrl')
if sslcrl is None:
sslcrl = val

if query:
if server_settings is None:
server_settings = query
Expand Down Expand Up @@ -443,7 +448,6 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
'`sslmode` parameter must be one of: {}'.format(modes))

# docs at https://www.postgresql.org/docs/10/static/libpq-connect.html
# Not implemented: sslcrl param.
if sslmode < SSLMode.allow:
ssl = False
else:
Expand All @@ -462,12 +466,18 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
if sslrootcert is None:
sslrootcert = os.getenv('PGSSLROOTCERT')

if sslcrl is None:
sslcrl = os.getenv('PGSSLCRL')

if sslcert:
ssl.load_cert_chain(sslcert, keyfile=sslkey)

if sslrootcert:
ssl.load_verify_locations(cafile=sslrootcert)

if sslcrl:
ssl.load_verify_locations(cafile=sslcrl)

elif ssl is True:
ssl = ssl_module.create_default_context()
sslmode = SSLMode.verify_full
Expand Down Expand Up @@ -495,7 +505,7 @@ def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
statement_cache_size,
max_cached_statement_lifetime,
max_cacheable_statement_size,
ssl, sslcert, sslkey, sslrootcert,
ssl, sslcert, sslkey, sslrootcert, sslcrl,
server_settings):

local_vars = locals()
Expand Down Expand Up @@ -525,7 +535,7 @@ def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
dsn=dsn, host=host, port=port, user=user,
password=password, passfile=passfile, ssl=ssl,
sslcert=sslcert, sslkey=sslkey, sslrootcert=sslrootcert,
database=database, connect_timeout=timeout,
sslcrl=sslcrl, database=database, connect_timeout=timeout,
server_settings=server_settings)

config = _ClientConfiguration(
Expand Down
6 changes: 6 additions & 0 deletions asyncpg/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,7 @@ async def connect(dsn=None, *,
sslcert=None,
sslkey=None,
sslrootcert=None,
sslcrl=None,
connection_class=Connection,
record_class=protocol.Record,
server_settings=None):
Expand Down Expand Up @@ -1912,6 +1913,10 @@ async def connect(dsn=None, *,
This parameter specifies the name of a file containing SSL certificate
authority (CA) certificate(s).
:param sslcrl
This parameter specifies the file name of the SSL certificate
revocation list (CRL).
:param dict server_settings:
An optional dict of server runtime parameters. Refer to
PostgreSQL documentation for
Expand Down Expand Up @@ -2007,6 +2012,7 @@ async def connect(dsn=None, *,
sslcert=sslcert,
sslkey=sslkey,
sslrootcert=sslrootcert,
sslcrl=sslcrl,
database=database,
server_settings=server_settings,
command_timeout=command_timeout,
Expand Down

0 comments on commit f66a4ef

Please sign in to comment.