Search code examples
python-2.7sslstomp.py

Protocol error on trying to connect using STOMP.py


In my current situation I am using the stomp.py library (http://jasonrbriggs.github.io/stomp.py/stomp.html#module-stomp.connect) to connect to an ActiveMQ instance on another server. I am on python 2.7 and the connection works just fine when no SSL is configured. I use provided connection method (1.2) to connect and provide the following parameters in addition to host and ports:

  1. ssl_key_file=ssl_key_file
  2. ssl_cert_file=ssl_cert_file
  3. ssl_version=ssl.PROTOCOL_TLSv1_2
  4. use_ssl=True

The key and cert files are text from said files which I got using the file open() method which seems to work fine.

I have tried among other options to also set the context in ssl.SSL_Context. I am quite sure the ActiveMQ uses SSL and has said protocol.

When I'm trying to connect using conn.start() I receive the following error:

File "/usr/local/lib/python2.7/dist-packages/stomp/transport.py", line 733, in attempt_connection
tls_context.load_cert_chain(certfile, keyfile, password)
IOError: [Errno 71] Protocol error

I am unable to find a working example on getting stomp.py to connect using SSL, so I cannot find a way to do this.

Is there anyone out there who has seen this before?


Solution

  • Found the answer myself after quite an extensive search. It turns out you need to set_ssl before.

    conn.set_ssl(for_hosts=[(activemq_url,activemq_port)],key_file=KEYFILE,cert_file=CERTFILE)
    

    Where KEYFILE and CERTFILE you need to provide a path where set_ssl can check for and pass in the contents using the file open() method.

    Note: You need to set this after creating connection but before the conn.start() method is called!