0

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?

4

1 回答 1

0

经过相当广泛的搜索后自己找到了答案。原来你需要 set_ssl 之前。

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

其中 KEYFILE 和 CERTFILE 您需要提供一个路径,在该路径中 set_ssl 可以使用文件 open() 方法检查并传入内容。

注意:您需要在创建连接之后但调用 conn.start() 方法之前进行设置!

于 2017-08-11T11:54:41.227 回答