I want to create an AMQP client with SSL and connect to my ActiveMQ Artemis broker. For this task I took an example project from the Qpid Proton repository and modified it a bit:
def on_start(self, event):
ssl_domain = SSLDomain(SSLDomain.MODE_CLIENT)
ssl_domain.set_credentials(cert_file=str('./ssl/cert.pem'),
key_file=str('./ssl/key.pem'),
password=str('QWErty123'))
ssl_domain.set_trusted_ca_db(certificate_db=str('./ssl/ca.pem'))
ssl_domain.set_peer_authentication(SSLDomain.VERIFY_PEER_NAME)
self.container = event.container
self.conn = event.container.connect(self.url, ssl_domain=ssl_domain, allowed_mechs="EXTERNAL")
self.server = event.container.create_sender(self.url)
cert.pem
and ca.pem
contain BEGIN/END CERTIFICATE, and key.pem
contains BEGIN/END PRIVATE KEY. URL is:
amqps://localhost:61616/Server.RQ
When I'm trying to run the project in Windows 10 I'm getting an error:
Traceback (most recent call last):
File "C:\Users\Daemon2017\PycharmProjects\python-server\server\client.py", line 43, in <module>
Container(Send("amqps://localhost:61616/Server.RQ", "Client.RQ")).run()
File "C:\Program Files\Python310\lib\site-packages\proton\_reactor.py", line 197, in run
while self.process():
File "C:\Program Files\Python310\lib\site-packages\proton\_reactor.py", line 260, in process
event.dispatch(handler)
File "C:\Program Files\Python310\lib\site-packages\proton\_events.py", line 161, in dispatch
self.dispatch(h, type)
File "C:\Program Files\Python310\lib\site-packages\proton\_events.py", line 158, in dispatch
_dispatch(handler, type.method, self)
File "C:\Program Files\Python310\lib\site-packages\proton\_events.py", line 129, in _dispatch
m(*args)
File "C:\Program Files\Python310\lib\site-packages\proton\_handlers.py", line 753, in on_reactor_init
self.on_start(event)
File "C:\Users\Daemon2017\PycharmProjects\python-server\server\client.py", line 16, in on_start
ssl_domain.set_credentials(cert_file=str('./ssl/cert.pem'),
File "C:\Program Files\Python310\lib\site-packages\proton\_transport.py", line 755, in set_credentials
return self._check(pn_ssl_domain_set_credentials(self._domain,
File "C:\Program Files\Python310\lib\site-packages\proton\_transport.py", line 725, in _check
raise exc("SSL failure.")
proton._exceptions.Timeout: SSL failure.
I assumed that something was wrong with the Windows libraries and tried to run the project in Ubuntu and got a different error:
Traceback (most recent call last):
File "/home/daemon2017/python-server/server/client.py", line 43, in <module>
Container(Send("amqps://localhost:61616/Server.RQ", "Client.RQ")).run()
File "/home/daemon2017/.local/lib/python3.10/site-packages/proton/_reactor.py", line 197, in run
while self.process():
File "/home/daemon2017/.local/lib/python3.10/site-packages/proton/_reactor.py", line 260, in process
event.dispatch(handler)
File "/home/daemon2017/.local/lib/python3.10/site-packages/proton/_events.py", line 161, in dispatch
self.dispatch(h, type)
File "/home/daemon2017/.local/lib/python3.10/site-packages/proton/_events.py", line 158, in dispatch
_dispatch(handler, type.method, self)
File "/home/daemon2017/.local/lib/python3.10/site-packages/proton/_events.py", line 129, in _dispatch
m(*args)
File "/home/daemon2017/.local/lib/python3.10/site-packages/proton/_handlers.py", line 753, in on_reactor_init
self.on_start(event)
File "/home/daemon2017/python-server/server/client.py", line 15, in on_start
ssl_domain = SSLDomain(SSLDomain.MODE_CLIENT)
File "/home/daemon2017/.local/lib/python3.10/site-packages/proton/_transport.py", line 720, in __init__
raise SSLUnavailable()
proton._exceptions.SSLUnavailable
What am I doing wrong?
Versions:
I realized that I was dealing with two different problems:
I managed to solve both problems:
1)I've created a bash-pipeline, that installs all dependencies for Ubuntu 20.04.6 LTS/22.04.1 LTS in a right order:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get install python3.9 python3-pip python3.9-dev python3.9-distutils pkg-config swig libsasl2-dev libssl-dev
python3.9 -m pip install python-qpid-proton --verbose --no-cache-dir
python3.9 -c "import proton; print('%s' % 'SSL present' if proton.SSL.present() else 'SSL NOT AVAILBLE')"
2)I've converted my Linux PEM to Windows p12:
openssl pkcs12 -export -out cert.p12 -passin pass:MYPASS -passout pass:MYPASS -inkey key.pem -in cert.pem -name cert_friendlyname
openssl pkcs12 -export -out ca.p12 -in ca.pem -name ca-certificate -nokeys -passout pass:
And now it works fine:
ssl_domain.set_credentials(cert_file=str('./ssl/cert.p12'),
key_file=str('cert_friendlyname'),
password=str('QWErty123'))
ssl_domain.set_trusted_ca_db(certificate_db=str('./ssl/ca.p12'))