Skip to content

Commit

Permalink
[fix] add cafile capath and cadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Mar 24, 2019
1 parent 309738b commit 4150514
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ Features

* Tracking unroutable messages
(Use **connection.channel(on_return_raises=False)** for disabling)
* Full SSL/TLS support
* Full SSL/TLS support with url query parameters:
* ``cafile=`` - string
* ``capath=`` - string
* ``cadata=`` - base64 encoded certificate
* Python `type hints`_
* Uses `pamqp`_ as an AMQP 0.9.1 frame encoder/decoder

Expand Down
13 changes: 11 additions & 2 deletions aiormq/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import platform
import ssl
import typing
from base64 import b64decode
from contextlib import suppress

import pamqp.frame
Expand Down Expand Up @@ -53,6 +54,10 @@ class Connection(Base):
HEARTBEAT_GRACE_MULTIPLIER = 3
_HEARTBEAT = pamqp.frame.marshal(Heartbeat(), 0)

@staticmethod
def _parse_ca_data(data):
return b64decode(data) if data else data

def __init__(self, url: URLorStr, *, parent=None,
loop: asyncio.get_event_loop() = None):

Expand All @@ -71,7 +76,9 @@ def __init__(self, url: URLorStr, *, parent=None,
self.reader = None # type: asyncio.StreamReader
self.writer = None # type: asyncio.StreamWriter
self.ssl_certs = SSLCerts(
ca=self.url.query.get('cafile'),
cafile=self.url.query.get('cafile'),
capath=self.url.query.get('capath'),
cadata=self._parse_ca_data(self.url.query.get('cadata')),
key=self.url.query.get('keyfile'),
cert=self.url.query.get('certfile'),
verify=self.url.query.get('no_verify_ssl', '0') == '0'
Expand Down Expand Up @@ -118,7 +125,9 @@ def _get_ssl_context(self):
if self.ssl_certs.key
else ssl.Purpose.CLIENT_AUTH
),
capath=self.ssl_certs.ca,
capath=self.ssl_certs.capath,
cafile=self.ssl_certs.cafile,
cadata=self.ssl_certs.cadata,
)

if self.ssl_certs.key:
Expand Down
4 changes: 3 additions & 1 deletion aiormq/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
'SSLCerts', [
('cert', str),
('key', str),
('ca', str),
('capath', str),
('cafile', str),
('cadata', bytes),
('verify', bool),
]
)
Expand Down

0 comments on commit 4150514

Please sign in to comment.