Skip to content

Commit f66a4ef

Browse files
committed
add support for sslcrl
1 parent bc856f9 commit f66a4ef

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

asyncpg/connect_utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def _parse_hostlist(hostlist, port, *, unquote=False):
222222

223223
def _parse_connect_dsn_and_args(*, dsn, host, port, user,
224224
password, passfile, database, ssl,
225-
sslcert, sslkey, sslrootcert,
225+
sslcert, sslkey, sslrootcert, sslcrl,
226226
connect_timeout, server_settings):
227227
# `auth_hosts` is the version of host information for the purposes
228228
# of reading the pgpass file.
@@ -326,6 +326,11 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
326326
if sslrootcert is None:
327327
sslrootcert = val
328328

329+
if 'sslcrl' in query:
330+
val = query.pop('sslcrl')
331+
if sslcrl is None:
332+
sslcrl = val
333+
329334
if query:
330335
if server_settings is None:
331336
server_settings = query
@@ -443,7 +448,6 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
443448
'`sslmode` parameter must be one of: {}'.format(modes))
444449

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

469+
if sslcrl is None:
470+
sslcrl = os.getenv('PGSSLCRL')
471+
465472
if sslcert:
466473
ssl.load_cert_chain(sslcert, keyfile=sslkey)
467474

468475
if sslrootcert:
469476
ssl.load_verify_locations(cafile=sslrootcert)
470477

478+
if sslcrl:
479+
ssl.load_verify_locations(cafile=sslcrl)
480+
471481
elif ssl is True:
472482
ssl = ssl_module.create_default_context()
473483
sslmode = SSLMode.verify_full
@@ -495,7 +505,7 @@ def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
495505
statement_cache_size,
496506
max_cached_statement_lifetime,
497507
max_cacheable_statement_size,
498-
ssl, sslcert, sslkey, sslrootcert,
508+
ssl, sslcert, sslkey, sslrootcert, sslcrl,
499509
server_settings):
500510

501511
local_vars = locals()
@@ -525,7 +535,7 @@ def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
525535
dsn=dsn, host=host, port=port, user=user,
526536
password=password, passfile=passfile, ssl=ssl,
527537
sslcert=sslcert, sslkey=sslkey, sslrootcert=sslrootcert,
528-
database=database, connect_timeout=timeout,
538+
sslcrl=sslcrl, database=database, connect_timeout=timeout,
529539
server_settings=server_settings)
530540

531541
config = _ClientConfiguration(

asyncpg/connection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,7 @@ async def connect(dsn=None, *,
17581758
sslcert=None,
17591759
sslkey=None,
17601760
sslrootcert=None,
1761+
sslcrl=None,
17611762
connection_class=Connection,
17621763
record_class=protocol.Record,
17631764
server_settings=None):
@@ -1912,6 +1913,10 @@ async def connect(dsn=None, *,
19121913
This parameter specifies the name of a file containing SSL certificate
19131914
authority (CA) certificate(s).
19141915
1916+
:param sslcrl
1917+
This parameter specifies the file name of the SSL certificate
1918+
revocation list (CRL).
1919+
19151920
:param dict server_settings:
19161921
An optional dict of server runtime parameters. Refer to
19171922
PostgreSQL documentation for
@@ -2007,6 +2012,7 @@ async def connect(dsn=None, *,
20072012
sslcert=sslcert,
20082013
sslkey=sslkey,
20092014
sslrootcert=sslrootcert,
2015+
sslcrl=sslcrl,
20102016
database=database,
20112017
server_settings=server_settings,
20122018
command_timeout=command_timeout,

0 commit comments

Comments
 (0)