pax_global_header00006660000000000000000000000064137324427670014531gustar00rootroot0000000000000052 comment=42f0b13001cb39aee97c2b60a3b4807314dfcb4d paho.mqtt.python-1.5.1/000077500000000000000000000000001373244276700147705ustar00rootroot00000000000000paho.mqtt.python-1.5.1/.gitignore000066400000000000000000000013761373244276700167670ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python /env/ /build/ /develop-eggs/ /dist/ /downloads/ /eggs/ /.eggs/ /lib/ /lib64/ /parts/ /sdist/ /var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. MANIFEST *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover .hypothesis/ # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ paho.mqtt.testing paho.mqtt.python-1.5.1/.travis.yml000066400000000000000000000005461373244276700171060ustar00rootroot00000000000000language: python jobs: include: - python: 3.8 env: TOXENV=py38 - python: 3.7 env: TOXENV=py37 - python: 3.6 env: TOXENV=py36 - python: 3.5 env: TOXENV=py35 - python: 2.7 env: TOXENV=py27 install: - git clone https://github.com/eclipse/paho.mqtt.testing.git || true - pip install tox script: - tox paho.mqtt.python-1.5.1/CONTRIBUTING.md000066400000000000000000000076461373244276700172360ustar00rootroot00000000000000# Contributing to Paho Thanks for your interest in this project! You can contribute bugfixes and new features by sending pull requests through GitHub. ## Legal In order for your contribution to be accepted, it must comply with the Eclipse Foundation IP policy. Please read the [Eclipse Foundation policy on accepting contributions via Git](http://wiki.eclipse.org/Development_Resources/Contributing_via_Git). 1. Sign the [Eclipse CLA](http://www.eclipse.org/legal/CLA.php) 1. Register for an Eclipse Foundation User ID. You can register [here](https://dev.eclipse.org/site_login/createaccount.php). 2. Log into the [Projects Portal](https://projects.eclipse.org/), and click on the '[Eclipse CLA](https://projects.eclipse.org/user/sign/cla)' link. 2. Go to your [account settings](https://dev.eclipse.org/site_login/myaccount.php#open_tab_accountsettings) and add your GitHub username to your account. 3. Make sure that you _sign-off_ your Git commits in the following format: ``` Signed-off-by: John Smith ``` This is usually at the bottom of the commit message. You can automate this by adding the '-s' flag when you make the commits. e.g. ```git commit -s -m "Adding a cool feature"``` 4. Ensure that the email address that you make your commits with is the same one you used to sign up to the Eclipse Foundation website with. ## Contributing a change 1. [Fork the repository on GitHub](https://github.com/eclipse/paho.mqtt.python/fork) 2. Clone the forked repository onto your computer: ``` git clone https://github.com//paho.mqtt.python.git ``` 3. Most changes will go to branch ``master``. This include both bug fixes and new features. Bug fixes are committed to ``master`` and if required, cherry-picked to the release branch. The only changes that goes directly to the release branch (``1.4``, ``1.5``, ...) are bug fixe that does not apply to ``master`` (e.g. because there are fixed on master by a refactoring, or any other huge change we do not want to cherry-pick to the release branch). 4. Create a new branch from the latest ```master``` branch with ```git checkout -b YOUR_BRANCH_NAME origin/master``` 5. Make your changes 6. Ensure that all new and existing tests pass by running ```tox``` 7. Commit the changes into the branch: ``` git commit -s ``` Make sure that your commit message is meaningful and describes your changes correctly. 8. If you have a lot of commits for the change, squash them into a single / few commits. 9. Push the changes in your branch to your forked repository. 10. Finally, go to [https://github.com/eclipse/paho.mqtt.python](https://github.com/eclipse/paho.mqtt.python) and create a pull request from your "YOUR_BRANCH_NAME" branch to the ``master`` (or release branch if applicable) to request review and merge of the commits in your pushed branch. What happens next depends on the content of the patch. If it is 100% authored by the contributor and is less than 1000 lines (and meets the needs of the project), then it can be pulled into the main repository. If not, more steps are required. These are detailed in the [legal process poster](http://www.eclipse.org/legal/EclipseLegalProcessPoster.pdf). ## Developer resources: Information regarding source code management, builds, coding standards, and more. - [https://projects.eclipse.org/projects/iot.paho/developer](https://projects.eclipse.org/projects/iot.paho/developer) Contact: -------- Contact the project developers via the project's development [mailing list](https://dev.eclipse.org/mailman/listinfo/paho-dev). Search for bugs: ---------------- This project uses [Github](https://github.com/eclipse/paho.mqtt.python/issues) to track ongoing development and issues. Create a new bug: ----------------- Be sure to search for existing bugs before you create another one. Remember that contributions are always welcome! - [Create new Paho bug](https://github.com/eclipse/paho.mqtt.python/issues) paho.mqtt.python-1.5.1/ChangeLog.txt000066400000000000000000000215211373244276700173610ustar00rootroot00000000000000v1.5.1 - 2020x-09-22 =================== - Exceptions that occur in callbacks are no longer suppressed by default. They can optionally be suppressed by setting `client.suppress_exceptions = True`. Closes #365. - Fix PUBREL remaining length of > 2 not being accepted for MQTT v5 message flows. Closes #481. - Fix MQTT v5 properties not being sent on retried or queued messages. - Fix errors related to detection of MQTT v5 first connections. - Fix for changes related to Python 3.9. v1.5.0 - 2019-10-30 =================== * Add support for clean_session on subscribe helper. Closes #219 * Add support for non-standard bridge connection. Closes #282 * Fix hang with QoS 2 message and clean_session = False. The fix replace hang with message DROP. See README for known limitation. Closes #284 and #286 * Fix connection establishement timeout. Closes #291 and #288 * Add support for connecting through a proxy. Closes #315 * Add MQTT v5 support. Closes #334 * Improve error message when sending queue is full. Closes #378 * Improve error handling during initialization on edge case. Closes #387 and #388 * Allow to specify local client port used (similar to bind_address). Closes #390 * Add method is_connected to know if MQTT connection is established. Closes #414 * Set connection timeout to keepalive. Closes #425 v1.4.0 - 2018-09-02 =================== - Fix hang when client restarted and broker resumed a session with Qos2 message. Closes #284. Note: this change replace the hang by a message lost ! See README for current limitation of paho-mqtt. - Fix reconnection loop when a clean_session=True client reconnect while Qos2 message are being sent. Note: this change replace the infinite reconnection loop by a possible duplicate QoS2 message. Only clean_session=True client are affected, see README for current limitation of paho-mqtt. - Catch and log any exception raised by user callback. Closes #294. - Improve support for external event loop (like asyncio). Closes #235. - Fix order of message with publish.multiple helper. Closes #87. - Fix hang on wait_for_published() on bad network. Closes #309. - Fix an issue with Websocket that seems to happen only on Windows. Closes #268. - Fix issue with Websocket payload size between 127 and 65536. Closes #267. - Closes socket in client destructor to avoid FD leak. Closes #170. - Fix uncaught timeout exception during connection. Closes #288. - Remove dup flag on PUBREL packet. Closes #298. - Use secure entropy source for Websocket mask_key (urandom). Closes #305. - Fix mid generation that was not thread-safe. - Replace print() statements with proper logging. Closes #214. - Allow insecure TLS on publish and subscribe helpers. Closes #299. - Allow to remove authentication (reset username to None). Closes #259. - Add support for the non-standard bridge mode. Closes #282. v1.3.1 - 2017-10-09 =================== - Fix reconnect_delay_set which ignored the max_delay. Closes #218. - Fix crash when connection is lost while trying to send message. Closes #208. - Fix issue with unicode topic when some character were multi-bytes UTF-8. - Fix issue with empty Client ID with broker that don't support them. Closes #209. - Fix issue with tls_set that did not allowed cert_reqs=ssl.CERT_NONE. Closes #123. - Relax requirement on pytest-runner, it's now only required for tests. Closes #207, #227. v1.3.0 - 2017-06-20 =================== - **BREAKING** Requires Python 2.7 or 3.4+. Closes #163. - **BREAKING** Remove support for SSL without SSLContext (Requires Python 2.7.9+ or 3.2+). Closes #115. - **BREAKING** on_connect callback is now always called flags. Previously this callback could accepts 3 OR 4 arguments, now it must accepts 4. Closes #197. - **BREAKING** tls_insecure_set() must now be called *after* tls_set() - Allow username and password to be zero length (as opposed to not being present). Closes #80. - Allow zero length client ids when using MQTT v3.1.1. - Add SSLContext support, including SNI. Closes #11. - Improved support for unicode topic and binary payload. Closes #15, #16. - Allow arbitrary Websocket headers and path. Closes #169. - Fix issue with large inbound payload over Websocket. Closes #107. - Add exponential delay for reconnection. Closes #195. - Move unit tests to pytest (#164) and tox (#187) - Add support for standard Python logging. Closes #95. - Fix duplicate incoming QoS==2 message. Closes #194. v1.2.3 - 2017-04-20 =================== - Fix possible hang of TLS connection during handshake. Closes #3. - Fix issue with publish helper with TLS connection. Closes #180. - Fix installation issue on non-UTF-8 system. Closes #181. - Fix non-working Websocket over TLS connection. Closes #182. v1.2.2 - 2017-04-11 =================== - Fix message lost when using paho.mqtt.publish helper with QoS=0 message. Closes #172. v1.2.1 - 2017-04-03 =================== - Handle unicode username and passwords correctly. Closes #79. - Fix handling of invalid UTF-8 topics on incoming messages - the library now does not attempt to decode the topic - this will happen when the user accesses msg.topic in the on_message callback. If the topic is not valid UTF-8, an exception will be raised. Closes #75. - Fix issue with WebSocket connection in case of network issue (timeout or connection broken). Closes #105. - Fix issue with SSL connection, where latest incoming message may be delayed or never processed. Closes #131. - Fix possible message lost with publish.single and publish.multiple. Closes #119. v1.2 - 2016-06-03 ================= - Client.publish() now returns an MQTTMessageInfo object. The MQTTMessageInfo object behaves like a tuple of (rc, mid) for backwards compatibility but also provides two functions: is_published() and wait_for_published(). This allows a client to determine whether any given message has been published without need for a callback, and also allows the client to block waiting until the message has been sent. - Further fix for Client constructor for the case where "localhost" is unresolvable. - Add paho.mqtt.subscribe module, with simple() and callback() helper functions. - Allow ^C to interrupt client loop. - Fix for keepalive=0 causing an infinite disconnect/reconnect loop. Closes #42. - Modify callbacks definition/structure to allow classical inheritence. Closes #53, #54. - Add websockets support. - Default MQTT version is again changed to v3.1.1. - Client.subscribe() now accepts unicode type topic inputs on Python 2. Closes #16. - paho.mqtt.publish() now raises an MQTTException on a CONNECT failure, rather than blindly continuing. Closes #6. - Don't block on TLS sockets on Python 3. Closes #2. - Client.publish() now accepts bytes() payloads on Python 3. Closes #1. - Don't attempt to join() own thread. Closes #14. - Allow the use of Client.message_callback_add() from inside callbacks. Closes #12. - Use a monotonic time source for keeping track of time, if available. Closes #56. v1.1 - 2015-01-30 ================= - Add support for wildcard certificates. Closes #440547. - Default connection behaviour has been reverted to MQTT v3.1 instead of v3.1.1. There is as yet insufficient support for v3.1.1 to rely on, and current v3.1 implementations do not return the correct CONNACK code to allow detection of the fault. Closes #451735. - Fix incorrect handling of queued messages after reconnecting. Closes #452672. - Fix possible race condition if the connection in loop_start() does not complete before loop_stop() is called, meaning the network thread never ends. Closes #448428. Thanks to Kees Bakker. v1.0.2 - 2014-09-13 =================== - Fix "protocol" not being used in publish.single() - Fix Client constructor for the case where "localhost" is unresolvable. Closes #439277. - Don't attempt to encode topic to utf-8 twice. Thanks to Luc Milland. - Handle "unicode" type payloads on Python 2.7. Thanks to Luc Milland. - Fix reconnecting after sending more QoS>0 messages than inflight messages is set to, whilst connecting. Closes #443935. Thanks to Hiram van Paassen. - Fix possible race condition when connecting with TLS and publishing at the same time, which could lead to PUBLISH data being sent before any other messages and unencrypted. Closes #443964. Thanks to Hiram van Paassen. - Handle exceptions from select() in client loop() function. Closes #443881. Thanks to Jeff Jasper. v1.0.1 ====== - Fix incorrect reconnect that occurred if calling loop_stop() before disconnect(). v1.0 ==== - Default protocol is now MQTT v3.1.1. - Client will reconnect using MQTT v3.1 if a v3.1.1 connection fails due to the incorrect protocol version number. - All strings are now correctly encoded as utf-8. - Add support for "session present" flag in on_connect callback. v0.9.1 ====== - Fix CONNECT packet for MQTT v3.1.1. - Fix potential lockup when publishing from on_publish callback. - Add version information to paho.mqtt.__version__ paho.mqtt.python-1.5.1/LICENSE.txt000066400000000000000000000002341373244276700166120ustar00rootroot00000000000000This project is dual licensed under the Eclipse Public License 1.0 and the Eclipse Distribution License 1.0 as described in the epl-v10 and edl-v10 files. paho.mqtt.python-1.5.1/MANIFEST.in000066400000000000000000000003131373244276700165230ustar00rootroot00000000000000include edl-v10 epl-v10 include README.rst include CONTRIBUTING.md include setup.py include notice.html include LICENSE.txt include about.html recursive-include src *.py recursive-include examples *.py paho.mqtt.python-1.5.1/Makefile000066400000000000000000000015551373244276700164360ustar00rootroot00000000000000# Set DESTDIR if it isn't given DESTDIR?=/ .PHONY : all clean clean-build clean-pyc clean-test install test upload all : python ./setup.py build install : all python ./setup.py install --root=${DESTDIR} clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts clean-build: ## remove build artifacts rm -fr build/ rm -fr dist/ rm -fr .eggs/ find . -name '*.egg-info' -exec rm -fr {} + find . -name '*.egg' -exec rm -f {} + clean-pyc: ## remove Python file artifacts find . -name '*.pyc' -exec rm -f {} + find . -name '*.pyo' -exec rm -f {} + find . -name '*~' -exec rm -f {} + find . -name '__pycache__' -exec rm -fr {} + clean-test: ## remove test and coverage artifacts rm -fr .tox/ rm -f .coverage rm -fr htmlcov/ test : python setup.py test $(MAKE) -C test test upload : test python ./setup.py sdist upload paho.mqtt.python-1.5.1/README.rst000066400000000000000000001305751373244276700164720ustar00rootroot00000000000000Eclipse Paho™ MQTT Python Client ================================ This document describes the source code for the `Eclipse Paho `_ MQTT Python client library, which implements versions 5.0, 3.1.1, and 3.1 of the MQTT protocol. This code provides a client class which enable applications to connect to an `MQTT `_ broker to publish messages, and to subscribe to topics and receive published messages. It also provides some helper functions to make publishing one off messages to an MQTT server very straightforward. It supports Python 2.7.9+ or 3.5+. The MQTT protocol is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. Designed as an extremely lightweight publish/subscribe messaging transport, it is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. Paho is an `Eclipse Foundation `_ project. Contents -------- * Installation_ * `Known limitations`_ * `Usage and API`_ * `Client`_ * `Constructor / reinitialise`_ * `Option functions`_ * `Connect / reconnect / disconnect`_ * `Network loop`_ * `Publishing`_ * `Subscribe / Unsubscribe`_ * `Callbacks`_ * `External event loop support`_ * `Global helper functions`_ * `Publish`_ * `Single`_ * `Multiple`_ * `Subscribe`_ * `Simple`_ * `Using Callback`_ * `Reporting bugs`_ * `More information`_ Installation ------------ The latest stable version is available in the Python Package Index (PyPi) and can be installed using :: pip install paho-mqtt Or with ``virtualenv``: :: virtualenv paho-mqtt source paho-mqtt/bin/activate pip install paho-mqtt To obtain the full code, including examples and tests, you can clone the git repository: :: git clone https://github.com/eclipse/paho.mqtt.python Once you have the code, it can be installed from your repository as well: :: cd paho.mqtt.python python setup.py install To perform all test (including MQTT v5 test), you also need to clone paho.mqtt.testing in paho.mqtt.python folder:: git clone https://github.com/eclipse/paho.mqtt.testing.git Known limitations ----------------- The following are the known unimplemented MQTT feature. When clean_session is False, the session is only stored in memory not persisted. This means that when client is restarted (not just reconnected, the object is recreated usually because the program was restarted) the session is lost. This result in possible message lost. The following part of client session is lost: * QoS 2 messages which have been received from the Server, but have not been completely acknowledged. Since the client will blindly acknowledge any PUBCOMP (last message of a QoS 2 transaction), it won't hang but will lost this QoS 2 message. * QoS 1 and QoS 2 messages which have been sent to the Server, but have not been completely acknowledged. This means that message passed to publish() may be lost. This could be mitigated by taking care that all message passed to publish() has a corresponding on_publish() call. It also means that the broker may have the Qos2 message in the session. Since the client start with an empty session it don't know it and will re-use the mid. This is not yet fixed. Also when clean_session is True, this library will republish QoS > 0 message accross network reconnection. This means that QoS > 0 message won't be lost. But the standard say that if we should discard any message for which the publish packet was sent. Our choice means that we are not compliant with the standard and it's possible for QoS 2 to be received twice. You should you clean_session = False if you need the QoS 2 guarantee of only one delivery. Usage and API ------------- Detailed API documentation is available through **pydoc**. Samples are available in the **examples** directory. The package provides two modules, a full client and a helper for simple publishing. Getting Started *************** Here is a very simple example that subscribes to the broker $SYS topic tree and prints out the resulting messages: .. code:: python import paho.mqtt.client as mqtt # The callback for when the client receives a CONNACK response from the server. def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe("$SYS/#") # The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): print(msg.topic+" "+str(msg.payload)) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect("mqtt.eclipse.org", 1883, 60) # Blocking call that processes network traffic, dispatches callbacks and # handles reconnecting. # Other loop*() functions are available that give a threaded interface and a # manual interface. client.loop_forever() Client ****** You can use the client class as an instance, within a class or by subclassing. The general usage flow is as follows: * Create a client instance * Connect to a broker using one of the ``connect*()`` functions * Call one of the ``loop*()`` functions to maintain network traffic flow with the broker * Use ``subscribe()`` to subscribe to a topic and receive messages * Use ``publish()`` to publish messages to the broker * Use ``disconnect()`` to disconnect from the broker Callbacks will be called to allow the application to process events as necessary. These callbacks are described below. Constructor / reinitialise `````````````````````````` Client() '''''''' .. code:: python Client(client_id="", clean_session=True, userdata=None, protocol=MQTTv311, transport="tcp") The ``Client()`` constructor takes the following arguments: client_id the unique client id string used when connecting to the broker. If ``client_id`` is zero length or ``None``, then one will be randomly generated. In this case the ``clean_session`` parameter must be ``True``. clean_session a boolean that determines the client type. If ``True``, the broker will remove all information about this client when it disconnects. If ``False``, the client is a durable client and subscription information and queued messages will be retained when the client disconnects. Note that a client will never discard its own outgoing messages on disconnect. Calling connect() or reconnect() will cause the messages to be resent. Use reinitialise() to reset a client to its original state. userdata user defined data of any type that is passed as the ``userdata`` parameter to callbacks. It may be updated at a later point with the ``user_data_set()`` function. protocol the version of the MQTT protocol to use for this client. Can be either ``MQTTv31`` or ``MQTTv311`` transport set to "websockets" to send MQTT over WebSockets. Leave at the default of "tcp" to use raw TCP. Constructor Example ................... .. code:: python import paho.mqtt.client as mqtt mqttc = mqtt.Client() reinitialise() '''''''''''''' .. code:: python reinitialise(client_id="", clean_session=True, userdata=None) The ``reinitialise()`` function resets the client to its starting state as if it had just been created. It takes the same arguments as the ``Client()`` constructor. Reinitialise Example .................... .. code:: python mqttc.reinitialise() Option functions ```````````````` These functions represent options that can be set on the client to modify its behaviour. In the majority of cases this must be done *before* connecting to a broker. max_inflight_messages_set() ''''''''''''''''''''''''''' .. code:: python max_inflight_messages_set(self, inflight) Set the maximum number of messages with QoS>0 that can be part way through their network flow at once. Defaults to 20. Increasing this value will consume more memory but can increase throughput. max_queued_messages_set() ''''''''''''''''''''''''' .. code:: python max_queued_messages_set(self, queue_size) Set the maximum number of outgoing messages with QoS>0 that can be pending in the outgoing message queue. Defaults to 0. 0 means unlimited. When the queue is full, any further outgoing messages would be dropped. message_retry_set() ''''''''''''''''''' .. code:: python message_retry_set(retry) Set the time in seconds before a message with QoS>0 is retried, if the broker does not respond. This is set to 5 seconds by default and should not normally need changing. ws_set_options() '''''''''''''''' .. code:: python ws_set_options(self, path="/mqtt", headers=None) Set websocket connection options. These options will only be used if ``transport="websockets"`` was passed into the ``Client()`` constructor. path The mqtt path to use on the broker. headers Either a dictionary specifying a list of extra headers which should be appended to the standard websocket headers, or a callable that takes the normal websocket headers and returns a new dictionary with a set of headers to connect to the broker. Must be called before ``connect*()``. An example of how this can be used with the AWS IoT platform is in the **examples** folder. tls_set() ''''''''' .. code:: python tls_set(ca_certs=None, certfile=None, keyfile=None, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLS, ciphers=None) Configure network encryption and authentication options. Enables SSL/TLS support. ca_certs a string path to the Certificate Authority certificate files that are to be treated as trusted by this client. If this is the only option given then the client will operate in a similar manner to a web browser. That is to say it will require the broker to have a certificate signed by the Certificate Authorities in ``ca_certs`` and will communicate using TLS v1, but will not attempt any form of authentication. This provides basic network encryption but may not be sufficient depending on how the broker is configured. By default, on Python 2.7.9+ or 3.4+, the default certification authority of the system is used. On older Python version this parameter is mandatory. certfile, keyfile strings pointing to the PEM encoded client certificate and private keys respectively. If these arguments are not ``None`` then they will be used as client information for TLS based authentication. Support for this feature is broker dependent. Note that if either of these files in encrypted and needs a password to decrypt it, Python will ask for the password at the command line. It is not currently possible to define a callback to provide the password. cert_reqs defines the certificate requirements that the client imposes on the broker. By default this is ``ssl.CERT_REQUIRED``, which means that the broker must provide a certificate. See the ssl pydoc for more information on this parameter. tls_version specifies the version of the SSL/TLS protocol to be used. By default (if the python version supports it) the highest TLS version is detected. If unavailable, TLS v1 is used. Previous versions (all versions beginning with SSL) are possible but not recommended due to possible security problems. ciphers a string specifying which encryption ciphers are allowable for this connection, or ``None`` to use the defaults. See the ssl pydoc for more information. Must be called before ``connect*()``. tls_set_context() ''''''''''''''''' .. code:: python tls_set_context(context=None) Configure network encryption and authentication context. Enables SSL/TLS support. context an ssl.SSLContext object. By default, this is given by ``ssl.create_default_context()``, if available (added in Python 3.4). If you're unsure about using this method, then either use the default context, or use the ``tls_set`` method. See the ssl module documentation section about `security considerations `_ for more information. Must be called before ``connect*()``. tls_insecure_set() '''''''''''''''''' .. code:: python tls_insecure_set(value) Configure verification of the server hostname in the server certificate. If ``value`` is set to ``True``, it is impossible to guarantee that the host you are connecting to is not impersonating your server. This can be useful in initial server testing, but makes it possible for a malicious third party to impersonate your server through DNS spoofing, for example. Do not use this function in a real system. Setting value to True means there is no point using encryption. Must be called before ``connect*()`` and after ``tls_set()`` or ``tls_set_context()``. enable_logger() ''''''''''''''' .. code:: python enable_logger(logger=None) Enable logging using the standard python logging package (See PEP 282). This may be used at the same time as the ``on_log`` callback method. If ``logger`` is specified, then that ``logging.Logger`` object will be used, otherwise one will be created automatically. Paho logging levels are converted to standard ones according to the following mapping: ==================== =============== Paho logging ==================== =============== ``MQTT_LOG_ERR`` ``logging.ERROR`` ``MQTT_LOG_WARNING`` ``logging.WARNING`` ``MQTT_LOG_NOTICE`` ``logging.INFO`` *(no direct equivalent)* ``MQTT_LOG_INFO`` ``logging.INFO`` ``MQTT_LOG_DEBUG`` ``logging.DEBUG`` ==================== =============== disable_logger() '''''''''''''''' .. code:: python disable_logger() Disable logging using standard python logging package. This has no effect on the ``on_log`` callback. username_pw_set() ''''''''''''''''' .. code:: python username_pw_set(username, password=None) Set a username and optionally a password for broker authentication. Must be called before ``connect*()``. user_data_set() ''''''''''''''' .. code:: python user_data_set(userdata) Set the private user data that will be passed to callbacks when events are generated. Use this for your own purpose to support your application. will_set() '''''''''' .. code:: python will_set(topic, payload=None, qos=0, retain=False) Set a Will to be sent to the broker. If the client disconnects without calling ``disconnect()``, the broker will publish the message on its behalf. topic the topic that the will message should be published on. payload the message to send as a will. If not given, or set to ``None`` a zero length message will be used as the will. Passing an int or float will result in the payload being converted to a string representing that number. If you wish to send a true int/float, use ``struct.pack()`` to create the payload you require. qos the quality of service level to use for the will. retain if set to ``True``, the will message will be set as the "last known good"/retained message for the topic. Raises a ``ValueError`` if ``qos`` is not 0, 1 or 2, or if ``topic`` is ``None`` or has zero string length. reconnect_delay_set ''''''''''''''''''' .. code:: python reconnect_delay_set(min_delay=1, max_delay=120) The client will automatically retry connection. Between each attempt it will wait a number of seconds between ``min_delay`` and ``max_delay``. When the connection is lost, initially the reconnection attempt is delayed of ``min_delay`` seconds. It's doubled between subsequent attempt up to ``max_delay``. The delay is reset to ``min_delay`` when the connection complete (e.g. the CONNACK is received, not just the TCP connection is established). Connect / reconnect / disconnect ```````````````````````````````` connect() ''''''''' .. code:: python connect(host, port=1883, keepalive=60, bind_address="") The ``connect()`` function connects the client to a broker. This is a blocking function. It takes the following arguments: host the hostname or IP address of the remote broker port the network port of the server host to connect to. Defaults to 1883. Note that the default port for MQTT over SSL/TLS is 8883 so if you are using ``tls_set()`` or ``tls_set_context()``, the port may need providing manually keepalive maximum period in seconds allowed between communications with the broker. If no other messages are being exchanged, this controls the rate at which the client will send ping messages to the broker bind_address the IP address of a local network interface to bind this client to, assuming multiple interfaces exist Callback ........ When the client receives a CONNACK message from the broker in response to the connect it generates an ``on_connect()`` callback. Connect Example ............... .. code:: python mqttc.connect("mqtt.eclipse.org") connect_async() ''''''''''''''' .. code:: python connect_async(host, port=1883, keepalive=60, bind_address="") Use in conjunction with ``loop_start()`` to connect in a non-blocking manner. The connection will not complete until ``loop_start()`` is called. Callback (connect) .................. When the client receives a CONNACK message from the broker in response to the connect it generates an ``on_connect()`` callback. connect_srv() ''''''''''''' .. code:: python connect_srv(domain, keepalive=60, bind_address="") Connect to a broker using an SRV DNS lookup to obtain the broker address. Takes the following arguments: domain the DNS domain to search for SRV records. If ``None``, try to determine the local domain name. See ``connect()`` for a description of the ``keepalive`` and ``bind_address`` arguments. Callback (connect_srv) ...................... When the client receives a CONNACK message from the broker in response to the connect it generates an ``on_connect()`` callback. SRV Connect Example ................... .. code:: python mqttc.connect_srv("eclipse.org") reconnect() ''''''''''' .. code:: python reconnect() Reconnect to a broker using the previously provided details. You must have called ``connect*()`` before calling this function. Callback (reconnect) .................... When the client receives a CONNACK message from the broker in response to the connect it generates an ``on_connect()`` callback. disconnect() '''''''''''' .. code:: python disconnect() Disconnect from the broker cleanly. Using ``disconnect()`` will not result in a will message being sent by the broker. Disconnect will not wait for all queued message to be sent, to ensure all messages are delivered, ``wait_for_publish()`` from ``MQTTMessageInfo`` should be used. See ``publish()`` for details. Callback (disconnect) ..................... When the client has sent the disconnect message it generates an ``on_disconnect()`` callback. Network loop ```````````` These functions are the driving force behind the client. If they are not called, incoming network data will not be processed and outgoing network data may not be sent in a timely fashion. There are four options for managing the network loop. Three are described here, the fourth in "External event loop support" below. Do not mix the different loop functions. loop() '''''' .. code:: python loop(timeout=1.0, max_packets=1) Call regularly to process network events. This call waits in ``select()`` until the network socket is available for reading or writing, if appropriate, then handles the incoming/outgoing data. This function blocks for up to ``timeout`` seconds. ``timeout`` must not exceed the ``keepalive`` value for the client or your client will be regularly disconnected by the broker. The ``max_packets`` argument is obsolete and should be left unset. Loop Example ............ .. code:: python run = True while run: mqttc.loop() loop_start() / loop_stop() '''''''''''''''''''''''''' .. code:: python loop_start() loop_stop(force=False) These functions implement a threaded interface to the network loop. Calling ``loop_start()`` once, before or after ``connect*()``, runs a thread in the background to call ``loop()`` automatically. This frees up the main thread for other work that may be blocking. This call also handles reconnecting to the broker. Call ``loop_stop()`` to stop the background thread. The ``force`` argument is currently ignored. Loop Start/Stop Example ....................... .. code:: python mqttc.connect("mqtt.eclipse.org") mqttc.loop_start() while True: temperature = sensor.blocking_read() mqttc.publish("paho/temperature", temperature) loop_forever() '''''''''''''' .. code:: python loop_forever(timeout=1.0, max_packets=1, retry_first_connection=False) This is a blocking form of the network loop and will not return until the client calls ``disconnect()``. It automatically handles reconnecting. Except for the first connection attempt when using connect_async, use ``retry_first_connection=True`` to make it retry the first connection. Warning: This might lead to situations where the client keeps connecting to an non existing host without failing. The ``timeout`` and ``max_packets`` arguments are obsolete and should be left unset. Publishing `````````` Send a message from the client to the broker. publish() ''''''''' .. code:: python publish(topic, payload=None, qos=0, retain=False) This causes a message to be sent to the broker and subsequently from the broker to any clients subscribing to matching topics. It takes the following arguments: topic the topic that the message should be published on payload the actual message to send. If not given, or set to ``None`` a zero length message will be used. Passing an int or float will result in the payload being converted to a string representing that number. If you wish to send a true int/float, use ``struct.pack()`` to create the payload you require qos the quality of service level to use retain if set to ``True``, the message will be set as the "last known good"/retained message for the topic. Returns a MQTTMessageInfo which expose the following attributes and methods: * ``rc``, the result of the publishing. It could be ``MQTT_ERR_SUCCESS`` to indicate success, ``MQTT_ERR_NO_CONN`` if the client is not currently connected, or ``MQTT_ERR_QUEUE_SIZE`` when ``max_queued_messages_set`` is used to indicate that message is neither queued nor sent. * ``mid`` is the message ID for the publish request. The mid value can be used to track the publish request by checking against the mid argument in the ``on_publish()`` callback if it is defined. ``wait_for_publish`` may be easier depending on your use-case. * ``wait_for_publish()`` will block until the message is published. It will raise ValueError if the message is not queued (rc == ``MQTT_ERR_QUEUE_SIZE``). * ``is_published`` returns True if the message has been published. It will raise ValueError if the message is not queued (rc == ``MQTT_ERR_QUEUE_SIZE``). A ``ValueError`` will be raised if topic is ``None``, has zero length or is invalid (contains a wildcard), if ``qos`` is not one of 0, 1 or 2, or if the length of the payload is greater than 268435455 bytes. Callback (publish) .................. When the message has been sent to the broker an ``on_publish()`` callback will be generated. Subscribe / Unsubscribe ``````````````````````` subscribe() ''''''''''' .. code:: python subscribe(topic, qos=0) Subscribe the client to one or more topics. This function may be called in three different ways: Simple string and integer ......................... e.g. ``subscribe("my/topic", 2)`` topic a string specifying the subscription topic to subscribe to. qos the desired quality of service level for the subscription. Defaults to 0. String and integer tuple ........................ e.g. ``subscribe(("my/topic", 1))`` topic a tuple of ``(topic, qos)``. Both topic and qos must be present in the tuple. qos not used. List of string and integer tuples ................................. e.g. ``subscribe([("my/topic", 0), ("another/topic", 2)])`` This allows multiple topic subscriptions in a single SUBSCRIPTION command, which is more efficient than using multiple calls to ``subscribe()``. topic a list of tuple of format ``(topic, qos)``. Both topic and qos must be present in all of the tuples. qos not used. The function returns a tuple ``(result, mid)``, where ``result`` is ``MQTT_ERR_SUCCESS`` to indicate success or ``(MQTT_ERR_NO_CONN, None)`` if the client is not currently connected. ``mid`` is the message ID for the subscribe request. The mid value can be used to track the subscribe request by checking against the mid argument in the ``on_subscribe()`` callback if it is defined. Raises a ``ValueError`` if ``qos`` is not 0, 1 or 2, or if topic is ``None`` or has zero string length, or if ``topic`` is not a string, tuple or list. Callback (subscribe) .................... When the broker has acknowledged the subscription, an ``on_subscribe()`` callback will be generated. unsubscribe() ''''''''''''' .. code:: python unsubscribe(topic) Unsubscribe the client from one or more topics. topic a single string, or list of strings that are the subscription topics to unsubscribe from. Returns a tuple ``(result, mid)``, where ``result`` is ``MQTT_ERR_SUCCESS`` to indicate success, or ``(MQTT_ERR_NO_CONN, None)`` if the client is not currently connected. ``mid`` is the message ID for the unsubscribe request. The mid value can be used to track the unsubscribe request by checking against the mid argument in the ``on_unsubscribe()`` callback if it is defined. Raises a ``ValueError`` if ``topic`` is ``None`` or has zero string length, or is not a string or list. Callback (unsubscribe) ...................... When the broker has acknowledged the unsubscribe, an ``on_unsubscribe()`` callback will be generated. Callbacks ````````` on_connect() '''''''''''' .. code:: python on_connect(client, userdata, flags, rc) Called when the broker responds to our connection request. client the client instance for this callback userdata the private user data as set in ``Client()`` or ``user_data_set()`` flags response flags sent by the broker rc the connection result flags is a dict that contains response flags from the broker: flags['session present'] - this flag is useful for clients that are using clean session set to 0 only. If a client with clean session=0, that reconnects to a broker that it has previously connected to, this flag indicates whether the broker still has the session information for the client. If 1, the session still exists. The value of rc indicates success or not: 0: Connection successful 1: Connection refused - incorrect protocol version 2: Connection refused - invalid client identifier 3: Connection refused - server unavailable 4: Connection refused - bad username or password 5: Connection refused - not authorised 6-255: Currently unused. On Connect Example .................. .. code:: python def on_connect(client, userdata, flags, rc): print("Connection returned result: "+connack_string(rc)) mqttc.on_connect = on_connect ... on_disconnect() ''''''''''''''' .. code:: python on_disconnect(client, userdata, rc) Called when the client disconnects from the broker. client the client instance for this callback userdata the private user data as set in ``Client()`` or ``user_data_set()`` rc the disconnection result The rc parameter indicates the disconnection state. If ``MQTT_ERR_SUCCESS`` (0), the callback was called in response to a ``disconnect()`` call. If any other value the disconnection was unexpected, such as might be caused by a network error. On Disconnect Example ..................... .. code:: python def on_disconnect(client, userdata, rc): if rc != 0: print("Unexpected disconnection.") mqttc.on_disconnect = on_disconnect ... on_message() '''''''''''' .. code:: python on_message(client, userdata, message) Called when a message has been received on a topic that the client subscribes to and the message does not match an existing topic filter callback. Use ``message_callback_add()`` to define a callback that will be called for specific topic filters. ``on_message`` will serve as fallback when none matched. client the client instance for this callback userdata the private user data as set in ``Client()`` or ``user_data_set()`` message an instance of MQTTMessage. This is a class with members ``topic``, ``payload``, ``qos``, ``retain``. On Message Example .................. .. code:: python def on_message(client, userdata, message): print("Received message '" + str(message.payload) + "' on topic '" + message.topic + "' with QoS " + str(message.qos)) mqttc.on_message = on_message ... message_callback_add() '''''''''''''''''''''' This function allows you to define callbacks that handle incoming messages for specific subscription filters, including with wildcards. This lets you, for example, subscribe to ``sensors/#`` and have one callback to handle ``sensors/temperature`` and another to handle ``sensors/humidity``. .. code:: python message_callback_add(sub, callback) sub the subscription filter to match against for this callback. Only one callback may be defined per literal sub string callback the callback to be used. Takes the same form as the ``on_message`` callback. If using ``message_callback_add()`` and ``on_message``, only messages that do not match a subscription specific filter will be passed to the ``on_message`` callback. If multiple sub match a topic, each callback will be called (e.g. sub ``sensors/#`` and sub ``+/humidity`` both match a message with a topic ``sensors/humidity``, so both callbacks will handle this message). message_callback_remove() ''''''''''''''''''''''''' Remove a topic/subscription specific callback previously registered using ``message_callback_add()``. .. code:: python message_callback_remove(sub) sub the subscription filter to remove on_publish() '''''''''''' .. code:: python on_publish(client, userdata, mid) Called when a message that was to be sent using the ``publish()`` call has completed transmission to the broker. For messages with QoS levels 1 and 2, this means that the appropriate handshakes have completed. For QoS 0, this simply means that the message has left the client. The ``mid`` variable matches the mid variable returned from the corresponding ``publish()`` call, to allow outgoing messages to be tracked. This callback is important because even if the publish() call returns success, it does not always mean that the message has been sent. on_subscribe() '''''''''''''' .. code:: python on_subscribe(client, userdata, mid, granted_qos) Called when the broker responds to a subscribe request. The ``mid`` variable matches the mid variable returned from the corresponding ``subscribe()`` call. The ``granted_qos`` variable is a list of integers that give the QoS level the broker has granted for each of the different subscription requests. on_unsubscribe() '''''''''''''''' .. code:: python on_unsubscribe(client, userdata, mid) Called when the broker responds to an unsubscribe request. The ``mid`` variable matches the mid variable returned from the corresponding ``unsubscribe()`` call. on_log() '''''''' .. code:: python on_log(client, userdata, level, buf) Called when the client has log information. Define to allow debugging. The ``level`` variable gives the severity of the message and will be one of ``MQTT_LOG_INFO``, ``MQTT_LOG_NOTICE``, ``MQTT_LOG_WARNING``, ``MQTT_LOG_ERR``, and ``MQTT_LOG_DEBUG``. The message itself is in ``buf``. This may be used at the same time as the standard Python logging, which can be enabled via the ``enable_logger`` method. on_socket_open() '''''''''''''''' :: on_socket_open(client, userdata, sock) Called when the socket has been opened. Use this to register the socket with an external event loop for reading. on_socket_close() ''''''''''''''''' :: on_socket_close(client, userdata, sock) Called when the socket is about to be closed. Use this to unregister a socket from an external event loop for reading. on_socket_register_write() '''''''''''''''''''''''''' :: on_socket_register_write(client, userdata, sock) Called when a write operation to the socket failed because it would have blocked, e.g. output buffer full. Use this to register the socket with an external event loop for writing. on_socket_unregister_write() '''''''''''''''''''''''''''' :: on_socket_unregister_write(client, userdata, sock) Called when a write operation to the socket succeeded after it had previously failed. Use this to unregister the socket from an external event loop for writing. External event loop support ``````````````````````````` loop_read() ''''''''''' .. code:: python loop_read(max_packets=1) Call when the socket is ready for reading. ``max_packets`` is obsolete and should be left unset. loop_write() '''''''''''' .. code:: python loop_write(max_packets=1) Call when the socket is ready for writing. ``max_packets`` is obsolete and should be left unset. loop_misc() ''''''''''' .. code:: python loop_misc() Call every few seconds to handle message retrying and pings. socket() '''''''' .. code:: python socket() Returns the socket object in use in the client to allow interfacing with other event loops. This call is particularly useful for select_ based loops. See ``examples/loop_select.py``. .. _select: https://docs.python.org/3/library/select.html#select.select want_write() '''''''''''' .. code:: python want_write() Returns true if there is data waiting to be written, to allow interfacing the client with other event loops. This call is particularly useful for select_ based loops. See ``examples/loop_select.py``. .. _select: https://docs.python.org/3/library/select.html#select.select state callbacks ''''''''''''''' :: on_socket_open on_socket_close on_socket_register_write on_socket_unregister_write Use these callbacks to get notified about state changes in the socket. This is particularly useful for event loops where you register or unregister a socket for reading+writing. See ``examples/loop_asyncio.py`` for an example. When the socket is opened, ``on_socket_open`` is called. Register the socket with your event loop for reading. When the socket is about to be closed, ``on_socket_close`` is called. Unregister the socket from your event loop for reading. When a write to the socket failed because it would have blocked, e.g. output buffer full, ``on_socket_register_write`` is called. Register the socket with your event loop for writing. When the next write to the socket succeeded, ``on_socket_unregister_write`` is called. Unregister the socket from your event loop for writing. The callbacks are always called in this order: - ``on_socket_open`` - Zero or more times: - ``on_socket_register_write`` - ``on_socket_unregister_write`` - ``on_socket_close`` Global helper functions ``````````````````````` The client module also offers some global helper functions. ``topic_matches_sub(sub, topic)`` can be used to check whether a ``topic`` matches a ``subscription``. For example: the topic ``foo/bar`` would match the subscription ``foo/#`` or ``+/bar`` the topic ``non/matching`` would not match the subscription ``non/+/+`` ``connack_string(connack_code)`` returns the error string associated with a CONNACK result. ``error_string(mqtt_errno)`` returns the error string associated with a Paho MQTT error number. Publish ******* This module provides some helper functions to allow straightforward publishing of messages in a one-shot manner. In other words, they are useful for the situation where you have a single/multiple messages you want to publish to a broker, then disconnect with nothing else required. The two functions provided are ``single()`` and ``multiple()``. Single `````` Publish a single message to a broker, then disconnect cleanly. .. code:: python single(topic, payload=None, qos=0, retain=False, hostname="localhost", port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None, protocol=mqtt.MQTTv311, transport="tcp") Publish Single Function arguments ''''''''''''''''''''''''''''''''' topic the only required argument must be the topic string to which the payload will be published. payload the payload to be published. If "" or None, a zero length payload will be published. qos the qos to use when publishing, default to 0. retain set the message to be retained (True) or not (False). hostname a string containing the address of the broker to connect to. Defaults to localhost. port the port to connect to the broker on. Defaults to 1883. client_id the MQTT client id to use. If "" or None, the Paho library will generate a client id automatically. keepalive the keepalive timeout value for the client. Defaults to 60 seconds. will a dict containing will parameters for the client: will = {'topic': "", 'payload':", 'qos':, 'retain':}. Topic is required, all other parameters are optional and will default to None, 0 and False respectively. Defaults to None, which indicates no will should be used. auth a dict containing authentication parameters for the client: auth = {'username':"", 'password':""} Username is required, password is optional and will default to None if not provided. Defaults to None, which indicates no authentication is to be used. tls a dict containing TLS configuration parameters for the client: dict = {'ca_certs':"", 'certfile':"", 'keyfile':"", 'tls_version':"", 'ciphers':"} ca_certs is required, all other parameters are optional and will default to None if not provided, which results in the client using the default behaviour - see the paho.mqtt.client documentation. Defaults to None, which indicates that TLS should not be used. protocol choose the version of the MQTT protocol to use. Use either ``MQTTv31`` or ``MQTTv311``. transport set to "websockets" to send MQTT over WebSockets. Leave at the default of "tcp" to use raw TCP. Publish Single Example '''''''''''''''''''''' .. code:: python import paho.mqtt.publish as publish publish.single("paho/test/single", "payload", hostname="mqtt.eclipse.org") Multiple ```````` Publish multiple messages to a broker, then disconnect cleanly. .. code:: python multiple(msgs, hostname="localhost", port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None, protocol=mqtt.MQTTv311, transport="tcp") Publish Multiple Function arguments ''''''''''''''''''''''''''''''''''' msgs a list of messages to publish. Each message is either a dict or a tuple. If a dict, only the topic must be present. Default values will be used for any missing arguments. The dict must be of the form: msg = {'topic':"", 'payload':"", 'qos':, 'retain':} topic must be present and may not be empty. If payload is "", None or not present then a zero length payload will be published. If qos is not present, the default of 0 is used. If retain is not present, the default of False is used. If a tuple, then it must be of the form: ("", "", qos, retain) See ``single()`` for the description of ``hostname``, ``port``, ``client_id``, ``keepalive``, ``will``, ``auth``, ``tls``, ``protocol``, ``transport``. Publish Multiple Example '''''''''''''''''''''''' .. code:: python import paho.mqtt.publish as publish msgs = [{'topic':"paho/test/multiple", 'payload':"multiple 1"}, ("paho/test/multiple", "multiple 2", 0, False)] publish.multiple(msgs, hostname="mqtt.eclipse.org") Subscribe ********* This module provides some helper functions to allow straightforward subscribing and processing of messages. The two functions provided are ``simple()`` and ``callback()``. Simple `````` Subscribe to a set of topics and return the messages received. This is a blocking function. .. code:: python simple(topics, qos=0, msg_count=1, retained=False, hostname="localhost", port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None, protocol=mqtt.MQTTv311) Simple Subscribe Function arguments ''''''''''''''''''''''''''''''''''' topics the only required argument is the topic string to which the client will subscribe. This can either be a string or a list of strings if multiple topics should be subscribed to. qos the qos to use when subscribing, defaults to 0. msg_count the number of messages to retrieve from the broker. Defaults to 1. If 1, a single MQTTMessage object will be returned. If >1, a list of MQTTMessages will be returned. retained set to True to consider retained messages, set to False to ignore messages with the retained flag set. hostname a string containing the address of the broker to connect to. Defaults to localhost. port the port to connect to the broker on. Defaults to 1883. client_id the MQTT client id to use. If "" or None, the Paho library will generate a client id automatically. keepalive the keepalive timeout value for the client. Defaults to 60 seconds. will a dict containing will parameters for the client: will = {'topic': "", 'payload':", 'qos':, 'retain':}. Topic is required, all other parameters are optional and will default to None, 0 and False respectively. Defaults to None, which indicates no will should be used. auth a dict containing authentication parameters for the client: auth = {'username':"", 'password':""} Username is required, password is optional and will default to None if not provided. Defaults to None, which indicates no authentication is to be used. tls a dict containing TLS configuration parameters for the client: dict = {'ca_certs':"", 'certfile':"", 'keyfile':"", 'tls_version':"", 'ciphers':"} ca_certs is required, all other parameters are optional and will default to None if not provided, which results in the client using the default behaviour - see the paho.mqtt.client documentation. Defaults to None, which indicates that TLS should not be used. protocol choose the version of the MQTT protocol to use. Use either ``MQTTv31`` or ``MQTTv311``. Simple Example '''''''''''''' .. code:: python import paho.mqtt.subscribe as subscribe msg = subscribe.simple("paho/test/simple", hostname="mqtt.eclipse.org") print("%s %s" % (msg.topic, msg.payload)) Using Callback `````````````` Subscribe to a set of topics and process the messages received using a user provided callback. .. code:: python callback(callback, topics, qos=0, userdata=None, hostname="localhost", port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None, protocol=mqtt.MQTTv311) Callback Subscribe Function arguments ''''''''''''''''''''''''''''''''''''' callback an "on_message" callback that will be used for each message received, and of the form .. code:: python def on_message(client, userdata, message) topics the topic string to which the client will subscribe. This can either be a string or a list of strings if multiple topics should be subscribed to. qos the qos to use when subscribing, defaults to 0. userdata a user provided object that will be passed to the on_message callback when a message is received. See ``simple()`` for the description of ``hostname``, ``port``, ``client_id``, ``keepalive``, ``will``, ``auth``, ``tls``, ``protocol``. Callback Example '''''''''''''''' .. code:: python import paho.mqtt.subscribe as subscribe def on_message_print(client, userdata, message): print("%s %s" % (message.topic, message.payload)) subscribe.callback(on_message_print, "paho/test/callback", hostname="mqtt.eclipse.org") Reporting bugs -------------- Please report bugs in the issues tracker at https://github.com/eclipse/paho.mqtt.python/issues. More information ---------------- Discussion of the Paho clients takes place on the `Eclipse paho-dev mailing list `_. General questions about the MQTT protocol itself (not this library) are discussed in the `MQTT Google Group `_. There is much more information available via the `MQTT community site `_. paho.mqtt.python-1.5.1/Vagrantfile000066400000000000000000000017721373244276700171640ustar00rootroot00000000000000Vagrant.configure("2") do |config| # The base OS config.vm.box = "ubuntu/trusty64" config.vm.provision :shell, :inline => "sudo apt-get update" # Install make config.vm.provision :shell, :inline => "apt-get install -y make" # Provision Python 2 config.vm.provision :shell, :inline => "apt-get upgrade -y python" config.vm.provision :shell, :inline => "apt-get install -y python-pip" config.vm.provision :shell, :inline => "python -m pip install --upgrade pip" config.vm.provision :shell, :inline => "python -m pip install virtualenv" # Provision Python 3 config.vm.provision :shell, :inline => "apt-get install -y python3" config.vm.provision :shell, :inline => "apt-get install -y python3-pip" config.vm.provision :shell, :inline => "python3 -m pip install --upgrade pip" config.vm.provision :shell, :inline => "python3 -m pip install virtualenv" # reassuring message to complete: config.vm.provision "shell", inline: "echo All set!", run: "always" end paho.mqtt.python-1.5.1/about.html000066400000000000000000000037571373244276700170040ustar00rootroot00000000000000 About

About This Content

December 9, 2013

License

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html and a copy of the EDL is available at http://www.eclipse.org/org/documents/edl-v10.php. For purposes of the EPL, "Program" will mean the Content.

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise indicated below, the terms and conditions of the EPL still apply to any source code in the Content and such source code may be obtained at http://www.eclipse.org.

Third Party Content

The Content includes items that have been sourced from third parties as set out below. If you did not receive this Content directly from the Eclipse Foundation, the following is provided for informational purposes only, and you should look to the Redistributor's license for terms and conditions of use.

None



paho.mqtt.python-1.5.1/edl-v10000066400000000000000000000030411373244276700160610ustar00rootroot00000000000000Eclipse Distribution License - v 1.0 Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. paho.mqtt.python-1.5.1/epl-v10000066400000000000000000000266571373244276700161170ustar00rootroot00000000000000Eclipse Public License - v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 1. DEFINITIONS "Contribution" means: a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and b) in the case of each subsequent Contributor: i) changes to the Program, and ii) additions to the Program; where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. "Contributor" means any person or entity that distributes the Program. "Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. "Program" means the Contributions distributed in accordance with this Agreement. "Recipient" means anyone who receives the Program under this Agreement, including all Contributors. 2. GRANT OF RIGHTS a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. 3. REQUIREMENTS A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: a) it complies with the terms and conditions of this Agreement; and b) its license agreement: i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. When the Program is made available in source code form: a) it must be made available under this Agreement; and b) a copy of this Agreement must be included with each copy of the Program. Contributors may not remove or alter any copyright notices contained within the Program. Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. 4. COMMERCIAL DISTRIBUTION Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. 5. NO WARRANTY EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. 6. DISCLAIMER OF LIABILITY EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 7. GENERAL If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. paho.mqtt.python-1.5.1/examples/000077500000000000000000000000001373244276700166065ustar00rootroot00000000000000paho.mqtt.python-1.5.1/examples/aws_iot.py000066400000000000000000000102271373244276700206270ustar00rootroot00000000000000import base64 import datetime import functools import hashlib import hmac import os import uuid from paho.mqtt.client import Client def get_amazon_auth_headers(access_key, secret_key, region, host, port, headers=None): """ Get the amazon auth headers for working with the amazon websockets protocol Requires a lot of extra stuff: http://docs.aws.amazon.com/general/latest/gr//sigv4-create-canonical-request.html http://docs.aws.amazon.com/general/latest/gr//signature-v4-examples.html#signature-v4-examples-pythonw http://docs.aws.amazon.com/general/latest/gr//sigv4-signed-request-examples.html#sig-v4-examples-get-auth-header Args: access_key (str): Amazon access key (AWS_ACCESS_KEY_ID) secret_key (str): Amazon secret access key (AWS_SECRET_ACCESS_KEY) region (str): aws region host (str): iot endpoint (xxxxxxxxxxxxxx.iot..amazonaws.com) headers (dict): a dictionary of the original headers- normally websocket headers Returns: dict: A string containing the headers that amazon expects in the auth request for the iot websocket service """ # pylint: disable=unused-variable,unused-argument def sign(key, msg): return hmac.new(key, msg.encode("utf-8"), hashlib.sha256).digest() def getSignatureKey(key, dateStamp, regionName, serviceName): kDate = sign(("AWS4" + key).encode("utf-8"), dateStamp) kRegion = sign(kDate, regionName) kService = sign(kRegion, serviceName) kSigning = sign(kService, "aws4_request") return kSigning service = "iotdevicegateway" algorithm = "AWS4-HMAC-SHA256" t = datetime.datetime.utcnow() amzdate = t.strftime('%Y%m%dT%H%M%SZ') datestamp = t.strftime("%Y%m%d") # Date w/o time, used in credential scope if headers is None: headers = { "Host": "{0:s}:443".format(host), "Upgrade": "websocket", "Connection": "Upgrade", "Origin": "https://{0:s}:443".format(host), "Sec-WebSocket-Key": base64.b64encode(uuid.uuid4().bytes), "Sec-Websocket-Version": "13", "Sec-Websocket-Protocol": "mqtt", } headers.update({ "X-Amz-Date": amzdate, }) # get into 'canonical' form - lowercase, sorted alphabetically canonical_headers = "\n".join(sorted("{}:{}".format(i.lower(), j).strip() for i, j in headers.items())) # Headers to sign - alphabetical order signed_headers = ";".join(sorted(i.lower().strip() for i in headers.keys())) # No payload payload_hash = hashlib.sha256("").hexdigest().lower() request_parts = [ "GET", "/mqtt", # no query parameters "", canonical_headers + "\n", signed_headers, payload_hash, ] canonical_request = "\n".join(request_parts) # now actually hash request and sign hashed_request = hashlib.sha256(canonical_request).hexdigest() credential_scope = "{datestamp:s}/{region:s}/{service:s}/aws4_request".format(**locals()) string_to_sign = "{algorithm:s}\n{amzdate:s}\n{credential_scope:s}\n{hashed_request:s}".format(**locals()) signing_key = getSignatureKey(secret_key, datestamp, region, service) signature = hmac.new(signing_key, (string_to_sign).encode('utf-8'), hashlib.sha256).hexdigest() # create auth header authorization_header = "{algorithm:s} Credential={access_key:s}/{credential_scope:s}, SignedHeaders={signed_headers:s}, Signature={signature:s}".format(**locals()) # get final header string headers["Authorization"] = authorization_header return headers def example_use(): access_key = os.environ["AWS_ACCESS_KEY_ID"] secret_key = os.environ["AWS_SECRET_ACCESS_KEY"] port = 8883 region = "eu-west-1" # This is specific to your AWS account host = "abc123def456.iot.{0:s}.amazonaws.com".format(region) extra_headers = functools.partial( get_amazon_auth_headers, access_key, secret_key, region, host, port, ) client = Client(transport="websockets") client.ws_set_options(headers=extra_headers) # Use client as normal from here paho.mqtt.python-1.5.1/examples/client_logger.py000066400000000000000000000020651373244276700220000ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2016 James Myatt # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # James Myatt - initial implementation # This shows a simple example of standard logging with an MQTT subscriber client. import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt import logging logging.basicConfig(level=logging.DEBUG) # If you want to use a specific client id, use # mqttc = mqtt.Client("client-id") # but note that the client id must be unique on the broker. Leaving the client # id parameter empty will generate a random id for you. mqttc = mqtt.Client() logger = logging.getLogger(__name__) mqttc.enable_logger(logger) mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.subscribe("$SYS/#", 0) mqttc.loop_forever() paho.mqtt.python-1.5.1/examples/client_mqtt_clear_retain.py000066400000000000000000000060451373244276700242200ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2013 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # Copyright (c) 2010,2011 Roger Light # All rights reserved. # This shows an example of an MQTT client that clears all of the retained messages it receives. import sys import getopt import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt final_mid = 0 def on_connect(mqttc, userdata, flags, rc): if userdata == True: print("rc: " + str(rc)) def on_message(mqttc, userdata, msg): global final_mid if msg.retain == 0: pass # sys.exit() else: if userdata == True: print("Clearing topic " + msg.topic) (rc, final_mid) = mqttc.publish(msg.topic, None, 1, True) def on_publish(mqttc, userdata, mid): global final_mid if mid == final_mid: sys.exit() def on_log(mqttc, userdata, level, string): print(string) def print_usage(): print( "mqtt_clear_retain.py [-d] [-h hostname] [-i clientid] [-k keepalive] [-p port] [-u username [-P password]] [-v] -t topic") def main(argv): debug = False host = "mqtt.eclipse.org" client_id = None keepalive = 60 port = 1883 password = None topic = None username = None verbose = False try: opts, args = getopt.getopt(argv, "dh:i:k:p:P:t:u:v", ["debug", "id", "keepalive", "port", "password", "topic", "username", "verbose"]) except getopt.GetoptError: print_usage() sys.exit(2) for opt, arg in opts: if opt in ("-d", "--debug"): debug = True elif opt in ("-h", "--host"): host = arg elif opt in ("-i", "--id"): client_id = arg elif opt in ("-k", "--keepalive"): keepalive = int(arg) elif opt in ("-p", "--port"): port = int(arg) elif opt in ("-P", "--password"): password = arg elif opt in ("-t", "--topic"): topic = arg print(topic) elif opt in ("-u", "--username"): username = arg elif opt in ("-v", "--verbose"): verbose = True if topic == None: print("You must provide a topic to clear.\n") print_usage() sys.exit(2) mqttc = mqtt.Client(client_id) mqttc._userdata = verbose mqttc.on_message = on_message mqttc.on_publish = on_publish mqttc.on_connect = on_connect if debug: mqttc.on_log = on_log if username: mqttc.username_pw_set(username, password) mqttc.connect(host, port, keepalive) mqttc.subscribe(topic) mqttc.loop_forever() if __name__ == "__main__": main(sys.argv[1:]) paho.mqtt.python-1.5.1/examples/client_pub-wait.py000066400000000000000000000033201373244276700222440ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2010-2013 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # Copyright (c) 2010,2011 Roger Light # All rights reserved. # This shows a simple example of waiting for a message to be published. import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): print("rc: " + str(rc)) def on_message(mqttc, obj, msg): print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload)) def on_publish(mqttc, obj, mid): print("mid: " + str(mid)) pass def on_subscribe(mqttc, obj, mid, granted_qos): print("Subscribed: " + str(mid) + " " + str(granted_qos)) def on_log(mqttc, obj, level, string): print(string) # If you want to use a specific client id, use # mqttc = mqtt.Client("client-id") # but note that the client id must be unique on the broker. Leaving the client # id parameter empty will generate a random id for you. mqttc = mqtt.Client() mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe # Uncomment to enable debug messages # mqttc.on_log = on_log mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.loop_start() print("tuple") (rc, mid) = mqttc.publish("tuple", "bar", qos=2) print("class") infot = mqttc.publish("class", "bar", qos=2) infot.wait_for_publish() paho.mqtt.python-1.5.1/examples/client_pub_opts.py000066400000000000000000000100601373244276700223460ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2017 Jon Levell # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # All rights reserved. # This shows a example of an MQTT publisher with the ability to use # user name, password CA certificates based on command line arguments import paho.mqtt.client as mqtt import os import ssl import argparse import time parser = argparse.ArgumentParser() parser.add_argument('-H', '--host', required=False, default="mqtt.eclipse.org") parser.add_argument('-t', '--topic', required=False, default="paho/test/opts") parser.add_argument('-q', '--qos', required=False, type=int,default=0) parser.add_argument('-c', '--clientid', required=False, default=None) parser.add_argument('-u', '--username', required=False, default=None) parser.add_argument('-d', '--disable-clean-session', action='store_true', help="disable 'clean session' (sub + msgs not cleared when client disconnects)") parser.add_argument('-p', '--password', required=False, default=None) parser.add_argument('-P', '--port', required=False, type=int, default=None, help='Defaults to 8883 for TLS or 1883 for non-TLS') parser.add_argument('-N', '--nummsgs', required=False, type=int, default=1, help='send this many messages before disconnecting') parser.add_argument('-S', '--delay', required=False, type=float, default=1, help='number of seconds to sleep between msgs') parser.add_argument('-k', '--keepalive', required=False, type=int, default=60) parser.add_argument('-s', '--use-tls', action='store_true') parser.add_argument('--insecure', action='store_true') parser.add_argument('-F', '--cacerts', required=False, default=None) parser.add_argument('--tls-version', required=False, default=None, help='TLS protocol version, can be one of tlsv1.2 tlsv1.1 or tlsv1\n') parser.add_argument('-D', '--debug', action='store_true') args, unknown = parser.parse_known_args() def on_connect(mqttc, obj, flags, rc): print("connect rc: " + str(rc)) def on_message(mqttc, obj, msg): print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload)) def on_publish(mqttc, obj, mid): print("mid: " + str(mid)) def on_subscribe(mqttc, obj, mid, granted_qos): print("Subscribed: " + str(mid) + " " + str(granted_qos)) def on_log(mqttc, obj, level, string): print(string) usetls = args.use_tls if args.cacerts: usetls = True port = args.port if port is None: if usetls: port = 8883 else: port = 1883 mqttc = mqtt.Client(args.clientid,clean_session = not args.disable_clean_session) if usetls: if args.tls_version == "tlsv1.2": tlsVersion = ssl.PROTOCOL_TLSv1_2 elif args.tls_version == "tlsv1.1": tlsVersion = ssl.PROTOCOL_TLSv1_1 elif args.tls_version == "tlsv1": tlsVersion = ssl.PROTOCOL_TLSv1 elif args.tls_version is None: tlsVersion = None else: print ("Unknown TLS version - ignoring") tlsVersion = None if not args.insecure: cert_required = ssl.CERT_REQUIRED else: cert_required = ssl.CERT_NONE mqttc.tls_set(ca_certs=args.cacerts, certfile=None, keyfile=None, cert_reqs=cert_required, tls_version=tlsVersion) if args.insecure: mqttc.tls_insecure_set(True) if args.username or args.password: mqttc.username_pw_set(args.username, args.password) mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe if args.debug: mqttc.on_log = on_log print("Connecting to "+args.host+" port: "+str(port)) mqttc.connect(args.host, port, args.keepalive) mqttc.loop_start() for x in range (0, args.nummsgs): msg_txt = '{"msgnum": "'+str(x)+'"}' print("Publishing: "+msg_txt) infot = mqttc.publish(args.topic, msg_txt, qos=args.qos) infot.wait_for_publish() time.sleep(args.delay) mqttc.disconnect() paho.mqtt.python-1.5.1/examples/client_rpc_math.py000066400000000000000000000056251373244276700223230ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2020 Frank Pagliughi # All rights reserved. # # This program and the accompanying materials are made available # under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Frank Pagliughi - initial implementation # # This shows an example of an MQTTv5 Remote Procedure Call (RPC) client. import context # Ensures paho is in PYTHONPATH import sys import time import json import paho.mqtt.client as mqtt from paho.mqtt.packettypes import PacketTypes # These will be updated with the server-assigned Client ID client_id = "mathcli" reply_to = "" # This correlates the outbound request with the returned reply corr_id = b"1" # This is sent in the message callback when we get the respone reply = None # The MQTTv5 callback takes the additional 'props' parameter. def on_connect(mqttc, userdata, flags, rc, props): global client_id, reply_to print("Connected: '"+str(flags)+"', '"+str(rc)+"', '"+str(props)) if hasattr(props, 'AssignedClientIdentifier'): client_id = props.AssignedClientIdentifier reply_to = "replies/math/" + client_id mqttc.subscribe(reply_to) # An incoming message should be the reply to our request def on_message(mqttc, userdata, msg): global reply print(msg.topic+" "+str(msg.payload)+" "+str(msg.properties)) props = msg.properties if not hasattr(props, 'CorrelationData'): print("No correlation ID") # Match the response to the request correlation ID. if props.CorrelationData == corr_id: reply = msg.payload if len(sys.argv) < 3: print("USAGE: client_rpc_math.py [add|mult] n1 n2 ...") sys.exit(1) mqttc = mqtt.Client(client_id="", protocol=mqtt.MQTTv5) mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.connect(host='localhost', clean_start=True) mqttc.loop_start() # Wait for connection to set `client_id`, etc. while not mqttc.is_connected(): time.sleep(0.1) # Properties for the request specify the ResponseTopic and CorrelationData props = mqtt.Properties(PacketTypes.PUBLISH) props.CorrelationData = corr_id props.ResponseTopic = reply_to # Uncomment to see what got set #print("Client ID: "+client_id) #print("Reply To: "+reply_to) #print(props) # The requested operation, 'add' or 'mult' func = sys.argv[1] # Gather the numeric parameters as an array of numbers # These can be int's or float's args = [] for s in sys.argv[2:]: args.append(float(s)) # Send the request topic = "requests/math/" + func payload = json.dumps(args) mqttc.publish(topic, payload, qos=1, properties=props) # Wait for the reply while reply is None: time.sleep(0.1) # Extract the response and print it. rsp = json.loads(reply) print("Response: "+str(rsp)) mqttc.loop_stop() paho.mqtt.python-1.5.1/examples/client_session_present.py000066400000000000000000000032141373244276700237410ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2014 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # Copyright (c) 2014 Roger Light # All rights reserved. # This demonstrates the session present flag when connecting. import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if obj == 0: print("First connection:") elif obj == 1: print("Second connection:") elif obj == 2: print("Third connection (with clean session=True):") print(" Session present: " + str(flags['session present'])) print(" Connection result: " + str(rc)) mqttc.disconnect() def on_disconnect(mqttc, obj, rc): mqttc.user_data_set(obj + 1) if obj == 0: mqttc.reconnect() def on_log(mqttc, obj, level, string): print(string) mqttc = mqtt.Client(client_id="asdfj", clean_session=False) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect # Uncomment to enable debug messages # mqttc.on_log = on_log mqttc.user_data_set(0) mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.loop_forever() # Clear session mqttc = mqtt.Client(client_id="asdfj", clean_session=True) mqttc.on_connect = on_connect mqttc.user_data_set(2) mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.loop_forever() paho.mqtt.python-1.5.1/examples/client_sub-class.py000066400000000000000000000030241373244276700224110ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2013 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # This example shows how you can use the MQTT client in a class. import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt class MyMQTTClass(mqtt.Client): def on_connect(self, mqttc, obj, flags, rc): print("rc: "+str(rc)) def on_message(self, mqttc, obj, msg): print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload)) def on_publish(self, mqttc, obj, mid): print("mid: "+str(mid)) def on_subscribe(self, mqttc, obj, mid, granted_qos): print("Subscribed: "+str(mid)+" "+str(granted_qos)) def on_log(self, mqttc, obj, level, string): print(string) def run(self): self.connect("mqtt.eclipse.org", 1883, 60) self.subscribe("$SYS/#", 0) rc = 0 while rc == 0: rc = self.loop() return rc # If you want to use a specific client id, use # mqttc = MyMQTTClass("client-id") # but note that the client id must be unique on the broker. Leaving the client # id parameter empty will generate a random id for you. mqttc = MyMQTTClass() rc = mqttc.run() print("rc: "+str(rc)) paho.mqtt.python-1.5.1/examples/client_sub-multiple-callback.py000066400000000000000000000034321373244276700246740ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2014 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # All rights reserved. # This shows a simple example of an MQTT subscriber using a per-subscription message handler. import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt def on_message_msgs(mosq, obj, msg): # This callback will only be called for messages with topics that match # $SYS/broker/messages/# print("MESSAGES: " + msg.topic + " " + str(msg.qos) + " " + str(msg.payload)) def on_message_bytes(mosq, obj, msg): # This callback will only be called for messages with topics that match # $SYS/broker/bytes/# print("BYTES: " + msg.topic + " " + str(msg.qos) + " " + str(msg.payload)) def on_message(mosq, obj, msg): # This callback will be called for messages that we receive that do not # match any patterns defined in topic specific callbacks, i.e. in this case # those messages that do not have topics $SYS/broker/messages/# nor # $SYS/broker/bytes/# print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload)) mqttc = mqtt.Client() # Add message callbacks that will only trigger on a specific subscription match. mqttc.message_callback_add("$SYS/broker/messages/#", on_message_msgs) mqttc.message_callback_add("$SYS/broker/bytes/#", on_message_bytes) mqttc.on_message = on_message mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.subscribe("$SYS/#", 0) mqttc.loop_forever() paho.mqtt.python-1.5.1/examples/client_sub-srv.py000066400000000000000000000032261373244276700221220ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2010-2013 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # Copyright (c) 2010,2011 Roger Light # All rights reserved. # This shows a simple example of an MQTT subscriber using connect_srv method. import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): print("Connected to %s:%s" % (mqttc._host, mqttc._port)) def on_message(mqttc, obj, msg): print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload)) def on_publish(mqttc, obj, mid): print("mid: "+str(mid)) def on_subscribe(mqttc, obj, mid, granted_qos): print("Subscribed: "+str(mid)+" "+str(granted_qos)) def on_log(mqttc, obj, level, string): print(string) # If you want to use a specific client id, use # mqttc = mqtt.Client("client-id") # but note that the client id must be unique on the broker. Leaving the client # id parameter empty will generate a random id for you. mqttc = mqtt.Client() mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe # Uncomment to enable debug messages #mqttc.on_log = on_log mqttc.connect_srv("mosquitto.org", 60) mqttc.subscribe("$SYS/broker/version", 0) rc = 0 while rc == 0: rc = mqttc.loop() print("rc: "+str(rc)) paho.mqtt.python-1.5.1/examples/client_sub-ws.py000066400000000000000000000031071373244276700217370ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2010-2013 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # Copyright (c) 2010,2011 Roger Light # All rights reserved. # This shows a simple example of an MQTT subscriber. import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): print("rc: "+str(rc)) def on_message(mqttc, obj, msg): print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload)) def on_publish(mqttc, obj, mid): print("mid: "+str(mid)) def on_subscribe(mqttc, obj, mid, granted_qos): print("Subscribed: "+str(mid)+" "+str(granted_qos)) def on_log(mqttc, obj, level, string): print(string) # If you want to use a specific client id, use # mqttc = mqtt.Client("client-id") # but note that the client id must be unique on the broker. Leaving the client # id parameter empty will generate a random id for you. mqttc = mqtt.Client(transport="websockets") mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe # Uncomment to enable debug messages mqttc.on_log = on_log mqttc.connect("test.mosquitto.org", 8080, 60) mqttc.subscribe("$SYS/broker/version", 0) mqttc.loop_forever() paho.mqtt.python-1.5.1/examples/client_sub.py000066400000000000000000000030741373244276700213130ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2010-2013 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # Copyright (c) 2010,2011 Roger Light # All rights reserved. # This shows a simple example of an MQTT subscriber. import context # Ensures paho is in PYTHONPATH import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): print("rc: " + str(rc)) def on_message(mqttc, obj, msg): print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload)) def on_publish(mqttc, obj, mid): print("mid: " + str(mid)) def on_subscribe(mqttc, obj, mid, granted_qos): print("Subscribed: " + str(mid) + " " + str(granted_qos)) def on_log(mqttc, obj, level, string): print(string) # If you want to use a specific client id, use # mqttc = mqtt.Client("client-id") # but note that the client id must be unique on the broker. Leaving the client # id parameter empty will generate a random id for you. mqttc = mqtt.Client() mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe # Uncomment to enable debug messages # mqttc.on_log = on_log mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.subscribe("$SYS/#", 0) mqttc.loop_forever() paho.mqtt.python-1.5.1/examples/client_sub_opts.py000066400000000000000000000071021373244276700223540ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2017 Jon Levell # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # All rights reserved. # This shows a example of an MQTT subscriber with the ability to use # user name, password CA certificates based on command line arguments import paho.mqtt.client as mqtt import os import ssl import argparse parser = argparse.ArgumentParser() parser.add_argument('-H', '--host', required=False, default="mqtt.eclipse.org") parser.add_argument('-t', '--topic', required=False, default="$SYS/#") parser.add_argument('-q', '--qos', required=False, type=int, default=0) parser.add_argument('-c', '--clientid', required=False, default=None) parser.add_argument('-u', '--username', required=False, default=None) parser.add_argument('-d', '--disable-clean-session', action='store_true', help="disable 'clean session' (sub + msgs not cleared when client disconnects)") parser.add_argument('-p', '--password', required=False, default=None) parser.add_argument('-P', '--port', required=False, type=int, default=None, help='Defaults to 8883 for TLS or 1883 for non-TLS') parser.add_argument('-k', '--keepalive', required=False, type=int, default=60) parser.add_argument('-s', '--use-tls', action='store_true') parser.add_argument('--insecure', action='store_true') parser.add_argument('-F', '--cacerts', required=False, default=None) parser.add_argument('--tls-version', required=False, default=None, help='TLS protocol version, can be one of tlsv1.2 tlsv1.1 or tlsv1\n') parser.add_argument('-D', '--debug', action='store_true') args, unknown = parser.parse_known_args() def on_connect(mqttc, obj, flags, rc): print("rc: " + str(rc)) def on_message(mqttc, obj, msg): print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload)) def on_publish(mqttc, obj, mid): print("mid: " + str(mid)) def on_subscribe(mqttc, obj, mid, granted_qos): print("Subscribed: " + str(mid) + " " + str(granted_qos)) def on_log(mqttc, obj, level, string): print(string) usetls = args.use_tls if args.cacerts: usetls = True port = args.port if port is None: if usetls: port = 8883 else: port = 1883 mqttc = mqtt.Client(args.clientid,clean_session = not args.disable_clean_session) if usetls: if args.tls_version == "tlsv1.2": tlsVersion = ssl.PROTOCOL_TLSv1_2 elif args.tls_version == "tlsv1.1": tlsVersion = ssl.PROTOCOL_TLSv1_1 elif args.tls_version == "tlsv1": tlsVersion = ssl.PROTOCOL_TLSv1 elif args.tls_version is None: tlsVersion = None else: print ("Unknown TLS version - ignoring") tlsVersion = None if not args.insecure: cert_required = ssl.CERT_REQUIRED else: cert_required = ssl.CERT_NONE mqttc.tls_set(ca_certs=args.cacerts, certfile=None, keyfile=None, cert_reqs=cert_required, tls_version=tlsVersion) if args.insecure: mqttc.tls_insecure_set(True) if args.username or args.password: mqttc.username_pw_set(args.username, args.password) mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe if args.debug: mqttc.on_log = on_log print("Connecting to "+args.host+" port: "+str(port)) mqttc.connect(args.host, port, args.keepalive) mqttc.subscribe(args.topic, args.qos) mqttc.loop_forever() paho.mqtt.python-1.5.1/examples/context.py000066400000000000000000000012211373244276700206400ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Ensure can import paho package try: import paho except ImportError: # This part is only required to run the examples from within the examples # directory when the module itself is not installed. import sys import os import inspect cmd_subfolder = os.path.realpath( os.path.abspath( os.path.join( os.path.split( inspect.getfile(inspect.currentframe()) )[0], "..", "src" ) ) ) if cmd_subfolder not in sys.path: sys.path.insert(0, cmd_subfolder) import paho paho.mqtt.python-1.5.1/examples/loop_asyncio.py000077500000000000000000000065051373244276700216670ustar00rootroot00000000000000#!/usr/bin/env python3 import socket import uuid import paho.mqtt.client as mqtt import asyncio client_id = 'paho-mqtt-python/issue72/' + str(uuid.uuid4()) topic = client_id print("Using client_id / topic: " + client_id) class AsyncioHelper: def __init__(self, loop, client): self.loop = loop self.client = client self.client.on_socket_open = self.on_socket_open self.client.on_socket_close = self.on_socket_close self.client.on_socket_register_write = self.on_socket_register_write self.client.on_socket_unregister_write = self.on_socket_unregister_write def on_socket_open(self, client, userdata, sock): print("Socket opened") def cb(): print("Socket is readable, calling loop_read") client.loop_read() self.loop.add_reader(sock, cb) self.misc = self.loop.create_task(self.misc_loop()) def on_socket_close(self, client, userdata, sock): print("Socket closed") self.loop.remove_reader(sock) self.misc.cancel() def on_socket_register_write(self, client, userdata, sock): print("Watching socket for writability.") def cb(): print("Socket is writable, calling loop_write") client.loop_write() self.loop.add_writer(sock, cb) def on_socket_unregister_write(self, client, userdata, sock): print("Stop watching socket for writability.") self.loop.remove_writer(sock) async def misc_loop(self): print("misc_loop started") while self.client.loop_misc() == mqtt.MQTT_ERR_SUCCESS: try: await asyncio.sleep(1) except asyncio.CancelledError: break print("misc_loop finished") class AsyncMqttExample: def __init__(self, loop): self.loop = loop def on_connect(self, client, userdata, flags, rc): print("Subscribing") client.subscribe(topic) def on_message(self, client, userdata, msg): if not self.got_message: print("Got unexpected message: {}".format(msg.decode())) else: self.got_message.set_result(msg.payload) def on_disconnect(self, client, userdata, rc): self.disconnected.set_result(rc) async def main(self): self.disconnected = self.loop.create_future() self.got_message = None self.client = mqtt.Client(client_id=client_id) self.client.on_connect = self.on_connect self.client.on_message = self.on_message self.client.on_disconnect = self.on_disconnect aioh = AsyncioHelper(self.loop, self.client) self.client.connect('mqtt.eclipse.org', 1883, 60) self.client.socket().setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2048) for c in range(3): await asyncio.sleep(5) print("Publishing") self.got_message = self.loop.create_future() self.client.publish(topic, b'Hello' * 40000, qos=1) msg = await self.got_message print("Got response with {} bytes".format(len(msg))) self.got_message = None self.client.disconnect() print("Disconnected: {}".format(await self.disconnected)) print("Starting") loop = asyncio.get_event_loop() loop.run_until_complete(AsyncMqttExample(loop).main()) loop.close() print("Finished") paho.mqtt.python-1.5.1/examples/loop_select.py000077500000000000000000000046541373244276700215040ustar00rootroot00000000000000#!/usr/bin/env python3 import socket import uuid import paho.mqtt.client as mqtt from select import select from time import time client_id = 'paho-mqtt-python/issue72/' + str(uuid.uuid4()) topic = client_id print("Using client_id / topic: " + client_id) class SelectMqttExample: def __init__(self): pass def on_connect(self, client, userdata, flags, rc): print("Subscribing") client.subscribe(topic) def on_message(self, client, userdata, msg): if self.state not in {1, 3, 5}: print("Got unexpected message: {}".format(msg.decode())) return print("Got message with len {}".format(len(msg.payload))) self.state += 1 self.t = time() def on_disconnect(self, client, userdata, rc): self.disconnected = True, rc def do_select(self): sock = self.client.socket() if not sock: raise Exception("Socket is gone") print("Selecting for reading" + (" and writing" if self.client.want_write() else "")) r, w, e = select( [sock], [sock] if self.client.want_write() else [], [], 1 ) if sock in r: print("Socket is readable, calling loop_read") self.client.loop_read() if sock in w: print("Socket is writable, calling loop_write") self.client.loop_write() self.client.loop_misc() def main(self): self.disconnected = (False, None) self.t = time() self.state = 0 self.client = mqtt.Client(client_id=client_id) self.client.on_connect = self.on_connect self.client.on_message = self.on_message self.client.on_disconnect = self.on_disconnect self.client.connect('mqtt.eclipse.org', 1883, 60) print("Socket opened") self.client.socket().setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2048) while not self.disconnected[0]: self.do_select() if self.state in {0, 2, 4}: if time() - self.t >= 5: print("Publishing") self.client.publish(topic, b'Hello' * 40000) self.state += 1 if self.state == 6: self.state += 1 self.client.disconnect() print("Disconnected: {}".format(self.disconnected[1])) print("Starting") SelectMqttExample().main() print("Finished") paho.mqtt.python-1.5.1/examples/publish_multiple.py000066400000000000000000000014041373244276700225400ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2014 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # This shows an example of using the publish.multiple helper function. import context # Ensures paho is in PYTHONPATH import paho.mqtt.publish as publish msgs = [{'topic': "paho/test/multiple", 'payload': "multiple 1"}, ("paho/test/multiple", "multiple 2", 0, False)] publish.multiple(msgs, hostname="mqtt.eclipse.org") paho.mqtt.python-1.5.1/examples/publish_single.py000066400000000000000000000012431373244276700221670ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2014 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # This shows an example of using the publish.single helper function. import context # Ensures paho is in PYTHONPATH import paho.mqtt.publish as publish publish.single("paho/test/single", "boo", hostname="mqtt.eclipse.org") paho.mqtt.python-1.5.1/examples/publish_utf8-27.py000066400000000000000000000013511373244276700220220ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2014 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # This shows an example of using the publish.single helper function with unicode topic and payload. import context # Ensures paho is in PYTHONPATH import paho.mqtt.publish as publish topic = u"paho/test/single/ô" payload = u"bôô" publish.single(topic, payload, hostname="mqtt.eclipse.org") paho.mqtt.python-1.5.1/examples/server_rpc_math.py000066400000000000000000000054541373244276700223530ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2020 Frank Pagliughi # All rights reserved. # # This program and the accompanying materials are made available # under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Frank Pagliughi - initial implementation # # This shows an example of an MQTTv5 Remote Procedure Call (RPC) server. import context # Ensures paho is in PYTHONPATH import json import paho.mqtt.client as mqtt from paho.mqtt.packettypes import PacketTypes # The math functions exported def add(nums): sum = 0 for x in nums: sum += x return sum def mult(nums): prod = 1 for x in nums: prod *= x return prod # Remember that the MQTTv5 callback takes the additional 'props' parameter. def on_connect(mqttc, userdata, flags, rc, props): print("Connected: '"+str(flags)+"', '"+str(rc)+"', '"+str(props)) if not flags["session present"]: print("Subscribing to math requests") mqttc.subscribe("requests/math/#") # Each incoming message should be an RPC request on the # 'requests/math/#' topic. def on_message(mqttc, userdata, msg): print(msg.topic + " " + str(msg.payload)) # Get the response properties, abort if they're not given props = msg.properties if not hasattr(props, 'ResponseTopic') or not hasattr(props, 'CorrelationData'): print("No reply requested") return corr_id = props.CorrelationData reply_to = props.ResponseTopic # The command parameters are in the payload nums = json.loads(msg.payload) # The requested command is at the end of the topic res = 0 if msg.topic.endswith("add"): res = add(nums) elif msg.topic.endswith("mult"): res = mult(nums) # Now we have the result, res, so send it back on the 'reply_to' # topic using the same correlation ID as the request. print("Sending response "+str(res)+" on '"+reply_to+"': "+str(corr_id)) props = mqtt.Properties(PacketTypes.PUBLISH) props.CorrelationData = corr_id payload = json.dumps(res) mqttc.publish(reply_to, payload, qos=1, properties=props) def on_log(mqttc, obj, level, string): print(string) # Typically with an RPC service, you want to make sure that you're the only # client answering requests for specific topics. Using a known client ID # might help. mqttc = mqtt.Client(client_id="paho_rpc_math_srvr", protocol=mqtt.MQTTv5) mqttc.on_message = on_message mqttc.on_connect = on_connect # Uncomment to enable debug messages #mqttc.on_log = on_log #mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.connect(host="localhost", clean_start=False) mqttc.loop_forever() paho.mqtt.python-1.5.1/examples/subscribe_callback.py000066400000000000000000000014071373244276700227570ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2016 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # This shows an example of using the subscribe.callback helper function. import context # Ensures paho is in PYTHONPATH import paho.mqtt.subscribe as subscribe def print_msg(client, userdata, message): print("%s : %s" % (message.topic, message.payload)) subscribe.callback(print_msg, "#", hostname="mqtt.eclipse.org") paho.mqtt.python-1.5.1/examples/subscribe_simple.py000066400000000000000000000013751373244276700225200ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2016 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Distribution License v1.0 # which accompanies this distribution. # # The Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial implementation # This shows an example of using the subscribe.simple helper function. import context # Ensures paho is in PYTHONPATH import paho.mqtt.subscribe as subscribe topics = ['#'] m = subscribe.simple(topics, hostname="mqtt.eclipse.org", retained=False, msg_count=2) for a in m: print(a.topic) print(a.payload) paho.mqtt.python-1.5.1/notice.html000066400000000000000000000220161373244276700171400ustar00rootroot00000000000000 Eclipse Foundation Software User Agreement

Eclipse Foundation Software User Agreement

February 1, 2011

Usage Of Content

THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.

Applicable Licenses

Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is provided with this Content and is also available at http://www.eclipse.org/legal/epl-v10.html. For purposes of the EPL, "Program" will mean the Content.

Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code repository ("Repository") in software modules ("Modules") and made available as downloadable archives ("Downloads").

  • Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"), plug-in fragments ("Fragments"), and features ("Features").
  • Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".
  • A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material. Each Feature may be packaged as a sub-directory in a directory named "features". Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of the Plug-ins and/or Fragments associated with that Feature.
  • Features may also include other Features ("Included Features"). Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of Included Features.

The terms and conditions governing Plug-ins and Fragments should be contained in files named "about.html" ("Abouts"). The terms and conditions governing Features and Included Features should be contained in files named "license.html" ("Feature Licenses"). Abouts and Feature Licenses may be located in any directory of a Download or Module including, but not limited to the following locations:

  • The top-level (root) directory
  • Plug-in and Fragment directories
  • Inside Plug-ins and Fragments packaged as JARs
  • Sub-directories of the directory named "src" of certain Plug-ins
  • Feature directories

Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license ("Feature Update License") during the installation process. If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or inform you where you can locate them. Feature Update Licenses may be found in the "license" property of files named "feature.properties" found within a Feature. Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in that directory.

THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. SOME OF THESE OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):

IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License is provided, please contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.

Use of Provisioning Technology

The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse Update Manager ("Provisioning Technology") for the purpose of allowing users to install software, documentation, information and/or other materials (collectively "Installable Software"). This capability is provided with the intent of allowing such users to install, extend and update Eclipse-based products. Information about packaging Installable Software is available at http://eclipse.org/equinox/p2/repository_packaging.html ("Specification").

You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:

  1. A series of actions may occur ("Provisioning Process") in which a user may execute the Provisioning Technology on a machine ("Target Machine") with the intent of installing, extending or updating the functionality of an Eclipse-based product.
  2. During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be accessed and copied to the Target Machine.
  3. Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable Software ("Installable Software Agreement") and such Installable Software Agreement shall be accessed from the Target Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.

Cryptography

Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted.

Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.

paho.mqtt.python-1.5.1/requirements.txt000066400000000000000000000002061373244276700202520ustar00rootroot00000000000000mock==3.0.5 pylama==7.7.1 pytest==4.6.6; python_version < '3.0' pytest==5.2.2; python_version >= '3.0' pytest-runner==5.2 tox==3.14.0 paho.mqtt.python-1.5.1/setup.cfg000066400000000000000000000002021373244276700166030ustar00rootroot00000000000000[aliases] test=pytest [tool:pytest] addopts=-r xs --pylama strict=True testpaths=tests src [pylama] linters=pyflakes skip=tests/* paho.mqtt.python-1.5.1/setup.py000066400000000000000000000036421373244276700165070ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from setuptools import setup, find_packages sys.path.insert(0, 'src') from paho.mqtt import __version__ with open('README.rst', 'rb') as readme_file: readme = readme_file.read().decode('utf-8') requirements = [] test_requirements = ['pytest', 'pylama', 'six'] needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv) setup_requirements = ['pytest-runner'] if needs_pytest else [] extra_requirements = {'proxy': ['PySocks']} if sys.version_info < (3, 0): test_requirements += ['mock'] setup( name='paho-mqtt', version=__version__, description='MQTT version 5.0/3.1.1 client class', long_description=readme, author='Roger Light', author_email='roger@atchoo.org', url='http://eclipse.org/paho', packages=find_packages('src'), package_dir={'': 'src'}, include_package_data=True, install_requires=requirements, license='Eclipse Public License v1.0 / Eclipse Distribution License v1.0', zip_safe=False, keywords='paho', classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Natural Language :: English', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Topic :: Communications', 'Topic :: Internet', ], test_suite='tests', tests_require=test_requirements, setup_requires=setup_requirements, extras_require=extra_requirements ) paho.mqtt.python-1.5.1/src/000077500000000000000000000000001373244276700155575ustar00rootroot00000000000000paho.mqtt.python-1.5.1/src/paho/000077500000000000000000000000001373244276700165065ustar00rootroot00000000000000paho.mqtt.python-1.5.1/src/paho/__init__.py000066400000000000000000000000001373244276700206050ustar00rootroot00000000000000paho.mqtt.python-1.5.1/src/paho/mqtt/000077500000000000000000000000001373244276700174735ustar00rootroot00000000000000paho.mqtt.python-1.5.1/src/paho/mqtt/__init__.py000066400000000000000000000001011373244276700215740ustar00rootroot00000000000000__version__ = "1.5.1" class MQTTException(Exception): pass paho.mqtt.python-1.5.1/src/paho/mqtt/client.py000066400000000000000000004477311373244276700213430ustar00rootroot00000000000000# Copyright (c) 2012-2019 Roger Light and others # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # and Eclipse Distribution License v1.0 which accompany this distribution. # # The Eclipse Public License is available at # http://www.eclipse.org/legal/epl-v10.html # and the Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial API and implementation # Ian Craggs - MQTT V5 support from .subscribeoptions import SubscribeOptions from .reasoncodes import ReasonCodes from .properties import Properties from .matcher import MQTTMatcher import logging import hashlib import string import base64 import uuid import time import threading import sys import struct """ This is an MQTT client module. MQTT is a lightweight pub/sub messaging protocol that is easy to implement and suitable for low powered devices. """ import collections import errno import os import platform import select import socket ssl = None try: import ssl except ImportError: pass socks = None try: import socks except ImportError: pass try: # Python 3 from urllib import request as urllib_dot_request from urllib import parse as urllib_dot_parse except ImportError: # Python 2 import urllib as urllib_dot_request import urlparse as urllib_dot_parse try: # Use monotonic clock if available time_func = time.monotonic except AttributeError: time_func = time.time try: import dns.resolver except ImportError: HAVE_DNS = False else: HAVE_DNS = True if platform.system() == 'Windows': EAGAIN = errno.WSAEWOULDBLOCK else: EAGAIN = errno.EAGAIN MQTTv31 = 3 MQTTv311 = 4 MQTTv5 = 5 if sys.version_info[0] >= 3: # define some alias for python2 compatibility unicode = str basestring = str # Message types CONNECT = 0x10 CONNACK = 0x20 PUBLISH = 0x30 PUBACK = 0x40 PUBREC = 0x50 PUBREL = 0x60 PUBCOMP = 0x70 SUBSCRIBE = 0x80 SUBACK = 0x90 UNSUBSCRIBE = 0xA0 UNSUBACK = 0xB0 PINGREQ = 0xC0 PINGRESP = 0xD0 DISCONNECT = 0xE0 AUTH = 0xF0 # Log levels MQTT_LOG_INFO = 0x01 MQTT_LOG_NOTICE = 0x02 MQTT_LOG_WARNING = 0x04 MQTT_LOG_ERR = 0x08 MQTT_LOG_DEBUG = 0x10 LOGGING_LEVEL = { MQTT_LOG_DEBUG: logging.DEBUG, MQTT_LOG_INFO: logging.INFO, MQTT_LOG_NOTICE: logging.INFO, # This has no direct equivalent level MQTT_LOG_WARNING: logging.WARNING, MQTT_LOG_ERR: logging.ERROR, } # CONNACK codes CONNACK_ACCEPTED = 0 CONNACK_REFUSED_PROTOCOL_VERSION = 1 CONNACK_REFUSED_IDENTIFIER_REJECTED = 2 CONNACK_REFUSED_SERVER_UNAVAILABLE = 3 CONNACK_REFUSED_BAD_USERNAME_PASSWORD = 4 CONNACK_REFUSED_NOT_AUTHORIZED = 5 # Connection state mqtt_cs_new = 0 mqtt_cs_connected = 1 mqtt_cs_disconnecting = 2 mqtt_cs_connect_async = 3 # Message state mqtt_ms_invalid = 0 mqtt_ms_publish = 1 mqtt_ms_wait_for_puback = 2 mqtt_ms_wait_for_pubrec = 3 mqtt_ms_resend_pubrel = 4 mqtt_ms_wait_for_pubrel = 5 mqtt_ms_resend_pubcomp = 6 mqtt_ms_wait_for_pubcomp = 7 mqtt_ms_send_pubrec = 8 mqtt_ms_queued = 9 # Error values MQTT_ERR_AGAIN = -1 MQTT_ERR_SUCCESS = 0 MQTT_ERR_NOMEM = 1 MQTT_ERR_PROTOCOL = 2 MQTT_ERR_INVAL = 3 MQTT_ERR_NO_CONN = 4 MQTT_ERR_CONN_REFUSED = 5 MQTT_ERR_NOT_FOUND = 6 MQTT_ERR_CONN_LOST = 7 MQTT_ERR_TLS = 8 MQTT_ERR_PAYLOAD_SIZE = 9 MQTT_ERR_NOT_SUPPORTED = 10 MQTT_ERR_AUTH = 11 MQTT_ERR_ACL_DENIED = 12 MQTT_ERR_UNKNOWN = 13 MQTT_ERR_ERRNO = 14 MQTT_ERR_QUEUE_SIZE = 15 MQTT_CLIENT = 0 MQTT_BRIDGE = 1 # For MQTT V5, use the clean start flag only on the first successful connect MQTT_CLEAN_START_FIRST_ONLY = 3 sockpair_data = b"0" class WebsocketConnectionError(ValueError): pass class WouldBlockError(Exception): pass def error_string(mqtt_errno): """Return the error string associated with an mqtt error number.""" if mqtt_errno == MQTT_ERR_SUCCESS: return "No error." elif mqtt_errno == MQTT_ERR_NOMEM: return "Out of memory." elif mqtt_errno == MQTT_ERR_PROTOCOL: return "A network protocol error occurred when communicating with the broker." elif mqtt_errno == MQTT_ERR_INVAL: return "Invalid function arguments provided." elif mqtt_errno == MQTT_ERR_NO_CONN: return "The client is not currently connected." elif mqtt_errno == MQTT_ERR_CONN_REFUSED: return "The connection was refused." elif mqtt_errno == MQTT_ERR_NOT_FOUND: return "Message not found (internal error)." elif mqtt_errno == MQTT_ERR_CONN_LOST: return "The connection was lost." elif mqtt_errno == MQTT_ERR_TLS: return "A TLS error occurred." elif mqtt_errno == MQTT_ERR_PAYLOAD_SIZE: return "Payload too large." elif mqtt_errno == MQTT_ERR_NOT_SUPPORTED: return "This feature is not supported." elif mqtt_errno == MQTT_ERR_AUTH: return "Authorisation failed." elif mqtt_errno == MQTT_ERR_ACL_DENIED: return "Access denied by ACL." elif mqtt_errno == MQTT_ERR_UNKNOWN: return "Unknown error." elif mqtt_errno == MQTT_ERR_ERRNO: return "Error defined by errno." elif mqtt_errno == MQTT_ERR_QUEUE_SIZE: return "Message queue full." else: return "Unknown error." def connack_string(connack_code): """Return the string associated with a CONNACK result.""" if connack_code == CONNACK_ACCEPTED: return "Connection Accepted." elif connack_code == CONNACK_REFUSED_PROTOCOL_VERSION: return "Connection Refused: unacceptable protocol version." elif connack_code == CONNACK_REFUSED_IDENTIFIER_REJECTED: return "Connection Refused: identifier rejected." elif connack_code == CONNACK_REFUSED_SERVER_UNAVAILABLE: return "Connection Refused: broker unavailable." elif connack_code == CONNACK_REFUSED_BAD_USERNAME_PASSWORD: return "Connection Refused: bad user name or password." elif connack_code == CONNACK_REFUSED_NOT_AUTHORIZED: return "Connection Refused: not authorised." else: return "Connection Refused: unknown reason." def base62(num, base=string.digits + string.ascii_letters, padding=1): """Convert a number to base-62 representation.""" assert num >= 0 digits = [] while num: num, rest = divmod(num, 62) digits.append(base[rest]) digits.extend(base[0] for _ in range(len(digits), padding)) return ''.join(reversed(digits)) def topic_matches_sub(sub, topic): """Check whether a topic matches a subscription. For example: foo/bar would match the subscription foo/# or +/bar non/matching would not match the subscription non/+/+ """ matcher = MQTTMatcher() matcher[sub] = True try: next(matcher.iter_match(topic)) return True except StopIteration: return False def _socketpair_compat(): """TCP/IP socketpair including Windows support""" listensock = socket.socket( socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_IP) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("127.0.0.1", 0)) listensock.listen(1) iface, port = listensock.getsockname() sock1 = socket.socket( socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_IP) sock1.setblocking(0) try: sock1.connect(("127.0.0.1", port)) except socket.error as err: if err.errno != errno.EINPROGRESS and err.errno != errno.EWOULDBLOCK and err.errno != EAGAIN: raise sock2, address = listensock.accept() sock2.setblocking(0) listensock.close() return (sock1, sock2) class MQTTMessageInfo(object): """This is a class returned from Client.publish() and can be used to find out the mid of the message that was published, and to determine whether the message has been published, and/or wait until it is published. """ __slots__ = 'mid', '_published', '_condition', 'rc', '_iterpos' def __init__(self, mid): self.mid = mid self._published = False self._condition = threading.Condition() self.rc = 0 self._iterpos = 0 def __str__(self): return str((self.rc, self.mid)) def __iter__(self): self._iterpos = 0 return self def __next__(self): return self.next() def next(self): if self._iterpos == 0: self._iterpos = 1 return self.rc elif self._iterpos == 1: self._iterpos = 2 return self.mid else: raise StopIteration def __getitem__(self, index): if index == 0: return self.rc elif index == 1: return self.mid else: raise IndexError("index out of range") def _set_as_published(self): with self._condition: self._published = True self._condition.notify() def wait_for_publish(self): """Block until the message associated with this object is published.""" if self.rc == MQTT_ERR_QUEUE_SIZE: raise ValueError('Message is not queued due to ERR_QUEUE_SIZE') with self._condition: while not self._published: self._condition.wait() def is_published(self): """Returns True if the message associated with this object has been published, else returns False.""" if self.rc == MQTT_ERR_QUEUE_SIZE: raise ValueError('Message is not queued due to ERR_QUEUE_SIZE') with self._condition: return self._published class MQTTMessage(object): """ This is a class that describes an incoming or outgoing message. It is passed to the on_message callback as the message parameter. Members: topic : String/bytes. topic that the message was published on. payload : String/bytes the message payload. qos : Integer. The message Quality of Service 0, 1 or 2. retain : Boolean. If true, the message is a retained message and not fresh. mid : Integer. The message id. properties: Properties class. In MQTT v5.0, the properties associated with the message. On Python 3, topic must be bytes. """ __slots__ = 'timestamp', 'state', 'dup', 'mid', '_topic', 'payload', 'qos', 'retain', 'info', 'properties' def __init__(self, mid=0, topic=b""): self.timestamp = 0 self.state = mqtt_ms_invalid self.dup = False self.mid = mid self._topic = topic self.payload = b"" self.qos = 0 self.retain = False self.info = MQTTMessageInfo(mid) def __eq__(self, other): """Override the default Equals behavior""" if isinstance(other, self.__class__): return self.mid == other.mid return False def __ne__(self, other): """Define a non-equality test""" return not self.__eq__(other) @property def topic(self): return self._topic.decode('utf-8') @topic.setter def topic(self, value): self._topic = value class Client(object): """MQTT version 3.1/3.1.1/5.0 client class. This is the main class for use communicating with an MQTT broker. General usage flow: * Use connect()/connect_async() to connect to a broker * Call loop() frequently to maintain network traffic flow with the broker * Or use loop_start() to set a thread running to call loop() for you. * Or use loop_forever() to handle calling loop() for you in a blocking * function. * Use subscribe() to subscribe to a topic and receive messages * Use publish() to send messages * Use disconnect() to disconnect from the broker Data returned from the broker is made available with the use of callback functions as described below. Callbacks ========= A number of callback functions are available to receive data back from the broker. To use a callback, define a function and then assign it to the client: def on_connect(client, userdata, flags, rc, properties=None): print("Connection returned " + str(rc)) client.on_connect = on_connect All of the callbacks as described below have a "client" and an "userdata" argument. "client" is the Client instance that is calling the callback. "userdata" is user data of any type and can be set when creating a new client instance or with user_data_set(userdata). If you wish to suppress exceptions within a callback, you should set `client.suppress_exceptions = True` The callbacks: on_connect(client, userdata, flags, rc, properties=None): called when the broker responds to our connection request. flags is a dict that contains response flags from the broker: flags['session present'] - this flag is useful for clients that are using clean session set to 0 only. If a client with clean session=0, that reconnects to a broker that it has previously connected to, this flag indicates whether the broker still has the session information for the client. If 1, the session still exists. The value of rc determines success or not: 0: Connection successful 1: Connection refused - incorrect protocol version 2: Connection refused - invalid client identifier 3: Connection refused - server unavailable 4: Connection refused - bad username or password 5: Connection refused - not authorised 6-255: Currently unused. on_disconnect(client, userdata, rc): called when the client disconnects from the broker. The rc parameter indicates the disconnection state. If MQTT_ERR_SUCCESS (0), the callback was called in response to a disconnect() call. If any other value the disconnection was unexpected, such as might be caused by a network error. on_disconnect(client, userdata, rc, properties): called when the MQTT V5 client disconnects from the broker. When using MQTT V5, the broker can send a disconnect message to the client. The message can contain a reason code and MQTT V5 properties. The properties parameter could be None if they do not exist in the disconnect message. on_message(client, userdata, message): called when a message has been received on a topic that the client subscribes to. The message variable is a MQTTMessage that describes all of the message parameters. on_publish(client, userdata, mid): called when a message that was to be sent using the publish() call has completed transmission to the broker. For messages with QoS levels 1 and 2, this means that the appropriate handshakes have completed. For QoS 0, this simply means that the message has left the client. The mid variable matches the mid variable returned from the corresponding publish() call, to allow outgoing messages to be tracked. This callback is important because even if the publish() call returns success, it does not always mean that the message has been sent. on_subscribe(client, userdata, mid, granted_qos, properties=None): called when the broker responds to a subscribe request. The mid variable matches the mid variable returned from the corresponding subscribe() call. The granted_qos variable is a list of integers that give the QoS level the broker has granted for each of the different subscription requests. on_unsubscribe(client, userdata, mid): called when the broker responds to an unsubscribe request. The mid variable matches the mid variable returned from the corresponding unsubscribe() call. on_log(client, userdata, level, buf): called when the client has log information. Define to allow debugging. The level variable gives the severity of the message and will be one of MQTT_LOG_INFO, MQTT_LOG_NOTICE, MQTT_LOG_WARNING, MQTT_LOG_ERR, and MQTT_LOG_DEBUG. The message itself is in buf. on_socket_open(client, userdata, sock): Called when the socket has been opened. Use this to register the socket with an external event loop for reading. on_socket_close(client, userdata, sock): Called when the socket is about to be closed. Use this to unregister a socket from an external event loop for reading. on_socket_register_write(client, userdata, sock): Called when a write operation to the socket failed because it would have blocked, e.g. output buffer full. Use this to register the socket with an external event loop for writing. on_socket_unregister_write(client, userdata, sock): Called when a write operation to the socket succeeded after it had previously failed. Use this to unregister the socket from an external event loop for writing. """ def __init__(self, client_id="", clean_session=None, userdata=None, protocol=MQTTv311, transport="tcp"): """client_id is the unique client id string used when connecting to the broker. If client_id is zero length or None, then the behaviour is defined by which protocol version is in use. If using MQTT v3.1.1, then a zero length client id will be sent to the broker and the broker will generate a random for the client. If using MQTT v3.1 then an id will be randomly generated. In both cases, clean_session must be True. If this is not the case a ValueError will be raised. clean_session is a boolean that determines the client type. If True, the broker will remove all information about this client when it disconnects. If False, the client is a persistent client and subscription information and queued messages will be retained when the client disconnects. Note that a client will never discard its own outgoing messages on disconnect. Calling connect() or reconnect() will cause the messages to be resent. Use reinitialise() to reset a client to its original state. The clean_session argument only applies to MQTT versions v3.1.1 and v3.1. It is not accepted if the MQTT version is v5.0 - use the clean_start argument on connect() instead. userdata is user defined data of any type that is passed as the "userdata" parameter to callbacks. It may be updated at a later point with the user_data_set() function. The protocol argument allows explicit setting of the MQTT version to use for this client. Can be paho.mqtt.client.MQTTv311 (v3.1.1), paho.mqtt.client.MQTTv31 (v3.1) or paho.mqtt.client.MQTTv5 (v5.0), with the default being v3.1.1. Set transport to "websockets" to use WebSockets as the transport mechanism. Set to "tcp" to use raw TCP, which is the default. """ if protocol == MQTTv5: if clean_session != None: raise ValueError('Clean session is not used for MQTT 5.0') else: if clean_session == None: clean_session = True if not clean_session and (client_id == "" or client_id is None): raise ValueError( 'A client id must be provided if clean session is False.') self._clean_session = clean_session if transport.lower() not in ('websockets', 'tcp'): raise ValueError( 'transport must be "websockets" or "tcp", not %s' % transport) self._transport = transport.lower() self._protocol = protocol self._userdata = userdata self._sock = None self._sockpairR, self._sockpairW = (None, None,) self._sockpairR, self._sockpairW = _socketpair_compat() self._keepalive = 60 self._message_retry = 20 self._last_retry_check = 0 self._client_mode = MQTT_CLIENT # [MQTT-3.1.3-4] Client Id must be UTF-8 encoded string. if client_id == "" or client_id is None: if protocol == MQTTv31: self._client_id = base62(uuid.uuid4().int, padding=22) else: self._client_id = b"" else: self._client_id = client_id if isinstance(self._client_id, unicode): self._client_id = self._client_id.encode('utf-8') self._username = None self._password = None self._in_packet = { "command": 0, "have_remaining": 0, "remaining_count": [], "remaining_mult": 1, "remaining_length": 0, "packet": b"", "to_process": 0, "pos": 0} self._out_packet = collections.deque() self._current_out_packet = None self._last_msg_in = time_func() self._last_msg_out = time_func() self._reconnect_min_delay = 1 self._reconnect_max_delay = 120 self._reconnect_delay = None self._ping_t = 0 self._last_mid = 0 self._state = mqtt_cs_new self._out_messages = collections.OrderedDict() self._in_messages = collections.OrderedDict() self._max_inflight_messages = 20 self._inflight_messages = 0 self._max_queued_messages = 0 self._connect_properties = None self._will_properties = None self._will = False self._will_topic = b"" self._will_payload = b"" self._will_qos = 0 self._will_retain = False self._on_message_filtered = MQTTMatcher() self._host = "" self._port = 1883 self._bind_address = "" self._bind_port = 0 self._proxy = {} self._in_callback_mutex = threading.Lock() self._callback_mutex = threading.RLock() self._out_packet_mutex = threading.Lock() self._current_out_packet_mutex = threading.RLock() self._msgtime_mutex = threading.Lock() self._out_message_mutex = threading.RLock() self._in_message_mutex = threading.Lock() self._reconnect_delay_mutex = threading.Lock() self._mid_generate_mutex = threading.Lock() self._thread = None self._thread_terminate = False self._ssl = False self._ssl_context = None # Only used when SSL context does not have check_hostname attribute self._tls_insecure = False self._logger = None self._registered_write = False # No default callbacks self._on_log = None self._on_connect = None self._on_subscribe = None self._on_message = None self._on_publish = None self._on_unsubscribe = None self._on_disconnect = None self._on_socket_open = None self._on_socket_close = None self._on_socket_register_write = None self._on_socket_unregister_write = None self._websocket_path = "/mqtt" self._websocket_extra_headers = None # for clean_start == MQTT_CLEAN_START_FIRST_ONLY self._mqttv5_first_connect = True self.suppress_exceptions = False # For callbacks def __del__(self): self._reset_sockets() def _sock_recv(self, bufsize): try: return self._sock.recv(bufsize) except socket.error as err: if self._ssl and err.errno == ssl.SSL_ERROR_WANT_READ: raise WouldBlockError() if self._ssl and err.errno == ssl.SSL_ERROR_WANT_WRITE: self._call_socket_register_write() raise WouldBlockError() if err.errno == EAGAIN: raise WouldBlockError() raise def _sock_send(self, buf): try: return self._sock.send(buf) except socket.error as err: if self._ssl and err.errno == ssl.SSL_ERROR_WANT_READ: raise WouldBlockError() if self._ssl and err.errno == ssl.SSL_ERROR_WANT_WRITE: self._call_socket_register_write() raise WouldBlockError() if err.errno == EAGAIN: self._call_socket_register_write() raise WouldBlockError() raise def _sock_close(self): """Close the connection to the server.""" if not self._sock: return try: sock = self._sock self._sock = None self._call_socket_unregister_write(sock) self._call_socket_close(sock) finally: # In case a callback fails, still close the socket to avoid leaking the file descriptor. sock.close() def _reset_sockets(self): self._sock_close() if self._sockpairR: self._sockpairR.close() self._sockpairR = None if self._sockpairW: self._sockpairW.close() self._sockpairW = None def reinitialise(self, client_id="", clean_session=True, userdata=None): self._reset_sockets() self.__init__(client_id, clean_session, userdata) def ws_set_options(self, path="/mqtt", headers=None): """ Set the path and headers for a websocket connection path is a string starting with / which should be the endpoint of the mqtt connection on the remote server headers can be either a dict or a callable object. If it is a dict then the extra items in the dict are added to the websocket headers. If it is a callable, then the default websocket headers are passed into this function and the result is used as the new headers. """ self._websocket_path = path if headers is not None: if isinstance(headers, dict) or callable(headers): self._websocket_extra_headers = headers else: raise ValueError( "'headers' option to ws_set_options has to be either a dictionary or callable") def tls_set_context(self, context=None): """Configure network encryption and authentication context. Enables SSL/TLS support. context : an ssl.SSLContext object. By default this is given by `ssl.create_default_context()`, if available. Must be called before connect() or connect_async().""" if self._ssl_context is not None: raise ValueError('SSL/TLS has already been configured.') # Assume that have SSL support, or at least that context input behaves like ssl.SSLContext # in current versions of Python if context is None: if hasattr(ssl, 'create_default_context'): context = ssl.create_default_context() else: raise ValueError('SSL/TLS context must be specified') self._ssl = True self._ssl_context = context # Ensure _tls_insecure is consistent with check_hostname attribute if hasattr(context, 'check_hostname'): self._tls_insecure = not context.check_hostname def tls_set(self, ca_certs=None, certfile=None, keyfile=None, cert_reqs=None, tls_version=None, ciphers=None): """Configure network encryption and authentication options. Enables SSL/TLS support. ca_certs : a string path to the Certificate Authority certificate files that are to be treated as trusted by this client. If this is the only option given then the client will operate in a similar manner to a web browser. That is to say it will require the broker to have a certificate signed by the Certificate Authorities in ca_certs and will communicate using TLS v1, but will not attempt any form of authentication. This provides basic network encryption but may not be sufficient depending on how the broker is configured. By default, on Python 2.7.9+ or 3.4+, the default certification authority of the system is used. On older Python version this parameter is mandatory. certfile and keyfile are strings pointing to the PEM encoded client certificate and private keys respectively. If these arguments are not None then they will be used as client information for TLS based authentication. Support for this feature is broker dependent. Note that if either of these files in encrypted and needs a password to decrypt it, Python will ask for the password at the command line. It is not currently possible to define a callback to provide the password. cert_reqs allows the certificate requirements that the client imposes on the broker to be changed. By default this is ssl.CERT_REQUIRED, which means that the broker must provide a certificate. See the ssl pydoc for more information on this parameter. tls_version allows the version of the SSL/TLS protocol used to be specified. By default TLS v1 is used. Previous versions (all versions beginning with SSL) are possible but not recommended due to possible security problems. ciphers is a string specifying which encryption ciphers are allowable for this connection, or None to use the defaults. See the ssl pydoc for more information. Must be called before connect() or connect_async().""" if ssl is None: raise ValueError('This platform has no SSL/TLS.') if not hasattr(ssl, 'SSLContext'): # Require Python version that has SSL context support in standard library raise ValueError( 'Python 2.7.9 and 3.2 are the minimum supported versions for TLS.') if ca_certs is None and not hasattr(ssl.SSLContext, 'load_default_certs'): raise ValueError('ca_certs must not be None.') # Create SSLContext object if tls_version is None: tls_version = ssl.PROTOCOL_TLSv1 # If the python version supports it, use highest TLS version automatically if hasattr(ssl, "PROTOCOL_TLS"): tls_version = ssl.PROTOCOL_TLS context = ssl.SSLContext(tls_version) # Configure context if certfile is not None: context.load_cert_chain(certfile, keyfile) if cert_reqs == ssl.CERT_NONE and hasattr(context, 'check_hostname'): context.check_hostname = False context.verify_mode = ssl.CERT_REQUIRED if cert_reqs is None else cert_reqs if ca_certs is not None: context.load_verify_locations(ca_certs) else: context.load_default_certs() if ciphers is not None: context.set_ciphers(ciphers) self.tls_set_context(context) if cert_reqs != ssl.CERT_NONE: # Default to secure, sets context.check_hostname attribute # if available self.tls_insecure_set(False) else: # But with ssl.CERT_NONE, we can not check_hostname self.tls_insecure_set(True) def tls_insecure_set(self, value): """Configure verification of the server hostname in the server certificate. If value is set to true, it is impossible to guarantee that the host you are connecting to is not impersonating your server. This can be useful in initial server testing, but makes it possible for a malicious third party to impersonate your server through DNS spoofing, for example. Do not use this function in a real system. Setting value to true means there is no point using encryption. Must be called before connect() and after either tls_set() or tls_set_context().""" if self._ssl_context is None: raise ValueError( 'Must configure SSL context before using tls_insecure_set.') self._tls_insecure = value # Ensure check_hostname is consistent with _tls_insecure attribute if hasattr(self._ssl_context, 'check_hostname'): # Rely on SSLContext to check host name # If verify_mode is CERT_NONE then the host name will never be checked self._ssl_context.check_hostname = not value def proxy_set(self, **proxy_args): """Configure proxying of MQTT connection. Enables support for SOCKS or HTTP proxies. Proxying is done through the PySocks library. Brief descriptions of the proxy_args parameters are below; see the PySocks docs for more info. (Required) proxy_type: One of {socks.HTTP, socks.SOCKS4, or socks.SOCKS5} proxy_addr: IP address or DNS name of proxy server (Optional) proxy_rdns: boolean indicating whether proxy lookup should be performed remotely (True, default) or locally (False) proxy_username: username for SOCKS5 proxy, or userid for SOCKS4 proxy proxy_password: password for SOCKS5 proxy Must be called before connect() or connect_async().""" if socks is None: raise ValueError("PySocks must be installed for proxy support.") elif not self._proxy_is_valid(proxy_args): raise ValueError("proxy_type and/or proxy_addr are invalid.") else: self._proxy = proxy_args def enable_logger(self, logger=None): """ Enables a logger to send log messages to """ if logger is None: if self._logger is not None: # Do not replace existing logger return logger = logging.getLogger(__name__) self._logger = logger def disable_logger(self): self._logger = None def connect(self, host, port=1883, keepalive=60, bind_address="", bind_port=0, clean_start=MQTT_CLEAN_START_FIRST_ONLY, properties=None): """Connect to a remote broker. host is the hostname or IP address of the remote broker. port is the network port of the server host to connect to. Defaults to 1883. Note that the default port for MQTT over SSL/TLS is 8883 so if you are using tls_set() the port may need providing. keepalive: Maximum period in seconds between communications with the broker. If no other messages are being exchanged, this controls the rate at which the client will send ping messages to the broker. clean_start: (MQTT v5.0 only) True, False or MQTT_CLEAN_START_FIRST_ONLY. Sets the MQTT v5.0 clean_start flag always, never or on the first successful connect only, respectively. MQTT session data (such as outstanding messages and subscriptions) is cleared on successful connect when the clean_start flag is set. properties: (MQTT v5.0 only) the MQTT v5.0 properties to be sent in the MQTT connect packet. """ if self._protocol == MQTTv5: self._mqttv5_first_connect = True else: if clean_start != MQTT_CLEAN_START_FIRST_ONLY: raise ValueError("Clean start only applies to MQTT V5") if properties != None: raise ValueError("Properties only apply to MQTT V5") self.connect_async(host, port, keepalive, bind_address, bind_port, clean_start, properties) return self.reconnect() def connect_srv(self, domain=None, keepalive=60, bind_address="", clean_start=MQTT_CLEAN_START_FIRST_ONLY, properties=None): """Connect to a remote broker. domain is the DNS domain to search for SRV records; if None, try to determine local domain name. keepalive, bind_address, clean_start and properties are as for connect() """ if HAVE_DNS is False: raise ValueError( 'No DNS resolver library found, try "pip install dnspython" or "pip3 install dnspython3".') if domain is None: domain = socket.getfqdn() domain = domain[domain.find('.') + 1:] try: rr = '_mqtt._tcp.%s' % domain if self._ssl: # IANA specifies secure-mqtt (not mqtts) for port 8883 rr = '_secure-mqtt._tcp.%s' % domain answers = [] for answer in dns.resolver.query(rr, dns.rdatatype.SRV): addr = answer.target.to_text()[:-1] answers.append( (addr, answer.port, answer.priority, answer.weight)) except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.NoNameservers): raise ValueError("No answer/NXDOMAIN for SRV in %s" % (domain)) # FIXME: doesn't account for weight for answer in answers: host, port, prio, weight = answer try: return self.connect(host, port, keepalive, bind_address, clean_start, properties) except Exception: pass raise ValueError("No SRV hosts responded") def connect_async(self, host, port=1883, keepalive=60, bind_address="", bind_port=0, clean_start=MQTT_CLEAN_START_FIRST_ONLY, properties=None): """Connect to a remote broker asynchronously. This is a non-blocking connect call that can be used with loop_start() to provide very quick start. host is the hostname or IP address of the remote broker. port is the network port of the server host to connect to. Defaults to 1883. Note that the default port for MQTT over SSL/TLS is 8883 so if you are using tls_set() the port may need providing. keepalive: Maximum period in seconds between communications with the broker. If no other messages are being exchanged, this controls the rate at which the client will send ping messages to the broker. clean_start: (MQTT v5.0 only) True, False or MQTT_CLEAN_START_FIRST_ONLY. Sets the MQTT v5.0 clean_start flag always, never or on the first successful connect only, respectively. MQTT session data (such as outstanding messages and subscriptions) is cleared on successful connect when the clean_start flag is set. properties: (MQTT v5.0 only) the MQTT v5.0 properties to be sent in the MQTT connect packet. Use the Properties class. """ if host is None or len(host) == 0: raise ValueError('Invalid host.') if port <= 0: raise ValueError('Invalid port number.') if keepalive < 0: raise ValueError('Keepalive must be >=0.') if bind_address != "" and bind_address is not None: if sys.version_info < (2, 7) or (3, 0) < sys.version_info < (3, 2): raise ValueError('bind_address requires Python 2.7 or 3.2.') if bind_port < 0: raise ValueError('Invalid bind port number.') self._host = host self._port = port self._keepalive = keepalive self._bind_address = bind_address self._bind_port = bind_port self._clean_start = clean_start self._connect_properties = properties self._state = mqtt_cs_connect_async def reconnect_delay_set(self, min_delay=1, max_delay=120): """ Configure the exponential reconnect delay When connection is lost, wait initially min_delay seconds and double this time every attempt. The wait is capped at max_delay. Once the client is fully connected (e.g. not only TCP socket, but received a success CONNACK), the wait timer is reset to min_delay. """ with self._reconnect_delay_mutex: self._reconnect_min_delay = min_delay self._reconnect_max_delay = max_delay self._reconnect_delay = None def reconnect(self): """Reconnect the client after a disconnect. Can only be called after connect()/connect_async().""" if len(self._host) == 0: raise ValueError('Invalid host.') if self._port <= 0: raise ValueError('Invalid port number.') self._in_packet = { "command": 0, "have_remaining": 0, "remaining_count": [], "remaining_mult": 1, "remaining_length": 0, "packet": b"", "to_process": 0, "pos": 0} with self._out_packet_mutex: self._out_packet = collections.deque() with self._current_out_packet_mutex: self._current_out_packet = None with self._msgtime_mutex: self._last_msg_in = time_func() self._last_msg_out = time_func() self._ping_t = 0 self._state = mqtt_cs_new self._sock_close() # Put messages in progress in a valid state. self._messages_reconnect_reset() sock = self._create_socket_connection() if self._ssl: # SSL is only supported when SSLContext is available (implies Python >= 2.7.9 or >= 3.2) verify_host = not self._tls_insecure try: # Try with server_hostname, even it's not supported in certain scenarios sock = self._ssl_context.wrap_socket( sock, server_hostname=self._host, do_handshake_on_connect=False, ) except ssl.CertificateError: # CertificateError is derived from ValueError raise except ValueError: # Python version requires SNI in order to handle server_hostname, but SNI is not available sock = self._ssl_context.wrap_socket( sock, do_handshake_on_connect=False, ) else: # If SSL context has already checked hostname, then don't need to do it again if (hasattr(self._ssl_context, 'check_hostname') and self._ssl_context.check_hostname): verify_host = False sock.settimeout(self._keepalive) sock.do_handshake() if verify_host: ssl.match_hostname(sock.getpeercert(), self._host) if self._transport == "websockets": sock.settimeout(self._keepalive) sock = WebsocketWrapper(sock, self._host, self._port, self._ssl, self._websocket_path, self._websocket_extra_headers) self._sock = sock self._sock.setblocking(0) self._registered_write = False self._call_socket_open() return self._send_connect(self._keepalive) def loop(self, timeout=1.0, max_packets=1): """Process network events. This function must be called regularly to ensure communication with the broker is carried out. It calls select() on the network socket to wait for network events. If incoming data is present it will then be processed. Outgoing commands, from e.g. publish(), are normally sent immediately that their function is called, but this is not always possible. loop() will also attempt to send any remaining outgoing messages, which also includes commands that are part of the flow for messages with QoS>0. timeout: The time in seconds to wait for incoming/outgoing network traffic before timing out and returning. max_packets: Not currently used. Returns MQTT_ERR_SUCCESS on success. Returns >0 on error. A ValueError will be raised if timeout < 0""" if timeout < 0.0: raise ValueError('Invalid timeout.') with self._current_out_packet_mutex: with self._out_packet_mutex: if self._current_out_packet is None and len(self._out_packet) > 0: self._current_out_packet = self._out_packet.popleft() if self._current_out_packet: wlist = [self._sock] else: wlist = [] # used to check if there are any bytes left in the (SSL) socket pending_bytes = 0 if hasattr(self._sock, 'pending'): pending_bytes = self._sock.pending() # if bytes are pending do not wait in select if pending_bytes > 0: timeout = 0.0 # sockpairR is used to break out of select() before the timeout, on a # call to publish() etc. rlist = [self._sock, self._sockpairR] try: socklist = select.select(rlist, wlist, [], timeout) except TypeError: # Socket isn't correct type, in likelihood connection is lost return MQTT_ERR_CONN_LOST except ValueError: # Can occur if we just reconnected but rlist/wlist contain a -1 for # some reason. return MQTT_ERR_CONN_LOST except Exception: # Note that KeyboardInterrupt, etc. can still terminate since they # are not derived from Exception return MQTT_ERR_UNKNOWN if self._sock in socklist[0] or pending_bytes > 0: rc = self.loop_read(max_packets) if rc or self._sock is None: return rc if self._sockpairR in socklist[0]: # Stimulate output write even though we didn't ask for it, because # at that point the publish or other command wasn't present. socklist[1].insert(0, self._sock) # Clear sockpairR - only ever a single byte written. try: self._sockpairR.recv(1) except socket.error as err: if err.errno != EAGAIN: raise if self._sock in socklist[1]: rc = self.loop_write(max_packets) if rc or self._sock is None: return rc return self.loop_misc() def publish(self, topic, payload=None, qos=0, retain=False, properties=None): """Publish a message on a topic. This causes a message to be sent to the broker and subsequently from the broker to any clients subscribing to matching topics. topic: The topic that the message should be published on. payload: The actual message to send. If not given, or set to None a zero length message will be used. Passing an int or float will result in the payload being converted to a string representing that number. If you wish to send a true int/float, use struct.pack() to create the payload you require. qos: The quality of service level to use. retain: If set to true, the message will be set as the "last known good"/retained message for the topic. properties: (MQTT v5.0 only) the MQTT v5.0 properties to be included. Use the Properties class. Returns a MQTTMessageInfo class, which can be used to determine whether the message has been delivered (using info.is_published()) or to block waiting for the message to be delivered (info.wait_for_publish()). The message ID and return code of the publish() call can be found at info.mid and info.rc. For backwards compatibility, the MQTTMessageInfo class is iterable so the old construct of (rc, mid) = client.publish(...) is still valid. rc is MQTT_ERR_SUCCESS to indicate success or MQTT_ERR_NO_CONN if the client is not currently connected. mid is the message ID for the publish request. The mid value can be used to track the publish request by checking against the mid argument in the on_publish() callback if it is defined. A ValueError will be raised if topic is None, has zero length or is invalid (contains a wildcard), except if the MQTT version used is v5.0. For v5.0, a zero length topic can be used when a Topic Alias has been set. A ValueError will be raised if qos is not one of 0, 1 or 2, or if the length of the payload is greater than 268435455 bytes.""" if self._protocol != MQTTv5: if topic is None or len(topic) == 0: raise ValueError('Invalid topic.') topic = topic.encode('utf-8') if self._topic_wildcard_len_check(topic) != MQTT_ERR_SUCCESS: raise ValueError('Publish topic cannot contain wildcards.') if qos < 0 or qos > 2: raise ValueError('Invalid QoS level.') if isinstance(payload, unicode): local_payload = payload.encode('utf-8') elif isinstance(payload, (bytes, bytearray)): local_payload = payload elif isinstance(payload, (int, float)): local_payload = str(payload).encode('ascii') elif payload is None: local_payload = b'' else: raise TypeError( 'payload must be a string, bytearray, int, float or None.') if len(local_payload) > 268435455: raise ValueError('Payload too large.') local_mid = self._mid_generate() if qos == 0: info = MQTTMessageInfo(local_mid) rc = self._send_publish( local_mid, topic, local_payload, qos, retain, False, info, properties) info.rc = rc return info else: message = MQTTMessage(local_mid, topic) message.timestamp = time_func() message.payload = local_payload message.qos = qos message.retain = retain message.dup = False message.properties = properties with self._out_message_mutex: if self._max_queued_messages > 0 and len(self._out_messages) >= self._max_queued_messages: message.info.rc = MQTT_ERR_QUEUE_SIZE return message.info if local_mid in self._out_messages: message.info.rc = MQTT_ERR_QUEUE_SIZE return message.info self._out_messages[message.mid] = message if self._max_inflight_messages == 0 or self._inflight_messages < self._max_inflight_messages: self._inflight_messages += 1 if qos == 1: message.state = mqtt_ms_wait_for_puback elif qos == 2: message.state = mqtt_ms_wait_for_pubrec rc = self._send_publish(message.mid, topic, message.payload, message.qos, message.retain, message.dup, message.info, message.properties) # remove from inflight messages so it will be send after a connection is made if rc is MQTT_ERR_NO_CONN: self._inflight_messages -= 1 message.state = mqtt_ms_publish message.info.rc = rc return message.info else: message.state = mqtt_ms_queued message.info.rc = MQTT_ERR_SUCCESS return message.info def username_pw_set(self, username, password=None): """Set a username and optionally a password for broker authentication. Must be called before connect() to have any effect. Requires a broker that supports MQTT v3.1. username: The username to authenticate with. Need have no relationship to the client id. Must be unicode [MQTT-3.1.3-11]. Set to None to reset client back to not using username/password for broker authentication. password: The password to authenticate with. Optional, set to None if not required. If it is unicode, then it will be encoded as UTF-8. """ # [MQTT-3.1.3-11] User name must be UTF-8 encoded string self._username = None if username is None else username.encode('utf-8') self._password = password if isinstance(self._password, unicode): self._password = self._password.encode('utf-8') def enable_bridge_mode(self): """Sets the client in a bridge mode instead of client mode. Must be called before connect() to have any effect. Requires brokers that support bridge mode. Under bridge mode, the broker will identify the client as a bridge and not send it's own messages back to it. Hence a subsciption of # is possible without message loops. This feature also correctly propagates the retain flag on the messages. Currently Mosquitto and RSMB support this feature. This feature can be used to create a bridge between multiple broker. """ self._client_mode = MQTT_BRIDGE def is_connected(self): """Returns the current status of the connection True if connection exists False if connection is closed """ return self._state == mqtt_cs_connected def disconnect(self, reasoncode=None, properties=None): """Disconnect a connected client from the broker. reasoncode: (MQTT v5.0 only) a ReasonCodes instance setting the MQTT v5.0 reasoncode to be sent with the disconnect. It is optional, the receiver then assuming that 0 (success) is the value. properties: (MQTT v5.0 only) a Properties instance setting the MQTT v5.0 properties to be included. Optional - if not set, no properties are sent. """ self._state = mqtt_cs_disconnecting if self._sock is None: return MQTT_ERR_NO_CONN return self._send_disconnect(reasoncode, properties) def subscribe(self, topic, qos=0, options=None, properties=None): """Subscribe the client to one or more topics. This function may be called in three different ways (and a further three for MQTT v5.0): Simple string and integer ------------------------- e.g. subscribe("my/topic", 2) topic: A string specifying the subscription topic to subscribe to. qos: The desired quality of service level for the subscription. Defaults to 0. options and properties: Not used. Simple string and subscribe options (MQTT v5.0 only) ---------------------------------------------------- e.g. subscribe("my/topic", options=SubscribeOptions(qos=2)) topic: A string specifying the subscription topic to subscribe to. qos: Not used. options: The MQTT v5.0 subscribe options. properties: a Properties instance setting the MQTT v5.0 properties to be included. Optional - if not set, no properties are sent. String and integer tuple ------------------------ e.g. subscribe(("my/topic", 1)) topic: A tuple of (topic, qos). Both topic and qos must be present in the tuple. qos and options: Not used. properties: Only used for MQTT v5.0. A Properties instance setting the MQTT v5.0 properties. Optional - if not set, no properties are sent. String and subscribe options tuple (MQTT v5.0 only) --------------------------------------------------- e.g. subscribe(("my/topic", SubscribeOptions(qos=1))) topic: A tuple of (topic, SubscribeOptions). Both topic and subscribe options must be present in the tuple. qos and options: Not used. properties: a Properties instance setting the MQTT v5.0 properties to be included. Optional - if not set, no properties are sent. List of string and integer tuples --------------------------------- e.g. subscribe([("my/topic", 0), ("another/topic", 2)]) This allows multiple topic subscriptions in a single SUBSCRIPTION command, which is more efficient than using multiple calls to subscribe(). topic: A list of tuple of format (topic, qos). Both topic and qos must be present in all of the tuples. qos, options and properties: Not used. List of string and subscribe option tuples (MQTT v5.0 only) ----------------------------------------------------------- e.g. subscribe([("my/topic", SubscribeOptions(qos=0), ("another/topic", SubscribeOptions(qos=2)]) This allows multiple topic subscriptions in a single SUBSCRIPTION command, which is more efficient than using multiple calls to subscribe(). topic: A list of tuple of format (topic, SubscribeOptions). Both topic and subscribe options must be present in all of the tuples. qos and options: Not used. properties: a Properties instance setting the MQTT v5.0 properties to be included. Optional - if not set, no properties are sent. The function returns a tuple (result, mid), where result is MQTT_ERR_SUCCESS to indicate success or (MQTT_ERR_NO_CONN, None) if the client is not currently connected. mid is the message ID for the subscribe request. The mid value can be used to track the subscribe request by checking against the mid argument in the on_subscribe() callback if it is defined. Raises a ValueError if qos is not 0, 1 or 2, or if topic is None or has zero string length, or if topic is not a string, tuple or list. """ topic_qos_list = None if isinstance(topic, tuple): if self._protocol == MQTTv5: topic, options = topic if not isinstance(options, SubscribeOptions): raise ValueError( 'Subscribe options must be instance of SubscribeOptions class.') else: topic, qos = topic if isinstance(topic, basestring): if qos < 0 or qos > 2: raise ValueError('Invalid QoS level.') if self._protocol == MQTTv5: if options == None: # if no options are provided, use the QoS passed instead options = SubscribeOptions(qos=qos) elif qos != 0: raise ValueError( 'Subscribe options and qos parameters cannot be combined.') if not isinstance(options, SubscribeOptions): raise ValueError( 'Subscribe options must be instance of SubscribeOptions class.') topic_qos_list = [(topic.encode('utf-8'), options)] else: if topic is None or len(topic) == 0: raise ValueError('Invalid topic.') topic_qos_list = [(topic.encode('utf-8'), qos)] elif isinstance(topic, list): topic_qos_list = [] if self._protocol == MQTTv5: for t, o in topic: if not isinstance(o, SubscribeOptions): # then the second value should be QoS if o < 0 or o > 2: raise ValueError('Invalid QoS level.') o = SubscribeOptions(qos=o) topic_qos_list.append((t.encode('utf-8'), o)) else: for t, q in topic: if q < 0 or q > 2: raise ValueError('Invalid QoS level.') if t is None or len(t) == 0 or not isinstance(t, basestring): raise ValueError('Invalid topic.') topic_qos_list.append((t.encode('utf-8'), q)) if topic_qos_list is None: raise ValueError("No topic specified, or incorrect topic type.") if any(self._filter_wildcard_len_check(topic) != MQTT_ERR_SUCCESS for topic, _ in topic_qos_list): raise ValueError('Invalid subscription filter.') if self._sock is None: return (MQTT_ERR_NO_CONN, None) return self._send_subscribe(False, topic_qos_list, properties) def unsubscribe(self, topic, properties=None): """Unsubscribe the client from one or more topics. topic: A single string, or list of strings that are the subscription topics to unsubscribe from. properties: (MQTT v5.0 only) a Properties instance setting the MQTT v5.0 properties to be included. Optional - if not set, no properties are sent. Returns a tuple (result, mid), where result is MQTT_ERR_SUCCESS to indicate success or (MQTT_ERR_NO_CONN, None) if the client is not currently connected. mid is the message ID for the unsubscribe request. The mid value can be used to track the unsubscribe request by checking against the mid argument in the on_unsubscribe() callback if it is defined. Raises a ValueError if topic is None or has zero string length, or is not a string or list. """ topic_list = None if topic is None: raise ValueError('Invalid topic.') if isinstance(topic, basestring): if len(topic) == 0: raise ValueError('Invalid topic.') topic_list = [topic.encode('utf-8')] elif isinstance(topic, list): topic_list = [] for t in topic: if len(t) == 0 or not isinstance(t, basestring): raise ValueError('Invalid topic.') topic_list.append(t.encode('utf-8')) if topic_list is None: raise ValueError("No topic specified, or incorrect topic type.") if self._sock is None: return (MQTT_ERR_NO_CONN, None) return self._send_unsubscribe(False, topic_list, properties) def loop_read(self, max_packets=1): """Process read network events. Use in place of calling loop() if you wish to handle your client reads as part of your own application. Use socket() to obtain the client socket to call select() or equivalent on. Do not use if you are using the threaded interface loop_start().""" if self._sock is None: return MQTT_ERR_NO_CONN max_packets = len(self._out_messages) + len(self._in_messages) if max_packets < 1: max_packets = 1 for _ in range(0, max_packets): if self._sock is None: return MQTT_ERR_NO_CONN rc = self._packet_read() if rc > 0: return self._loop_rc_handle(rc) elif rc == MQTT_ERR_AGAIN: return MQTT_ERR_SUCCESS return MQTT_ERR_SUCCESS def loop_write(self, max_packets=1): """Process write network events. Use in place of calling loop() if you wish to handle your client writes as part of your own application. Use socket() to obtain the client socket to call select() or equivalent on. Use want_write() to determine if there is data waiting to be written. Do not use if you are using the threaded interface loop_start().""" if self._sock is None: return MQTT_ERR_NO_CONN max_packets = len(self._out_packet) + 1 if max_packets < 1: max_packets = 1 try: for _ in range(0, max_packets): rc = self._packet_write() if rc > 0: return self._loop_rc_handle(rc) elif rc == MQTT_ERR_AGAIN: return MQTT_ERR_SUCCESS return MQTT_ERR_SUCCESS finally: if self.want_write(): self._call_socket_register_write() else: self._call_socket_unregister_write() def want_write(self): """Call to determine if there is network data waiting to be written. Useful if you are calling select() yourself rather than using loop(). """ if self._current_out_packet or len(self._out_packet) > 0: return True else: return False def loop_misc(self): """Process miscellaneous network events. Use in place of calling loop() if you wish to call select() or equivalent on. Do not use if you are using the threaded interface loop_start().""" if self._sock is None: return MQTT_ERR_NO_CONN now = time_func() self._check_keepalive() if self._last_retry_check + 1 < now: # Only check once a second at most self._message_retry_check() self._last_retry_check = now if self._ping_t > 0 and now - self._ping_t >= self._keepalive: # client->ping_t != 0 means we are waiting for a pingresp. # This hasn't happened in the keepalive time so we should disconnect. self._sock_close() if self._state == mqtt_cs_disconnecting: rc = MQTT_ERR_SUCCESS else: rc = 1 self._do_on_disconnect(rc) return MQTT_ERR_CONN_LOST return MQTT_ERR_SUCCESS def max_inflight_messages_set(self, inflight): """Set the maximum number of messages with QoS>0 that can be part way through their network flow at once. Defaults to 20.""" if inflight < 0: raise ValueError('Invalid inflight.') self._max_inflight_messages = inflight def max_queued_messages_set(self, queue_size): """Set the maximum number of messages in the outgoing message queue. 0 means unlimited.""" if queue_size < 0: raise ValueError('Invalid queue size.') if not isinstance(queue_size, int): raise ValueError('Invalid type of queue size.') self._max_queued_messages = queue_size return self def message_retry_set(self, retry): """Set the timeout in seconds before a message with QoS>0 is retried. 20 seconds by default.""" if retry < 0: raise ValueError('Invalid retry.') self._message_retry = retry def user_data_set(self, userdata): """Set the user data variable passed to callbacks. May be any data type.""" self._userdata = userdata def will_set(self, topic, payload=None, qos=0, retain=False, properties=None): """Set a Will to be sent by the broker in case the client disconnects unexpectedly. This must be called before connect() to have any effect. topic: The topic that the will message should be published on. payload: The message to send as a will. If not given, or set to None a zero length message will be used as the will. Passing an int or float will result in the payload being converted to a string representing that number. If you wish to send a true int/float, use struct.pack() to create the payload you require. qos: The quality of service level to use for the will. retain: If set to true, the will message will be set as the "last known good"/retained message for the topic. properties: (MQTT v5.0 only) a Properties instance setting the MQTT v5.0 properties to be included with the will message. Optional - if not set, no properties are sent. Raises a ValueError if qos is not 0, 1 or 2, or if topic is None or has zero string length. """ if topic is None or len(topic) == 0: raise ValueError('Invalid topic.') if qos < 0 or qos > 2: raise ValueError('Invalid QoS level.') if properties != None and not isinstance(properties, Properties): raise ValueError( "The properties argument must be an instance of the Properties class.") if isinstance(payload, unicode): self._will_payload = payload.encode('utf-8') elif isinstance(payload, (bytes, bytearray)): self._will_payload = payload elif isinstance(payload, (int, float)): self._will_payload = str(payload).encode('ascii') elif payload is None: self._will_payload = b"" else: raise TypeError( 'payload must be a string, bytearray, int, float or None.') self._will = True self._will_topic = topic.encode('utf-8') self._will_qos = qos self._will_retain = retain self._will_properties = properties def will_clear(self): """ Removes a will that was previously configured with will_set(). Must be called before connect() to have any effect.""" self._will = False self._will_topic = b"" self._will_payload = b"" self._will_qos = 0 self._will_retain = False def socket(self): """Return the socket or ssl object for this client.""" return self._sock def loop_forever(self, timeout=1.0, max_packets=1, retry_first_connection=False): """This function call loop() for you in an infinite blocking loop. It is useful for the case where you only want to run the MQTT client loop in your program. loop_forever() will handle reconnecting for you. If you call disconnect() in a callback it will return. timeout: The time in seconds to wait for incoming/outgoing network traffic before timing out and returning. max_packets: Not currently used. retry_first_connection: Should the first connection attempt be retried on failure. Raises socket.error on first connection failures unless retry_first_connection=True """ run = True while run: if self._thread_terminate is True: break if self._state == mqtt_cs_connect_async: try: self.reconnect() except (socket.error, OSError, WebsocketConnectionError): if not retry_first_connection: raise self._easy_log( MQTT_LOG_DEBUG, "Connection failed, retrying") self._reconnect_wait() else: break while run: rc = MQTT_ERR_SUCCESS while rc == MQTT_ERR_SUCCESS: rc = self.loop(timeout, max_packets) # We don't need to worry about locking here, because we've # either called loop_forever() when in single threaded mode, or # in multi threaded mode when loop_stop() has been called and # so no other threads can access _current_out_packet, # _out_packet or _messages. if (self._thread_terminate is True and self._current_out_packet is None and len(self._out_packet) == 0 and len(self._out_messages) == 0): rc = 1 run = False def should_exit(): return self._state == mqtt_cs_disconnecting or run is False or self._thread_terminate is True if should_exit(): run = False else: self._reconnect_wait() if should_exit(): run = False else: try: self.reconnect() except (socket.error, OSError, WebsocketConnectionError): self._easy_log( MQTT_LOG_DEBUG, "Connection failed, retrying") return rc def loop_start(self): """This is part of the threaded client interface. Call this once to start a new thread to process network traffic. This provides an alternative to repeatedly calling loop() yourself. """ if self._thread is not None: return MQTT_ERR_INVAL self._thread_terminate = False self._thread = threading.Thread(target=self._thread_main) self._thread.daemon = True self._thread.start() def loop_stop(self, force=False): """This is part of the threaded client interface. Call this once to stop the network thread previously created with loop_start(). This call will block until the network thread finishes. The force parameter is currently ignored. """ if self._thread is None: return MQTT_ERR_INVAL self._thread_terminate = True if threading.current_thread() != self._thread: self._thread.join() self._thread = None @property def on_log(self): """If implemented, called when the client has log information. Defined to allow debugging.""" return self._on_log @on_log.setter def on_log(self, func): """ Define the logging callback implementation. Expected signature is: log_callback(client, userdata, level, buf) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() level: gives the severity of the message and will be one of MQTT_LOG_INFO, MQTT_LOG_NOTICE, MQTT_LOG_WARNING, MQTT_LOG_ERR, and MQTT_LOG_DEBUG. buf: the message itself """ self._on_log = func @property def on_connect(self): """If implemented, called when the broker responds to our connection request.""" return self._on_connect @on_connect.setter def on_connect(self, func): """ Define the connect callback implementation. Expected signature for MQTT v3.1 and v3.1.1 is: connect_callback(client, userdata, flags, rc, properties=None) and for MQTT v5.0: connect_callback(client, userdata, flags, reasonCode, properties) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() flags: response flags sent by the broker rc: the connection result reasonCode: the MQTT v5.0 reason code: an instance of the ReasonCode class. ReasonCode may be compared to interger. properties: the MQTT v5.0 properties returned from the broker. An instance of the Properties class. For MQTT v3.1 and v3.1.1 properties is not provided but for compatibility with MQTT v5.0, we recommand adding properties=None. flags is a dict that contains response flags from the broker: flags['session present'] - this flag is useful for clients that are using clean session set to 0 only. If a client with clean session=0, that reconnects to a broker that it has previously connected to, this flag indicates whether the broker still has the session information for the client. If 1, the session still exists. The value of rc indicates success or not: 0: Connection successful 1: Connection refused - incorrect protocol version 2: Connection refused - invalid client identifier 3: Connection refused - server unavailable 4: Connection refused - bad username or password 5: Connection refused - not authorised 6-255: Currently unused. """ with self._callback_mutex: self._on_connect = func @property def on_subscribe(self): """If implemented, called when the broker responds to a subscribe request.""" return self._on_subscribe @on_subscribe.setter def on_subscribe(self, func): """ Define the suscribe callback implementation. Expected signature for MQTT v3.1.1 and v3.1 is: subscribe_callback(client, userdata, mid, granted_qos, properties=None) and for MQTT v5.0: subscribe_callback(client, userdata, mid, reasonCodes, properties) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() mid: matches the mid variable returned from the corresponding subscribe() call. granted_qos: list of integers that give the QoS level the broker has granted for each of the different subscription requests. reasonCodes: the MQTT v5.0 reason codes received from the broker for each subscription. A list of ReasonCodes instances. properties: the MQTT v5.0 properties received from the broker. A list of Properties class instances. """ with self._callback_mutex: self._on_subscribe = func @property def on_message(self): """If implemented, called when a message has been received on a topic that the client subscribes to. This callback will be called for every message received. Use message_callback_add() to define multiple callbacks that will be called for specific topic filters.""" return self._on_message @on_message.setter def on_message(self, func): """ Define the message received callback implementation. Expected signature is: on_message_callback(client, userdata, message) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() message: an instance of MQTTMessage. This is a class with members topic, payload, qos, retain. """ with self._callback_mutex: self._on_message = func @property def on_publish(self): """If implemented, called when a message that was to be sent using the publish() call has completed transmission to the broker. For messages with QoS levels 1 and 2, this means that the appropriate handshakes have completed. For QoS 0, this simply means that the message has left the client. This callback is important because even if the publish() call returns success, it does not always mean that the message has been sent.""" return self._on_publish @on_publish.setter def on_publish(self, func): """ Define the published message callback implementation. Expected signature is: on_publish_callback(client, userdata, mid) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() mid: matches the mid variable returned from the corresponding publish() call, to allow outgoing messages to be tracked. """ with self._callback_mutex: self._on_publish = func @property def on_unsubscribe(self): """If implemented, called when the broker responds to an unsubscribe request.""" return self._on_unsubscribe @on_unsubscribe.setter def on_unsubscribe(self, func): """ Define the unsubscribe callback implementation. Expected signature for MQTT v3.1.1 and v3.1 is: unsubscribe_callback(client, userdata, mid) and for MQTT v5.0: unsubscribe_callback(client, userdata, mid, properties, reasonCodes) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() mid: matches the mid variable returned from the corresponding unsubscribe() call. properties: the MQTT v5.0 properties received from the broker. A list of Properties class instances. reasonCodes: the MQTT v5.0 reason codes received from the broker for each unsubscribe topic. A list of ReasonCodes instances """ with self._callback_mutex: self._on_unsubscribe = func @property def on_disconnect(self): """If implemented, called when the client disconnects from the broker. """ return self._on_disconnect @on_disconnect.setter def on_disconnect(self, func): """ Define the disconnect callback implementation. Expected signature for MQTT v3.1.1 and v3.1 is: disconnect_callback(client, userdata, rc) and for MQTT v5.0: disconnect_callback(client, userdata, reasonCode, properties) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() rc: the disconnection result The rc parameter indicates the disconnection state. If MQTT_ERR_SUCCESS (0), the callback was called in response to a disconnect() call. If any other value the disconnection was unexpected, such as might be caused by a network error. """ with self._callback_mutex: self._on_disconnect = func @property def on_socket_open(self): """If implemented, called just after the socket was opend.""" return self._on_socket_open @on_socket_open.setter def on_socket_open(self, func): """Define the socket_open callback implementation. This should be used to register the socket to an external event loop for reading. Expected signature is: socket_open_callback(client, userdata, socket) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() sock: the socket which was just opened. """ with self._callback_mutex: self._on_socket_open = func def _call_socket_open(self): """Call the socket_open callback with the just-opened socket""" with self._callback_mutex: if self.on_socket_open: with self._in_callback_mutex: try: self.on_socket_open(self, self._userdata, self._sock) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_socket_open: %s', err) if not self.suppress_exceptions: raise @property def on_socket_close(self): """If implemented, called just before the socket is closed.""" return self._on_socket_close @on_socket_close.setter def on_socket_close(self, func): """Define the socket_close callback implementation. This should be used to unregister the socket from an external event loop for reading. Expected signature is: socket_close_callback(client, userdata, socket) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() sock: the socket which is about to be closed. """ with self._callback_mutex: self._on_socket_close = func def _call_socket_close(self, sock): """Call the socket_close callback with the about-to-be-closed socket""" with self._callback_mutex: if self.on_socket_close: with self._in_callback_mutex: try: self.on_socket_close(self, self._userdata, sock) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_socket_close: %s', err) if not self.suppress_exceptions: raise @property def on_socket_register_write(self): """If implemented, called when the socket needs writing but can't.""" return self._on_socket_register_write @on_socket_register_write.setter def on_socket_register_write(self, func): """Define the socket_register_write callback implementation. This should be used to register the socket with an external event loop for writing. Expected signature is: socket_register_write_callback(client, userdata, socket) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() sock: the socket which should be registered for writing """ with self._callback_mutex: self._on_socket_register_write = func def _call_socket_register_write(self): """Call the socket_register_write callback with the unwritable socket""" if not self._sock or self._registered_write: return self._registered_write = True with self._callback_mutex: if self.on_socket_register_write: try: self.on_socket_register_write( self, self._userdata, self._sock) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_socket_register_write: %s', err) if not self.suppress_exceptions: raise @property def on_socket_unregister_write(self): """If implemented, called when the socket doesn't need writing anymore.""" return self._on_socket_unregister_write @on_socket_unregister_write.setter def on_socket_unregister_write(self, func): """Define the socket_unregister_write callback implementation. This should be used to unregister the socket from an external event loop for writing. Expected signature is: socket_unregister_write_callback(client, userdata, socket) client: the client instance for this callback userdata: the private user data as set in Client() or userdata_set() sock: the socket which should be unregistered for writing """ with self._callback_mutex: self._on_socket_unregister_write = func def _call_socket_unregister_write(self, sock=None): """Call the socket_unregister_write callback with the writable socket""" sock = sock or self._sock if not sock or not self._registered_write: return self._registered_write = False with self._callback_mutex: if self.on_socket_unregister_write: try: self.on_socket_unregister_write(self, self._userdata, sock) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_socket_unregister_write: %s', err) if not self.suppress_exceptions: raise def message_callback_add(self, sub, callback): """Register a message callback for a specific topic. Messages that match 'sub' will be passed to 'callback'. Any non-matching messages will be passed to the default on_message callback. Call multiple times with different 'sub' to define multiple topic specific callbacks. Topic specific callbacks may be removed with message_callback_remove().""" if callback is None or sub is None: raise ValueError("sub and callback must both be defined.") with self._callback_mutex: self._on_message_filtered[sub] = callback def message_callback_remove(self, sub): """Remove a message callback previously registered with message_callback_add().""" if sub is None: raise ValueError("sub must defined.") with self._callback_mutex: try: del self._on_message_filtered[sub] except KeyError: # no such subscription pass # ============================================================ # Private functions # ============================================================ def _loop_rc_handle(self, rc, properties=None): if rc: self._sock_close() if self._state == mqtt_cs_disconnecting: rc = MQTT_ERR_SUCCESS self._do_on_disconnect(rc, properties) return rc def _packet_read(self): # This gets called if pselect() indicates that there is network data # available - ie. at least one byte. What we do depends on what data we # already have. # If we've not got a command, attempt to read one and save it. This should # always work because it's only a single byte. # Then try to read the remaining length. This may fail because it is may # be more than one byte - will need to save data pending next read if it # does fail. # Then try to read the remaining payload, where 'payload' here means the # combined variable header and actual payload. This is the most likely to # fail due to longer length, so save current data and current position. # After all data is read, send to _mqtt_handle_packet() to deal with. # Finally, free the memory and reset everything to starting conditions. if self._in_packet['command'] == 0: try: command = self._sock_recv(1) except WouldBlockError: return MQTT_ERR_AGAIN except socket.error as err: self._easy_log( MQTT_LOG_ERR, 'failed to receive on socket: %s', err) return 1 else: if len(command) == 0: return 1 command, = struct.unpack("!B", command) self._in_packet['command'] = command if self._in_packet['have_remaining'] == 0: # Read remaining # Algorithm for decoding taken from pseudo code at # http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/topic/com.ibm.etools.mft.doc/ac10870_.htm while True: try: byte = self._sock_recv(1) except WouldBlockError: return MQTT_ERR_AGAIN except socket.error as err: self._easy_log( MQTT_LOG_ERR, 'failed to receive on socket: %s', err) return 1 else: if len(byte) == 0: return 1 byte, = struct.unpack("!B", byte) self._in_packet['remaining_count'].append(byte) # Max 4 bytes length for remaining length as defined by protocol. # Anything more likely means a broken/malicious client. if len(self._in_packet['remaining_count']) > 4: return MQTT_ERR_PROTOCOL self._in_packet['remaining_length'] += ( byte & 127) * self._in_packet['remaining_mult'] self._in_packet['remaining_mult'] = self._in_packet['remaining_mult'] * 128 if (byte & 128) == 0: break self._in_packet['have_remaining'] = 1 self._in_packet['to_process'] = self._in_packet['remaining_length'] while self._in_packet['to_process'] > 0: try: data = self._sock_recv(self._in_packet['to_process']) except WouldBlockError: return MQTT_ERR_AGAIN except socket.error as err: self._easy_log( MQTT_LOG_ERR, 'failed to receive on socket: %s', err) return 1 else: if len(data) == 0: return 1 self._in_packet['to_process'] -= len(data) self._in_packet['packet'] += data # All data for this packet is read. self._in_packet['pos'] = 0 rc = self._packet_handle() # Free data and reset values self._in_packet = { 'command': 0, 'have_remaining': 0, 'remaining_count': [], 'remaining_mult': 1, 'remaining_length': 0, 'packet': b"", 'to_process': 0, 'pos': 0} with self._msgtime_mutex: self._last_msg_in = time_func() return rc def _packet_write(self): self._current_out_packet_mutex.acquire() while self._current_out_packet: packet = self._current_out_packet try: write_length = self._sock_send( packet['packet'][packet['pos']:]) except (AttributeError, ValueError): self._current_out_packet_mutex.release() return MQTT_ERR_SUCCESS except WouldBlockError: self._current_out_packet_mutex.release() return MQTT_ERR_AGAIN except socket.error as err: self._current_out_packet_mutex.release() self._easy_log( MQTT_LOG_ERR, 'failed to receive on socket: %s', err) return 1 if write_length > 0: packet['to_process'] -= write_length packet['pos'] += write_length if packet['to_process'] == 0: if (packet['command'] & 0xF0) == PUBLISH and packet['qos'] == 0: with self._callback_mutex: if self.on_publish: with self._in_callback_mutex: try: self.on_publish( self, self._userdata, packet['mid']) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_publish: %s', err) if not self.suppress_exceptions: raise packet['info']._set_as_published() if (packet['command'] & 0xF0) == DISCONNECT: self._current_out_packet_mutex.release() with self._msgtime_mutex: self._last_msg_out = time_func() self._do_on_disconnect(0) self._sock_close() return MQTT_ERR_SUCCESS with self._out_packet_mutex: if len(self._out_packet) > 0: self._current_out_packet = self._out_packet.popleft() else: self._current_out_packet = None else: break self._current_out_packet_mutex.release() with self._msgtime_mutex: self._last_msg_out = time_func() return MQTT_ERR_SUCCESS def _easy_log(self, level, fmt, *args): if self.on_log is not None: buf = fmt % args try: self.on_log(self, self._userdata, level, buf) except Exception: # Can't _easy_log this, as we'll recurse until we break pass # self._logger will pick this up, so we're fine if self._logger is not None: level_std = LOGGING_LEVEL[level] self._logger.log(level_std, fmt, *args) def _check_keepalive(self): if self._keepalive == 0: return MQTT_ERR_SUCCESS now = time_func() with self._msgtime_mutex: last_msg_out = self._last_msg_out last_msg_in = self._last_msg_in if self._sock is not None and (now - last_msg_out >= self._keepalive or now - last_msg_in >= self._keepalive): if self._state == mqtt_cs_connected and self._ping_t == 0: self._send_pingreq() with self._msgtime_mutex: self._last_msg_out = now self._last_msg_in = now else: self._sock_close() if self._state == mqtt_cs_disconnecting: rc = MQTT_ERR_SUCCESS else: rc = 1 self._do_on_disconnect(rc) def _mid_generate(self): with self._mid_generate_mutex: self._last_mid += 1 if self._last_mid == 65536: self._last_mid = 1 return self._last_mid @staticmethod def _topic_wildcard_len_check(topic): # Search for + or # in a topic. Return MQTT_ERR_INVAL if found. # Also returns MQTT_ERR_INVAL if the topic string is too long. # Returns MQTT_ERR_SUCCESS if everything is fine. if b'+' in topic or b'#' in topic or len(topic) > 65535: return MQTT_ERR_INVAL else: return MQTT_ERR_SUCCESS @staticmethod def _filter_wildcard_len_check(sub): if (len(sub) == 0 or len(sub) > 65535 or any(b'+' in p or b'#' in p for p in sub.split(b'/') if len(p) > 1) or b'#/' in sub): return MQTT_ERR_INVAL else: return MQTT_ERR_SUCCESS def _send_pingreq(self): self._easy_log(MQTT_LOG_DEBUG, "Sending PINGREQ") rc = self._send_simple_command(PINGREQ) if rc == MQTT_ERR_SUCCESS: self._ping_t = time_func() return rc def _send_pingresp(self): self._easy_log(MQTT_LOG_DEBUG, "Sending PINGRESP") return self._send_simple_command(PINGRESP) def _send_puback(self, mid): self._easy_log(MQTT_LOG_DEBUG, "Sending PUBACK (Mid: %d)", mid) return self._send_command_with_mid(PUBACK, mid, False) def _send_pubcomp(self, mid): self._easy_log(MQTT_LOG_DEBUG, "Sending PUBCOMP (Mid: %d)", mid) return self._send_command_with_mid(PUBCOMP, mid, False) def _pack_remaining_length(self, packet, remaining_length): remaining_bytes = [] while True: byte = remaining_length % 128 remaining_length = remaining_length // 128 # If there are more digits to encode, set the top bit of this digit if remaining_length > 0: byte |= 0x80 remaining_bytes.append(byte) packet.append(byte) if remaining_length == 0: # FIXME - this doesn't deal with incorrectly large payloads return packet def _pack_str16(self, packet, data): if isinstance(data, unicode): data = data.encode('utf-8') packet.extend(struct.pack("!H", len(data))) packet.extend(data) def _send_publish(self, mid, topic, payload=b'', qos=0, retain=False, dup=False, info=None, properties=None): # we assume that topic and payload are already properly encoded assert not isinstance(topic, unicode) and not isinstance( payload, unicode) and payload is not None if self._sock is None: return MQTT_ERR_NO_CONN command = PUBLISH | ((dup & 0x1) << 3) | (qos << 1) | retain packet = bytearray() packet.append(command) payloadlen = len(payload) remaining_length = 2 + len(topic) + payloadlen if payloadlen == 0: if self._protocol == MQTTv5: self._easy_log( MQTT_LOG_DEBUG, "Sending PUBLISH (d%d, q%d, r%d, m%d), '%s', properties=%s (NULL payload)", dup, qos, retain, mid, topic, properties ) else: self._easy_log( MQTT_LOG_DEBUG, "Sending PUBLISH (d%d, q%d, r%d, m%d), '%s' (NULL payload)", dup, qos, retain, mid, topic ) else: if self._protocol == MQTTv5: self._easy_log( MQTT_LOG_DEBUG, "Sending PUBLISH (d%d, q%d, r%d, m%d), '%s', properties=%s, ... (%d bytes)", dup, qos, retain, mid, topic, properties, payloadlen ) else: self._easy_log( MQTT_LOG_DEBUG, "Sending PUBLISH (d%d, q%d, r%d, m%d), '%s', ... (%d bytes)", dup, qos, retain, mid, topic, payloadlen ) if qos > 0: # For message id remaining_length += 2 if self._protocol == MQTTv5: if properties == None: packed_properties = b'\x00' else: packed_properties = properties.pack() remaining_length += len(packed_properties) self._pack_remaining_length(packet, remaining_length) self._pack_str16(packet, topic) if qos > 0: # For message id packet.extend(struct.pack("!H", mid)) if self._protocol == MQTTv5: packet.extend(packed_properties) packet.extend(payload) return self._packet_queue(PUBLISH, packet, mid, qos, info) def _send_pubrec(self, mid): self._easy_log(MQTT_LOG_DEBUG, "Sending PUBREC (Mid: %d)", mid) return self._send_command_with_mid(PUBREC, mid, False) def _send_pubrel(self, mid): self._easy_log(MQTT_LOG_DEBUG, "Sending PUBREL (Mid: %d)", mid) return self._send_command_with_mid(PUBREL | 2, mid, False) def _send_command_with_mid(self, command, mid, dup): # For PUBACK, PUBCOMP, PUBREC, and PUBREL if dup: command |= 0x8 remaining_length = 2 packet = struct.pack('!BBH', command, remaining_length, mid) return self._packet_queue(command, packet, mid, 1) def _send_simple_command(self, command): # For DISCONNECT, PINGREQ and PINGRESP remaining_length = 0 packet = struct.pack('!BB', command, remaining_length) return self._packet_queue(command, packet, 0, 0) def _send_connect(self, keepalive): proto_ver = self._protocol # hard-coded UTF-8 encoded string protocol = b"MQTT" if proto_ver >= MQTTv311 else b"MQIsdp" remaining_length = 2 + len(protocol) + 1 + \ 1 + 2 + 2 + len(self._client_id) connect_flags = 0 if self._protocol == MQTTv5: if self._clean_start == True: connect_flags |= 0x02 elif self._clean_start == MQTT_CLEAN_START_FIRST_ONLY and self._mqttv5_first_connect: connect_flags |= 0x02 elif self._clean_session: connect_flags |= 0x02 if self._will: remaining_length += 2 + \ len(self._will_topic) + 2 + len(self._will_payload) connect_flags |= 0x04 | ((self._will_qos & 0x03) << 3) | ( (self._will_retain & 0x01) << 5) if self._username is not None: remaining_length += 2 + len(self._username) connect_flags |= 0x80 if self._password is not None: connect_flags |= 0x40 remaining_length += 2 + len(self._password) if self._protocol == MQTTv5: if self._connect_properties == None: packed_connect_properties = b'\x00' else: packed_connect_properties = self._connect_properties.pack() remaining_length += len(packed_connect_properties) if self._will: if self._will_properties == None: packed_will_properties = b'\x00' else: packed_will_properties = self._will_properties.pack() remaining_length += len(packed_will_properties) command = CONNECT packet = bytearray() packet.append(command) # as per the mosquitto broker, if the MSB of this version is set # to 1, then it treats the connection as a bridge if self._client_mode == MQTT_BRIDGE: proto_ver |= 0x80 self._pack_remaining_length(packet, remaining_length) packet.extend(struct.pack("!H" + str(len(protocol)) + "sBBH", len(protocol), protocol, proto_ver, connect_flags, keepalive)) if self._protocol == MQTTv5: packet += packed_connect_properties self._pack_str16(packet, self._client_id) if self._will: if self._protocol == MQTTv5: packet += packed_will_properties self._pack_str16(packet, self._will_topic) self._pack_str16(packet, self._will_payload) if self._username is not None: self._pack_str16(packet, self._username) if self._password is not None: self._pack_str16(packet, self._password) self._keepalive = keepalive if self._protocol == MQTTv5: self._easy_log( MQTT_LOG_DEBUG, "Sending CONNECT (u%d, p%d, wr%d, wq%d, wf%d, c%d, k%d) client_id=%s properties=%s", (connect_flags & 0x80) >> 7, (connect_flags & 0x40) >> 6, (connect_flags & 0x20) >> 5, (connect_flags & 0x18) >> 3, (connect_flags & 0x4) >> 2, (connect_flags & 0x2) >> 1, keepalive, self._client_id, self._connect_properties ) else: self._easy_log( MQTT_LOG_DEBUG, "Sending CONNECT (u%d, p%d, wr%d, wq%d, wf%d, c%d, k%d) client_id=%s", (connect_flags & 0x80) >> 7, (connect_flags & 0x40) >> 6, (connect_flags & 0x20) >> 5, (connect_flags & 0x18) >> 3, (connect_flags & 0x4) >> 2, (connect_flags & 0x2) >> 1, keepalive, self._client_id ) return self._packet_queue(command, packet, 0, 0) def _send_disconnect(self, reasoncode=None, properties=None): if self._protocol == MQTTv5: self._easy_log(MQTT_LOG_DEBUG, "Sending DISCONNECT reasonCode=%s properties=%s", reasoncode, properties ) else: self._easy_log(MQTT_LOG_DEBUG, "Sending DISCONNECT") remaining_length = 0 command = DISCONNECT packet = bytearray() packet.append(command) if self._protocol == MQTTv5: if properties != None or reasoncode != None: if reasoncode == None: reasoncode = ReasonCodes(DISCONNECT >> 4, identifier=0) remaining_length += 1 if properties != None: packed_props = properties.pack() remaining_length += len(packed_props) self._pack_remaining_length(packet, remaining_length) if self._protocol == MQTTv5: if reasoncode != None: packet += reasoncode.pack() if properties != None: packet += packed_props return self._packet_queue(command, packet, 0, 0) def _send_subscribe(self, dup, topics, properties=None): remaining_length = 2 if self._protocol == MQTTv5: if properties == None: packed_subscribe_properties = b'\x00' else: packed_subscribe_properties = properties.pack() remaining_length += len(packed_subscribe_properties) for t, _ in topics: remaining_length += 2 + len(t) + 1 command = SUBSCRIBE | (dup << 3) | 0x2 packet = bytearray() packet.append(command) self._pack_remaining_length(packet, remaining_length) local_mid = self._mid_generate() packet.extend(struct.pack("!H", local_mid)) if self._protocol == MQTTv5: packet += packed_subscribe_properties for t, q in topics: self._pack_str16(packet, t) if self._protocol == MQTTv5: packet += q.pack() else: packet.append(q) self._easy_log( MQTT_LOG_DEBUG, "Sending SUBSCRIBE (d%d, m%d) %s", dup, local_mid, topics, ) return (self._packet_queue(command, packet, local_mid, 1), local_mid) def _send_unsubscribe(self, dup, topics, properties=None): remaining_length = 2 if self._protocol == MQTTv5: if properties == None: packed_unsubscribe_properties = b'\x00' else: packed_unsubscribe_properties = properties.pack() remaining_length += len(packed_unsubscribe_properties) for t in topics: remaining_length += 2 + len(t) command = UNSUBSCRIBE | (dup << 3) | 0x2 packet = bytearray() packet.append(command) self._pack_remaining_length(packet, remaining_length) local_mid = self._mid_generate() packet.extend(struct.pack("!H", local_mid)) if self._protocol == MQTTv5: packet += packed_unsubscribe_properties for t in topics: self._pack_str16(packet, t) # topics_repr = ", ".join("'"+topic.decode('utf8')+"'" for topic in topics) if self._protocol == MQTTv5: self._easy_log( MQTT_LOG_DEBUG, "Sending UNSUBSCRIBE (d%d, m%d) %s %s", dup, local_mid, properties, topics, ) else: self._easy_log( MQTT_LOG_DEBUG, "Sending UNSUBSCRIBE (d%d, m%d) %s", dup, local_mid, topics, ) return (self._packet_queue(command, packet, local_mid, 1), local_mid) def _message_retry_check_actual(self, messages, mutex): with mutex: now = time_func() for m in messages.values(): if m.timestamp + self._message_retry < now: if m.state == mqtt_ms_wait_for_puback or m.state == mqtt_ms_wait_for_pubrec: m.timestamp = now m.dup = True self._send_publish( m.mid, m.topic.encode('utf-8'), m.payload, m.qos, m.retain, m.dup, properties=m.properties, ) elif m.state == mqtt_ms_wait_for_pubrel: m.timestamp = now self._send_pubrec(m.mid) elif m.state == mqtt_ms_wait_for_pubcomp: m.timestamp = now self._send_pubrel(m.mid) def _message_retry_check(self): self._message_retry_check_actual( self._out_messages, self._out_message_mutex) self._message_retry_check_actual( self._in_messages, self._in_message_mutex) def _check_clean_session(self): if self._protocol == MQTTv5: if self._clean_start == MQTT_CLEAN_START_FIRST_ONLY: return self._mqttv5_first_connect else: return self._clean_start else: return self._clean_session def _messages_reconnect_reset_out(self): with self._out_message_mutex: self._inflight_messages = 0 for m in self._out_messages.values(): m.timestamp = 0 if self._max_inflight_messages == 0 or self._inflight_messages < self._max_inflight_messages: if m.qos == 0: m.state = mqtt_ms_publish elif m.qos == 1: # self._inflight_messages = self._inflight_messages + 1 if m.state == mqtt_ms_wait_for_puback: m.dup = True m.state = mqtt_ms_publish elif m.qos == 2: # self._inflight_messages = self._inflight_messages + 1 if self._check_clean_session(): if m.state != mqtt_ms_publish: m.dup = True m.state = mqtt_ms_publish else: if m.state == mqtt_ms_wait_for_pubcomp: m.state = mqtt_ms_resend_pubrel else: if m.state == mqtt_ms_wait_for_pubrec: m.dup = True m.state = mqtt_ms_publish else: m.state = mqtt_ms_queued def _messages_reconnect_reset_in(self): with self._in_message_mutex: if self._check_clean_session(): self._in_messages = collections.OrderedDict() return for m in self._in_messages.values(): m.timestamp = 0 if m.qos != 2: self._in_messages.pop(m.mid) else: # Preserve current state pass def _messages_reconnect_reset(self): self._messages_reconnect_reset_out() self._messages_reconnect_reset_in() def _packet_queue(self, command, packet, mid, qos, info=None): mpkt = { 'command': command, 'mid': mid, 'qos': qos, 'pos': 0, 'to_process': len(packet), 'packet': packet, 'info': info} with self._out_packet_mutex: self._out_packet.append(mpkt) if self._current_out_packet_mutex.acquire(False): if self._current_out_packet is None and len(self._out_packet) > 0: self._current_out_packet = self._out_packet.popleft() self._current_out_packet_mutex.release() # Write a single byte to sockpairW (connected to sockpairR) to break # out of select() if in threaded mode. try: self._sockpairW.send(sockpair_data) except socket.error as err: if err.errno != EAGAIN: raise if self._thread is None: if self._in_callback_mutex.acquire(False): self._in_callback_mutex.release() return self.loop_write() self._call_socket_register_write() return MQTT_ERR_SUCCESS def _packet_handle(self): cmd = self._in_packet['command'] & 0xF0 if cmd == PINGREQ: return self._handle_pingreq() elif cmd == PINGRESP: return self._handle_pingresp() elif cmd == PUBACK: return self._handle_pubackcomp("PUBACK") elif cmd == PUBCOMP: return self._handle_pubackcomp("PUBCOMP") elif cmd == PUBLISH: return self._handle_publish() elif cmd == PUBREC: return self._handle_pubrec() elif cmd == PUBREL: return self._handle_pubrel() elif cmd == CONNACK: return self._handle_connack() elif cmd == SUBACK: return self._handle_suback() elif cmd == UNSUBACK: return self._handle_unsuback() elif cmd == DISCONNECT and self._protocol == MQTTv5: # only allowed in MQTT 5.0 return self._handle_disconnect() else: # If we don't recognise the command, return an error straight away. self._easy_log(MQTT_LOG_ERR, "Error: Unrecognised command %s", cmd) return MQTT_ERR_PROTOCOL def _handle_pingreq(self): if self._in_packet['remaining_length'] != 0: return MQTT_ERR_PROTOCOL self._easy_log(MQTT_LOG_DEBUG, "Received PINGREQ") return self._send_pingresp() def _handle_pingresp(self): if self._in_packet['remaining_length'] != 0: return MQTT_ERR_PROTOCOL # No longer waiting for a PINGRESP. self._ping_t = 0 self._easy_log(MQTT_LOG_DEBUG, "Received PINGRESP") return MQTT_ERR_SUCCESS def _handle_connack(self): if self._protocol == MQTTv5: if self._in_packet['remaining_length'] < 2: return MQTT_ERR_PROTOCOL elif self._in_packet['remaining_length'] != 2: return MQTT_ERR_PROTOCOL if self._protocol == MQTTv5: (flags, result) = struct.unpack( "!BB", self._in_packet['packet'][:2]) reason = ReasonCodes(CONNACK >> 4, identifier=result) properties = Properties(CONNACK >> 4) properties.unpack(self._in_packet['packet'][2:]) else: (flags, result) = struct.unpack("!BB", self._in_packet['packet']) if self._protocol == MQTTv311: if result == CONNACK_REFUSED_PROTOCOL_VERSION: self._easy_log( MQTT_LOG_DEBUG, "Received CONNACK (%s, %s), attempting downgrade to MQTT v3.1.", flags, result ) # Downgrade to MQTT v3.1 self._protocol = MQTTv31 return self.reconnect() elif (result == CONNACK_REFUSED_IDENTIFIER_REJECTED and self._client_id == b''): self._easy_log( MQTT_LOG_DEBUG, "Received CONNACK (%s, %s), attempting to use non-empty CID", flags, result, ) self._client_id = base62(uuid.uuid4().int, padding=22) return self.reconnect() if result == 0: self._state = mqtt_cs_connected self._reconnect_delay = None if self._protocol == MQTTv5: self._easy_log( MQTT_LOG_DEBUG, "Received CONNACK (%s, %s) properties=%s", flags, reason, properties) else: self._easy_log( MQTT_LOG_DEBUG, "Received CONNACK (%s, %s)", flags, result) # it won't be the first successful connect any more self._mqttv5_first_connect = False with self._callback_mutex: if self.on_connect: flags_dict = {} flags_dict['session present'] = flags & 0x01 with self._in_callback_mutex: try: if self._protocol == MQTTv5: self.on_connect(self, self._userdata, flags_dict, reason, properties) else: self.on_connect( self, self._userdata, flags_dict, result) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_connect: %s', err) if not self.suppress_exceptions: raise if result == 0: rc = 0 with self._out_message_mutex: for m in self._out_messages.values(): m.timestamp = time_func() if m.state == mqtt_ms_queued: self.loop_write() # Process outgoing messages that have just been queued up return MQTT_ERR_SUCCESS if m.qos == 0: with self._in_callback_mutex: # Don't call loop_write after _send_publish() rc = self._send_publish( m.mid, m.topic.encode('utf-8'), m.payload, m.qos, m.retain, m.dup, properties=m.properties ) if rc != 0: return rc elif m.qos == 1: if m.state == mqtt_ms_publish: self._inflight_messages += 1 m.state = mqtt_ms_wait_for_puback with self._in_callback_mutex: # Don't call loop_write after _send_publish() rc = self._send_publish( m.mid, m.topic.encode('utf-8'), m.payload, m.qos, m.retain, m.dup, properties=m.properties ) if rc != 0: return rc elif m.qos == 2: if m.state == mqtt_ms_publish: self._inflight_messages += 1 m.state = mqtt_ms_wait_for_pubrec with self._in_callback_mutex: # Don't call loop_write after _send_publish() rc = self._send_publish( m.mid, m.topic.encode('utf-8'), m.payload, m.qos, m.retain, m.dup, properties=m.properties ) if rc != 0: return rc elif m.state == mqtt_ms_resend_pubrel: self._inflight_messages += 1 m.state = mqtt_ms_wait_for_pubcomp with self._in_callback_mutex: # Don't call loop_write after _send_publish() rc = self._send_pubrel(m.mid) if rc != 0: return rc self.loop_write() # Process outgoing messages that have just been queued up return rc elif result > 0 and result < 6: return MQTT_ERR_CONN_REFUSED else: return MQTT_ERR_PROTOCOL def _handle_disconnect(self): packet_type = DISCONNECT >> 4 reasonCode = properties = None if self._in_packet['remaining_length'] > 2: reasonCode = ReasonCodes(packet_type) reasonCode.unpack(self._in_packet['packet']) if self._in_packet['remaining_length'] > 3: properties = Properties(packet_type) props, props_len = properties.unpack( self._in_packet['packet'][1:]) self._easy_log(MQTT_LOG_DEBUG, "Received DISCONNECT %s %s", reasonCode, properties ) self._loop_rc_handle(reasonCode, properties) return MQTT_ERR_SUCCESS def _handle_suback(self): self._easy_log(MQTT_LOG_DEBUG, "Received SUBACK") pack_format = "!H" + str(len(self._in_packet['packet']) - 2) + 's' (mid, packet) = struct.unpack(pack_format, self._in_packet['packet']) if self._protocol == MQTTv5: properties = Properties(SUBACK >> 4) props, props_len = properties.unpack(packet) reasoncodes = [] for c in packet[props_len:]: if sys.version_info[0] < 3: c = ord(c) reasoncodes.append(ReasonCodes(SUBACK >> 4, identifier=c)) else: pack_format = "!" + "B" * len(packet) granted_qos = struct.unpack(pack_format, packet) with self._callback_mutex: if self.on_subscribe: with self._in_callback_mutex: # Don't call loop_write after _send_publish() try: if self._protocol == MQTTv5: self.on_subscribe( self, self._userdata, mid, reasoncodes, properties) else: self.on_subscribe( self, self._userdata, mid, granted_qos) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_subscribe: %s', err) if not self.suppress_exceptions: raise return MQTT_ERR_SUCCESS def _handle_publish(self): rc = 0 header = self._in_packet['command'] message = MQTTMessage() message.dup = (header & 0x08) >> 3 message.qos = (header & 0x06) >> 1 message.retain = (header & 0x01) pack_format = "!H" + str(len(self._in_packet['packet']) - 2) + 's' (slen, packet) = struct.unpack(pack_format, self._in_packet['packet']) pack_format = '!' + str(slen) + 's' + str(len(packet) - slen) + 's' (topic, packet) = struct.unpack(pack_format, packet) if self._protocol != MQTTv5 and len(topic) == 0: return MQTT_ERR_PROTOCOL # Handle topics with invalid UTF-8 # This replaces an invalid topic with a message and the hex # representation of the topic for logging. When the user attempts to # access message.topic in the callback, an exception will be raised. try: print_topic = topic.decode('utf-8') except UnicodeDecodeError: print_topic = "TOPIC WITH INVALID UTF-8: " + str(topic) message.topic = topic if message.qos > 0: pack_format = "!H" + str(len(packet) - 2) + 's' (message.mid, packet) = struct.unpack(pack_format, packet) if self._protocol == MQTTv5: message.properties = Properties(PUBLISH >> 4) props, props_len = message.properties.unpack(packet) packet = packet[props_len:] message.payload = packet if self._protocol == MQTTv5: self._easy_log( MQTT_LOG_DEBUG, "Received PUBLISH (d%d, q%d, r%d, m%d), '%s', properties=%s, ... (%d bytes)", message.dup, message.qos, message.retain, message.mid, print_topic, message.properties, len(message.payload) ) else: self._easy_log( MQTT_LOG_DEBUG, "Received PUBLISH (d%d, q%d, r%d, m%d), '%s', ... (%d bytes)", message.dup, message.qos, message.retain, message.mid, print_topic, len(message.payload) ) message.timestamp = time_func() if message.qos == 0: self._handle_on_message(message) return MQTT_ERR_SUCCESS elif message.qos == 1: rc = self._send_puback(message.mid) self._handle_on_message(message) return rc elif message.qos == 2: rc = self._send_pubrec(message.mid) message.state = mqtt_ms_wait_for_pubrel with self._in_message_mutex: self._in_messages[message.mid] = message return rc else: return MQTT_ERR_PROTOCOL def _handle_pubrel(self): if self._protocol == MQTTv5: if self._in_packet['remaining_length'] < 2: return MQTT_ERR_PROTOCOL elif self._in_packet['remaining_length'] != 2: return MQTT_ERR_PROTOCOL mid, = struct.unpack("!H", self._in_packet['packet']) self._easy_log(MQTT_LOG_DEBUG, "Received PUBREL (Mid: %d)", mid) with self._in_message_mutex: if mid in self._in_messages: # Only pass the message on if we have removed it from the queue - this # prevents multiple callbacks for the same message. message = self._in_messages.pop(mid) self._handle_on_message(message) self._inflight_messages -= 1 if self._max_inflight_messages > 0: with self._out_message_mutex: rc = self._update_inflight() if rc != MQTT_ERR_SUCCESS: return rc # FIXME: this should only be done if the message is known # If unknown it's a protocol error and we should close the connection. # But since we don't have (on disk) persistence for the session, it # is possible that we must known about this message. # Choose to acknwoledge this messsage (and thus losing a message) but # avoid hanging. See #284. return self._send_pubcomp(mid) def _update_inflight(self): # Dont lock message_mutex here for m in self._out_messages.values(): if self._inflight_messages < self._max_inflight_messages: if m.qos > 0 and m.state == mqtt_ms_queued: self._inflight_messages += 1 if m.qos == 1: m.state = mqtt_ms_wait_for_puback elif m.qos == 2: m.state = mqtt_ms_wait_for_pubrec rc = self._send_publish( m.mid, m.topic.encode('utf-8'), m.payload, m.qos, m.retain, m.dup, properties=m.properties, ) if rc != 0: return rc else: return MQTT_ERR_SUCCESS return MQTT_ERR_SUCCESS def _handle_pubrec(self): if self._protocol == MQTTv5: if self._in_packet['remaining_length'] < 2: return MQTT_ERR_PROTOCOL elif self._in_packet['remaining_length'] != 2: return MQTT_ERR_PROTOCOL mid, = struct.unpack("!H", self._in_packet['packet'][:2]) if self._protocol == MQTTv5: if self._in_packet['remaining_length'] > 2: reasonCode = ReasonCodes(PUBREC >> 4) reasonCode.unpack(self._in_packet['packet'][2:]) if self._in_packet['remaining_length'] > 3: properties = Properties(PUBREC >> 4) props, props_len = properties.unpack( self._in_packet['packet'][3:]) self._easy_log(MQTT_LOG_DEBUG, "Received PUBREC (Mid: %d)", mid) with self._out_message_mutex: if mid in self._out_messages: msg = self._out_messages[mid] msg.state = mqtt_ms_wait_for_pubcomp msg.timestamp = time_func() return self._send_pubrel(mid) return MQTT_ERR_SUCCESS def _handle_unsuback(self): if self._protocol == MQTTv5: if self._in_packet['remaining_length'] < 4: return MQTT_ERR_PROTOCOL elif self._in_packet['remaining_length'] != 2: return MQTT_ERR_PROTOCOL mid, = struct.unpack("!H", self._in_packet['packet'][:2]) if self._protocol == MQTTv5: packet = self._in_packet['packet'][2:] properties = Properties(UNSUBACK >> 4) props, props_len = properties.unpack(packet) reasoncodes = [] for c in packet[props_len:]: if sys.version_info[0] < 3: c = ord(c) reasoncodes.append(ReasonCodes(UNSUBACK >> 4, identifier=c)) if len(reasoncodes) == 1: reasoncodes = reasoncodes[0] self._easy_log(MQTT_LOG_DEBUG, "Received UNSUBACK (Mid: %d)", mid) with self._callback_mutex: if self.on_unsubscribe: with self._in_callback_mutex: try: if self._protocol == MQTTv5: self.on_unsubscribe( self, self._userdata, mid, properties, reasoncodes) else: self.on_unsubscribe(self, self._userdata, mid) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_unsubscribe: %s', err) if not self.suppress_exceptions: raise return MQTT_ERR_SUCCESS def _do_on_disconnect(self, rc, properties=None): with self._callback_mutex: if self.on_disconnect: with self._in_callback_mutex: try: if properties: self.on_disconnect( self, self._userdata, rc, properties) else: self.on_disconnect(self, self._userdata, rc) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_disconnect: %s', err) if not self.suppress_exceptions: raise def _do_on_publish(self, mid): with self._callback_mutex: if self.on_publish: with self._in_callback_mutex: try: self.on_publish(self, self._userdata, mid) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_publish: %s', err) if not self.suppress_exceptions: raise msg = self._out_messages.pop(mid) msg.info._set_as_published() if msg.qos > 0: self._inflight_messages -= 1 if self._max_inflight_messages > 0: rc = self._update_inflight() if rc != MQTT_ERR_SUCCESS: return rc return MQTT_ERR_SUCCESS def _handle_pubackcomp(self, cmd): if self._protocol == MQTTv5: if self._in_packet['remaining_length'] < 2: return MQTT_ERR_PROTOCOL elif self._in_packet['remaining_length'] != 2: return MQTT_ERR_PROTOCOL packet_type = PUBACK if cmd == "PUBACK" else PUBCOMP packet_type = packet_type >> 4 mid, = struct.unpack("!H", self._in_packet['packet'][:2]) if self._protocol == MQTTv5: if self._in_packet['remaining_length'] > 2: reasonCode = ReasonCodes(packet_type) reasonCode.unpack(self._in_packet['packet'][2:]) if self._in_packet['remaining_length'] > 3: properties = Properties(packet_type) props, props_len = properties.unpack( self._in_packet['packet'][3:]) self._easy_log(MQTT_LOG_DEBUG, "Received %s (Mid: %d)", cmd, mid) with self._out_message_mutex: if mid in self._out_messages: # Only inform the client the message has been sent once. rc = self._do_on_publish(mid) return rc return MQTT_ERR_SUCCESS def _handle_on_message(self, message): matched = False with self._callback_mutex: try: topic = message.topic except UnicodeDecodeError: topic = None if topic is not None: for callback in self._on_message_filtered.iter_match(message.topic): with self._in_callback_mutex: try: callback(self, self._userdata, message) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in user defined callback function %s: %s', callback.__name__, err ) if not self.suppress_exceptions: raise matched = True if matched == False and self.on_message: with self._in_callback_mutex: try: self.on_message(self, self._userdata, message) except Exception as err: self._easy_log( MQTT_LOG_ERR, 'Caught exception in on_message: %s', err) if not self.suppress_exceptions: raise def _thread_main(self): self.loop_forever(retry_first_connection=True) def _reconnect_wait(self): # See reconnect_delay_set for details now = time_func() with self._reconnect_delay_mutex: if self._reconnect_delay is None: self._reconnect_delay = self._reconnect_min_delay else: self._reconnect_delay = min( self._reconnect_delay * 2, self._reconnect_max_delay, ) target_time = now + self._reconnect_delay remaining = target_time - now while (self._state != mqtt_cs_disconnecting and not self._thread_terminate and remaining > 0): time.sleep(min(remaining, 1)) remaining = target_time - time_func() @staticmethod def _proxy_is_valid(p): def check(t, a): return (socks is not None and t in set([socks.HTTP, socks.SOCKS4, socks.SOCKS5]) and a) if isinstance(p, dict): return check(p.get("proxy_type"), p.get("proxy_addr")) elif isinstance(p, (list, tuple)): return len(p) == 6 and check(p[0], p[1]) else: return False def _get_proxy(self): if socks is None: return None # First, check if the user explicitly passed us a proxy to use if self._proxy_is_valid(self._proxy): return self._proxy # Next, check for an mqtt_proxy environment variable as long as the host # we're trying to connect to isn't listed under the no_proxy environment # variable (matches built-in module urllib's behavior) if not (hasattr(urllib_dot_request, "proxy_bypass") and urllib_dot_request.proxy_bypass(self._host)): env_proxies = urllib_dot_request.getproxies() if "mqtt" in env_proxies: parts = urllib_dot_parse.urlparse(env_proxies["mqtt"]) if parts.scheme == "http": proxy = { "proxy_type": socks.HTTP, "proxy_addr": parts.hostname, "proxy_port": parts.port } return proxy elif parts.scheme == "socks": proxy = { "proxy_type": socks.SOCKS5, "proxy_addr": parts.hostname, "proxy_port": parts.port } return proxy # Finally, check if the user has monkeypatched the PySocks library with # a default proxy socks_default = socks.get_default_proxy() if self._proxy_is_valid(socks_default): proxy_keys = ("proxy_type", "proxy_addr", "proxy_port", "proxy_rdns", "proxy_username", "proxy_password") return dict(zip(proxy_keys, socks_default)) # If we didn't find a proxy through any of the above methods, return # None to indicate that the connection should be handled normally return None def _create_socket_connection(self): proxy = self._get_proxy() addr = (self._host, self._port) source = (self._bind_address, self._bind_port) if sys.version_info < (2, 7) or (3, 0) < sys.version_info < (3, 2): # Have to short-circuit here because of unsupported source_address # param in earlier Python versions. return socket.create_connection(addr, timeout=self._keepalive) if proxy: return socks.create_connection(addr, source_address=source, timeout=self._keepalive, **proxy) else: return socket.create_connection(addr, source_address=source, timeout=self._keepalive) # Compatibility class for easy porting from mosquitto.py. class Mosquitto(Client): def __init__(self, client_id="", clean_session=True, userdata=None): super(Mosquitto, self).__init__(client_id, clean_session, userdata) class WebsocketWrapper(object): OPCODE_CONTINUATION = 0x0 OPCODE_TEXT = 0x1 OPCODE_BINARY = 0x2 OPCODE_CONNCLOSE = 0x8 OPCODE_PING = 0x9 OPCODE_PONG = 0xa def __init__(self, socket, host, port, is_ssl, path, extra_headers): self.connected = False self._ssl = is_ssl self._host = host self._port = port self._socket = socket self._path = path self._sendbuffer = bytearray() self._readbuffer = bytearray() self._requested_size = 0 self._payload_head = 0 self._readbuffer_head = 0 self._do_handshake(extra_headers) def __del__(self): self._sendbuffer = None self._readbuffer = None def _do_handshake(self, extra_headers): sec_websocket_key = uuid.uuid4().bytes sec_websocket_key = base64.b64encode(sec_websocket_key) websocket_headers = { "Host": "{self._host:s}:{self._port:d}".format(self=self), "Upgrade": "websocket", "Connection": "Upgrade", "Origin": "https://{self._host:s}:{self._port:d}".format(self=self), "Sec-WebSocket-Key": sec_websocket_key.decode("utf8"), "Sec-Websocket-Version": "13", "Sec-Websocket-Protocol": "mqtt", } # This is checked in ws_set_options so it will either be None, a # dictionary, or a callable if isinstance(extra_headers, dict): websocket_headers.update(extra_headers) elif callable(extra_headers): websocket_headers = extra_headers(websocket_headers) header = "\r\n".join([ "GET {self._path} HTTP/1.1".format(self=self), "\r\n".join("{}: {}".format(i, j) for i, j in websocket_headers.items()), "\r\n", ]).encode("utf8") self._socket.send(header) has_secret = False has_upgrade = False while True: # read HTTP response header as lines byte = self._socket.recv(1) self._readbuffer.extend(byte) # line end if byte == b"\n": if len(self._readbuffer) > 2: # check upgrade if b"connection" in str(self._readbuffer).lower().encode('utf-8'): if b"upgrade" not in str(self._readbuffer).lower().encode('utf-8'): raise WebsocketConnectionError( "WebSocket handshake error, connection not upgraded") else: has_upgrade = True # check key hash if b"sec-websocket-accept" in str(self._readbuffer).lower().encode('utf-8'): GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" server_hash = self._readbuffer.decode( 'utf-8').split(": ", 1)[1] server_hash = server_hash.strip().encode('utf-8') client_hash = sec_websocket_key.decode('utf-8') + GUID client_hash = hashlib.sha1(client_hash.encode('utf-8')) client_hash = base64.b64encode(client_hash.digest()) if server_hash != client_hash: raise WebsocketConnectionError( "WebSocket handshake error, invalid secret key") else: has_secret = True else: # ending linebreak break # reset linebuffer self._readbuffer = bytearray() # connection reset elif not byte: raise WebsocketConnectionError("WebSocket handshake error") if not has_upgrade or not has_secret: raise WebsocketConnectionError("WebSocket handshake error") self._readbuffer = bytearray() self.connected = True def _create_frame(self, opcode, data, do_masking=1): header = bytearray() length = len(data) mask_key = bytearray(os.urandom(4)) mask_flag = do_masking # 1 << 7 is the final flag, we don't send continuated data header.append(1 << 7 | opcode) if length < 126: header.append(mask_flag << 7 | length) elif length < 65536: header.append(mask_flag << 7 | 126) header += struct.pack("!H", length) elif length < 0x8000000000000001: header.append(mask_flag << 7 | 127) header += struct.pack("!Q", length) else: raise ValueError("Maximum payload size is 2^63") if mask_flag == 1: for index in range(length): data[index] ^= mask_key[index % 4] data = mask_key + data return header + data def _buffered_read(self, length): # try to recv and strore needed bytes wanted_bytes = length - (len(self._readbuffer) - self._readbuffer_head) if wanted_bytes > 0: data = self._socket.recv(wanted_bytes) if not data: raise socket.error(errno.ECONNABORTED, 0) else: self._readbuffer.extend(data) if len(data) < wanted_bytes: raise socket.error(EAGAIN, 0) self._readbuffer_head += length return self._readbuffer[self._readbuffer_head - length:self._readbuffer_head] def _recv_impl(self, length): # try to decode websocket payload part from data try: self._readbuffer_head = 0 result = None chunk_startindex = self._payload_head chunk_endindex = self._payload_head + length header1 = self._buffered_read(1) header2 = self._buffered_read(1) opcode = (header1[0] & 0x0f) maskbit = (header2[0] & 0x80) == 0x80 lengthbits = (header2[0] & 0x7f) payload_length = lengthbits mask_key = None # read length if lengthbits == 0x7e: value = self._buffered_read(2) payload_length, = struct.unpack("!H", value) elif lengthbits == 0x7f: value = self._buffered_read(8) payload_length, = struct.unpack("!Q", value) # read mask if maskbit: mask_key = self._buffered_read(4) # if frame payload is shorter than the requested data, read only the possible part readindex = chunk_endindex if payload_length < readindex: readindex = payload_length if readindex > 0: # get payload chunk payload = self._buffered_read(readindex) # unmask only the needed part if maskbit: for index in range(chunk_startindex, readindex): payload[index] ^= mask_key[index % 4] result = payload[chunk_startindex:readindex] self._payload_head = readindex else: payload = bytearray() # check if full frame arrived and reset readbuffer and payloadhead if needed if readindex == payload_length: self._readbuffer = bytearray() self._payload_head = 0 # respond to non-binary opcodes, their arrival is not guaranteed beacause of non-blocking sockets if opcode == WebsocketWrapper.OPCODE_CONNCLOSE: frame = self._create_frame( WebsocketWrapper.OPCODE_CONNCLOSE, payload, 0) self._socket.send(frame) if opcode == WebsocketWrapper.OPCODE_PING: frame = self._create_frame( WebsocketWrapper.OPCODE_PONG, payload, 0) self._socket.send(frame) if opcode == WebsocketWrapper.OPCODE_BINARY and payload_length > 0: return result else: raise socket.error(EAGAIN, 0) except socket.error as err: if err.errno == errno.ECONNABORTED: self.connected = False return b'' else: # no more data raise def _send_impl(self, data): # if previous frame was sent successfully if len(self._sendbuffer) == 0: # create websocket frame frame = self._create_frame( WebsocketWrapper.OPCODE_BINARY, bytearray(data)) self._sendbuffer.extend(frame) self._requested_size = len(data) # try to write out as much as possible length = self._socket.send(self._sendbuffer) self._sendbuffer = self._sendbuffer[length:] if len(self._sendbuffer) == 0: # buffer sent out completely, return with payload's size return self._requested_size else: # couldn't send whole data, request the same data again with 0 as sent length return 0 def recv(self, length): return self._recv_impl(length) def read(self, length): return self._recv_impl(length) def send(self, data): return self._send_impl(data) def write(self, data): return self._send_impl(data) def close(self): self._socket.close() def fileno(self): return self._socket.fileno() def pending(self): # Fix for bug #131: a SSL socket may still have data available # for reading without select() being aware of it. if self._ssl: return self._socket.pending() else: # normal socket rely only on select() return 0 def setblocking(self, flag): self._socket.setblocking(flag) paho.mqtt.python-1.5.1/src/paho/mqtt/matcher.py000066400000000000000000000053271373244276700214770ustar00rootroot00000000000000class MQTTMatcher(object): """Intended to manage topic filters including wildcards. Internally, MQTTMatcher use a prefix tree (trie) to store values associated with filters, and has an iter_match() method to iterate efficiently over all filters that match some topic name.""" class Node(object): __slots__ = '_children', '_content' def __init__(self): self._children = {} self._content = None def __init__(self): self._root = self.Node() def __setitem__(self, key, value): """Add a topic filter :key to the prefix tree and associate it to :value""" node = self._root for sym in key.split('/'): node = node._children.setdefault(sym, self.Node()) node._content = value def __getitem__(self, key): """Retrieve the value associated with some topic filter :key""" try: node = self._root for sym in key.split('/'): node = node._children[sym] if node._content is None: raise KeyError(key) return node._content except KeyError: raise KeyError(key) def __delitem__(self, key): """Delete the value associated with some topic filter :key""" lst = [] try: parent, node = None, self._root for k in key.split('/'): parent, node = node, node._children[k] lst.append((parent, k, node)) # TODO node._content = None except KeyError: raise KeyError(key) else: # cleanup for parent, k, node in reversed(lst): if node._children or node._content is not None: break del parent._children[k] def iter_match(self, topic): """Return an iterator on all values associated with filters that match the :topic""" lst = topic.split('/') normal = not topic.startswith('$') def rec(node, i=0): if i == len(lst): if node._content is not None: yield node._content else: part = lst[i] if part in node._children: for content in rec(node._children[part], i + 1): yield content if '+' in node._children and (normal or i > 0): for content in rec(node._children['+'], i + 1): yield content if '#' in node._children and (normal or i > 0): content = node._children['#']._content if content is not None: yield content return rec(self._root) paho.mqtt.python-1.5.1/src/paho/mqtt/packettypes.py000066400000000000000000000026551373244276700224110ustar00rootroot00000000000000""" ******************************************************************* Copyright (c) 2017, 2019 IBM Corp. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v1.0 which accompany this distribution. The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. Contributors: Ian Craggs - initial implementation and/or documentation ******************************************************************* """ class PacketTypes: """ Packet types class. Includes the AUTH packet for MQTT v5.0. Holds constants for each packet type such as PacketTypes.PUBLISH and packet name strings: PacketTypes.Names[PacketTypes.PUBLISH]. """ indexes = range(1, 16) # Packet types CONNECT, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, \ PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, \ PINGREQ, PINGRESP, DISCONNECT, AUTH = indexes # Dummy packet type for properties use - will delay only applies to will WILLMESSAGE = 99 Names = [ "reserved", \ "Connect", "Connack", "Publish", "Puback", "Pubrec", "Pubrel", \ "Pubcomp", "Subscribe", "Suback", "Unsubscribe", "Unsuback", \ "Pingreq", "Pingresp", "Disconnect", "Auth"] paho.mqtt.python-1.5.1/src/paho/mqtt/properties.py000066400000000000000000000401631373244276700222450ustar00rootroot00000000000000""" ******************************************************************* Copyright (c) 2017, 2019 IBM Corp. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v1.0 which accompany this distribution. The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. Contributors: Ian Craggs - initial implementation and/or documentation ******************************************************************* """ import sys, struct from .packettypes import PacketTypes class MQTTException(Exception): pass class MalformedPacket(MQTTException): pass def writeInt16(length): # serialize a 16 bit integer to network format return bytearray(struct.pack("!H", length)) def readInt16(buf): # deserialize a 16 bit integer from network format return struct.unpack("!H", buf[:2])[0] def writeInt32(length): # serialize a 32 bit integer to network format return bytearray(struct.pack("!L", length)) def readInt32(buf): # deserialize a 32 bit integer from network format return struct.unpack("!L", buf[:4])[0] def writeUTF(data): # data could be a string, or bytes. If string, encode into bytes with utf-8 if sys.version_info[0] < 3: data = bytearray(data, 'utf-8') else: data = data if type(data) == type(b"") else bytes(data, "utf-8") return writeInt16(len(data)) + data def readUTF(buffer, maxlen): if maxlen >= 2: length = readInt16(buffer) else: raise MalformedPacket("Not enough data to read string length") maxlen -= 2 if length > maxlen: raise MalformedPacket("Length delimited string too long") buf = buffer[2:2+length].decode("utf-8") # look for chars which are invalid for MQTT for c in buf: # look for D800-DFFF in the UTF string ord_c = ord(c) if ord_c >= 0xD800 and ord_c <= 0xDFFF: raise MalformedPacket("[MQTT-1.5.4-1] D800-DFFF found in UTF-8 data") if ord_c == 0x00: # look for null in the UTF string raise MalformedPacket("[MQTT-1.5.4-2] Null found in UTF-8 data") if ord_c == 0xFEFF: raise MalformedPacket("[MQTT-1.5.4-3] U+FEFF in UTF-8 data") return buf, length+2 def writeBytes(buffer): return writeInt16(len(buffer)) + buffer def readBytes(buffer): length = readInt16(buffer) return buffer[2:2+length], length+2 class VariableByteIntegers: # Variable Byte Integer """ MQTT variable byte integer helper class. Used in several places in MQTT v5.0 properties. """ @staticmethod def encode(x): """ Convert an integer 0 <= x <= 268435455 into multi-byte format. Returns the buffer convered from the integer. """ assert 0 <= x <= 268435455 buffer = b'' while 1: digit = x % 128 x //= 128 if x > 0: digit |= 0x80 if sys.version_info[0] >= 3: buffer += bytes([digit]) else: buffer += bytes(chr(digit)) if x == 0: break return buffer @staticmethod def decode(buffer): """ Get the value of a multi-byte integer from a buffer Return the value, and the number of bytes used. [MQTT-1.5.5-1] the encoded value MUST use the minimum number of bytes necessary to represent the value """ multiplier = 1 value = 0 bytes = 0 while 1: bytes += 1 digit = buffer[0] buffer = buffer[1:] value += (digit & 127) * multiplier if digit & 128 == 0: break multiplier *= 128 return (value, bytes) class Properties(object): """MQTT v5.0 properties class. See Properties.names for a list of accepted property names along with their numeric values. See Properties.properties for the data type of each property. Example of use: publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.UserProperty = ("a", "2") publish_properties.UserProperty = ("c", "3") First the object is created with packet type as argument, no properties will be present at this point. Then properties are added as attributes, the name of which is the string property name without the spaces. """ def __init__(self, packetType): self.packetType = packetType self.types = ["Byte", "Two Byte Integer", "Four Byte Integer", "Variable Byte Integer", "Binary Data", "UTF-8 Encoded String", "UTF-8 String Pair"] self.names = { "Payload Format Indicator": 1, "Message Expiry Interval": 2, "Content Type": 3, "Response Topic": 8, "Correlation Data": 9, "Subscription Identifier": 11, "Session Expiry Interval": 17, "Assigned Client Identifier": 18, "Server Keep Alive": 19, "Authentication Method": 21, "Authentication Data": 22, "Request Problem Information": 23, "Will Delay Interval": 24, "Request Response Information": 25, "Response Information": 26, "Server Reference": 28, "Reason String": 31, "Receive Maximum": 33, "Topic Alias Maximum": 34, "Topic Alias": 35, "Maximum QoS": 36, "Retain Available": 37, "User Property": 38, "Maximum Packet Size": 39, "Wildcard Subscription Available": 40, "Subscription Identifier Available": 41, "Shared Subscription Available": 42 } self.properties = { # id: type, packets # payload format indicator 1: (self.types.index("Byte"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]), 2: (self.types.index("Four Byte Integer"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]), 3: (self.types.index("UTF-8 Encoded String"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]), 8: (self.types.index("UTF-8 Encoded String"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]), 9: (self.types.index("Binary Data"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]), 11: (self.types.index("Variable Byte Integer"), [PacketTypes.PUBLISH, PacketTypes.SUBSCRIBE]), 17: (self.types.index("Four Byte Integer"), [PacketTypes.CONNECT, PacketTypes.CONNACK, PacketTypes.DISCONNECT]), 18: (self.types.index("UTF-8 Encoded String"), [PacketTypes.CONNACK]), 19: (self.types.index("Two Byte Integer"), [PacketTypes.CONNACK]), 21: (self.types.index("UTF-8 Encoded String"), [PacketTypes.CONNECT, PacketTypes.CONNACK, PacketTypes.AUTH]), 22: (self.types.index("Binary Data"), [PacketTypes.CONNECT, PacketTypes.CONNACK, PacketTypes.AUTH]), 23: (self.types.index("Byte"), [PacketTypes.CONNECT]), 24: (self.types.index("Four Byte Integer"), [PacketTypes.WILLMESSAGE]), 25: (self.types.index("Byte"), [PacketTypes.CONNECT]), 26: (self.types.index("UTF-8 Encoded String"), [PacketTypes.CONNACK]), 28: (self.types.index("UTF-8 Encoded String"), [PacketTypes.CONNACK, PacketTypes.DISCONNECT]), 31: (self.types.index("UTF-8 Encoded String"), [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.PUBREL, PacketTypes.PUBCOMP, PacketTypes.SUBACK, PacketTypes.UNSUBACK, PacketTypes.DISCONNECT, PacketTypes.AUTH]), 33: (self.types.index("Two Byte Integer"), [PacketTypes.CONNECT, PacketTypes.CONNACK]), 34: (self.types.index("Two Byte Integer"), [PacketTypes.CONNECT, PacketTypes.CONNACK]), 35: (self.types.index("Two Byte Integer"), [PacketTypes.PUBLISH]), 36: (self.types.index("Byte"), [PacketTypes.CONNACK]), 37: (self.types.index("Byte"), [PacketTypes.CONNACK]), 38: (self.types.index("UTF-8 String Pair"), [PacketTypes.CONNECT, PacketTypes.CONNACK, PacketTypes.PUBLISH, PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.PUBREL, PacketTypes.PUBCOMP, PacketTypes.SUBSCRIBE, PacketTypes.SUBACK, PacketTypes.UNSUBSCRIBE, PacketTypes.UNSUBACK, PacketTypes.DISCONNECT, PacketTypes.AUTH, PacketTypes.WILLMESSAGE]), 39: (self.types.index("Four Byte Integer"), [PacketTypes.CONNECT, PacketTypes.CONNACK]), 40: (self.types.index("Byte"), [PacketTypes.CONNACK]), 41: (self.types.index("Byte"), [PacketTypes.CONNACK]), 42: (self.types.index("Byte"), [PacketTypes.CONNACK]), } def allowsMultiple(self, compressedName): return self.getIdentFromName(compressedName) in [11, 38] def getIdentFromName(self, compressedName): # return the identifier corresponding to the property name result = -1 for name in self.names.keys(): if compressedName == name.replace(' ', ''): result = self.names[name] break return result def __setattr__(self, name, value): name = name.replace(' ', '') privateVars = ["packetType", "types", "names", "properties"] if name in privateVars: object.__setattr__(self, name, value) else: # the name could have spaces in, or not. Remove spaces before assignment if name not in [aname.replace(' ', '') for aname in self.names.keys()]: raise MQTTException( "Property name must be one of "+str(self.names.keys())) # check that this attribute applies to the packet type if self.packetType not in self.properties[self.getIdentFromName(name)][1]: raise MQTTException("Property %s does not apply to packet type %s" % (name, PacketTypes.Names[self.packetType])) if self.allowsMultiple(name): if type(value) != type([]): value = [value] if hasattr(self, name): value = object.__getattribute__(self, name) + value object.__setattr__(self, name, value) def __str__(self): buffer = "[" first = True for name in self.names.keys(): compressedName = name.replace(' ', '') if hasattr(self, compressedName): if not first: buffer += ", " buffer += compressedName + " : " + \ str(getattr(self, compressedName)) first = False buffer += "]" return buffer def json(self): data = {} for name in self.names.keys(): compressedName = name.replace(' ', '') if hasattr(self, compressedName): data[compressedName] = getattr(self, compressedName) return data def isEmpty(self): rc = True for name in self.names.keys(): compressedName = name.replace(' ', '') if hasattr(self, compressedName): rc = False break return rc def clear(self): for name in self.names.keys(): compressedName = name.replace(' ', '') if hasattr(self, compressedName): delattr(self, compressedName) def writeProperty(self, identifier, type, value): buffer = b"" buffer += VariableByteIntegers.encode(identifier) # identifier if type == self.types.index("Byte"): # value if sys.version_info[0] < 3: buffer += chr(value) else: buffer += bytes([value]) elif type == self.types.index("Two Byte Integer"): buffer += writeInt16(value) elif type == self.types.index("Four Byte Integer"): buffer += writeInt32(value) elif type == self.types.index("Variable Byte Integer"): buffer += VariableByteIntegers.encode(value) elif type == self.types.index("Binary Data"): buffer += writeBytes(value) elif type == self.types.index("UTF-8 Encoded String"): buffer += writeUTF(value) elif type == self.types.index("UTF-8 String Pair"): buffer += writeUTF(value[0]) + writeUTF(value[1]) return buffer def pack(self): # serialize properties into buffer for sending over network buffer = b"" for name in self.names.keys(): compressedName = name.replace(' ', '') if hasattr(self, compressedName): identifier = self.getIdentFromName(compressedName) attr_type = self.properties[identifier][0] if self.allowsMultiple(compressedName): for prop in getattr(self, compressedName): buffer += self.writeProperty(identifier, attr_type, prop) else: buffer += self.writeProperty(identifier, attr_type, getattr(self, compressedName)) return VariableByteIntegers.encode(len(buffer)) + buffer def readProperty(self, buffer, type, propslen): if type == self.types.index("Byte"): value = buffer[0] valuelen = 1 elif type == self.types.index("Two Byte Integer"): value = readInt16(buffer) valuelen = 2 elif type == self.types.index("Four Byte Integer"): value = readInt32(buffer) valuelen = 4 elif type == self.types.index("Variable Byte Integer"): value, valuelen = VariableByteIntegers.decode(buffer) elif type == self.types.index("Binary Data"): value, valuelen = readBytes(buffer) elif type == self.types.index("UTF-8 Encoded String"): value, valuelen = readUTF(buffer, propslen) elif type == self.types.index("UTF-8 String Pair"): value, valuelen = readUTF(buffer, propslen) buffer = buffer[valuelen:] # strip the bytes used by the value value1, valuelen1 = readUTF(buffer, propslen - valuelen) value = (value, value1) valuelen += valuelen1 return value, valuelen def getNameFromIdent(self, identifier): rc = None for name in self.names: if self.names[name] == identifier: rc = name return rc def unpack(self, buffer): if sys.version_info[0] < 3: buffer = bytearray(buffer) self.clear() # deserialize properties into attributes from buffer received from network propslen, VBIlen = VariableByteIntegers.decode(buffer) buffer = buffer[VBIlen:] # strip the bytes used by the VBI propslenleft = propslen while propslenleft > 0: # properties length is 0 if there are none identifier, VBIlen = VariableByteIntegers.decode( buffer) # property identifier buffer = buffer[VBIlen:] # strip the bytes used by the VBI propslenleft -= VBIlen attr_type = self.properties[identifier][0] value, valuelen = self.readProperty( buffer, attr_type, propslenleft) buffer = buffer[valuelen:] # strip the bytes used by the value propslenleft -= valuelen propname = self.getNameFromIdent(identifier) compressedName = propname.replace(' ', '') if not self.allowsMultiple(compressedName) and hasattr(self, compressedName): raise MQTTException( "Property '%s' must not exist more than once" % property) setattr(self, propname, value) return self, propslen + VBIlen paho.mqtt.python-1.5.1/src/paho/mqtt/publish.py000066400000000000000000000222541373244276700215200ustar00rootroot00000000000000# Copyright (c) 2014 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # and Eclipse Distribution License v1.0 which accompany this distribution. # # The Eclipse Public License is available at # http://www.eclipse.org/legal/epl-v10.html # and the Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial API and implementation """ This module provides some helper functions to allow straightforward publishing of messages in a one-shot manner. In other words, they are useful for the situation where you have a single/multiple messages you want to publish to a broker, then disconnect and nothing else is required. """ from __future__ import absolute_import import collections try: from collections.abc import Iterable except ImportError: from collections import Iterable from . import client as paho from .. import mqtt def _do_publish(client): """Internal function""" message = client._userdata.popleft() if isinstance(message, dict): client.publish(**message) elif isinstance(message, (tuple, list)): client.publish(*message) else: raise TypeError('message must be a dict, tuple, or list') def _on_connect(client, userdata, flags, rc): """Internal callback""" #pylint: disable=invalid-name, unused-argument if rc == 0: if len(userdata) > 0: _do_publish(client) else: raise mqtt.MQTTException(paho.connack_string(rc)) def _on_publish(client, userdata, mid): """Internal callback""" #pylint: disable=unused-argument if len(userdata) == 0: client.disconnect() else: _do_publish(client) def multiple(msgs, hostname="localhost", port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None, protocol=paho.MQTTv311, transport="tcp", proxy_args=None): """Publish multiple messages to a broker, then disconnect cleanly. This function creates an MQTT client, connects to a broker and publishes a list of messages. Once the messages have been delivered, it disconnects cleanly from the broker. msgs : a list of messages to publish. Each message is either a dict or a tuple. If a dict, only the topic must be present. Default values will be used for any missing arguments. The dict must be of the form: msg = {'topic':"", 'payload':"", 'qos':, 'retain':} topic must be present and may not be empty. If payload is "", None or not present then a zero length payload will be published. If qos is not present, the default of 0 is used. If retain is not present, the default of False is used. If a tuple, then it must be of the form: ("", "", qos, retain) hostname : a string containing the address of the broker to connect to. Defaults to localhost. port : the port to connect to the broker on. Defaults to 1883. client_id : the MQTT client id to use. If "" or None, the Paho library will generate a client id automatically. keepalive : the keepalive timeout value for the client. Defaults to 60 seconds. will : a dict containing will parameters for the client: will = {'topic': "", 'payload':", 'qos':, 'retain':}. Topic is required, all other parameters are optional and will default to None, 0 and False respectively. Defaults to None, which indicates no will should be used. auth : a dict containing authentication parameters for the client: auth = {'username':"", 'password':""} Username is required, password is optional and will default to None if not provided. Defaults to None, which indicates no authentication is to be used. tls : a dict containing TLS configuration parameters for the client: dict = {'ca_certs':"", 'certfile':"", 'keyfile':"", 'tls_version':"", 'ciphers':", 'insecure':""} ca_certs is required, all other parameters are optional and will default to None if not provided, which results in the client using the default behaviour - see the paho.mqtt.client documentation. Alternatively, tls input can be an SSLContext object, which will be processed using the tls_set_context method. Defaults to None, which indicates that TLS should not be used. transport : set to "tcp" to use the default setting of transport which is raw TCP. Set to "websockets" to use WebSockets as the transport. proxy_args: a dictionary that will be given to the client. """ if not isinstance(msgs, Iterable): raise TypeError('msgs must be an iterable') client = paho.Client(client_id=client_id, userdata=collections.deque(msgs), protocol=protocol, transport=transport) client.on_publish = _on_publish client.on_connect = _on_connect if proxy_args is not None: client.proxy_set(**proxy_args) if auth: username = auth.get('username') if username: password = auth.get('password') client.username_pw_set(username, password) else: raise KeyError("The 'username' key was not found, this is " "required for auth") if will is not None: client.will_set(**will) if tls is not None: if isinstance(tls, dict): insecure = tls.pop('insecure', False) client.tls_set(**tls) if insecure: # Must be set *after* the `client.tls_set()` call since it sets # up the SSL context that `client.tls_insecure_set` alters. client.tls_insecure_set(insecure) else: # Assume input is SSLContext object client.tls_set_context(tls) client.connect(hostname, port, keepalive) client.loop_forever() def single(topic, payload=None, qos=0, retain=False, hostname="localhost", port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None, protocol=paho.MQTTv311, transport="tcp", proxy_args=None): """Publish a single message to a broker, then disconnect cleanly. This function creates an MQTT client, connects to a broker and publishes a single message. Once the message has been delivered, it disconnects cleanly from the broker. topic : the only required argument must be the topic string to which the payload will be published. payload : the payload to be published. If "" or None, a zero length payload will be published. qos : the qos to use when publishing, default to 0. retain : set the message to be retained (True) or not (False). hostname : a string containing the address of the broker to connect to. Defaults to localhost. port : the port to connect to the broker on. Defaults to 1883. client_id : the MQTT client id to use. If "" or None, the Paho library will generate a client id automatically. keepalive : the keepalive timeout value for the client. Defaults to 60 seconds. will : a dict containing will parameters for the client: will = {'topic': "", 'payload':", 'qos':, 'retain':}. Topic is required, all other parameters are optional and will default to None, 0 and False respectively. Defaults to None, which indicates no will should be used. auth : a dict containing authentication parameters for the client: auth = {'username':"", 'password':""} Username is required, password is optional and will default to None if not provided. Defaults to None, which indicates no authentication is to be used. tls : a dict containing TLS configuration parameters for the client: dict = {'ca_certs':"", 'certfile':"", 'keyfile':"", 'tls_version':"", 'ciphers':", 'insecure':""} ca_certs is required, all other parameters are optional and will default to None if not provided, which results in the client using the default behaviour - see the paho.mqtt.client documentation. Defaults to None, which indicates that TLS should not be used. Alternatively, tls input can be an SSLContext object, which will be processed using the tls_set_context method. transport : set to "tcp" to use the default setting of transport which is raw TCP. Set to "websockets" to use WebSockets as the transport. proxy_args: a dictionary that will be given to the client. """ msg = {'topic':topic, 'payload':payload, 'qos':qos, 'retain':retain} multiple([msg], hostname, port, client_id, keepalive, will, auth, tls, protocol, transport, proxy_args) paho.mqtt.python-1.5.1/src/paho/mqtt/reasoncodes.py000066400000000000000000000206161373244276700223570ustar00rootroot00000000000000""" ******************************************************************* Copyright (c) 2017, 2019 IBM Corp. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v1.0 which accompany this distribution. The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. Contributors: Ian Craggs - initial implementation and/or documentation ******************************************************************* """ import sys from .packettypes import PacketTypes class ReasonCodes: """MQTT version 5.0 reason codes class. See ReasonCodes.names for a list of possible numeric values along with their names and the packets to which they apply. """ def __init__(self, packetType, aName="Success", identifier=-1): """ packetType: the type of the packet, such as PacketTypes.CONNECT that this reason code will be used with. Some reason codes have different names for the same identifier when used a different packet type. aName: the String name of the reason code to be created. Ignored if the identifier is set. identifier: an integer value of the reason code to be created. """ self.packetType = packetType self.names = { 0: {"Success": [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.PUBREL, PacketTypes.PUBCOMP, PacketTypes.UNSUBACK, PacketTypes.AUTH], "Normal disconnection": [PacketTypes.DISCONNECT], "Granted QoS 0": [PacketTypes.SUBACK]}, 1: {"Granted QoS 1": [PacketTypes.SUBACK]}, 2: {"Granted QoS 2": [PacketTypes.SUBACK]}, 4: {"Disconnect with will message": [PacketTypes.DISCONNECT]}, 16: {"No matching subscribers": [PacketTypes.PUBACK, PacketTypes.PUBREC]}, 17: {"No subscription found": [PacketTypes.UNSUBACK]}, 24: {"Continue authentication": [PacketTypes.AUTH]}, 25: {"Re-authenticate": [PacketTypes.AUTH]}, 128: {"Unspecified error": [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.SUBACK, PacketTypes.UNSUBACK, PacketTypes.DISCONNECT], }, 129: {"Malformed packet": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 130: {"Protocol error": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 131: {"Implementation specific error": [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.SUBACK, PacketTypes.UNSUBACK, PacketTypes.DISCONNECT], }, 132: {"Unsupported protocol version": [PacketTypes.CONNACK]}, 133: {"Client identifier not valid": [PacketTypes.CONNACK]}, 134: {"Bad user name or password": [PacketTypes.CONNACK]}, 135: {"Not authorized": [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.SUBACK, PacketTypes.UNSUBACK, PacketTypes.DISCONNECT], }, 136: {"Server unavailable": [PacketTypes.CONNACK]}, 137: {"Server busy": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 138: {"Banned": [PacketTypes.CONNACK]}, 139: {"Server shutting down": [PacketTypes.DISCONNECT]}, 140: {"Bad authentication method": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 141: {"Keep alive timeout": [PacketTypes.DISCONNECT]}, 142: {"Session taken over": [PacketTypes.DISCONNECT]}, 143: {"Topic filter invalid": [PacketTypes.SUBACK, PacketTypes.UNSUBACK, PacketTypes.DISCONNECT]}, 144: {"Topic name invalid": [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.DISCONNECT]}, 145: {"Packet identifier in use": [PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.SUBACK, PacketTypes.UNSUBACK]}, 146: {"Packet identifier not found": [PacketTypes.PUBREL, PacketTypes.PUBCOMP]}, 147: {"Receive maximum exceeded": [PacketTypes.DISCONNECT]}, 148: {"Topic alias invalid": [PacketTypes.DISCONNECT]}, 149: {"Packet too large": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 150: {"Message rate too high": [PacketTypes.DISCONNECT]}, 151: {"Quota exceeded": [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.SUBACK, PacketTypes.DISCONNECT], }, 152: {"Administrative action": [PacketTypes.DISCONNECT]}, 153: {"Payload format invalid": [PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.DISCONNECT]}, 154: {"Retain not supported": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 155: {"QoS not supported": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 156: {"Use another server": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 157: {"Server moved": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 158: {"Shared subscription not supported": [PacketTypes.SUBACK, PacketTypes.DISCONNECT]}, 159: {"Connection rate exceeded": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 160: {"Maximum connect time": [PacketTypes.DISCONNECT]}, 161: {"Subscription identifiers not supported": [PacketTypes.SUBACK, PacketTypes.DISCONNECT]}, 162: {"Wildcard subscription not supported": [PacketTypes.SUBACK, PacketTypes.DISCONNECT]}, } if identifier == -1: if packetType == PacketTypes.DISCONNECT and aName == "Success": aName = "Normal disconnection" self.set(aName) else: self.value = identifier self.getName() # check it's good def __getName__(self, packetType, identifier): """ Get the reason code string name for a specific identifier. The name can vary by packet type for the same identifier, which is why the packet type is also required. Used when displaying the reason code. """ assert identifier in self.names.keys(), identifier names = self.names[identifier] namelist = [name for name in names.keys() if packetType in names[name]] assert len(namelist) == 1 return namelist[0] def getId(self, name): """ Get the numeric id corresponding to a reason code name. Used when setting the reason code for a packetType check that only valid codes for the packet are set. """ identifier = None for code in self.names.keys(): if name in self.names[code].keys(): if self.packetType in self.names[code][name]: identifier = code break assert identifier != None, name return identifier def set(self, name): self.value = self.getId(name) def unpack(self, buffer): c = buffer[0] if sys.version_info[0] < 3: c = ord(c) name = self.__getName__(self.packetType, c) self.value = self.getId(name) return 1 def getName(self): """Returns the reason code name corresponding to the numeric value which is set. """ return self.__getName__(self.packetType, self.value) def __eq__(self, other): if isinstance(other, int): return self.value == other if isinstance(other, str): return self.value == str(self) if isinstance(other, ReasonCodes): return self.value == other.value return False def __str__(self): return self.getName() def json(self): return self.getName() def pack(self): return bytearray([self.value])paho.mqtt.python-1.5.1/src/paho/mqtt/subscribe.py000066400000000000000000000256021373244276700220330ustar00rootroot00000000000000# Copyright (c) 2016 Roger Light # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # and Eclipse Distribution License v1.0 which accompany this distribution. # # The Eclipse Public License is available at # http://www.eclipse.org/legal/epl-v10.html # and the Eclipse Distribution License is available at # http://www.eclipse.org/org/documents/edl-v10.php. # # Contributors: # Roger Light - initial API and implementation """ This module provides some helper functions to allow straightforward subscribing to topics and retrieving messages. The two functions are simple(), which returns one or messages matching a set of topics, and callback() which allows you to pass a callback for processing of messages. """ from __future__ import absolute_import from . import client as paho from .. import mqtt def _on_connect(client, userdata, flags, rc): """Internal callback""" if rc != 0: raise mqtt.MQTTException(paho.connack_string(rc)) if isinstance(userdata['topics'], list): for topic in userdata['topics']: client.subscribe(topic, userdata['qos']) else: client.subscribe(userdata['topics'], userdata['qos']) def _on_message_callback(client, userdata, message): """Internal callback""" userdata['callback'](client, userdata['userdata'], message) def _on_message_simple(client, userdata, message): """Internal callback""" if userdata['msg_count'] == 0: return # Don't process stale retained messages if 'retained' was false if message.retain and not userdata['retained']: return userdata['msg_count'] = userdata['msg_count'] - 1 if userdata['messages'] is None and userdata['msg_count'] == 0: userdata['messages'] = message client.disconnect() return userdata['messages'].append(message) if userdata['msg_count'] == 0: client.disconnect() def callback(callback, topics, qos=0, userdata=None, hostname="localhost", port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None, protocol=paho.MQTTv311, transport="tcp", clean_session=True, proxy_args=None): """Subscribe to a list of topics and process them in a callback function. This function creates an MQTT client, connects to a broker and subscribes to a list of topics. Incoming messages are processed by the user provided callback. This is a blocking function and will never return. callback : function of the form "on_message(client, userdata, message)" for processing the messages received. topics : either a string containing a single topic to subscribe to, or a list of topics to subscribe to. qos : the qos to use when subscribing. This is applied to all topics. userdata : passed to the callback hostname : a string containing the address of the broker to connect to. Defaults to localhost. port : the port to connect to the broker on. Defaults to 1883. client_id : the MQTT client id to use. If "" or None, the Paho library will generate a client id automatically. keepalive : the keepalive timeout value for the client. Defaults to 60 seconds. will : a dict containing will parameters for the client: will = {'topic': "", 'payload':", 'qos':, 'retain':}. Topic is required, all other parameters are optional and will default to None, 0 and False respectively. Defaults to None, which indicates no will should be used. auth : a dict containing authentication parameters for the client: auth = {'username':"", 'password':""} Username is required, password is optional and will default to None if not provided. Defaults to None, which indicates no authentication is to be used. tls : a dict containing TLS configuration parameters for the client: dict = {'ca_certs':"", 'certfile':"", 'keyfile':"", 'tls_version':"", 'ciphers':", 'insecure':""} ca_certs is required, all other parameters are optional and will default to None if not provided, which results in the client using the default behaviour - see the paho.mqtt.client documentation. Alternatively, tls input can be an SSLContext object, which will be processed using the tls_set_context method. Defaults to None, which indicates that TLS should not be used. transport : set to "tcp" to use the default setting of transport which is raw TCP. Set to "websockets" to use WebSockets as the transport. clean_session : a boolean that determines the client type. If True, the broker will remove all information about this client when it disconnects. If False, the client is a persistent client and subscription information and queued messages will be retained when the client disconnects. Defaults to True. proxy_args: a dictionary that will be given to the client. """ if qos < 0 or qos > 2: raise ValueError('qos must be in the range 0-2') callback_userdata = { 'callback':callback, 'topics':topics, 'qos':qos, 'userdata':userdata} client = paho.Client(client_id=client_id, userdata=callback_userdata, protocol=protocol, transport=transport, clean_session=clean_session) client.on_message = _on_message_callback client.on_connect = _on_connect if proxy_args is not None: client.proxy_set(**proxy_args) if auth: username = auth.get('username') if username: password = auth.get('password') client.username_pw_set(username, password) else: raise KeyError("The 'username' key was not found, this is " "required for auth") if will is not None: client.will_set(**will) if tls is not None: if isinstance(tls, dict): insecure = tls.pop('insecure', False) client.tls_set(**tls) if insecure: # Must be set *after* the `client.tls_set()` call since it sets # up the SSL context that `client.tls_insecure_set` alters. client.tls_insecure_set(insecure) else: # Assume input is SSLContext object client.tls_set_context(tls) client.connect(hostname, port, keepalive) client.loop_forever() def simple(topics, qos=0, msg_count=1, retained=True, hostname="localhost", port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None, protocol=paho.MQTTv311, transport="tcp", clean_session=True, proxy_args=None): """Subscribe to a list of topics and return msg_count messages. This function creates an MQTT client, connects to a broker and subscribes to a list of topics. Once "msg_count" messages have been received, it disconnects cleanly from the broker and returns the messages. topics : either a string containing a single topic to subscribe to, or a list of topics to subscribe to. qos : the qos to use when subscribing. This is applied to all topics. msg_count : the number of messages to retrieve from the broker. if msg_count == 1 then a single MQTTMessage will be returned. if msg_count > 1 then a list of MQTTMessages will be returned. retained : If set to True, retained messages will be processed the same as non-retained messages. If set to False, retained messages will be ignored. This means that with retained=False and msg_count=1, the function will return the first message received that does not have the retained flag set. hostname : a string containing the address of the broker to connect to. Defaults to localhost. port : the port to connect to the broker on. Defaults to 1883. client_id : the MQTT client id to use. If "" or None, the Paho library will generate a client id automatically. keepalive : the keepalive timeout value for the client. Defaults to 60 seconds. will : a dict containing will parameters for the client: will = {'topic': "", 'payload':", 'qos':, 'retain':}. Topic is required, all other parameters are optional and will default to None, 0 and False respectively. Defaults to None, which indicates no will should be used. auth : a dict containing authentication parameters for the client: auth = {'username':"", 'password':""} Username is required, password is optional and will default to None if not provided. Defaults to None, which indicates no authentication is to be used. tls : a dict containing TLS configuration parameters for the client: dict = {'ca_certs':"", 'certfile':"", 'keyfile':"", 'tls_version':"", 'ciphers':", 'insecure':""} ca_certs is required, all other parameters are optional and will default to None if not provided, which results in the client using the default behaviour - see the paho.mqtt.client documentation. Alternatively, tls input can be an SSLContext object, which will be processed using the tls_set_context method. Defaults to None, which indicates that TLS should not be used. transport : set to "tcp" to use the default setting of transport which is raw TCP. Set to "websockets" to use WebSockets as the transport. clean_session : a boolean that determines the client type. If True, the broker will remove all information about this client when it disconnects. If False, the client is a persistent client and subscription information and queued messages will be retained when the client disconnects. Defaults to True. proxy_args: a dictionary that will be given to the client. """ if msg_count < 1: raise ValueError('msg_count must be > 0') # Set ourselves up to return a single message if msg_count == 1, or a list # if > 1. if msg_count == 1: messages = None else: messages = [] userdata = {'retained':retained, 'msg_count':msg_count, 'messages':messages} callback(_on_message_simple, topics, qos, userdata, hostname, port, client_id, keepalive, will, auth, tls, protocol, transport, clean_session, proxy_args) return userdata['messages'] paho.mqtt.python-1.5.1/src/paho/mqtt/subscribeoptions.py000066400000000000000000000110101373244276700234330ustar00rootroot00000000000000""" ******************************************************************* Copyright (c) 2017, 2019 IBM Corp. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v1.0 which accompany this distribution. The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. Contributors: Ian Craggs - initial implementation and/or documentation ******************************************************************* """ import sys class MQTTException(Exception): pass class SubscribeOptions(object): """The MQTT v5.0 subscribe options class. The options are: qos: As in MQTT v3.1.1. noLocal: True or False. If set to True, the subscriber will not receive its own publications. retainAsPublished: True or False. If set to True, the retain flag on received publications will be as set by the publisher. retainHandling: RETAIN_SEND_ON_SUBSCRIBE, RETAIN_SEND_IF_NEW_SUB or RETAIN_DO_NOT_SEND Controls when the broker should send retained messages: - RETAIN_SEND_ON_SUBSCRIBE: on any successful subscribe request - RETAIN_SEND_IF_NEW_SUB: only if the subscribe request is new - RETAIN_DO_NOT_SEND: never send retained messages """ # retain handling options RETAIN_SEND_ON_SUBSCRIBE, RETAIN_SEND_IF_NEW_SUB, RETAIN_DO_NOT_SEND = range( 0, 3) def __init__(self, qos=0, noLocal=False, retainAsPublished=False, retainHandling=RETAIN_SEND_ON_SUBSCRIBE): """ qos: 0, 1 or 2. 0 is the default. noLocal: True or False. False is the default and corresponds to MQTT v3.1.1 behavior. retainAsPublished: True or False. False is the default and corresponds to MQTT v3.1.1 behavior. retainHandling: RETAIN_SEND_ON_SUBSCRIBE, RETAIN_SEND_IF_NEW_SUB or RETAIN_DO_NOT_SEND RETAIN_SEND_ON_SUBSCRIBE is the default and corresponds to MQTT v3.1.1 behavior. """ object.__setattr__(self, "names", ["QoS", "noLocal", "retainAsPublished", "retainHandling"]) self.QoS = qos # bits 0,1 self.noLocal = noLocal # bit 2 self.retainAsPublished = retainAsPublished # bit 3 self.retainHandling = retainHandling # bits 4 and 5: 0, 1 or 2 assert self.QoS in [0, 1, 2] assert self.retainHandling in [ 0, 1, 2], "Retain handling should be 0, 1 or 2" def __setattr__(self, name, value): if name not in self.names: raise MQTTException( name + " Attribute name must be one of "+str(self.names)) object.__setattr__(self, name, value) def pack(self): assert self.QoS in [0, 1, 2] assert self.retainHandling in [ 0, 1, 2], "Retain handling should be 0, 1 or 2" noLocal = 1 if self.noLocal else 0 retainAsPublished = 1 if self.retainAsPublished else 0 data = [(self.retainHandling << 4) | (retainAsPublished << 3) | (noLocal << 2) | self.QoS] if sys.version_info[0] >= 3: buffer = bytes(data) else: buffer = bytearray(data) return buffer def unpack(self, buffer): b0 = buffer[0] self.retainHandling = ((b0 >> 4) & 0x03) self.retainAsPublished = True if ((b0 >> 3) & 0x01) == 1 else False self.noLocal = True if ((b0 >> 2) & 0x01) == 1 else False self.QoS = (b0 & 0x03) assert self.retainHandling in [ 0, 1, 2], "Retain handling should be 0, 1 or 2, not %d" % self.retainHandling assert self.QoS in [ 0, 1, 2], "QoS should be 0, 1 or 2, not %d" % self.QoS return 1 def __repr__(self): return str(self) def __str__(self): return "{QoS="+str(self.QoS)+", noLocal="+str(self.noLocal) +\ ", retainAsPublished="+str(self.retainAsPublished) +\ ", retainHandling="+str(self.retainHandling)+"}" def json(self): data = { "QoS": self.QoS, "noLocal": self.noLocal, "retainAsPublished": self.retainAsPublished, "retainHandling": self.retainHandling, } return data paho.mqtt.python-1.5.1/test/000077500000000000000000000000001373244276700157475ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/Makefile000066400000000000000000000001321373244276700174030ustar00rootroot00000000000000.PHONY: all test clean all : test : $(MAKE) -C lib test clean : $(MAKE) -C lib clean paho.mqtt.python-1.5.1/test/lib/000077500000000000000000000000001373244276700165155ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/lib/01-keepalive-pingreq.py000077500000000000000000000022321373244276700227170ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a pingreq after the keepalive time # The client should connect to port 1888 with keepalive=4, clean session set, # and client id 01-keepalive-pingreq # The client should send a PINGREQ message after the appropriate amount of time # (4 seconds after no traffic). import time import context import paho_test rc = 1 keepalive = 4 connect_packet = paho_test.gen_connect("01-keepalive-pingreq", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) pingreq_packet = paho_test.gen_pingreq() pingresp_packet = paho_test.gen_pingresp() sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(keepalive+10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "pingreq", pingreq_packet): time.sleep(1.0) conn.send(pingresp_packet) if paho_test.expect_packet(conn, "pingreq", pingreq_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/01-no-clean-session.py000077500000000000000000000012741373244276700224710ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect with clean session not set. # The client should connect to port 1888 with keepalive=60, clean session not # set, and client id 01-no-clean-session. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("01-no-clean-session", clean_session=False, keepalive=keepalive) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/01-unpwd-empty-password-set.py000077500000000000000000000014251373244276700242340ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect with a username and password. # The client should connect to port 1888 with keepalive=60, clean session set, # client id 01-unpwd-set, username set to uname and password set to empty string import context import paho_test rc = 1 keepalive = 60 username = "uname" password = "" connect_packet = paho_test.gen_connect( "01-unpwd-set", keepalive=keepalive, username=username, password=password) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/01-unpwd-empty-set.py000077500000000000000000000013761373244276700224010ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect with a username and password. # The client should connect to port 1888 with keepalive=60, clean session set, # client id 01-unpwd-set, username and password set to empty string. import context import paho_test rc = 1 keepalive = 60 username = "" password = "" connect_packet = paho_test.gen_connect( "01-unpwd-set", keepalive=keepalive, username=username, password='') sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/01-unpwd-set.py000077500000000000000000000014331373244276700212370ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect with a username and password. # The client should connect to port 1888 with keepalive=60, clean session set, # client id 01-unpwd-set, username set to uname and password set to ;'[08gn=# import context import paho_test rc = 1 keepalive = 60 username = "uname" password = ";'[08gn=#" connect_packet = paho_test.gen_connect( "01-unpwd-set", keepalive=keepalive, username=username, password=password) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/01-unpwd-unicode-set.py000066400000000000000000000016101373244276700226550ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect with a unicode username and password. # The client should connect to port 1888 with keepalive=60, clean session set, # client id 01-unpwd-unicode-set, username and password from corresponding variables from __future__ import unicode_literals import context import paho_test rc = 1 keepalive = 60 username = "\u00fas\u00e9rn\u00e1m\u00e9-h\u00e9ll\u00f3" password = "h\u00e9ll\u00f3" connect_packet = paho_test.gen_connect( "01-unpwd-unicode-set", keepalive=keepalive, username=username, password=password) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/01-will-set.py000077500000000000000000000016351373244276700210550ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect with a will. # Will QoS=1, will retain=1. # The client should connect to port 1888 with keepalive=60, clean session set, # client id 01-will-set will topic set to topic/on/unexpected/disconnect , will # payload set to "will message", will qos set to 1 and will retain set. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect( "01-will-set", keepalive=keepalive, will_topic="topic/on/unexpected/disconnect", will_qos=1, will_retain=True, will_payload="will message".encode('utf-8')) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/01-will-unpwd-set.py000077500000000000000000000017441373244276700222110ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect with a will, username and password. # The client should connect to port 1888 with keepalive=60, clean session set, # client id 01-will-unpwd-set , will topic set to "will-topic", will payload # set to "will message", will qos=2, will retain not set, username set to # "oibvvwqw" and password set to "#'^2hg9a&nm38*us". import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("01-will-unpwd-set", keepalive=keepalive, username="oibvvwqw", password="#'^2hg9a&nm38*us", will_topic="will-topic", will_qos=2, will_payload="will message".encode('utf-8')) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/01-zero-length-clientid.py000077500000000000000000000014031373244276700233350ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client connects correctly with a zero length clientid. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("", keepalive=keepalive, proto_name="MQTT", proto_ver=4) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/02-subscribe-qos0.py000077500000000000000000000030461373244276700221550ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct SUBSCRIBE to a topic with QoS 0. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id subscribe-qos0-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a SUBSCRIBE # message to subscribe to topic "qos0/test" with QoS=0. If rc!=0, the client # should exit with an error. # Upon receiving the correct SUBSCRIBE message, the test will reply with a # SUBACK message with the accepted QoS set to 0. On receiving the SUBACK # message, the client should send a DISCONNECT message. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("subscribe-qos0-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 1 subscribe_packet = paho_test.gen_subscribe(mid, "qos0/test", 0) suback_packet = paho_test.gen_suback(mid, 0) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "subscribe", subscribe_packet): conn.send(suback_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/02-subscribe-qos1.py000077500000000000000000000030461373244276700221560ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct SUBSCRIBE to a topic with QoS 1. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id subscribe-qos1-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a SUBSCRIBE # message to subscribe to topic "qos1/test" with QoS=1. If rc!=0, the client # should exit with an error. # Upon receiving the correct SUBSCRIBE message, the test will reply with a # SUBACK message with the accepted QoS set to 1. On receiving the SUBACK # message, the client should send a DISCONNECT message. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("subscribe-qos1-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 1 subscribe_packet = paho_test.gen_subscribe(mid, "qos1/test", 1) suback_packet = paho_test.gen_suback(mid, 1) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "subscribe", subscribe_packet): conn.send(suback_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/02-subscribe-qos2.py000077500000000000000000000030461373244276700221570ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct SUBSCRIBE to a topic with QoS 2. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id subscribe-qos2-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a SUBSCRIBE # message to subscribe to topic "qos2/test" with QoS=2. If rc!=0, the client # should exit with an error. # Upon receiving the correct SUBSCRIBE message, the test will reply with a # SUBACK message with the accepted QoS set to 2. On receiving the SUBACK # message, the client should send a DISCONNECT message. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("subscribe-qos2-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 1 subscribe_packet = paho_test.gen_subscribe(mid, "qos2/test", 2) suback_packet = paho_test.gen_suback(mid, 2) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "subscribe", subscribe_packet): conn.send(suback_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/02-unsubscribe.py000077500000000000000000000017421373244276700216410ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct UNSUBSCRIBE packet. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("unsubscribe-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 1 unsubscribe_packet = paho_test.gen_unsubscribe(mid, "unsubscribe/test") unsuback_packet = paho_test.gen_unsuback(mid) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "unsubscribe", unsubscribe_packet): conn.send(unsuback_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-b2c-qos1.py000077500000000000000000000031111373244276700223010ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client responds correctly to a PUBLISH with QoS 1. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id publish-qos1-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK the client should verify that rc==0. # The test will send the client a PUBLISH message with topic # "pub/qos1/receive", payload of "message", QoS=1 and mid=123. The client # should handle this as per the spec by sending a PUBACK message. # The client should then exit with return code==0. import time import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("publish-qos1-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 123 publish_packet = paho_test.gen_publish( u"pub/qos1/receive", qos=1, mid=mid, payload="message".encode('utf-8')) puback_packet = paho_test.gen_puback(mid) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) conn.send(publish_packet) if paho_test.expect_packet(conn, "puback", puback_packet): rc = 0 conn.close() finally: for i in range(0, 5): if client.returncode != None: break time.sleep(0.1) client.terminate() client.wait() sock.close() if client.returncode != 0: exit(1) exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-b2c-qos2.py000077500000000000000000000044221373244276700223100ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client responds correctly to a PUBLISH with QoS 1. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id publish-qos2-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK the client should verify that rc==0. # The test will send the client a PUBLISH message with topic # "pub/qos2/receive", payload of "message", QoS=2 and mid=13423. The client # should handle this as per the spec by sending a PUBREC message. # The test will not respond to the first PUBREC message, so the client must # resend the PUBREC message with dup=1. Note that to keep test durations low, a # message retry timeout of less than 5 seconds is required for this test. # On receiving the second PUBREC with dup==1, the test will send the correct # PUBREL message. The client should respond to this with the correct PUBCOMP # message and then exit with return code=0. import time import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("publish-qos2-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 13423 publish_packet = paho_test.gen_publish( u"pub/qos2/receive", qos=2, mid=mid, payload="message".encode('utf-8')) pubrec_packet = paho_test.gen_pubrec(mid) pubrel_packet = paho_test.gen_pubrel(mid) pubcomp_packet = paho_test.gen_pubcomp(mid) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) conn.send(publish_packet) if paho_test.expect_packet(conn, "pubrec", pubrec_packet): # Should be repeated due to timeout if paho_test.expect_packet(conn, "pubrec", pubrec_packet): conn.send(pubrel_packet) if paho_test.expect_packet(conn, "pubcomp", pubcomp_packet): rc = 0 conn.close() finally: for i in range(0, 5): if client.returncode != None: break time.sleep(0.1) client.terminate() client.wait() sock.close() if client.returncode != 0: exit(1) exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-c2b-qos1-disconnect.py000077500000000000000000000031171373244276700244360ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct PUBLISH to a topic with QoS 1, then responds correctly to a disconnect. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect( "publish-qos1-test", keepalive=keepalive, clean_session=False, ) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 1 publish_packet = paho_test.gen_publish( u"pub/qos1/test", qos=1, mid=mid, payload="message".encode('utf-8')) publish_packet_dup = paho_test.gen_publish( u"pub/qos1/test", qos=1, mid=mid, payload="message".encode('utf-8'), dup=True) puback_packet = paho_test.gen_puback(mid) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(15) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): # Disconnect client. It should reconnect. conn.close() (conn, address) = sock.accept() conn.settimeout(15) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "retried publish", publish_packet_dup): conn.send(puback_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-c2b-qos1-timeout.py000077500000000000000000000041641373244276700237760ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct PUBLISH to a topic with QoS 1 and responds to a delay. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id publish-qos1-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK the client should verify that rc==0. If not, it should exit with # return code=1. # On a successful CONNACK, the client should send a PUBLISH message with topic # "pub/qos1/test", payload "message" and QoS=1. # The test will not respond to the first PUBLISH message, so the client must # resend the PUBLISH message with dup=1. Note that to keep test durations low, a # message retry timeout of less than 5 seconds is required for this test. # On receiving the second PUBLISH message, the test will send the correct # PUBACK response. On receiving the correct PUBACK response, the client should # send a DISCONNECT message. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("publish-qos1-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 1 publish_packet = paho_test.gen_publish( u"pub/qos1/test", qos=1, mid=mid, payload="message".encode('utf-8')) publish_packet_dup = paho_test.gen_publish( u"pub/qos1/test", qos=1, mid=mid, payload="message".encode('utf-8'), dup=True) puback_packet = paho_test.gen_puback(mid) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(5) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): # Delay for > 3 seconds (message retry time) if paho_test.expect_packet(conn, "dup publish", publish_packet_dup): conn.send(puback_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-c2b-qos2-disconnect.py000077500000000000000000000044621373244276700244430ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct PUBLISH to a topic with QoS 2 and responds to a disconnect. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect( "publish-qos2-test", keepalive=keepalive, clean_session=False, ) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 1 publish_packet = paho_test.gen_publish( u"pub/qos2/test", qos=2, mid=mid, payload="message".encode('utf-8')) publish_dup_packet = paho_test.gen_publish( u"pub/qos2/test", qos=2, mid=mid, payload="message".encode('utf-8'), dup=True) pubrec_packet = paho_test.gen_pubrec(mid) pubrel_packet = paho_test.gen_pubrel(mid) pubcomp_packet = paho_test.gen_pubcomp(mid) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(5) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): # Disconnect client. It should reconnect. conn.close() (conn, address) = sock.accept() conn.settimeout(15) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "retried publish", publish_dup_packet): conn.send(pubrec_packet) if paho_test.expect_packet(conn, "pubrel", pubrel_packet): # Disconnect client. It should reconnect. conn.close() (conn, address) = sock.accept() conn.settimeout(15) # Complete connection and message flow. if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "retried pubrel", pubrel_packet): conn.send(pubcomp_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-c2b-qos2-timeout.py000077500000000000000000000053201373244276700237720ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct PUBLISH to a topic with QoS 1 and responds to a delay. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id publish-qos2-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK the client should verify that rc==0. If not, it should exit with # return code=1. # On a successful CONNACK, the client should send a PUBLISH message with topic # "pub/qos2/test", payload "message" and QoS=2. # The test will not respond to the first PUBLISH message, so the client must # resend the PUBLISH message with dup=1. Note that to keep test durations low, a # message retry timeout of less than 5 seconds is required for this test. # On receiving the second PUBLISH message, the test will send the correct # PUBREC response. On receiving the correct PUBREC response, the client should # send a PUBREL message. # The test will not respond to the first PUBREL message, so the client must # resend the PUBREL message with dup=1. On receiving the second PUBREL message, # the test will send the correct PUBCOMP response. On receiving the correct # PUBCOMP response, the client should send a DISCONNECT message. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("publish-qos2-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() mid = 1 publish_packet = paho_test.gen_publish( u"pub/qos2/test", qos=2, mid=mid, payload="message".encode('utf-8')) publish_dup_packet = paho_test.gen_publish( u"pub/qos2/test", qos=2, mid=mid, payload="message".encode('utf-8'), dup=True) pubrec_packet = paho_test.gen_pubrec(mid) pubrel_packet = paho_test.gen_pubrel(mid) pubcomp_packet = paho_test.gen_pubcomp(mid) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(5) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): # Delay for > 3 seconds (message retry time) if paho_test.expect_packet(conn, "dup publish", publish_dup_packet): conn.send(pubrec_packet) if paho_test.expect_packet(conn, "pubrel", pubrel_packet): if paho_test.expect_packet(conn, "dup pubrel", pubrel_packet): conn.send(pubcomp_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-helper-qos0.py000077500000000000000000000026741373244276700231260ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct PUBLISH to a topic with QoS 0. # Use paho.mqtt.publish helper for that. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id publish-helper-qos0-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a PUBLISH message # to topic "pub/qos0/test" with payload "message" and QoS=0. If rc!=0, the # client should exit with an error. # After sending the PUBLISH message, the client should send a # DISCONNECT message. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect( "publish-helper-qos0-test", keepalive=keepalive, ) connack_packet = paho_test.gen_connack(rc=0) publish_packet = paho_test.gen_publish( u"pub/qos0/test", qos=0, payload="message".encode('utf-8'), ) disconnect_packet = paho_test.gen_disconnect() sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-helper-qos1-disconnect.py000077500000000000000000000031771373244276700252550ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct PUBLISH to a topic with QoS 1, # then responds correctly to a disconnect. # Use paho.mqtt.publish helper for that. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect( "publish-helper-qos1-disconnect-test", keepalive=keepalive, ) connack_packet = paho_test.gen_connack(rc=0) mid = 1 publish_packet = paho_test.gen_publish( u"pub/qos1/test", qos=1, mid=mid, payload="message".encode('utf-8'), ) publish_packet_dup = paho_test.gen_publish( u"pub/qos1/test", qos=1, mid=mid, payload="message".encode('utf-8'), dup=True, ) puback_packet = paho_test.gen_puback(mid) disconnect_packet = paho_test.gen_disconnect() sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): # Disconnect client. It should reconnect. conn.close() (conn, address) = sock.accept() conn.settimeout(15) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "retried publish", publish_packet_dup): conn.send(puback_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-qos0-no-payload.py000077500000000000000000000025771373244276700237140ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct PUBLISH to a topic with QoS 0 and no payload. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id publish-qos0-test-np # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a PUBLISH message # to topic "pub/qos0/no-payload/test" with zero length payload and QoS=0. If # rc!=0, the client should exit with an error. # After sending the PUBLISH message, the client should send a DISCONNECT message. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("publish-qos0-test-np", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) publish_packet = paho_test.gen_publish(u"pub/qos0/no-payload/test", qos=0) disconnect_packet = paho_test.gen_disconnect() sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/03-publish-qos0.py000077500000000000000000000025651373244276700216500ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct PUBLISH to a topic with QoS 0. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id publish-qos0-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a PUBLISH message # to topic "pub/qos0/test" with payload "message" and QoS=0. If rc!=0, the # client should exit with an error. # After sending the PUBLISH message, the client should send a DISCONNECT message. import context import paho_test rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("publish-qos0-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) publish_packet = paho_test.gen_publish(u"pub/qos0/test", qos=0, payload="message".encode('utf-8')) disconnect_packet = paho_test.gen_disconnect() sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/04-retain-qos0.py000077500000000000000000000015171373244276700214610ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client sends a correct retained PUBLISH to a topic with QoS 0. import context import paho_test rc = 1 keepalive = 60 mid = 16 connect_packet = paho_test.gen_connect("retain-qos0-test", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) publish_packet = paho_test.gen_publish( u"retain/qos0/test", qos=0, payload="retained message".encode('utf-8'), retain=True) sock = paho_test.create_server_socket() client = context.start_client() try: (conn, address) = sock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "publish", publish_packet): rc = 0 conn.close() finally: client.terminate() client.wait() sock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/08-ssl-bad-cacert.py000077500000000000000000000002251373244276700221020ustar00rootroot00000000000000#!/usr/bin/env python import context context.check_ssl() rc = 1 client = context.start_client() client.wait() rc = client.returncode exit(rc) paho.mqtt.python-1.5.1/test/lib/08-ssl-connect-cert-auth.py000077500000000000000000000024341373244276700234440ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect and subsequent disconnect when using SSL. # Client must provide a certificate. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id 08-ssl-connect-crt-auth # It should use the CA certificate ssl/all-ca.crt for verifying the server. # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a DISCONNECT # message. If rc!=0, the client should exit with an error. import context import paho_test from paho_test import ssl context.check_ssl() rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("08-ssl-connect-crt-auth", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() ssock = paho_test.create_server_socket_ssl(cert_reqs=ssl.CERT_REQUIRED) client = context.start_client() try: (conn, address) = ssock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() ssock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/08-ssl-connect-no-auth.py000077500000000000000000000023001373244276700231130ustar00rootroot00000000000000#!/usr/bin/env python # Test whether a client produces a correct connect and subsequent disconnect when using SSL. # The client should connect to port 1888 with keepalive=60, clean session set, # and client id 08-ssl-connect-no-auth # It should use the CA certificate ssl/all-ca.crt for verifying the server. # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a DISCONNECT # message. If rc!=0, the client should exit with an error. import context import paho_test context.check_ssl() rc = 1 keepalive = 60 connect_packet = paho_test.gen_connect("08-ssl-connect-no-auth", keepalive=keepalive) connack_packet = paho_test.gen_connack(rc=0) disconnect_packet = paho_test.gen_disconnect() ssock = paho_test.create_server_socket_ssl() client = context.start_client() try: (conn, address) = ssock.accept() conn.settimeout(10) if paho_test.expect_packet(conn, "connect", connect_packet): conn.send(connack_packet) if paho_test.expect_packet(conn, "disconnect", disconnect_packet): rc = 0 conn.close() finally: client.terminate() client.wait() ssock.close() exit(rc) paho.mqtt.python-1.5.1/test/lib/08-ssl-fake-cacert.py000077500000000000000000000007751373244276700222740ustar00rootroot00000000000000#!/usr/bin/env python import time import context import paho_test from paho_test import ssl context.check_ssl() ssock = paho_test.create_server_socket_ssl(cert_reqs=ssl.CERT_REQUIRED) client = context.start_client() try: (conn, address) = ssock.accept() conn.close() except ssl.SSLError: # Expected error due to ca certs not matching. pass finally: time.sleep(1.0) client.terminate() client.wait() ssock.close() if client.returncode == 0: exit(0) else: exit(1) paho.mqtt.python-1.5.1/test/lib/Makefile000066400000000000000000000035411373244276700201600ustar00rootroot00000000000000.PHONY: all test .NOTPARALLEL: all : test : python ./01-will-set.py python/01-will-set.test python ./01-unpwd-set.py python/01-unpwd-set.test python ./01-unpwd-unicode-set.py python/01-unpwd-unicode-set.test python ./01-unpwd-empty-password-set.py python/01-unpwd-empty-password-set.test python ./01-unpwd-empty-set.py python/01-unpwd-empty-set.test python ./01-will-unpwd-set.py python/01-will-unpwd-set.test python ./01-zero-length-clientid.py python/01-zero-length-clientid.test python ./01-no-clean-session.py python/01-no-clean-session.test python ./01-keepalive-pingreq.py python/01-keepalive-pingreq.test python ./02-subscribe-qos0.py python/02-subscribe-qos0.test python ./02-subscribe-qos1.py python/02-subscribe-qos1.test python ./02-subscribe-qos2.py python/02-subscribe-qos2.test python ./02-unsubscribe.py python/02-unsubscribe.test python ./03-publish-qos0.py python/03-publish-qos0.test python ./03-publish-qos0-no-payload.py python/03-publish-qos0-no-payload.test python ./03-publish-c2b-qos1-timeout.py python/03-publish-c2b-qos1-timeout.test python ./03-publish-c2b-qos1-disconnect.py python/03-publish-c2b-qos1-disconnect.test python ./03-publish-c2b-qos2-timeout.py python/03-publish-c2b-qos2-timeout.test python ./03-publish-c2b-qos2-disconnect.py python/03-publish-c2b-qos2-disconnect.test python ./03-publish-b2c-qos1.py python/03-publish-b2c-qos1.test python ./03-publish-b2c-qos2.py python/03-publish-b2c-qos2.test python ./03-publish-helper-qos0.py python/03-publish-helper-qos0.test python ./03-publish-helper-qos1-disconnect.py python/03-publish-helper-qos1-disconnect.test python ./04-retain-qos0.py python/04-retain-qos0.test python ./08-ssl-connect-no-auth.py python/08-ssl-connect-no-auth.test python ./08-ssl-connect-cert-auth.py python/08-ssl-connect-cert-auth.test python ./08-ssl-bad-cacert.py python/08-ssl-bad-cacert.test paho.mqtt.python-1.5.1/test/lib/context.py000066400000000000000000000023141373244276700205530ustar00rootroot00000000000000# -*- coding: utf-8 -*- import sys import os import subprocess try: import ssl except ImportError: ssl = None # Ensure can import paho_test package try: import paho_test except ImportError: # This part is only required when paho_test module is not on Python path # From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder import inspect cmd_subfolder = os.path.realpath( os.path.abspath( os.path.join( os.path.split( inspect.getfile(inspect.currentframe()) )[0], "..", ) ) ) if cmd_subfolder not in sys.path: sys.path.insert(0, cmd_subfolder) import paho_test env = dict(os.environ) pp = env.get('PYTHONPATH', '') env['PYTHONPATH'] = '../../src' + os.pathsep + pp def start_client(): args = [sys.executable, ] + sys.argv[1:] client = subprocess.Popen(args, env=env) return client def check_ssl(): if ssl is None: print("WARNING: SSL not available in current environment") exit(0) if not hasattr(ssl, 'SSLContext'): print("WARNING: SSL without SSLContext is not supported") exit(0) paho.mqtt.python-1.5.1/test/lib/python/000077500000000000000000000000001373244276700200365ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/lib/python/01-keepalive-pingreq.test000077500000000000000000000005761373244276700246000ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) run = -1 mqttc = mqtt.Client("01-keepalive-pingreq") mqttc.on_connect = on_connect mqttc.connect("localhost", 1888, 4) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/01-no-clean-session.test000077500000000000000000000003021373244276700243300ustar00rootroot00000000000000#!/usr/bin/env python import paho.mqtt.client as mqtt mqttc = mqtt.Client("01-no-clean-session", False) run = -1 mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/01-unpwd-empty-password-set.test000077500000000000000000000003271373244276700261040ustar00rootroot00000000000000#!/usr/bin/env python import paho.mqtt.client as mqtt mqttc = mqtt.Client("01-unpwd-set") run = -1 mqttc.username_pw_set("uname", "") mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/01-unpwd-empty-set.test000077500000000000000000000003221373244276700242370ustar00rootroot00000000000000#!/usr/bin/env python import paho.mqtt.client as mqtt mqttc = mqtt.Client("01-unpwd-set") run = -1 mqttc.username_pw_set("", "") mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/01-unpwd-set.test000077500000000000000000000003401373244276700231030ustar00rootroot00000000000000#!/usr/bin/env python import paho.mqtt.client as mqtt mqttc = mqtt.Client("01-unpwd-set") run = -1 mqttc.username_pw_set("uname", ";'[08gn=#") mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/01-unpwd-unicode-set.test000066400000000000000000000005461373244276700245340ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import unicode_literals import paho.mqtt.client as mqtt mqttc = mqtt.Client("01-unpwd-unicode-set") run = -1 username = "\u00fas\u00e9rn\u00e1m\u00e9-h\u00e9ll\u00f3" password = "h\u00e9ll\u00f3" mqttc.username_pw_set(username, password) mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/01-will-set.test000077500000000000000000000003751373244276700227250ustar00rootroot00000000000000#!/usr/bin/env python import paho.mqtt.client as mqtt mqttc = mqtt.Client("01-will-set") run = -1 mqttc.will_set("topic/on/unexpected/disconnect", "will message", 1, True) mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/01-will-unpwd-set.test000077500000000000000000000004461373244276700240570ustar00rootroot00000000000000#!/usr/bin/env python import paho.mqtt.client as mqtt mqttc = mqtt.Client("01-will-unpwd-set") run = -1 mqttc.username_pw_set("oibvvwqw", "#'^2hg9a&nm38*us") mqttc.will_set("will-topic", "will message", 2, False) mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/01-zero-length-clientid.test000077500000000000000000000010201373244276700252000ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.disconnect() def on_disconnect(mqttc, obj, rc): mqttc.loop() obj = rc run = -1 mqttc = mqtt.Client("", run, protocol=mqtt.MQTTv311) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/02-subscribe-qos0.test000077500000000000000000000011601373244276700240200ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.subscribe("qos0/test", 0) def on_disconnect(mqttc, obj, rc): obj = rc def on_subscribe(mqttc, obj, mid, granted_qos): mqttc.disconnect() run = -1 mqttc = mqtt.Client("subscribe-qos0-test", run) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.on_subscribe = on_subscribe mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/02-subscribe-qos1.test000077500000000000000000000011601373244276700240210ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.subscribe("qos1/test", 1) def on_disconnect(mqttc, obj, rc): obj = rc def on_subscribe(mqttc, obj, mid, granted_qos): mqttc.disconnect() run = -1 mqttc = mqtt.Client("subscribe-qos1-test", run) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.on_subscribe = on_subscribe mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/02-subscribe-qos2.test000077500000000000000000000011601373244276700240220ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.subscribe("qos2/test", 2) def on_disconnect(mqttc, obj, rc): obj = rc def on_subscribe(mqttc, obj, mid, granted_qos): mqttc.disconnect() run = -1 mqttc = mqtt.Client("subscribe-qos2-test", run) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.on_subscribe = on_subscribe mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/02-unsubscribe.test000077500000000000000000000011541373244276700235060ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.unsubscribe("unsubscribe/test") def on_disconnect(mqttc, obj, rc): obj = rc def on_unsubscribe(mqttc, obj, mid): mqttc.disconnect() run = -1 mqttc = mqtt.Client("unsubscribe-test", run) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.on_unsubscribe = on_unsubscribe mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/03-publish-b2c-qos1.test000077500000000000000000000021661373244276700241620ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt if sys.version_info[0] < 3: expected_payload = "message" else: expected_payload = b"message" def on_message(mqttc, obj, msg): if msg.mid != 123: print("Invalid mid: ("+str(msg.mid)+")") exit(1) if msg.topic != "pub/qos1/receive": print("Invalid topic: ("+str(msg.topic)+")") exit(1) if msg.payload != expected_payload: print("Invalid payload: ("+str(msg.payload)+")") exit(1) if msg.qos != 1: print("Invalid qos: ("+str(msg.qos)+")") exit(1) if msg.retain != False: print("Invalid retain: ("+str(msg.retain)+")") exit(1) exit(0) def on_connect(mqttc, obj, flags, rc): if rc != 0: print("Connect failed ("+str(rc)+")") exit(rc) mqttc = mqtt.Client("publish-qos1-test") mqttc.message_retry_set(3) mqttc.on_connect = on_connect mqttc.on_message = on_message mqttc.connect("localhost", 1888) rc = 0 while rc == 0: rc = mqttc.loop() print("rc: "+str(rc)) exit(1) paho.mqtt.python-1.5.1/test/lib/python/03-publish-b2c-qos2.test000077500000000000000000000021411373244276700241540ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt if sys.version_info[0] < 3: expected_payload = "message" else: expected_payload = b"message" def on_message(mqttc, obj, msg): global run if msg.mid != 13423: print("Invalid mid ("+str(msg.mid)+")") exit(1) if msg.topic != "pub/qos2/receive": print("Invalid topic ("+str(msg.topic)+")") exit(1) if msg.payload != expected_payload: print("Invalid payload ("+str(msg.payload)+")") exit(1) if msg.qos != 2: print("Invalid qos ("+str(msg.qos)+")") exit(1) if msg.retain != False: print("Invalid retain ("+str(msg.retain)+")") exit(1) run = 0 def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) run = -1 mqttc = mqtt.Client("publish-qos2-test", run) mqttc.message_retry_set(3) mqttc.on_connect = on_connect mqttc.on_message = on_message mqttc.connect("localhost", 1888) rc = 0 while run == -1 and rc == 0: rc = mqttc.loop(0.3) exit(run) paho.mqtt.python-1.5.1/test/lib/python/03-publish-c2b-qos1-disconnect.test000077500000000000000000000015541373244276700263110ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt sent_mid = -1 def on_connect(mqttc, obj, flags, rc): global sent_mid if rc != 0: exit(rc) else: if sent_mid == -1: res = mqttc.publish("pub/qos1/test", "message", 1) sent_mid = res[1] def on_disconnect(mqttc, obj, rc): if rc == 1: mqttc.reconnect() else: run = 0 def on_publish(mqttc, obj, mid): global sent_mid if mid == sent_mid: mqttc.disconnect() else: exit(1) mqttc = mqtt.Client("publish-qos1-test", clean_session=False) mqttc.message_retry_set(3) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.on_publish = on_publish mqttc.connect("localhost", 1888) rc = 0 while True: rc = mqttc.loop() paho.mqtt.python-1.5.1/test/lib/python/03-publish-c2b-qos1-timeout.test000077500000000000000000000014461373244276700256460ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt sent_mid = -1 def on_connect(mqttc, obj, flags, rc): global sent_mid if rc != 0: exit(rc) else: res = mqttc.publish("pub/qos1/test", "message", 1) sent_mid = res[1] def on_disconnect(mqttc, obj, rc): run = 0 def on_publish(mqttc, obj, mid): global sent_mid if mid == sent_mid: mqttc.disconnect() else: exit(1) run = -1 mqttc = mqtt.Client("publish-qos1-test", run) mqttc.message_retry_set(3) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.on_publish = on_publish mqttc.connect("localhost", 1888) rc = 0 while run == -1 and rc == 0: rc = mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/03-publish-c2b-qos2-disconnect.test000077500000000000000000000014651373244276700263130ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt first_connection = 1 def on_connect(mqttc, obj, flags, rc): global first_connection if rc != 0: exit(rc) else: if first_connection == 1: mqttc.publish("pub/qos2/test", "message", 2) first_connection = 0 def on_disconnect(mqttc, obj, rc): if rc == 1: mqttc.reconnect() else: run = 0 def on_publish(mqttc, obj, mid): mqttc.disconnect() mqttc = mqtt.Client("publish-qos2-test", clean_session=False) mqttc.message_retry_set(3) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.on_publish = on_publish mqttc.connect("localhost", 1888) rc = 0 while True: rc = mqttc.loop() paho.mqtt.python-1.5.1/test/lib/python/03-publish-c2b-qos2-timeout.test000077500000000000000000000012321373244276700256400ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.publish("pub/qos2/test", "message", 2) def on_disconnect(mqttc, obj, rc): run = 0 def on_publish(mqttc, obj, mid): mqttc.disconnect() run = -1 mqttc = mqtt.Client("publish-qos2-test", run) mqttc.message_retry_set(3) mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.on_publish = on_publish mqttc.connect("localhost", 1888) rc = 0 while run == -1 and rc == 0: rc = mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/03-publish-helper-qos0.test000077500000000000000000000003201373244276700247600ustar00rootroot00000000000000#!/usr/bin/env python import paho.mqtt.publish paho.mqtt.publish.single( "pub/qos0/test", "message", qos=0, hostname="localhost", port=1888, client_id="publish-helper-qos0-test", ) paho.mqtt.python-1.5.1/test/lib/python/03-publish-helper-qos1-disconnect.test000077500000000000000000000003331373244276700271140ustar00rootroot00000000000000#!/usr/bin/env python import paho.mqtt.publish paho.mqtt.publish.single( "pub/qos1/test", "message", qos=1, hostname="localhost", port=1888, client_id="publish-helper-qos1-disconnect-test", ) paho.mqtt.python-1.5.1/test/lib/python/03-publish-qos0-no-payload.test000077500000000000000000000012141373244276700255470ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt sent_mid = -1 def on_connect(mqttc, obj, flags, rc): global sent_mid if rc != 0: exit(rc) else: (res, sent_mid) = mqttc.publish("pub/qos0/no-payload/test") def on_publish(mqttc, obj, mid): global sent_mid, run if sent_mid == mid: mqttc.disconnect() run = 0 run = -1 mqttc = mqtt.Client("publish-qos0-test-np", run) mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/03-publish-qos0.test000077500000000000000000000012071373244276700235100ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt sent_mid = -1 def on_connect(mqttc, obj, flags, rc): global sent_mid if rc != 0: exit(rc) else: res = mqttc.publish("pub/qos0/test", "message") sent_mid = res[1] def on_publish(mqttc, obj, mid): global sent_mid, run if sent_mid == mid: mqttc.disconnect() run = -1 mqttc = mqtt.Client("publish-qos0-test", run) mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/04-retain-qos0.test000077500000000000000000000007151373244276700233300ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.publish("retain/qos0/test", "retained message", 0, True) run = -1 mqttc = mqtt.Client("retain-qos0-test", run) mqttc.on_connect = on_connect mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/08-ssl-bad-cacert.test000077500000000000000000000006041373244276700237530ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt if sys.version_info < (2, 7, 9): print("WARNING: SSL/TLS not supported on Python 2.6") exit(0) rc = 1 mqttc = mqtt.Client("08-ssl-bad-cacert") try: mqttc.tls_set("this/file/doesnt/exist") except IOError as err: rc = 0 exit(rc) paho.mqtt.python-1.5.1/test/lib/python/08-ssl-connect-cert-auth.test000077500000000000000000000012631373244276700253130ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt if sys.version_info < (2, 7, 9): print("WARNING: SSL/TLS not supported on Python 2.6") exit(0) def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.disconnect() def on_disconnect(mqttc, obj, rc): obj = rc run = -1 mqttc = mqtt.Client("08-ssl-connect-crt-auth", run) mqttc.tls_set("../ssl/all-ca.crt", "../ssl/client.crt", "../ssl/client.key") mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/08-ssl-connect-no-auth.test000077500000000000000000000012101373244276700247620ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import paho.mqtt.client as mqtt if sys.version_info < (2, 7, 9): print("WARNING: SSL/TLS not supported on Python 2.6") exit(0) def on_connect(mqttc, obj, flags, rc): if rc != 0: exit(rc) else: mqttc.disconnect() def on_disconnect(mqttc, obj, rc): obj = rc run = -1 mqttc = mqtt.Client("08-ssl-connect-no-auth", run) mqttc.tls_set("../ssl/all-ca.crt") mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect mqttc.connect("localhost", 1888) while run == -1: mqttc.loop() exit(run) paho.mqtt.python-1.5.1/test/lib/python/08-ssl-fake-cacert.test000077500000000000000000000012411373244276700241310ustar00rootroot00000000000000#!/usr/bin/env python import os import subprocess import socket import sys import time from struct import * import ssl import paho.mqtt.client as mqtt if sys.version_info < (2, 7, 9): print("WARNING: SSL/TLS not supported on Python 2.6") exit(0) def on_connect(mqttc, obj, flags, rc): exit(1) mqttc = mqtt.Client("08-ssl-fake-cacert") mqttc.tls_set("../ssl/test-fake-root-ca.crt", "../ssl/client.crt", "../ssl/client.key") mqttc.on_connect = on_connect try: mqttc.connect("localhost", 1888) except ssl.SSLError as msg: if msg.errno == 1 and "certificate verify failed" in msg.strerror: exit(0) else: exit(1) else: exit(1) paho.mqtt.python-1.5.1/test/paho_test.py000066400000000000000000000324751373244276700203220ustar00rootroot00000000000000import binascii import struct import socket import sys try: import ssl except ImportError: ssl = None if sys.version_info[0] >= 3: # define some alias for python2 compatibility unicode = str def create_server_socket(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.settimeout(10) sock.bind(('', 1888)) sock.listen(5) return sock def create_server_socket_ssl(*args, **kwargs): if ssl is None: raise RuntimeError ssl_version = ssl.PROTOCOL_TLSv1 if hasattr(ssl, "PROTOCOL_TLS"): ssl_version = ssl.PROTOCOL_TLS sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) ssock = ssl.wrap_socket( sock, ca_certs="../ssl/all-ca.crt", keyfile="../ssl/server.key", certfile="../ssl/server.crt", server_side=True, ssl_version=ssl_version, **kwargs) ssock.settimeout(10) ssock.bind(('', 1888)) ssock.listen(5) return ssock def expect_packet(sock, name, expected): if len(expected) > 0: rlen = len(expected) else: rlen = 1 packet_recvd = sock.recv(rlen) return packet_matches(name, packet_recvd, expected) def packet_matches(name, recvd, expected): if recvd != expected: print("FAIL: Received incorrect " + name + ".") try: print("Received: " + to_string(recvd)) except struct.error: print("Received (not decoded): 0x" + binascii.b2a_hex(recvd).decode('utf8')) try: print("Expected: " + to_string(expected)) except struct.error: print("Expected (not decoded): 0x" + binascii.b2a_hex(expected).decode('utf8')) return 0 else: return 1 def remaining_length(packet): l = min(5, len(packet)) all_bytes = struct.unpack("!" + "B" * l, packet[:l]) mult = 1 rl = 0 for i in range(1, l - 1): byte = all_bytes[i] rl += (byte & 127) * mult mult *= 128 if byte & 128 == 0: packet = packet[i + 1:] break return (packet, rl) def to_string(packet): if len(packet) == 0: return "" packet0 = struct.unpack("!B", packet[0:1]) packet0 = packet0[0] cmd = packet0 & 0xF0 if cmd == 0x00: # Reserved return "0x00" elif cmd == 0x10: # CONNECT (packet, rl) = remaining_length(packet) pack_format = "!H" + str(len(packet) - 2) + 's' (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen) + 'sBBH' + str(len(packet) - slen - 4) + 's' (protocol, proto_ver, flags, keepalive, packet) = struct.unpack(pack_format, packet) s = "CONNECT, proto=" + protocol + str(proto_ver) + ", keepalive=" + str(keepalive) if flags & 2: s = s + ", clean-session" else: s = s + ", durable" pack_format = "!H" + str(len(packet) - 2) + 's' (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen) + 's' + str(len(packet) - slen) + 's' (client_id, packet) = struct.unpack(pack_format, packet) s = s + ", id=" + client_id if flags & 4: pack_format = "!H" + str(len(packet) - 2) + 's' (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen) + 's' + str(len(packet) - slen) + 's' (will_topic, packet) = struct.unpack(pack_format, packet) s = s + ", will-topic=" + will_topic pack_format = "!H" + str(len(packet) - 2) + 's' (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen) + 's' + str(len(packet) - slen) + 's' (will_message, packet) = struct.unpack(pack_format, packet) s = s + ", will-message=" + will_message s = s + ", will-qos=" + str((flags & 24) >> 3) s = s + ", will-retain=" + str((flags & 32) >> 5) if flags & 128: pack_format = "!H" + str(len(packet) - 2) + 's' (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen) + 's' + str(len(packet) - slen) + 's' (username, packet) = struct.unpack(pack_format, packet) s = s + ", username=" + username if flags & 64: pack_format = "!H" + str(len(packet) - 2) + 's' (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen) + 's' + str(len(packet) - slen) + 's' (password, packet) = struct.unpack(pack_format, packet) s = s + ", password=" + password return s elif cmd == 0x20: # CONNACK (cmd, rl, resv, rc) = struct.unpack('!BBBB', packet) return "CONNACK, rl=" + str(rl) + ", res=" + str(resv) + ", rc=" + str(rc) elif cmd == 0x30: # PUBLISH dup = (packet0 & 0x08) >> 3 qos = (packet0 & 0x06) >> 1 retain = (packet0 & 0x01) (packet, rl) = remaining_length(packet) pack_format = "!H" + str(len(packet) - 2) + 's' (tlen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(tlen) + 's' + str(len(packet) - tlen) + 's' (topic, packet) = struct.unpack(pack_format, packet) s = "PUBLISH, rl=" + str(rl) + ", topic=" + topic + ", qos=" + str(qos) + ", retain=" + str( retain) + ", dup=" + str(dup) if qos > 0: pack_format = "!H" + str(len(packet) - 2) + 's' (mid, packet) = struct.unpack(pack_format, packet) s = s + ", mid=" + str(mid) s = s + ", payload=" + packet return s elif cmd == 0x40: # PUBACK (cmd, rl, mid) = struct.unpack('!BBH', packet) return "PUBACK, rl=" + str(rl) + ", mid=" + str(mid) elif cmd == 0x50: # PUBREC (cmd, rl, mid) = struct.unpack('!BBH', packet) return "PUBREC, rl=" + str(rl) + ", mid=" + str(mid) elif cmd == 0x60: # PUBREL dup = (packet0 & 0x08) >> 3 (cmd, rl, mid) = struct.unpack('!BBH', packet) return "PUBREL, rl=" + str(rl) + ", mid=" + str(mid) + ", dup=" + str(dup) elif cmd == 0x70: # PUBCOMP (cmd, rl, mid) = struct.unpack('!BBH', packet) return "PUBCOMP, rl=" + str(rl) + ", mid=" + str(mid) elif cmd == 0x80: # SUBSCRIBE (packet, rl) = remaining_length(packet) pack_format = "!H" + str(len(packet) - 2) + 's' (mid, packet) = struct.unpack(pack_format, packet) s = "SUBSCRIBE, rl=" + str(rl) + ", mid=" + str(mid) topic_index = 0 while len(packet) > 0: pack_format = "!H" + str(len(packet) - 2) + 's' (tlen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(tlen) + 'sB' + str(len(packet) - tlen - 1) + 's' (topic, qos, packet) = struct.unpack(pack_format, packet) s = s + ", topic" + str(topic_index) + "=" + topic + "," + str(qos) return s elif cmd == 0x90: # SUBACK (packet, rl) = remaining_length(packet) pack_format = "!H" + str(len(packet) - 2) + 's' (mid, packet) = struct.unpack(pack_format, packet) pack_format = "!" + "B" * len(packet) granted_qos = struct.unpack(pack_format, packet) s = "SUBACK, rl=" + str(rl) + ", mid=" + str(mid) + ", granted_qos=" + str(granted_qos[0]) for i in range(1, len(granted_qos) - 1): s = s + ", " + str(granted_qos[i]) return s elif cmd == 0xA0: # UNSUBSCRIBE (packet, rl) = remaining_length(packet) pack_format = "!H" + str(len(packet) - 2) + 's' (mid, packet) = struct.unpack(pack_format, packet) s = "UNSUBSCRIBE, rl=" + str(rl) + ", mid=" + str(mid) topic_index = 0 while len(packet) > 0: pack_format = "!H" + str(len(packet) - 2) + 's' (tlen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(tlen) + 's' + str(len(packet) - tlen) + 's' (topic, packet) = struct.unpack(pack_format, packet) s = s + ", topic" + str(topic_index) + "=" + topic return s elif cmd == 0xB0: # UNSUBACK (cmd, rl, mid) = struct.unpack('!BBH', packet) return "UNSUBACK, rl=" + str(rl) + ", mid=" + str(mid) elif cmd == 0xC0: # PINGREQ (cmd, rl) = struct.unpack('!BB', packet) return "PINGREQ, rl=" + str(rl) elif cmd == 0xD0: # PINGRESP (cmd, rl) = struct.unpack('!BB', packet) return "PINGRESP, rl=" + str(rl) elif cmd == 0xE0: # DISCONNECT (cmd, rl) = struct.unpack('!BB', packet) return "DISCONNECT, rl=" + str(rl) elif cmd == 0xF0: # Reserved return "0xF0" def gen_connect(client_id, clean_session=True, keepalive=60, username=None, password=None, will_topic=None, will_qos=0, will_retain=False, will_payload="", proto_name=None, proto_ver=4): proto_name = b"MQTT" if proto_ver >= 4 else b"MQIsdp" if client_id is None: remaining_length = 12 else: client_id = client_id.encode('utf-8') remaining_length = 2 + len(proto_name) + 1 + 1 + 2 + 2 + len(client_id) connect_flags = 0 if clean_session: connect_flags = connect_flags | 0x02 if will_topic is not None: will_topic = will_topic.encode('utf-8') remaining_length = remaining_length + 2 + len(will_topic) + 2 + len(will_payload) connect_flags = connect_flags | 0x04 | ((will_qos & 0x03) << 3) if will_retain: connect_flags = connect_flags | 32 if username is not None: username = username.encode('utf-8') remaining_length = remaining_length + 2 + len(username) connect_flags = connect_flags | 0x80 if password is not None: password = password.encode('utf-8') connect_flags = connect_flags | 0x40 remaining_length = remaining_length + 2 + len(password) rl = pack_remaining_length(remaining_length) packet = struct.pack("!B" + str(len(rl)) + "s", 0x10, rl) packet = packet + struct.pack("!H" + str(len(proto_name)) + "sBBH", len(proto_name), proto_name, proto_ver, connect_flags, keepalive) if client_id is not None: packet = packet + struct.pack("!H" + str(len(client_id)) + "s", len(client_id), client_id) if will_topic is not None: packet = packet + struct.pack("!H" + str(len(will_topic)) + "s", len(will_topic), will_topic) if len(will_payload) > 0: packet = packet + struct.pack("!H" + str(len(will_payload)) + "s", len(will_payload), will_payload) else: packet = packet + struct.pack("!H", 0) if username is not None: packet = packet + struct.pack("!H" + str(len(username)) + "s", len(username), username) if password is not None: packet = packet + struct.pack("!H" + str(len(password)) + "s", len(password), password) return packet def gen_connack(resv=0, rc=0): return struct.pack('!BBBB', 32, 2, resv, rc) def gen_publish(topic, qos, payload=None, retain=False, dup=False, mid=0): if isinstance(topic, unicode): topic = topic.encode('utf-8') rl = 2 + len(topic) pack_format = "!BBH" + str(len(topic)) + "s" if qos > 0: rl = rl + 2 pack_format = pack_format + "H" if payload is not None: rl = rl + len(payload) pack_format = pack_format + str(len(payload)) + "s" else: payload = b"" pack_format = pack_format + "0s" cmd = 48 | (qos << 1) if retain: cmd = cmd + 1 if dup: cmd = cmd + 8 if qos > 0: return struct.pack(pack_format, cmd, rl, len(topic), topic, mid, payload) else: return struct.pack(pack_format, cmd, rl, len(topic), topic, payload) def gen_puback(mid): return struct.pack('!BBH', 64, 2, mid) def gen_pubrec(mid): return struct.pack('!BBH', 80, 2, mid) def gen_pubrel(mid): cmd = 96 + 2 return struct.pack('!BBH', cmd, 2, mid) def gen_pubcomp(mid): return struct.pack('!BBH', 112, 2, mid) def gen_subscribe(mid, topic, qos): topic = topic.encode('utf-8') pack_format = "!BBHH" + str(len(topic)) + "sB" return struct.pack(pack_format, 130, 2 + 2 + len(topic) + 1, mid, len(topic), topic, qos) def gen_suback(mid, qos): return struct.pack('!BBHB', 144, 2 + 1, mid, qos) def gen_unsubscribe(mid, topic): topic = topic.encode('utf-8') pack_format = "!BBHH" + str(len(topic)) + "s" return struct.pack(pack_format, 162, 2 + 2 + len(topic), mid, len(topic), topic) def gen_unsuback(mid): return struct.pack('!BBH', 176, 2, mid) def gen_pingreq(): return struct.pack('!BB', 192, 0) def gen_pingresp(): return struct.pack('!BB', 208, 0) def gen_disconnect(): return struct.pack('!BB', 224, 0) def pack_remaining_length(remaining_length): s = b"" while True: byte = remaining_length % 128 remaining_length = remaining_length // 128 # If there are more digits to encode, set the top bit of this digit if remaining_length > 0: byte = byte | 0x80 s = s + struct.pack("!B", byte) if remaining_length == 0: return s paho.mqtt.python-1.5.1/test/ssl/000077500000000000000000000000001373244276700165505ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/ssl/all-ca.crt000066400000000000000000000131201373244276700204100ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 1 (0x1) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA Validity Not Before: Jul 28 09:12:10 2020 GMT Not After : Jul 27 09:12:10 2025 GMT Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:c2:33:17:27:8f:e6:b3:b3:96:d8:fc:cc:11:8d: 5e:da:3d:a5:8e:3a:14:c7:e6:38:80:25:e6:27:c4: cf:6f:3c:b8:18:4a:6e:53:ee:81:dc:c6:e2:4a:29: 18:d9:d3:d8:45:3f:19:2c:01:b5:61:ce:b9:f1:89: 9b:0b:0c:af:f2:38:05:2e:cf:e4:57:c5:9f:4f:fc: 42:a1:2f:cc:2a:59:fa:1a:4a:24:24:55:60:d3:25: d5:a7:0f:d8:5d:f3:9a:dc:d8:13:8c:37:ae:8d:27: bb:d2:2c:37:34:3e:11:16:02:46:03:b2:48:24:de: 5e:d0:65:63:cd:0d:af:58:48:13:dc:93:d0:52:84: fa:05:69:4c:09:69:da:00:c2:af:8a:00:4c:1c:c2: 1c:f5:8b:a9:f4:30:13:33:50:fd:6a:1e:8a:10:8d: cd:01:11:1b:cf:a3:30:80:4b:96:a3:b6:e1:ed:df: 6e:69:5f:26:ed:75:9e:04:3f:49:cd:c9:6f:4a:05: 6f:6d:45:09:09:a8:34:03:97:f2:77:ae:8e:96:7f: a8:52:7b:20:71:35:2d:11:17:52:cd:b1:b1:93:26: 2f:9a:17:c1:48:3e:15:99:85:db:c6:bd:c3:35:0f: fd:d1:d9:2a:63:2b:96:59:35:93:c1:cf:5c:e1:72: 3c:73 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: 63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 X509v3 Authority Key Identifier: keyid:C7:BD:C0:22:65:FF:A7:97:A7:CB:9D:7E:44:E5:13:77:39:7D:BE:BA X509v3 Basic Constraints: CA:TRUE Signature Algorithm: sha256WithRSAEncryption 18:5c:f3:6a:e2:82:d1:ba:ee:de:00:29:4e:b3:f7:87:46:1b: fa:7e:52:9d:87:d8:73:19:5b:38:7a:af:31:aa:4c:bd:fe:45: 95:25:03:48:15:d7:e5:38:4f:e3:39:93:99:10:b4:06:dc:5a: 87:af:22:b5:2f:82:da:ef:6c:b5:f3:9c:82:71:0f:f4:d0:65: 46:b7:23:b1:7d:51:8d:d7:7c:80:12:39:99:46:2b:d4:db:c7: 42:96:1a:b6:0f:b3:10:9e:ad:84:0e:87:38:e8:34:f8:04:3d: a2:fc:3d:24:1e:09:d6:63:52:82:e4:35:ae:39:5e:f9:82:a7: ac:23:87:0e:fb:2d:ae:08:da:2a:3f:51:ee:f6:85:3a:43:80: b0:f1:96:0c:fa:10:80:18:7b:75:14:70:09:48:fc:0c:38:ee: ab:e4:32:7d:80:77:a8:2a:63:15:c9:11:b7:a9:0c:77:7d:be: d6:a3:48:37:1e:56:33:13:71:e1:12:90:ce:95:72:68:ae:d5: 01:82:00:67:1b:ae:9d:93:5b:5d:c1:3d:6e:30:e5:e1:35:ac: 59:3b:eb:ef:ee:83:0b:eb:e5:ea:9c:62:29:8c:73:a3:b5:45: 45:e8:53:ea:b8:48:16:7e:f8:c5:af:4b:89:b5:1b:94:a5:85: d9:d5:f4:13 -----BEGIN CERTIFICATE----- MIIDmDCCAoCgAwIBAgIBATANBgkqhkiG9w0BAQsFADBtMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe Fw0yMDA3MjgwOTEyMTBaFw0yNTA3MjcwOTEyMTBaMGAxCzAJBgNVBAYTAkdCMRMw EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV BAsMB1Rlc3RpbmcxEzARBgNVBAMMClNpZ25pbmcgQ0EwggEiMA0GCSqGSIb3DQEB AQUAA4IBDwAwggEKAoIBAQDCMxcnj+azs5bY/MwRjV7aPaWOOhTH5jiAJeYnxM9v PLgYSm5T7oHcxuJKKRjZ09hFPxksAbVhzrnxiZsLDK/yOAUuz+RXxZ9P/EKhL8wq WfoaSiQkVWDTJdWnD9hd85rc2BOMN66NJ7vSLDc0PhEWAkYDskgk3l7QZWPNDa9Y SBPck9BShPoFaUwJadoAwq+KAEwcwhz1i6n0MBMzUP1qHooQjc0BERvPozCAS5aj tuHt325pXybtdZ4EP0nNyW9KBW9tRQkJqDQDl/J3ro6Wf6hSeyBxNS0RF1LNsbGT Ji+aF8FIPhWZhdvGvcM1D/3R2SpjK5ZZNZPBz1zhcjxzAgMBAAGjUDBOMB0GA1Ud DgQWBBRjrYnEIxMT0esATQEOJeNeDJ1ByTAfBgNVHSMEGDAWgBTHvcAiZf+nl6fL nX5E5RN3OX2+ujAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAYXPNq 4oLRuu7eAClOs/eHRhv6flKdh9hzGVs4eq8xqky9/kWVJQNIFdflOE/jOZOZELQG 3FqHryK1L4La72y185yCcQ/00GVGtyOxfVGN13yAEjmZRivU28dClhq2D7MQnq2E Doc46DT4BD2i/D0kHgnWY1KC5DWuOV75gqesI4cO+y2uCNoqP1Hu9oU6Q4Cw8ZYM +hCAGHt1FHAJSPwMOO6r5DJ9gHeoKmMVyRG3qQx3fb7Wo0g3HlYzE3HhEpDOlXJo rtUBggBnG66dk1tdwT1uMOXhNaxZO+vv7oML6+XqnGIpjHOjtUVF6FPquEgWfvjF r0uJtRuUpYXZ1fQT -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- MIIDuDCCAqCgAwIBAgIUfktixcRWQfrifKAqkK/KyuylnZkwDQYJKoZIhvcNAQEL BQAwbTELMAkGA1UEBhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcM BURlcmJ5MRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3Rpbmcx EDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjAwNzI4MDkxMjEwWhcNMzAwNzI2MDkxMjEw WjBtMQswCQYDVQQGEwJHQjETMBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwF RGVyYnkxFTATBgNVBAoMDFBhaG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQ MA4GA1UEAwwHUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB ANvaqRfpEO9TFwwB/5syttx8Zaeyq+d0z0uyQuWPIWbp1iUrwTZTb7kwG/9HdNC0 t1KSwdb4Er9B/ycT65lUETlIE3MfzCu6nI/qiIC+yhsCBtdeVALfB2esdCQ+X2Ls jfavpsMDrbjrZ1fyFCYdK0Ka4F3YMyNYj75Bj0/DbUXsgGYL20Qe4uS2yNElQGqo 0mR21lDOhKAI0bVfrdafwfFZB5CIdx2e0kApwAQQOe3xgs3maTR5VQlIdFBApx0y afpJBW2XD/12QWKnOhObTw4QD3OdeXldE8gXrM4qZIrr8/zM/IIsUxSSMb2FIxMU HsMeILzvNuXjgx6fwROW5JECAwEAAaNQME4wHQYDVR0OBBYEFMe9wCJl/6eXp8ud fkTlE3c5fb66MB8GA1UdIwQYMBaAFMe9wCJl/6eXp8udfkTlE3c5fb66MAwGA1Ud EwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAIVn3TZjJNuoySnx8QJAwNPy9A+F oxUgYsjSKoagKc5Rk1czRwNawdeATb0HugT1oVrkbv71vrhBVNWSA9gtV46x9zoD HjxHjkd3owfOmW3VMPPqqBoKK0plmDQMEqB3j8+Pmvtjvl18BntAqWs2OyTLPqZV 0HNQ4bV1ArvwkE++8GYcuYfOU4ORxtPZFUKRc6ailf5Z9H4TEwS+BcOUZ8BaOYX5 5tyvvt7nnaF3v5fcnlX1nEvNJRwdOvo7+cLcOd4ehW8bBLiS2mEUDW/D712sSyId Xuoms4rmP66gCC29h72fj0aL6/PXxrDaZo+7MStB5tCkJK6kP58Elk64654= -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/client-expired.crt000066400000000000000000000107001373244276700221740ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 3 (0x3) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Aug 20 00:00:00 2012 GMT Not After : Aug 21 00:00:00 2012 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=test client expired Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:b5:85:9e:ea:67:a7:6e:35:bc:0a:60:5f:dd:2f: b8:5d:ab:1f:56:82:1a:55:82:1e:ba:7e:05:59:fc: 97:11:7b:73:59:f2:61:84:3b:da:ff:09:ba:21:25: b9:38:4b:76:c1:ae:2d:a0:7e:20:23:e9:21:50:e7: b9:a3:81:35:d7:f1:39:3c:8f:d5:34:82:7a:e4:68: 4b:f3:f1:23:3b:67:e9:3e:d4:97:01:86:8e:52:fa: a2:a7:41:ea:03:92:fc:f9:1b:bb:9e:4d:b2:32:78: 7e:da:8c:95:ef:c9:53:97:30:34:9e:5c:d0:b3:2f: 44:33:01:29:23:bd:b8:82:05:f5:12:f6:9e:d2:6a: 6f:74:14:12:08:6e:c2:85:88:7f:a4:7c:f5:e7:76: e2:2b:e8:c1:44:bf:1d:c7:c6:b4:84:c4:4b:4e:56: 63:dc:91:b0:91:68:d3:07:55:c0:e3:92:ad:e4:75: 2b:aa:f4:67:7e:7f:91:40:22:4e:11:6d:5e:97:ba: 9a:ea:11:a8:19:1f:74:72:2b:a9:8f:05:24:03:11: 1f:9c:ac:33:49:37:43:60:c7:0b:87:77:01:64:ad: f5:b4:42:c5:ca:38:6f:fc:0d:b1:df:f7:94:e5:14: d9:b9:7f:a1:da:2a:51:ab:4d:da:32:5c:3a:5b:5c: 0e:a1 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 5E:12:4A:C4:94:EA:40:AC:15:A8:14:93:63:F9:61:C8:35:89:79:9E X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption b1:91:cd:ed:2f:8a:32:1f:90:7d:8f:5f:64:84:89:f9:9d:5c: 97:d6:d7:cd:08:ba:2d:8c:56:ca:f8:41:93:7a:4e:3e:d2:81: 57:e5:d4:3f:0c:3a:c8:f9:b1:5b:4c:8d:fc:cd:3c:d4:96:0a: 63:22:32:de:0e:c6:9c:f4:37:97:43:4b:aa:c9:e9:9d:85:4a: f4:92:8b:14:50:8e:17:a5:41:49:70:9b:ae:2d:6b:07:d5:33: 64:86:bc:95:b2:46:dc:d4:be:77:35:04:91:99:08:31:53:d8: 5c:5e:44:91:1e:90:3c:c3:6a:f9:fb:05:17:e9:16:3a:0d:ad: 5d:af:4e:6a:4f:f2:b6:6f:9a:1f:59:4d:11:c4:94:dd:b0:af: 3c:68:cb:cf:4d:3d:b0:88:97:2b:7b:cd:bf:20:c0:57:ab:f5: db:63:b7:7e:23:3c:dd:60:be:fb:20:e7:b6:14:30:c3:2f:09: a1:44:41:f1:bc:b9:75:4c:c3:5e:4c:5c:5c:a7:a9:67:58:a6: ed:de:2a:be:d9:28:03:ad:17:c0:de:aa:05:fc:8e:b7:cc:c1: bc:8d:12:06:62:83:6f:e7:9a:7c:a5:31:73:5f:75:31:ac:c7: b8:1b:c4:82:ea:c2:09:d6:d8:7f:27:6f:08:b9:13:e6:3a:60: e5:e3:a3:24 -----BEGIN CERTIFICATE----- MIID1zCCAr+gAwIBAgIBAzANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTEyMDgyMDAwMDAw MFoXDTEyMDgyMTAwMDAwMFowgYAxCzAJBgNVBAYTAkdCMRgwFgYDVQQIDA9Ob3R0 aW5naGFtc2hpcmUxEzARBgNVBAcMCk5vdHRpbmdoYW0xDzANBgNVBAoMBlNlcnZl cjETMBEGA1UECwwKUHJvZHVjdGlvbjEcMBoGA1UEAwwTdGVzdCBjbGllbnQgZXhw aXJlZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALWFnupnp241vApg X90vuF2rH1aCGlWCHrp+BVn8lxF7c1nyYYQ72v8JuiEluThLdsGuLaB+ICPpIVDn uaOBNdfxOTyP1TSCeuRoS/PxIztn6T7UlwGGjlL6oqdB6gOS/Pkbu55NsjJ4ftqM le/JU5cwNJ5c0LMvRDMBKSO9uIIF9RL2ntJqb3QUEghuwoWIf6R89ed24ivowUS/ HcfGtITES05WY9yRsJFo0wdVwOOSreR1K6r0Z35/kUAiThFtXpe6muoRqBkfdHIr qY8FJAMRH5ysM0k3Q2DHC4d3AWSt9bRCxco4b/wNsd/3lOUU2bl/odoqUatN2jJc OltcDqECAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNT TCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFF4SSsSU6kCsFagUk2P5 Ycg1iXmeMB8GA1UdIwQYMBaAFGOticQjExPR6wBNAQ4l414MnUHJMA0GCSqGSIb3 DQEBCwUAA4IBAQCxkc3tL4oyH5B9j19khIn5nVyX1tfNCLotjFbK+EGTek4+0oFX 5dQ/DDrI+bFbTI38zTzUlgpjIjLeDsac9DeXQ0uqyemdhUr0kosUUI4XpUFJcJuu LWsH1TNkhryVskbc1L53NQSRmQgxU9hcXkSRHpA8w2r5+wUX6RY6Da1dr05qT/K2 b5ofWU0RxJTdsK88aMvPTT2wiJcre82/IMBXq/XbY7d+IzzdYL77IOe2FDDDLwmh REHxvLl1TMNeTFxcp6lnWKbt3iq+2SgDrRfA3qoF/I63zMG8jRIGYoNv55p8pTFz X3UxrMe4G8SC6sIJ1th/J28IuRPmOmDl46Mk -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/client-revoked.crt000066400000000000000000000107001373244276700221730ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 4 (0x4) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Jul 28 09:12:11 2020 GMT Not After : Jul 27 09:12:11 2025 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=test client revoked Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:a4:22:2c:88:b3:4f:f2:a0:b0:18:7d:28:d8:b4: 69:72:a0:ad:90:f9:c4:1b:c1:f9:b1:e0:e5:87:02: 74:21:6d:ad:87:87:e2:6b:af:82:02:6f:e8:65:a9: 04:f8:05:a5:90:59:de:c9:26:41:a3:7b:dd:d6:91: 0f:6b:57:92:04:54:e6:a1:74:1c:af:38:b7:f9:e8: c8:fb:bb:ff:ac:23:58:77:17:3a:76:42:a6:0f:f1: dc:bc:76:7e:25:1b:8a:89:8a:5b:06:76:41:6a:29: 5c:72:27:e4:1b:68:c7:ca:3d:57:31:5e:9a:9d:5c: 88:c8:bc:d8:e6:bd:b5:be:91:88:e4:4e:8b:37:33: 13:6d:00:37:b4:12:02:da:1c:31:61:0e:e8:b5:0d: f2:f4:e2:46:55:d1:21:bf:ea:92:c3:8c:3d:16:0c: a4:e5:dd:d6:e5:f6:39:b5:4d:69:65:c0:fe:bf:1c: 33:23:b4:f8:94:40:28:47:e7:8f:59:06:31:72:4b: 6b:55:f2:7d:aa:c6:96:ff:1c:08:28:ab:82:b7:99: 22:1f:1c:08:54:d1:4c:f6:f2:79:06:77:da:58:63: 48:47:7f:13:6c:7f:eb:d3:06:1d:25:72:4b:04:d1: 2e:1d:76:a8:56:f5:59:bc:be:c7:78:6d:e2:1d:57: b2:f3 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 21:58:60:7A:B1:55:A8:CA:EF:2A:D2:0B:25:83:81:DB:E3:A8:7C:7B X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption ac:60:10:4d:cc:10:f8:71:5f:a2:94:20:d8:9e:8c:d9:fc:10: 4c:d7:b5:b7:57:8b:08:a5:97:50:24:27:38:47:e9:37:49:35: 92:07:fc:e2:75:37:4d:3c:b4:24:2c:62:da:6f:40:8a:55:d6: a3:bf:ef:a0:90:8d:4e:ee:51:c7:5a:30:cc:36:9f:8c:72:c7: 36:4c:c4:96:ce:bf:df:e9:58:5a:54:63:be:e5:9c:27:63:e6: 55:4e:2f:09:df:10:b2:7c:42:eb:f1:86:66:f2:07:ca:b3:e5: ca:14:58:34:ac:ac:4e:99:e4:37:c7:b1:8c:56:23:9a:5c:a8: fe:17:77:ec:ce:c8:77:25:35:b7:98:1c:90:25:bc:fc:5a:4b: 85:b0:96:55:ca:cb:83:bc:a1:2a:1a:f1:cb:73:e1:8d:4b:65: ca:86:1f:43:a5:f1:4a:86:d2:50:81:c3:c1:e6:c6:ed:15:0f: 01:2c:58:63:44:4e:17:c0:59:d1:cf:c8:cb:37:9c:9e:dc:e1: 83:10:90:9e:35:9d:43:23:f2:b9:1d:91:00:33:b4:eb:6a:9d: 5a:1c:e0:b8:6b:f0:dc:05:ae:15:f3:42:7f:0c:9a:bd:06:25: 75:79:53:ea:a8:9b:f5:4c:96:52:1a:85:91:a5:68:08:a5:f4: 32:ca:9d:58 -----BEGIN CERTIFICATE----- MIID1zCCAr+gAwIBAgIBBDANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTIwMDcyODA5MTIx MVoXDTI1MDcyNzA5MTIxMVowgYAxCzAJBgNVBAYTAkdCMRgwFgYDVQQIDA9Ob3R0 aW5naGFtc2hpcmUxEzARBgNVBAcMCk5vdHRpbmdoYW0xDzANBgNVBAoMBlNlcnZl cjETMBEGA1UECwwKUHJvZHVjdGlvbjEcMBoGA1UEAwwTdGVzdCBjbGllbnQgcmV2 b2tlZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKQiLIizT/KgsBh9 KNi0aXKgrZD5xBvB+bHg5YcCdCFtrYeH4muvggJv6GWpBPgFpZBZ3skmQaN73daR D2tXkgRU5qF0HK84t/noyPu7/6wjWHcXOnZCpg/x3Lx2fiUbiomKWwZ2QWopXHIn 5Btox8o9VzFemp1ciMi82Oa9tb6RiOROizczE20AN7QSAtocMWEO6LUN8vTiRlXR Ib/qksOMPRYMpOXd1uX2ObVNaWXA/r8cMyO0+JRAKEfnj1kGMXJLa1XyfarGlv8c CCirgreZIh8cCFTRTPbyeQZ32lhjSEd/E2x/69MGHSVySwTRLh12qFb1Wby+x3ht 4h1XsvMCAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNT TCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFCFYYHqxVajK7yrSCyWD gdvjqHx7MB8GA1UdIwQYMBaAFGOticQjExPR6wBNAQ4l414MnUHJMA0GCSqGSIb3 DQEBCwUAA4IBAQCsYBBNzBD4cV+ilCDYnozZ/BBM17W3V4sIpZdQJCc4R+k3STWS B/zidTdNPLQkLGLab0CKVdajv++gkI1O7lHHWjDMNp+Mcsc2TMSWzr/f6VhaVGO+ 5ZwnY+ZVTi8J3xCyfELr8YZm8gfKs+XKFFg0rKxOmeQ3x7GMViOaXKj+F3fszsh3 JTW3mByQJbz8WkuFsJZVysuDvKEqGvHLc+GNS2XKhh9DpfFKhtJQgcPB5sbtFQ8B LFhjRE4XwFnRz8jLN5ye3OGDEJCeNZ1DI/K5HZEAM7Trap1aHOC4a/DcBa4V80J/ DJq9BiV1eVPqqJv1TJZSGoWRpWgIpfQyyp1Y -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/client-revoked.key000066400000000000000000000032171373244276700222000ustar00rootroot00000000000000-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEApCIsiLNP8qCwGH0o2LRpcqCtkPnEG8H5seDlhwJ0IW2th4fi a6+CAm/oZakE+AWlkFneySZBo3vd1pEPa1eSBFTmoXQcrzi3+ejI+7v/rCNYdxc6 dkKmD/HcvHZ+JRuKiYpbBnZBailccifkG2jHyj1XMV6anVyIyLzY5r21vpGI5E6L NzMTbQA3tBIC2hwxYQ7otQ3y9OJGVdEhv+qSw4w9Fgyk5d3W5fY5tU1pZcD+vxwz I7T4lEAoR+ePWQYxcktrVfJ9qsaW/xwIKKuCt5kiHxwIVNFM9vJ5BnfaWGNIR38T bH/r0wYdJXJLBNEuHXaoVvVZvL7HeG3iHVey8wIDAQABAoIBAQChkF4kBdX5sEEH KhSOFDEEO7P+VE29QRjIBugJGNo1mZ/KHHE9rRqdyYiKoXCZr/1EdaJ+gGD2S1SY BFyYPjAmgWgwn3oo5Pz8TC+i1HEdAgHv4HaUuJB8e4jcHwuW/WBGeWGWn8tOc/5j BG9ep6qaofz1RPmPUun2JyafIzkGpumKl2NPzmhtj+ZN2IricLwEA18FYenUNAFT gUUYY9Xyx4C1hGT+UnSus7NNRpm9OUnUPHuoMi7Ef3Xgr/lDIFZh5uG/RIFZbkLS wDY9gkadW5OCvUa00zfiM55eflY6l/CoQIaotgmYQGssU8nYzCSjBANSg/cc85QJ enA84TLRAoGBANa9SQjNfkoAZOMnf9jTnRBRiXLv4Tca2iucSNoYP1yPpvQ6evj7 6b3L+95saUTtTTlAVPyGqSYtMaWujSz88bkeakfwPbhtOJCE+5DAHNWHTLJOB/mU cRlwMtyTSSdWgFMM0ebQR4sNEnTJgsBFbXvu4wYmGWQ4KIhUOnd2cN+5AoGBAMOr qKWyyrHoevso61JFqGbbOrNoNZMJf1GEZ/ix3BWLha6V23LMjfAOevAbyqpzES6z fPJdGfQE+ZJjbJtfQJJmBod1MIMSsMprp3wESbDaVg97Csoyy2YGhbQFcqBB4gY9 mK6mp3U4iGqMtd6oxywKU9hzldYf+bdru1gtncYLAoGAVti81eON5M3d/4R1DzMe PYBMb4CWfBvPCn4tdI8D6SJr6jBQlawEL291ENKVjHvQlIvxEyQ++qKihphenkg6 Vpz3bNq7i4AYtVIjD7qyrqUGnsIyNX0UdK5M06p5loBEa9IufgPUO2dxBGyPBcXO bqYBiPYVpNOViPVPpArxwXkCgYEAmgMDO2j/Iglaw1Xx40/wvQTRr2TWxmUzUXZm X9me4VZwYnqRwEpBbjH3kgZN/tuTKq8cKageRXOk/RRE6AaRTKoBeZ1EEeckQC98 JKE7X3h7RLQUShKxBh0cIBYpovo4bbEN/GowZJOazEL048z0+DUoybYwudlxNG4X h9Bf3wECgYByHMLRnyY3U6TV++dGYffjC1yxJLG0UtDzt89uG+68GEIoBhdOI/1w //qZVdpPJUU2wrPi23sM5Sdo+UQ8ERAD2uPuUaEyMVcpCWaixo0sfwW30D5YgPK1 +5ybe13ENAK8YR4CaglhatCd4PfTsq9Hzh2QaeKmYgq+dWhoHBLiKg== -----END RSA PRIVATE KEY----- paho.mqtt.python-1.5.1/test/ssl/client.crt000066400000000000000000000106541373244276700205460ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 2 (0x2) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Jul 28 09:12:10 2020 GMT Not After : Jul 27 09:12:10 2025 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=test client Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:b5:85:9e:ea:67:a7:6e:35:bc:0a:60:5f:dd:2f: b8:5d:ab:1f:56:82:1a:55:82:1e:ba:7e:05:59:fc: 97:11:7b:73:59:f2:61:84:3b:da:ff:09:ba:21:25: b9:38:4b:76:c1:ae:2d:a0:7e:20:23:e9:21:50:e7: b9:a3:81:35:d7:f1:39:3c:8f:d5:34:82:7a:e4:68: 4b:f3:f1:23:3b:67:e9:3e:d4:97:01:86:8e:52:fa: a2:a7:41:ea:03:92:fc:f9:1b:bb:9e:4d:b2:32:78: 7e:da:8c:95:ef:c9:53:97:30:34:9e:5c:d0:b3:2f: 44:33:01:29:23:bd:b8:82:05:f5:12:f6:9e:d2:6a: 6f:74:14:12:08:6e:c2:85:88:7f:a4:7c:f5:e7:76: e2:2b:e8:c1:44:bf:1d:c7:c6:b4:84:c4:4b:4e:56: 63:dc:91:b0:91:68:d3:07:55:c0:e3:92:ad:e4:75: 2b:aa:f4:67:7e:7f:91:40:22:4e:11:6d:5e:97:ba: 9a:ea:11:a8:19:1f:74:72:2b:a9:8f:05:24:03:11: 1f:9c:ac:33:49:37:43:60:c7:0b:87:77:01:64:ad: f5:b4:42:c5:ca:38:6f:fc:0d:b1:df:f7:94:e5:14: d9:b9:7f:a1:da:2a:51:ab:4d:da:32:5c:3a:5b:5c: 0e:a1 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 5E:12:4A:C4:94:EA:40:AC:15:A8:14:93:63:F9:61:C8:35:89:79:9E X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption 4e:f3:5d:99:00:94:57:9e:a7:19:b8:9e:ee:f2:f9:01:9e:b7: 02:e7:fe:a4:89:cf:a1:5f:04:4e:46:98:b8:aa:de:8d:f4:c2: 6b:71:25:08:f4:64:7e:99:5e:07:dd:43:43:cf:08:f7:e7:11: f1:79:1d:7a:0b:d3:b2:f1:70:9d:da:dd:c6:f7:a0:e2:3b:64: 22:7b:74:b8:70:93:74:51:a2:c4:aa:3d:15:b1:b9:68:20:9e: ec:98:1d:86:4d:e9:42:61:41:92:a7:08:12:27:f3:7e:3e:6a: 54:1e:76:19:f5:b5:11:4d:de:25:22:63:ef:78:17:61:3e:4c: d2:ea:ff:e9:1c:52:a8:82:29:24:cd:50:75:72:32:c1:00:83: bf:14:c3:c6:bd:b0:0f:4f:83:86:ea:67:7a:8d:82:c6:42:4a: e5:73:4b:69:c2:96:9a:74:ea:5e:82:62:8c:a4:02:17:08:cf: f6:07:76:84:b5:91:b1:ce:79:4a:be:e5:43:5d:31:55:5e:4e: 38:42:cd:70:9b:22:c4:3e:ee:24:fa:ae:07:ae:75:f5:f9:b5: 05:53:58:bd:12:50:1f:68:5e:ff:8d:30:2d:61:85:97:5a:48: 0c:61:ab:ad:4c:95:67:32:c4:8c:3f:dd:9f:39:ed:9a:be:73: 50:53:20:de -----BEGIN CERTIFICATE----- MIIDzjCCAragAwIBAgIBAjANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTIwMDcyODA5MTIx MFoXDTI1MDcyNzA5MTIxMFoweDELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy MRMwEQYDVQQLDApQcm9kdWN0aW9uMRQwEgYDVQQDDAt0ZXN0IGNsaWVudDCCASIw DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALWFnupnp241vApgX90vuF2rH1aC GlWCHrp+BVn8lxF7c1nyYYQ72v8JuiEluThLdsGuLaB+ICPpIVDnuaOBNdfxOTyP 1TSCeuRoS/PxIztn6T7UlwGGjlL6oqdB6gOS/Pkbu55NsjJ4ftqMle/JU5cwNJ5c 0LMvRDMBKSO9uIIF9RL2ntJqb3QUEghuwoWIf6R89ed24ivowUS/HcfGtITES05W Y9yRsJFo0wdVwOOSreR1K6r0Z35/kUAiThFtXpe6muoRqBkfdHIrqY8FJAMRH5ys M0k3Q2DHC4d3AWSt9bRCxco4b/wNsd/3lOUU2bl/odoqUatN2jJcOltcDqECAwEA AaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0 ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFF4SSsSU6kCsFagUk2P5Ycg1iXmeMB8G A1UdIwQYMBaAFGOticQjExPR6wBNAQ4l414MnUHJMA0GCSqGSIb3DQEBCwUAA4IB AQBO812ZAJRXnqcZuJ7u8vkBnrcC5/6kic+hXwRORpi4qt6N9MJrcSUI9GR+mV4H 3UNDzwj35xHxeR16C9Oy8XCd2t3G96DiO2Qie3S4cJN0UaLEqj0VsbloIJ7smB2G TelCYUGSpwgSJ/N+PmpUHnYZ9bURTd4lImPveBdhPkzS6v/pHFKogikkzVB1cjLB AIO/FMPGvbAPT4OG6md6jYLGQkrlc0tpwpaadOpegmKMpAIXCM/2B3aEtZGxznlK vuVDXTFVXk44Qs1wmyLEPu4k+q4HrnX1+bUFU1i9ElAfaF7/jTAtYYWXWkgMYaut TJVnMsSMP92fOe2avnNQUyDe -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/client.csr000066400000000000000000000020011373244276700205300ustar00rootroot00000000000000-----BEGIN CERTIFICATE REQUEST----- MIICvTCCAaUCAQAweDELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRpbmdoYW1z aGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVyMRMwEQYD VQQLDApQcm9kdWN0aW9uMRQwEgYDVQQDDAt0ZXN0IGNsaWVudDCCASIwDQYJKoZI hvcNAQEBBQADggEPADCCAQoCggEBALWFnupnp241vApgX90vuF2rH1aCGlWCHrp+ BVn8lxF7c1nyYYQ72v8JuiEluThLdsGuLaB+ICPpIVDnuaOBNdfxOTyP1TSCeuRo S/PxIztn6T7UlwGGjlL6oqdB6gOS/Pkbu55NsjJ4ftqMle/JU5cwNJ5c0LMvRDMB KSO9uIIF9RL2ntJqb3QUEghuwoWIf6R89ed24ivowUS/HcfGtITES05WY9yRsJFo 0wdVwOOSreR1K6r0Z35/kUAiThFtXpe6muoRqBkfdHIrqY8FJAMRH5ysM0k3Q2DH C4d3AWSt9bRCxco4b/wNsd/3lOUU2bl/odoqUatN2jJcOltcDqECAwEAAaAAMA0G CSqGSIb3DQEBCwUAA4IBAQANrZ/V/Kiy3KqrtGsBu4Hg2YcQ3Jj6FaUN2vbsQGeF +FIJQwfWCy+fzmW7rp7nlgSfJg5P1FPY/FEYax5sNRrqTEakj4/JeSGj+DTkl7X/ hK28a0yH5VBPrlczjJ0eD0oiBvYu79MFVoIhvzTeJejXWrh5D9jAQliQfhb3H5VN ayJLzngXSYVfH/jHlxVcwjr9/0CfDJL+cSxaFr/VM4uYOGPa7hxX2yc/ApihpEpi PIqdzfE5Z/68ulXx+9Hk9M9eOfLTbDNQYjinpCeN1EPNI/96ZZNcVCJnoC6cEhRx kyKcUFnJWZF/J4DTQ7NlDpNs/mlolPqqscLTxGHHCODf -----END CERTIFICATE REQUEST----- paho.mqtt.python-1.5.1/test/ssl/client.key000066400000000000000000000032171373244276700205430ustar00rootroot00000000000000-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEAtYWe6menbjW8CmBf3S+4XasfVoIaVYIeun4FWfyXEXtzWfJh hDva/wm6ISW5OEt2wa4toH4gI+khUOe5o4E11/E5PI/VNIJ65GhL8/EjO2fpPtSX AYaOUvqip0HqA5L8+Ru7nk2yMnh+2oyV78lTlzA0nlzQsy9EMwEpI724ggX1Evae 0mpvdBQSCG7ChYh/pHz153biK+jBRL8dx8a0hMRLTlZj3JGwkWjTB1XA45Kt5HUr qvRnfn+RQCJOEW1el7qa6hGoGR90ciupjwUkAxEfnKwzSTdDYMcLh3cBZK31tELF yjhv/A2x3/eU5RTZuX+h2ipRq03aMlw6W1wOoQIDAQABAoIBAH53pgxyQziJv4UL OD8GbFD2VFMVOfuxOG9+NYRIc4f+lpNoR4C1oxJlWISXn8AU85xlGezjcskSN+AC UlgUQcs9iT8khsqazbws3h4LNxzAfMUFoF+zu50ceg5F4iCzXATCyai1QR3gzaC+ qgfyIIcJUt+yksUEfWN7v4njOJV9HDKbCErnRDmUicN0W0OgT0U44vmoumxRwVCB lt2NKuA98wSHUD4aVoHninxwC2LLfZHIuE7Ty9o/urbc6Lo6I+HaKSSuqhpWRHXA bsWUm5ST6XO0pcUX+pFubs1tHp0BoxnZG3Lf2qF2d202e2ysjqC9jloMSQR0VUwP X799T0ECgYEA5BOBHXonYFLRC4bmzfOlkmj1lPwIjew8a8zjVAtnEUkKL4pURr+/ JGEB8dcArUakxZx+7qCQwyG8JJ988feU69BunB9MDIKBMDOFhuKA4bkUUtwqshDQ iejvxzCBYOxuKDtR8gu8gNocrd07uCgNlT9W6osiKd9bw9DMzVWpGKUCgYEAy778 nAWIVwCmMxzS2FW32e/iBqNgOOegDq1UbKXP7OWapeZaUDcGU8jkOEtApZ3sIjOy ogIARuvqN400Q7phtb6VeHaJ3rpi+jEe5mE74baaPu2YFII4TaIKzVKE+kbGUSRe ZXjxazY1gGm6iRd/XbMqoJ185C0c2F6HZfEbAU0CgYEAldtu6aRafQLNUgqYWlgt wS5vti2HnWDMLnSYJZ+8X/Ii3CvCxh21BL0snu+LBU82cpUqHbaoh14CFfopCX+I fQ0dsD0sJcgWBErGAGORFT8baHo7H3bG3uaLrdBkIgAXPR4E8MnfWLZ3Q5HqbEz8 58SPYlp63xJgZCAsgPo4ufUCgYEAk4NGb0vOJ3eP3Se8O+brwn1cPwQgUXLZvmad 3j+6p8Cg1AZQUw1TpmunWF6bgo0w/p5BcexS+QYrQGcadQLHZYeDvoDMVxbJPG09 +vxhF41WZcMtvYN+ci6k9X0OTAnb4bmcIomK+N15pOxnooQBsfxbG4iKeMV0we7G xvbmX20CgYAd2eHNwB0sE1tiiMAMeIt5NNip7/HWMSuHNfjDEFpdRD6+Cl/CpVCw c8fp637WVGoD7wgAZiDHsySZ9RXTIAD7BJElctbV/1iTwZsZtkMiOU9PPAIU6qBQ DfIKGspehKqSjJvBD7YpxINZ7s2+DwMhinzmRLXzCBBI/hNa5VZLFQ== -----END RSA PRIVATE KEY----- paho.mqtt.python-1.5.1/test/ssl/crl.pem000066400000000000000000000012521373244276700200330ustar00rootroot00000000000000-----BEGIN X509 CRL----- MIIBzzCBuAIBATANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjETMBEGA1UE CAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYDVQQLDAdU ZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBFw0yMDA3MjgwOTEyMTFaFw0yMDA4 MjcwOTEyMTFaMBQwEgIBBBcNMjAwNzI4MDkxMjExWqAOMAwwCgYDVR0UBAMCAQEw DQYJKoZIhvcNAQELBQADggEBABxVRuI9LoDx0+9PjxmFeW3A0tAtY3A6LnQHbGmz zW9Ov6DR/FgGtV6KvuEQb7N59/40H09CE/iKRNQjsDetVBYAEVXqfiCHrEVxnlox fKwyrpqDnQQdM8BjNAZaF9sY2XLCvqT+x0hiw7WPZxuYFJou/aPUEJmMbGqWwSzQ 5n+gjpLxqSolyWp8hmRWPo+UZbTRUmaLOpV2Xli949tadBHPbFAKcNmzEqwFpeK9 /do30Nm560ri5na61VEpj/I18hDF0I17agsDyHOh52XwOG0u+B09+GolnZnf6kiE XZ+G4Kq1gUWyityXQglEfvW2KPYaZSpaW1EsUhafSVJWOpQ= -----END X509 CRL----- paho.mqtt.python-1.5.1/test/ssl/demoCA/000077500000000000000000000000001373244276700177005ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/ssl/demoCA/crlnumber000066400000000000000000000000031373244276700216050ustar00rootroot0000000000000004 paho.mqtt.python-1.5.1/test/ssl/demoCA/index.txt000066400000000000000000000002261373244276700215500ustar00rootroot00000000000000R 391118144000Z 120703155846Z CDAE0E564A2891A7 unknown /C=GB/ST=United Kingdom/L=Derby/O=Mosquitto Test Suite/OU=Broker Test/CN=localhost-client-test paho.mqtt.python-1.5.1/test/ssl/demoCA/index.txt.attr000066400000000000000000000000241373244276700225150ustar00rootroot00000000000000unique_subject = no paho.mqtt.python-1.5.1/test/ssl/demoCA/serial000066400000000000000000000000031373244276700210730ustar00rootroot0000000000000001 paho.mqtt.python-1.5.1/test/ssl/gen.sh000077500000000000000000000100661373244276700176630ustar00rootroot00000000000000#!/bin/sh # This file generates the keys and certificates used for testing mosquitto. # None of the keys are encrypted, so do not just use this script to generate # files for your own use. set -e rm -f *.crt *.key *.csr for a in root signing; do rm -rf ${a}CA/ mkdir -p ${a}CA/newcerts touch ${a}CA/index.txt echo 01 > ${a}CA/serial echo 01 > ${a}CA/crlnumber done rm -rf certs BASESUBJ="/C=GB/ST=Derbyshire/L=Derby/O=Paho Project/OU=Testing" SBASESUBJ="/C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production" BBASESUBJ="/C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Bridge" # The root CA openssl genrsa -out test-root-ca.key 2048 openssl req -new -x509 -days 3650 -key test-root-ca.key -out test-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Root CA/" # Another root CA that doesn't sign anything openssl genrsa -out test-bad-root-ca.key 2048 openssl req -new -x509 -days 3650 -key test-bad-root-ca.key -out test-bad-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Bad Root CA/" # This is a root CA that has the exact same details as the real root CA, but is a different key and certificate. Effectively a "fake" CA. openssl genrsa -out test-fake-root-ca.key 2048 openssl req -new -x509 -days 3650 -key test-fake-root-ca.key -out test-fake-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Root CA/" # An intermediate CA, signed by the root CA, used to sign server/client csrs. openssl genrsa -out test-signing-ca.key 2048 openssl req -out test-signing-ca.csr -key test-signing-ca.key -new -config openssl.cnf -subj "${BASESUBJ}/CN=Signing CA/" openssl ca -batch -config openssl.cnf -name CA_root -extensions v3_ca -out test-signing-ca.crt -infiles test-signing-ca.csr # An alternative intermediate CA, signed by the root CA, not used to sign anything. openssl genrsa -out test-alt-ca.key 2048 openssl req -out test-alt-ca.csr -key test-alt-ca.key -new -config openssl.cnf -subj "${BASESUBJ}/CN=Alternative Signing CA/" openssl ca -batch -config openssl.cnf -name CA_root -extensions v3_ca -out test-alt-ca.crt -infiles test-alt-ca.csr # Valid server key and certificate. openssl genrsa -out server.key 2048 openssl req -new -key server.key -out server.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=localhost/" openssl ca -batch -config openssl.cnf -name CA_signing -out server.crt -infiles server.csr # Expired server certificate, based on the above server key. openssl req -new -days 1 -key server.key -out server-expired.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=localhost/" echo -n > signingCA/index.txt echo 01 > signingCA/serial openssl ca -batch -config openssl.cnf -name CA_signing -days 1 -startdate 120820000000Z -enddate 120821000000Z -out server-expired.crt -infiles server-expired.csr # Valid client key and certificate. openssl genrsa -out client.key 2048 openssl req -new -key client.key -out client.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client/" openssl ca -batch -config openssl.cnf -name CA_signing -out client.crt -infiles client.csr # Expired client certificate, based on the above client key. openssl req -new -days 1 -key client.key -out client-expired.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client expired/" openssl ca -batch -config openssl.cnf -name CA_signing -days 1 -startdate 120820000000Z -enddate 120821000000Z -out client-expired.crt -infiles client-expired.csr # Revoked client certificate, based on a new client key. openssl genrsa -out client-revoked.key 2048 openssl req -new -days 1 -key client-revoked.key -out client-revoked.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client revoked/" openssl ca -batch -config openssl.cnf -name CA_signing -out client-revoked.crt -infiles client-revoked.csr openssl ca -batch -config openssl.cnf -name CA_signing -revoke client-revoked.crt openssl ca -batch -config openssl.cnf -name CA_signing -gencrl -out crl.pem cat test-signing-ca.crt test-root-ca.crt > all-ca.crt #mkdir certs #cp test-signing-ca.crt certs/test-signing-ca.pem #cp test-root-ca.crt certs/test-root.ca.pem c_rehash certs rm -f client-expired.csr client-revoked.csr server-expired.csr server.csr test-alt-ca.csrpaho.mqtt.python-1.5.1/test/ssl/openssl.cnf000066400000000000000000000270601373244276700207300ustar00rootroot00000000000000# # OpenSSL example configuration file. # This is mostly being used for generation of certificate requests. # # This definition stops the following lines choking if HOME isn't # defined. HOME = . RANDFILE = $ENV::HOME/.rnd # Extra OBJECT IDENTIFIER info: #oid_file = $ENV::HOME/.oid oid_section = new_oids # To use this configuration file with the "-extfile" option of the # "openssl x509" utility, name here the section containing the # X.509v3 extensions to use: # extensions = # (Alternatively, use a configuration file that has only # X.509v3 extensions in its main [= default] section.) [ new_oids ] # We can add new OIDs in here for use by 'ca', 'req' and 'ts'. # Add a simple OID like this: # testoid1=1.2.3.4 # Or use config file substitution like this: # testoid2=${testoid1}.5.6 # Policies used by the TSA examples. tsa_policy1 = 1.2.3.4.1 tsa_policy2 = 1.2.3.4.5.6 tsa_policy3 = 1.2.3.4.5.7 #################################################################### [ ca ] default_ca = CA_default # The default ca section #################################################################### [ CA_signing ] dir = ./signingCA # Where everything is kept certs = $dir/certs # Where the issued certs are kept crl_dir = $dir/crl # Where the issued crl are kept database = $dir/index.txt # database index file. #unique_subject = no # Set to 'no' to allow creation of # several ctificates with same subject. new_certs_dir = $dir/newcerts # default place for new certs. certificate = test-signing-ca.crt # The CA certificate serial = $dir/serial # The current serial number crlnumber = $dir/crlnumber # the current crl number # must be commented out to leave a V1 CRL crl = $dir/crl.pem # The current CRL private_key = test-signing-ca.key # The private key RANDFILE = $dir/.rand # private random number file x509_extensions = usr_cert # The extentions to add to the cert # Comment out the following two lines for the "traditional" # (and highly broken) format. name_opt = ca_default # Subject Name options cert_opt = ca_default # Certificate field options # Extension copying option: use with caution. # copy_extensions = copy # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs # so this is commented out by default to leave a V1 CRL. # crlnumber must also be commented out to leave a V1 CRL. # crl_extensions = crl_ext default_days = 1825 # how long to certify for default_crl_days= 30 # how long before next CRL default_md = default # use public key default MD preserve = no # keep passed DN ordering # A few difference way of specifying how similar the request should look # For type CA, the listed attributes must be the same, and the optional # and supplied fields are just that :-) policy = policy_anything [ CA_inter ] dir = ./interCA certs = $dir/certs crl_dir = $dir/crl database = $dir/index.txt new_certs_dir = $dir/newcerts certificate = test-inter-ca.crt serial = $dir/serial crlnumber = $dir/crlnumber crl = $dir/crl.pem private_key = test-inter-ca.key RANDFILE = $dir/.rand #x509_extensions = v3_ca x509_extensions = usr_cert name_opt = ca_default cert_opt = ca_default default_days = 1825 default_crl_days = 30 default_md = default preserve = no policy = policy_match unique_subject = yes [ CA_root ] dir = ./rootCA certs = $dir/certs crl_dir = $dir/crl database = $dir/index.txt new_certs_dir = $dir/newcerts certificate = test-root-ca.crt serial = $dir/serial crlnumber = $dir/crlnumber crl = $dir/crl.pem private_key = test-root-ca.key RANDFILE = $dir/.rand x509_extensions = v3_ca name_opt = ca_default cert_opt = ca_default default_days = 1825 default_crl_days = 30 default_md = default preserve = no policy = policy_match unique_subject = yes # For the CA policy [ policy_match ] countryName = match stateOrProvinceName = match organizationName = match organizationalUnitName = optional commonName = supplied emailAddress = optional # For the 'anything' policy # At this point in time, you must list all acceptable 'object' # types. [ policy_anything ] countryName = optional stateOrProvinceName = optional localityName = optional organizationName = optional organizationalUnitName = optional commonName = supplied emailAddress = optional #################################################################### [ req ] default_bits = 2048 default_keyfile = privkey.pem distinguished_name = req_distinguished_name attributes = req_attributes x509_extensions = v3_ca # The extentions to add to the self signed cert # Passwords for private keys if not present they will be prompted for # input_password = secret # output_password = secret # This sets a mask for permitted string types. There are several options. # default: PrintableString, T61String, BMPString. # pkix : PrintableString, BMPString (PKIX recommendation before 2004) # utf8only: only UTF8Strings (PKIX recommendation after 2004). # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). # MASK:XXXX a literal mask value. # WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. string_mask = utf8only # req_extensions = v3_req # The extensions to add to a certificate request [ req_distinguished_name ] countryName = Country Name (2 letter code) countryName_default = GB countryName_min = 2 countryName_max = 2 stateOrProvinceName = State or Province Name (full name) stateOrProvinceName_default = Derbyshire localityName = Locality Name (eg, city) localityName_default = Derby 0.organizationName = Organization Name (eg, company) 0.organizationName_default = Paho Project # we can do this but it is not needed normally :-) #1.organizationName = Second Organization Name (eg, company) #1.organizationName_default = World Wide Web Pty Ltd organizationalUnitName = Organizational Unit Name (eg, section) organizationalUnitName_default = Testing commonName = Common Name (e.g. server FQDN or YOUR name) commonName_max = 64 emailAddress = Email Address emailAddress_max = 64 # SET-ex3 = SET extension number 3 [ req_attributes ] challengePassword = A challenge password challengePassword_min = 4 challengePassword_max = 20 unstructuredName = An optional company name [ usr_cert ] # These extensions are added when 'ca' signs a request. # This goes against PKIX guidelines but some CAs do it and some software # requires this to avoid interpreting an end user certificate as a CA. basicConstraints=CA:FALSE # Here are some examples of the usage of nsCertType. If it is omitted # the certificate can be used for anything *except* object signing. # This is OK for an SSL server. # nsCertType = server # For an object signing certificate this would be used. # nsCertType = objsign # For normal client use this is typical # nsCertType = client, email # and for everything including object signing: # nsCertType = client, email, objsign # This is typical in keyUsage for a client certificate. # keyUsage = nonRepudiation, digitalSignature, keyEncipherment # This will be displayed in Netscape's comment listbox. nsComment = "OpenSSL Generated Certificate" # PKIX recommendations harmless if included in all certificates. subjectKeyIdentifier=hash authorityKeyIdentifier=keyid,issuer # This stuff is for subjectAltName and issuerAltname. # Import the email address. # subjectAltName=email:copy # An alternative to produce certificates that aren't # deprecated according to PKIX. # subjectAltName=email:move # Copy subject details # issuerAltName=issuer:copy #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem #nsBaseUrl #nsRevocationUrl #nsRenewalUrl #nsCaPolicyUrl #nsSslServerName # This is required for TSA certificates. # extendedKeyUsage = critical,timeStamping [ v3_req ] # Extensions to add to a certificate request basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment [ v3_ca ] # Extensions for a typical CA # PKIX recommendation. subjectKeyIdentifier=hash authorityKeyIdentifier=keyid:always,issuer # This is what PKIX recommends but some broken software chokes on critical # extensions. #basicConstraints = critical,CA:true # So we do this instead. basicConstraints = CA:true # Key usage: this is typical for a CA certificate. However since it will # prevent it being used as an test self-signed certificate it is best # left out by default. # keyUsage = cRLSign, keyCertSign # Some might want this also # nsCertType = sslCA, emailCA # Include email address in subject alt name: another PKIX recommendation # subjectAltName=email:copy # Copy issuer details # issuerAltName=issuer:copy # DER hex encoding of an extension: beware experts only! # obj=DER:02:03 # Where 'obj' is a standard or added object # You can even override a supported extension: # basicConstraints= critical, DER:30:03:01:01:FF [ crl_ext ] # CRL extensions. # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. # issuerAltName=issuer:copy authorityKeyIdentifier=keyid:always [ proxy_cert_ext ] # These extensions should be added when creating a proxy certificate # This goes against PKIX guidelines but some CAs do it and some software # requires this to avoid interpreting an end user certificate as a CA. basicConstraints=CA:FALSE # Here are some examples of the usage of nsCertType. If it is omitted # the certificate can be used for anything *except* object signing. # This is OK for an SSL server. # nsCertType = server # For an object signing certificate this would be used. # nsCertType = objsign # For normal client use this is typical # nsCertType = client, email # and for everything including object signing: # nsCertType = client, email, objsign # This is typical in keyUsage for a client certificate. # keyUsage = nonRepudiation, digitalSignature, keyEncipherment # This will be displayed in Netscape's comment listbox. nsComment = "OpenSSL Generated Certificate" # PKIX recommendations harmless if included in all certificates. subjectKeyIdentifier=hash authorityKeyIdentifier=keyid,issuer # This stuff is for subjectAltName and issuerAltname. # Import the email address. # subjectAltName=email:copy # An alternative to produce certificates that aren't # deprecated according to PKIX. # subjectAltName=email:move # Copy subject details # issuerAltName=issuer:copy #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem #nsBaseUrl #nsRevocationUrl #nsRenewalUrl #nsCaPolicyUrl #nsSslServerName # This really needs to be in place for it to be a proxy certificate. proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo #################################################################### [ tsa ] default_tsa = tsa_config1 # the default TSA section [ tsa_config1 ] # These are used by the TSA reply generation only. dir = ./demoCA # TSA root directory serial = $dir/tsaserial # The current serial number (mandatory) crypto_device = builtin # OpenSSL engine to use for signing signer_cert = $dir/tsacert.pem # The TSA signing certificate # (optional) certs = $dir/cacert.pem # Certificate chain to include in reply # (optional) signer_key = $dir/private/tsakey.pem # The TSA private key (optional) default_policy = tsa_policy1 # Policy if request did not specify it # (optional) other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional) digests = md5, sha1 # Acceptable message digests (mandatory) accuracy = secs:1, millisecs:500, microsecs:100 # (optional) clock_precision_digits = 0 # number of digits after dot. (optional) ordering = yes # Is ordering defined for timestamps? # (optional, default: no) tsa_name = yes # Must the TSA name be included in the reply? # (optional, default: no) ess_cert_id_chain = no # Must the ESS cert id chain be included? # (optional, default: no) paho.mqtt.python-1.5.1/test/ssl/rootCA/000077500000000000000000000000001373244276700177375ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/ssl/rootCA/crlnumber000066400000000000000000000000031373244276700216440ustar00rootroot0000000000000001 paho.mqtt.python-1.5.1/test/ssl/rootCA/index.txt000066400000000000000000000002741373244276700216120ustar00rootroot00000000000000V 250727091210Z 01 unknown /C=GB/ST=Derbyshire/O=Paho Project/OU=Testing/CN=Signing CA V 250727091210Z 02 unknown /C=GB/ST=Derbyshire/O=Paho Project/OU=Testing/CN=Alternative Signing CA paho.mqtt.python-1.5.1/test/ssl/rootCA/index.txt.attr000066400000000000000000000000251373244276700225550ustar00rootroot00000000000000unique_subject = yes paho.mqtt.python-1.5.1/test/ssl/rootCA/index.txt.attr.old000066400000000000000000000000251373244276700233320ustar00rootroot00000000000000unique_subject = yes paho.mqtt.python-1.5.1/test/ssl/rootCA/index.txt.old000066400000000000000000000001301373244276700223560ustar00rootroot00000000000000V 250727091210Z 01 unknown /C=GB/ST=Derbyshire/O=Paho Project/OU=Testing/CN=Signing CA paho.mqtt.python-1.5.1/test/ssl/rootCA/newcerts/000077500000000000000000000000001373244276700215715ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/ssl/rootCA/newcerts/01.pem000066400000000000000000000104121373244276700225120ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 1 (0x1) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA Validity Not Before: Jul 28 09:12:10 2020 GMT Not After : Jul 27 09:12:10 2025 GMT Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:c2:33:17:27:8f:e6:b3:b3:96:d8:fc:cc:11:8d: 5e:da:3d:a5:8e:3a:14:c7:e6:38:80:25:e6:27:c4: cf:6f:3c:b8:18:4a:6e:53:ee:81:dc:c6:e2:4a:29: 18:d9:d3:d8:45:3f:19:2c:01:b5:61:ce:b9:f1:89: 9b:0b:0c:af:f2:38:05:2e:cf:e4:57:c5:9f:4f:fc: 42:a1:2f:cc:2a:59:fa:1a:4a:24:24:55:60:d3:25: d5:a7:0f:d8:5d:f3:9a:dc:d8:13:8c:37:ae:8d:27: bb:d2:2c:37:34:3e:11:16:02:46:03:b2:48:24:de: 5e:d0:65:63:cd:0d:af:58:48:13:dc:93:d0:52:84: fa:05:69:4c:09:69:da:00:c2:af:8a:00:4c:1c:c2: 1c:f5:8b:a9:f4:30:13:33:50:fd:6a:1e:8a:10:8d: cd:01:11:1b:cf:a3:30:80:4b:96:a3:b6:e1:ed:df: 6e:69:5f:26:ed:75:9e:04:3f:49:cd:c9:6f:4a:05: 6f:6d:45:09:09:a8:34:03:97:f2:77:ae:8e:96:7f: a8:52:7b:20:71:35:2d:11:17:52:cd:b1:b1:93:26: 2f:9a:17:c1:48:3e:15:99:85:db:c6:bd:c3:35:0f: fd:d1:d9:2a:63:2b:96:59:35:93:c1:cf:5c:e1:72: 3c:73 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: 63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 X509v3 Authority Key Identifier: keyid:C7:BD:C0:22:65:FF:A7:97:A7:CB:9D:7E:44:E5:13:77:39:7D:BE:BA X509v3 Basic Constraints: CA:TRUE Signature Algorithm: sha256WithRSAEncryption 18:5c:f3:6a:e2:82:d1:ba:ee:de:00:29:4e:b3:f7:87:46:1b: fa:7e:52:9d:87:d8:73:19:5b:38:7a:af:31:aa:4c:bd:fe:45: 95:25:03:48:15:d7:e5:38:4f:e3:39:93:99:10:b4:06:dc:5a: 87:af:22:b5:2f:82:da:ef:6c:b5:f3:9c:82:71:0f:f4:d0:65: 46:b7:23:b1:7d:51:8d:d7:7c:80:12:39:99:46:2b:d4:db:c7: 42:96:1a:b6:0f:b3:10:9e:ad:84:0e:87:38:e8:34:f8:04:3d: a2:fc:3d:24:1e:09:d6:63:52:82:e4:35:ae:39:5e:f9:82:a7: ac:23:87:0e:fb:2d:ae:08:da:2a:3f:51:ee:f6:85:3a:43:80: b0:f1:96:0c:fa:10:80:18:7b:75:14:70:09:48:fc:0c:38:ee: ab:e4:32:7d:80:77:a8:2a:63:15:c9:11:b7:a9:0c:77:7d:be: d6:a3:48:37:1e:56:33:13:71:e1:12:90:ce:95:72:68:ae:d5: 01:82:00:67:1b:ae:9d:93:5b:5d:c1:3d:6e:30:e5:e1:35:ac: 59:3b:eb:ef:ee:83:0b:eb:e5:ea:9c:62:29:8c:73:a3:b5:45: 45:e8:53:ea:b8:48:16:7e:f8:c5:af:4b:89:b5:1b:94:a5:85: d9:d5:f4:13 -----BEGIN CERTIFICATE----- MIIDmDCCAoCgAwIBAgIBATANBgkqhkiG9w0BAQsFADBtMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe Fw0yMDA3MjgwOTEyMTBaFw0yNTA3MjcwOTEyMTBaMGAxCzAJBgNVBAYTAkdCMRMw EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV BAsMB1Rlc3RpbmcxEzARBgNVBAMMClNpZ25pbmcgQ0EwggEiMA0GCSqGSIb3DQEB AQUAA4IBDwAwggEKAoIBAQDCMxcnj+azs5bY/MwRjV7aPaWOOhTH5jiAJeYnxM9v PLgYSm5T7oHcxuJKKRjZ09hFPxksAbVhzrnxiZsLDK/yOAUuz+RXxZ9P/EKhL8wq WfoaSiQkVWDTJdWnD9hd85rc2BOMN66NJ7vSLDc0PhEWAkYDskgk3l7QZWPNDa9Y SBPck9BShPoFaUwJadoAwq+KAEwcwhz1i6n0MBMzUP1qHooQjc0BERvPozCAS5aj tuHt325pXybtdZ4EP0nNyW9KBW9tRQkJqDQDl/J3ro6Wf6hSeyBxNS0RF1LNsbGT Ji+aF8FIPhWZhdvGvcM1D/3R2SpjK5ZZNZPBz1zhcjxzAgMBAAGjUDBOMB0GA1Ud DgQWBBRjrYnEIxMT0esATQEOJeNeDJ1ByTAfBgNVHSMEGDAWgBTHvcAiZf+nl6fL nX5E5RN3OX2+ujAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAYXPNq 4oLRuu7eAClOs/eHRhv6flKdh9hzGVs4eq8xqky9/kWVJQNIFdflOE/jOZOZELQG 3FqHryK1L4La72y185yCcQ/00GVGtyOxfVGN13yAEjmZRivU28dClhq2D7MQnq2E Doc46DT4BD2i/D0kHgnWY1KC5DWuOV75gqesI4cO+y2uCNoqP1Hu9oU6Q4Cw8ZYM +hCAGHt1FHAJSPwMOO6r5DJ9gHeoKmMVyRG3qQx3fb7Wo0g3HlYzE3HhEpDOlXJo rtUBggBnG66dk1tdwT1uMOXhNaxZO+vv7oML6+XqnGIpjHOjtUVF6FPquEgWfvjF r0uJtRuUpYXZ1fQT -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/rootCA/newcerts/02.pem000066400000000000000000000104461373244276700225220ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 2 (0x2) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA Validity Not Before: Jul 28 09:12:10 2020 GMT Not After : Jul 27 09:12:10 2025 GMT Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Alternative Signing CA Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:bd:c2:9f:2c:d2:a7:25:79:f0:3f:29:65:ac:d3: 8c:ea:72:d2:73:2d:1b:5b:e3:0c:a1:5a:40:f4:a9: 68:bc:a4:50:77:c9:08:75:12:a3:21:3d:a9:d6:dc: dc:08:b4:47:32:7e:ad:f4:87:de:48:fd:83:d1:b7: e4:ce:3b:8b:87:99:3c:fa:6b:0e:1c:70:71:6d:d9: b4:75:7c:6e:2a:03:cc:0e:bb:c7:8c:31:53:67:11: 2f:fd:97:c9:67:05:48:23:81:60:f5:94:94:af:61: 1c:a8:c1:4d:fe:2b:2e:f8:e6:bd:30:c2:52:ec:56: 7a:b7:64:d0:a2:bf:09:e4:d2:a3:c3:f1:f9:e7:12: 96:45:06:20:a2:fd:49:43:87:a7:0f:c1:c6:58:46: 9f:1d:9f:be:86:ce:49:de:c7:35:4d:fd:08:9a:61: 3f:ed:1f:cd:5c:55:77:4f:cc:0e:52:51:2a:7e:04: 4c:10:e1:79:88:9e:f6:8b:6b:bc:20:d2:6b:e9:c4: c6:94:bc:d8:06:57:a1:b6:b2:30:cd:0d:d3:27:b3: 9e:1b:ac:40:81:6a:f0:a3:f6:62:22:14:40:61:9d: 26:82:b1:aa:fa:0a:0a:45:54:7d:5d:02:59:70:e6: d2:f9:fc:45:58:83:10:2a:db:10:e3:7d:10:73:1b: d9:49 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: 3A:BA:37:57:E0:82:EB:BA:77:1B:50:07:A6:C9:22:EA:92:76:F9:1C X509v3 Authority Key Identifier: keyid:C7:BD:C0:22:65:FF:A7:97:A7:CB:9D:7E:44:E5:13:77:39:7D:BE:BA X509v3 Basic Constraints: CA:TRUE Signature Algorithm: sha256WithRSAEncryption 05:07:f6:5d:7d:2d:5e:35:07:82:1e:cd:06:e6:b6:4c:1b:03: b4:28:3e:16:22:0d:26:5f:f9:69:19:72:24:5a:fb:c6:cf:70: c8:a6:a6:19:8d:10:56:c4:d5:76:bb:38:93:e0:ff:d0:a0:81: 47:36:e7:b6:f5:bf:99:36:28:d1:db:59:c0:e9:84:95:0f:db: c0:84:86:9a:ef:78:ac:dd:83:6d:51:e8:ae:28:b4:f8:78:bb: 91:87:f5:35:21:fd:12:ff:41:33:7f:22:1e:16:f3:43:c9:97: e2:16:35:db:e8:c8:ee:5a:3e:d4:43:c1:90:52:12:7c:f7:7e: 18:ee:60:be:61:41:3a:aa:2d:99:f3:44:86:3c:fd:03:e1:a2: d8:e1:1c:49:b0:39:3e:8c:f6:38:00:4a:84:a5:54:98:ef:c0: 6d:2d:48:4a:13:fb:80:5f:58:a1:95:86:3a:a1:63:56:fe:23: 7f:db:c9:19:a5:22:cb:34:a9:10:cb:b4:95:9f:c9:c6:16:e0: e3:50:7a:29:60:b0:fe:c7:f5:c8:f9:c6:3b:82:a6:a8:d9:0c: 5b:aa:58:f2:31:c3:98:20:87:d8:a1:63:ad:52:ae:b2:85:57: 10:d5:75:9e:73:35:47:c5:22:26:1f:53:38:52:4d:fd:2e:16: 00:15:d4:da -----BEGIN CERTIFICATE----- MIIDpDCCAoygAwIBAgIBAjANBgkqhkiG9w0BAQsFADBtMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe Fw0yMDA3MjgwOTEyMTBaFw0yNTA3MjcwOTEyMTBaMGwxCzAJBgNVBAYTAkdCMRMw EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV BAsMB1Rlc3RpbmcxHzAdBgNVBAMMFkFsdGVybmF0aXZlIFNpZ25pbmcgQ0EwggEi MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC9wp8s0qclefA/KWWs04zqctJz LRtb4wyhWkD0qWi8pFB3yQh1EqMhPanW3NwItEcyfq30h95I/YPRt+TOO4uHmTz6 aw4ccHFt2bR1fG4qA8wOu8eMMVNnES/9l8lnBUgjgWD1lJSvYRyowU3+Ky745r0w wlLsVnq3ZNCivwnk0qPD8fnnEpZFBiCi/UlDh6cPwcZYRp8dn76GzknexzVN/Qia YT/tH81cVXdPzA5SUSp+BEwQ4XmInvaLa7wg0mvpxMaUvNgGV6G2sjDNDdMns54b rECBavCj9mIiFEBhnSaCsar6CgpFVH1dAllw5tL5/EVYgxAq2xDjfRBzG9lJAgMB AAGjUDBOMB0GA1UdDgQWBBQ6ujdX4ILruncbUAemySLqknb5HDAfBgNVHSMEGDAW gBTHvcAiZf+nl6fLnX5E5RN3OX2+ujAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEB CwUAA4IBAQAFB/ZdfS1eNQeCHs0G5rZMGwO0KD4WIg0mX/lpGXIkWvvGz3DIpqYZ jRBWxNV2uziT4P/QoIFHNue29b+ZNijR21nA6YSVD9vAhIaa73is3YNtUeiuKLT4 eLuRh/U1If0S/0EzfyIeFvNDyZfiFjXb6MjuWj7UQ8GQUhJ8934Y7mC+YUE6qi2Z 80SGPP0D4aLY4RxJsDk+jPY4AEqEpVSY78BtLUhKE/uAX1ihlYY6oWNW/iN/28kZ pSLLNKkQy7SVn8nGFuDjUHopYLD+x/XI+cY7gqao2QxbqljyMcOYIIfYoWOtUq6y hVcQ1XWeczVHxSImH1M4Uk39LhYAFdTa -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/rootCA/serial000066400000000000000000000000031373244276700211320ustar00rootroot0000000000000003 paho.mqtt.python-1.5.1/test/ssl/rootCA/serial.old000066400000000000000000000000031373244276700217070ustar00rootroot0000000000000002 paho.mqtt.python-1.5.1/test/ssl/server-expired.crt000066400000000000000000000106521373244276700222320ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 1 (0x1) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Aug 20 00:00:00 2012 GMT Not After : Aug 21 00:00:00 2012 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=localhost Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:f8:5a:e9:fb:cc:aa:7f:8a:71:10:31:34:09:93: 9a:bb:d9:da:2d:02:46:3e:1a:ed:ee:5a:3b:e8:1d: ed:3d:55:f8:bc:c5:0b:f4:77:3d:ae:4e:4a:83:a0: 23:90:15:ef:99:5e:8e:fa:08:ce:04:82:71:75:02: 54:51:72:ab:02:ea:06:07:7a:60:8d:7b:9c:54:53: 24:b6:26:89:2b:c6:fa:fc:89:da:20:95:4c:92:e8: 99:45:ea:d5:ba:42:62:11:05:88:94:79:0f:fe:68: 12:b3:b0:5c:ea:39:0d:6f:cf:e2:12:16:cf:e0:5d: 37:69:fd:8c:ab:51:ac:a8:97:bb:be:5c:29:17:eb: ee:4d:43:2e:24:cb:af:84:e4:96:36:33:3e:9a:45: 54:25:77:ef:ed:76:4b:5e:6a:1b:35:83:09:54:f1: d1:b0:59:32:c4:64:bb:50:8f:43:e2:dd:15:c6:c4: b8:f2:12:9b:fb:86:48:9c:21:d4:bd:da:26:71:8e: ed:3f:9a:27:15:04:c2:2c:2c:4a:bf:21:fe:6d:35: 40:cb:78:41:e2:cd:d4:39:bf:9a:1a:43:c1:d2:9e: a9:44:24:e4:dd:ef:9d:5b:6c:d5:44:5c:32:2f:4f: 41:9f:0f:27:3d:55:91:96:ca:22:1b:d6:18:f9:63: a1:61 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 8F:E3:5C:A3:F0:4A:C3:1C:62:92:0A:83:37:BD:E8:B9:B6:91:22:E4 X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption 59:0b:b1:28:ab:1b:31:93:37:b2:76:ef:83:97:09:0e:fe:44: be:c0:c3:53:bf:82:79:de:e3:a7:90:54:af:70:c0:ac:a5:83: 24:0c:53:fc:b3:a5:d8:a2:f1:85:3f:d3:05:fe:30:a2:95:97: b9:c0:74:68:9b:a9:39:6d:c5:a9:aa:a6:2c:e9:75:99:68:74: aa:8f:fa:01:86:fe:54:1c:c7:7f:7f:1b:6b:39:cf:f9:6f:55: 4a:6f:5b:00:bc:d3:54:85:4a:e1:14:b7:94:cc:57:0a:a3:4c: b5:13:ae:92:cd:c8:a2:d2:8d:28:03:a1:9b:b3:87:c4:68:a1: 27:5b:61:95:e0:f4:5e:71:6a:83:a1:6a:00:43:d9:93:fa:8d: 85:9a:ee:36:08:36:71:b5:d9:d5:36:90:99:02:27:64:97:87: c1:d9:a0:4d:1b:27:66:0c:3d:52:94:91:13:86:70:12:15:3a: eb:e5:10:40:9e:4b:9b:34:2e:07:f3:6f:83:5a:79:a1:91:d6: 01:4d:75:3c:f3:14:53:1c:9b:b6:11:55:db:21:87:22:90:0d: d8:69:a5:46:07:6c:7a:96:db:e9:49:4f:51:be:b2:ae:e8:37: 4c:90:32:6c:95:35:e8:6e:a4:84:cb:57:dd:e2:f2:bf:37:62: 39:e0:0f:f4 -----BEGIN CERTIFICATE----- MIIDzDCCArSgAwIBAgIBATANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTEyMDgyMDAwMDAw MFoXDTEyMDgyMTAwMDAwMFowdjELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy MRMwEQYDVQQLDApQcm9kdWN0aW9uMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0G CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQD4Wun7zKp/inEQMTQJk5q72dotAkY+ Gu3uWjvoHe09Vfi8xQv0dz2uTkqDoCOQFe+ZXo76CM4EgnF1AlRRcqsC6gYHemCN e5xUUyS2Jokrxvr8idoglUyS6JlF6tW6QmIRBYiUeQ/+aBKzsFzqOQ1vz+ISFs/g XTdp/YyrUayol7u+XCkX6+5NQy4ky6+E5JY2Mz6aRVQld+/tdkteahs1gwlU8dGw WTLEZLtQj0Pi3RXGxLjyEpv7hkicIdS92iZxju0/micVBMIsLEq/If5tNUDLeEHi zdQ5v5oaQ8HSnqlEJOTd751bbNVEXDIvT0GfDyc9VZGWyiIb1hj5Y6FhAgMBAAGj ezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVk IENlcnRpZmljYXRlMB0GA1UdDgQWBBSP41yj8ErDHGKSCoM3vei5tpEi5DAfBgNV HSMEGDAWgBRjrYnEIxMT0esATQEOJeNeDJ1ByTANBgkqhkiG9w0BAQsFAAOCAQEA WQuxKKsbMZM3snbvg5cJDv5EvsDDU7+Ced7jp5BUr3DArKWDJAxT/LOl2KLxhT/T Bf4wopWXucB0aJupOW3FqaqmLOl1mWh0qo/6AYb+VBzHf38baznP+W9VSm9bALzT VIVK4RS3lMxXCqNMtROuks3IotKNKAOhm7OHxGihJ1thleD0XnFqg6FqAEPZk/qN hZruNgg2cbXZ1TaQmQInZJeHwdmgTRsnZgw9UpSRE4ZwEhU66+UQQJ5LmzQuB/Nv g1p5oZHWAU11PPMUUxybthFV2yGHIpAN2GmlRgdsepbb6UlPUb6yrug3TJAybJU1 6G6khMtX3eLyvzdiOeAP9A== -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/server.crt000066400000000000000000000106521373244276700205740ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 1 (0x1) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Jul 28 09:12:10 2020 GMT Not After : Jul 27 09:12:10 2025 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=localhost Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:f8:5a:e9:fb:cc:aa:7f:8a:71:10:31:34:09:93: 9a:bb:d9:da:2d:02:46:3e:1a:ed:ee:5a:3b:e8:1d: ed:3d:55:f8:bc:c5:0b:f4:77:3d:ae:4e:4a:83:a0: 23:90:15:ef:99:5e:8e:fa:08:ce:04:82:71:75:02: 54:51:72:ab:02:ea:06:07:7a:60:8d:7b:9c:54:53: 24:b6:26:89:2b:c6:fa:fc:89:da:20:95:4c:92:e8: 99:45:ea:d5:ba:42:62:11:05:88:94:79:0f:fe:68: 12:b3:b0:5c:ea:39:0d:6f:cf:e2:12:16:cf:e0:5d: 37:69:fd:8c:ab:51:ac:a8:97:bb:be:5c:29:17:eb: ee:4d:43:2e:24:cb:af:84:e4:96:36:33:3e:9a:45: 54:25:77:ef:ed:76:4b:5e:6a:1b:35:83:09:54:f1: d1:b0:59:32:c4:64:bb:50:8f:43:e2:dd:15:c6:c4: b8:f2:12:9b:fb:86:48:9c:21:d4:bd:da:26:71:8e: ed:3f:9a:27:15:04:c2:2c:2c:4a:bf:21:fe:6d:35: 40:cb:78:41:e2:cd:d4:39:bf:9a:1a:43:c1:d2:9e: a9:44:24:e4:dd:ef:9d:5b:6c:d5:44:5c:32:2f:4f: 41:9f:0f:27:3d:55:91:96:ca:22:1b:d6:18:f9:63: a1:61 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 8F:E3:5C:A3:F0:4A:C3:1C:62:92:0A:83:37:BD:E8:B9:B6:91:22:E4 X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption b4:32:28:0f:3f:ba:4d:97:0c:0d:8a:7e:cc:dd:cc:99:a4:50: 62:91:f5:21:e0:48:8f:a3:bb:90:5d:99:28:27:68:83:da:07: 60:cd:f2:b7:eb:81:91:4b:43:7b:44:c5:7f:3f:3f:f9:dc:11: 3e:8c:ba:bd:13:73:f8:81:8f:4d:3c:4a:4a:a7:13:fc:7d:c3: 33:a2:4f:8e:39:43:f9:7c:ec:59:ad:54:47:e3:08:a3:7b:bd: e5:ca:00:b0:5b:ce:3d:f6:0d:a7:35:25:9e:a3:50:17:92:2c: 12:ae:d1:85:17:bc:09:b2:5c:06:a6:24:ad:2f:d0:57:5b:0d: 83:b5:c8:f7:c0:f9:31:d1:0c:1b:70:c4:a7:91:86:40:f7:76: a0:a1:72:7f:d2:a3:c4:ff:67:a8:8a:e2:e9:82:19:a1:93:25: 27:cb:66:12:78:d7:f0:a0:69:3e:42:77:94:f4:15:a9:48:d0: 73:fc:e8:53:61:87:cb:95:de:73:bf:2a:ba:fc:32:74:ab:ba: bf:21:45:85:56:ab:56:cb:51:58:fc:c6:49:a9:39:db:f3:76: 2a:18:be:c6:0a:d6:5c:09:5c:1e:1f:d7:41:4c:34:f1:59:ce: 7d:c9:fd:82:65:a5:ae:46:34:f7:13:c1:cf:a3:0e:32:c0:fc: 0f:77:99:f9 -----BEGIN CERTIFICATE----- MIIDzDCCArSgAwIBAgIBATANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTIwMDcyODA5MTIx MFoXDTI1MDcyNzA5MTIxMFowdjELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy MRMwEQYDVQQLDApQcm9kdWN0aW9uMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0G CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQD4Wun7zKp/inEQMTQJk5q72dotAkY+ Gu3uWjvoHe09Vfi8xQv0dz2uTkqDoCOQFe+ZXo76CM4EgnF1AlRRcqsC6gYHemCN e5xUUyS2Jokrxvr8idoglUyS6JlF6tW6QmIRBYiUeQ/+aBKzsFzqOQ1vz+ISFs/g XTdp/YyrUayol7u+XCkX6+5NQy4ky6+E5JY2Mz6aRVQld+/tdkteahs1gwlU8dGw WTLEZLtQj0Pi3RXGxLjyEpv7hkicIdS92iZxju0/micVBMIsLEq/If5tNUDLeEHi zdQ5v5oaQ8HSnqlEJOTd751bbNVEXDIvT0GfDyc9VZGWyiIb1hj5Y6FhAgMBAAGj ezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVk IENlcnRpZmljYXRlMB0GA1UdDgQWBBSP41yj8ErDHGKSCoM3vei5tpEi5DAfBgNV HSMEGDAWgBRjrYnEIxMT0esATQEOJeNeDJ1ByTANBgkqhkiG9w0BAQsFAAOCAQEA tDIoDz+6TZcMDYp+zN3MmaRQYpH1IeBIj6O7kF2ZKCdog9oHYM3yt+uBkUtDe0TF fz8/+dwRPoy6vRNz+IGPTTxKSqcT/H3DM6JPjjlD+XzsWa1UR+MIo3u95coAsFvO PfYNpzUlnqNQF5IsEq7RhRe8CbJcBqYkrS/QV1sNg7XI98D5MdEMG3DEp5GGQPd2 oKFyf9KjxP9nqIri6YIZoZMlJ8tmEnjX8KBpPkJ3lPQVqUjQc/zoU2GHy5Xec78q uvwydKu6vyFFhVarVstRWPzGSak52/N2Khi+xgrWXAlcHh/XQUw08VnOfcn9gmWl rkY09xPBz6MOMsD8D3eZ+Q== -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/server.key000066400000000000000000000032171373244276700205730ustar00rootroot00000000000000-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA+Frp+8yqf4pxEDE0CZOau9naLQJGPhrt7lo76B3tPVX4vMUL 9Hc9rk5Kg6AjkBXvmV6O+gjOBIJxdQJUUXKrAuoGB3pgjXucVFMktiaJK8b6/Ina IJVMkuiZRerVukJiEQWIlHkP/mgSs7Bc6jkNb8/iEhbP4F03af2Mq1GsqJe7vlwp F+vuTUMuJMuvhOSWNjM+mkVUJXfv7XZLXmobNYMJVPHRsFkyxGS7UI9D4t0VxsS4 8hKb+4ZInCHUvdomcY7tP5onFQTCLCxKvyH+bTVAy3hB4s3UOb+aGkPB0p6pRCTk 3e+dW2zVRFwyL09Bnw8nPVWRlsoiG9YY+WOhYQIDAQABAoIBAD0hC4SpzLGV3txw b/GHfkeMiLIZZDa3JCdN2H76lsFJHu8/xQCINQtpQ9gAG6DEdXQXnTOX5TWg8dIu H5jok4UlGxTOH2PTsBflWxzmgU7gLDjqqWDpvq5OSCO4eKDe5ApyhTqeTbx921SV LVmNb2w9C9UN/l6oMxKIkQ4+DTR1oGEyRITLWPqfMKuBWAhU4FlTLdPvS8XskQRR R8fyC4rnTOMVMdeHeQXjV/tjRTBbET5MA5Ih6hK4r86rQ68R6pAKHNqkg/37H0Q2 cqMLX+W3o0hcj0ccbvamZRfUMJUIsy3y7uLbsvJB/5NhTjydfN4ikHXdaRpa26Lm X5ylFD0CgYEA//fKipCTA4SRr8gBNYK/yv2i+SzNzOHlCAWyZJGFGgq0IEDCjnIQ rSrxZvfjn+6ywwdy4XVjuwe5PYWmdIp0j7xNEzrqHjAss7ReCzbg+kT9E/tyryQP cqzCZGyXjdu+vkAIL636O7nPdjDnSa2KyT7uap+Ez2FqjLuRA8Gcd1MCgYEA+GLg 8T4Tznz1bcBX9y5Dkio1aaQrRwCpB5mFZ1gkKN/7vyjw/V8tS8NfltSQZfSS6c8G 58iEuX1BYNwgZymUYSWzqFVBC5mN+JwOsupo/m0ytzs171417dc9TA04yhNjglvK 3lNrOD4sfYI/WlQIyH5afo7Fzw0UdGrzQ7uVcfsCgYEAgb1VGfrBqWzOcyyLAFZv ZDI/ItFE1u5AqlpI25SuxE5ckmSAuLa0ITG8/hXzeCMC1Lu3zPM1Q51clQRjJHrx LdGht3eLJxX/8m4fpMuCKRhCtpgivwcmFVffiAtKngqdmczW2WPzi8ZYk22iLcQa rnqJWd3U8VBNM1v22tKNviUCgYAhS5fdnrWm+0cm9B6WisQSBshsJc6LUQJXe3PP e5g1RnkHkeRkAmse+cyJemr0z8kVwGOrlEx+VNT7t+Y8De3O6+/eQ7dZZ7cJOVob D6MNX/Ppbe137cgK3sxfsnIHXHv9UHKsRMBdpK/wDxKQ+CzJO27EAj1v2NACHwgG 71FEGwKBgQC1n15hbR3hiwteW404BX644w6jv0nt3Bq1jyTa/DrLoHgAlTMrmQQ4 dbgcS9v78g34iO7zGotG8fV+lqGGseamxpGqjZQ4KHdlNaiJdA8ZlDx/12VMkK44 ghqfZOceWb+zyPSgQSn0NVCH/HJriEVuzR205acH+ikOtYd6r45Lwg== -----END RSA PRIVATE KEY----- paho.mqtt.python-1.5.1/test/ssl/signingCA/000077500000000000000000000000001373244276700204125ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/ssl/signingCA/crlnumber000066400000000000000000000000031373244276700223170ustar00rootroot0000000000000002 paho.mqtt.python-1.5.1/test/ssl/signingCA/crlnumber.old000066400000000000000000000000031373244276700230740ustar00rootroot0000000000000001 paho.mqtt.python-1.5.1/test/ssl/signingCA/index.txt000066400000000000000000000006731373244276700222700ustar00rootroot00000000000000V 120821000000Z 01 unknown /C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production/CN=localhost V 250727091210Z 02 unknown /C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production/CN=test client V 120821000000Z 03 unknown /C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production/CN=test client expired R 250727091211Z 200728091211Z 04 unknown /C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production/CN=test client revoked paho.mqtt.python-1.5.1/test/ssl/signingCA/index.txt.attr000066400000000000000000000000251373244276700232300ustar00rootroot00000000000000unique_subject = yes paho.mqtt.python-1.5.1/test/ssl/signingCA/index.txt.attr.old000066400000000000000000000000251373244276700240050ustar00rootroot00000000000000unique_subject = yes paho.mqtt.python-1.5.1/test/ssl/signingCA/index.txt.old000066400000000000000000000006561373244276700230460ustar00rootroot00000000000000V 120821000000Z 01 unknown /C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production/CN=localhost V 250727091210Z 02 unknown /C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production/CN=test client V 120821000000Z 03 unknown /C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production/CN=test client expired V 250727091211Z 04 unknown /C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production/CN=test client revoked paho.mqtt.python-1.5.1/test/ssl/signingCA/newcerts/000077500000000000000000000000001373244276700222445ustar00rootroot00000000000000paho.mqtt.python-1.5.1/test/ssl/signingCA/newcerts/01.pem000066400000000000000000000106521373244276700231730ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 1 (0x1) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Aug 20 00:00:00 2012 GMT Not After : Aug 21 00:00:00 2012 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=localhost Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:f8:5a:e9:fb:cc:aa:7f:8a:71:10:31:34:09:93: 9a:bb:d9:da:2d:02:46:3e:1a:ed:ee:5a:3b:e8:1d: ed:3d:55:f8:bc:c5:0b:f4:77:3d:ae:4e:4a:83:a0: 23:90:15:ef:99:5e:8e:fa:08:ce:04:82:71:75:02: 54:51:72:ab:02:ea:06:07:7a:60:8d:7b:9c:54:53: 24:b6:26:89:2b:c6:fa:fc:89:da:20:95:4c:92:e8: 99:45:ea:d5:ba:42:62:11:05:88:94:79:0f:fe:68: 12:b3:b0:5c:ea:39:0d:6f:cf:e2:12:16:cf:e0:5d: 37:69:fd:8c:ab:51:ac:a8:97:bb:be:5c:29:17:eb: ee:4d:43:2e:24:cb:af:84:e4:96:36:33:3e:9a:45: 54:25:77:ef:ed:76:4b:5e:6a:1b:35:83:09:54:f1: d1:b0:59:32:c4:64:bb:50:8f:43:e2:dd:15:c6:c4: b8:f2:12:9b:fb:86:48:9c:21:d4:bd:da:26:71:8e: ed:3f:9a:27:15:04:c2:2c:2c:4a:bf:21:fe:6d:35: 40:cb:78:41:e2:cd:d4:39:bf:9a:1a:43:c1:d2:9e: a9:44:24:e4:dd:ef:9d:5b:6c:d5:44:5c:32:2f:4f: 41:9f:0f:27:3d:55:91:96:ca:22:1b:d6:18:f9:63: a1:61 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 8F:E3:5C:A3:F0:4A:C3:1C:62:92:0A:83:37:BD:E8:B9:B6:91:22:E4 X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption 59:0b:b1:28:ab:1b:31:93:37:b2:76:ef:83:97:09:0e:fe:44: be:c0:c3:53:bf:82:79:de:e3:a7:90:54:af:70:c0:ac:a5:83: 24:0c:53:fc:b3:a5:d8:a2:f1:85:3f:d3:05:fe:30:a2:95:97: b9:c0:74:68:9b:a9:39:6d:c5:a9:aa:a6:2c:e9:75:99:68:74: aa:8f:fa:01:86:fe:54:1c:c7:7f:7f:1b:6b:39:cf:f9:6f:55: 4a:6f:5b:00:bc:d3:54:85:4a:e1:14:b7:94:cc:57:0a:a3:4c: b5:13:ae:92:cd:c8:a2:d2:8d:28:03:a1:9b:b3:87:c4:68:a1: 27:5b:61:95:e0:f4:5e:71:6a:83:a1:6a:00:43:d9:93:fa:8d: 85:9a:ee:36:08:36:71:b5:d9:d5:36:90:99:02:27:64:97:87: c1:d9:a0:4d:1b:27:66:0c:3d:52:94:91:13:86:70:12:15:3a: eb:e5:10:40:9e:4b:9b:34:2e:07:f3:6f:83:5a:79:a1:91:d6: 01:4d:75:3c:f3:14:53:1c:9b:b6:11:55:db:21:87:22:90:0d: d8:69:a5:46:07:6c:7a:96:db:e9:49:4f:51:be:b2:ae:e8:37: 4c:90:32:6c:95:35:e8:6e:a4:84:cb:57:dd:e2:f2:bf:37:62: 39:e0:0f:f4 -----BEGIN CERTIFICATE----- MIIDzDCCArSgAwIBAgIBATANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTEyMDgyMDAwMDAw MFoXDTEyMDgyMTAwMDAwMFowdjELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy MRMwEQYDVQQLDApQcm9kdWN0aW9uMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0G CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQD4Wun7zKp/inEQMTQJk5q72dotAkY+ Gu3uWjvoHe09Vfi8xQv0dz2uTkqDoCOQFe+ZXo76CM4EgnF1AlRRcqsC6gYHemCN e5xUUyS2Jokrxvr8idoglUyS6JlF6tW6QmIRBYiUeQ/+aBKzsFzqOQ1vz+ISFs/g XTdp/YyrUayol7u+XCkX6+5NQy4ky6+E5JY2Mz6aRVQld+/tdkteahs1gwlU8dGw WTLEZLtQj0Pi3RXGxLjyEpv7hkicIdS92iZxju0/micVBMIsLEq/If5tNUDLeEHi zdQ5v5oaQ8HSnqlEJOTd751bbNVEXDIvT0GfDyc9VZGWyiIb1hj5Y6FhAgMBAAGj ezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVk IENlcnRpZmljYXRlMB0GA1UdDgQWBBSP41yj8ErDHGKSCoM3vei5tpEi5DAfBgNV HSMEGDAWgBRjrYnEIxMT0esATQEOJeNeDJ1ByTANBgkqhkiG9w0BAQsFAAOCAQEA WQuxKKsbMZM3snbvg5cJDv5EvsDDU7+Ced7jp5BUr3DArKWDJAxT/LOl2KLxhT/T Bf4wopWXucB0aJupOW3FqaqmLOl1mWh0qo/6AYb+VBzHf38baznP+W9VSm9bALzT VIVK4RS3lMxXCqNMtROuks3IotKNKAOhm7OHxGihJ1thleD0XnFqg6FqAEPZk/qN hZruNgg2cbXZ1TaQmQInZJeHwdmgTRsnZgw9UpSRE4ZwEhU66+UQQJ5LmzQuB/Nv g1p5oZHWAU11PPMUUxybthFV2yGHIpAN2GmlRgdsepbb6UlPUb6yrug3TJAybJU1 6G6khMtX3eLyvzdiOeAP9A== -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/signingCA/newcerts/02.pem000066400000000000000000000106541373244276700231760ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 2 (0x2) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Jul 28 09:12:10 2020 GMT Not After : Jul 27 09:12:10 2025 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=test client Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:b5:85:9e:ea:67:a7:6e:35:bc:0a:60:5f:dd:2f: b8:5d:ab:1f:56:82:1a:55:82:1e:ba:7e:05:59:fc: 97:11:7b:73:59:f2:61:84:3b:da:ff:09:ba:21:25: b9:38:4b:76:c1:ae:2d:a0:7e:20:23:e9:21:50:e7: b9:a3:81:35:d7:f1:39:3c:8f:d5:34:82:7a:e4:68: 4b:f3:f1:23:3b:67:e9:3e:d4:97:01:86:8e:52:fa: a2:a7:41:ea:03:92:fc:f9:1b:bb:9e:4d:b2:32:78: 7e:da:8c:95:ef:c9:53:97:30:34:9e:5c:d0:b3:2f: 44:33:01:29:23:bd:b8:82:05:f5:12:f6:9e:d2:6a: 6f:74:14:12:08:6e:c2:85:88:7f:a4:7c:f5:e7:76: e2:2b:e8:c1:44:bf:1d:c7:c6:b4:84:c4:4b:4e:56: 63:dc:91:b0:91:68:d3:07:55:c0:e3:92:ad:e4:75: 2b:aa:f4:67:7e:7f:91:40:22:4e:11:6d:5e:97:ba: 9a:ea:11:a8:19:1f:74:72:2b:a9:8f:05:24:03:11: 1f:9c:ac:33:49:37:43:60:c7:0b:87:77:01:64:ad: f5:b4:42:c5:ca:38:6f:fc:0d:b1:df:f7:94:e5:14: d9:b9:7f:a1:da:2a:51:ab:4d:da:32:5c:3a:5b:5c: 0e:a1 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 5E:12:4A:C4:94:EA:40:AC:15:A8:14:93:63:F9:61:C8:35:89:79:9E X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption 4e:f3:5d:99:00:94:57:9e:a7:19:b8:9e:ee:f2:f9:01:9e:b7: 02:e7:fe:a4:89:cf:a1:5f:04:4e:46:98:b8:aa:de:8d:f4:c2: 6b:71:25:08:f4:64:7e:99:5e:07:dd:43:43:cf:08:f7:e7:11: f1:79:1d:7a:0b:d3:b2:f1:70:9d:da:dd:c6:f7:a0:e2:3b:64: 22:7b:74:b8:70:93:74:51:a2:c4:aa:3d:15:b1:b9:68:20:9e: ec:98:1d:86:4d:e9:42:61:41:92:a7:08:12:27:f3:7e:3e:6a: 54:1e:76:19:f5:b5:11:4d:de:25:22:63:ef:78:17:61:3e:4c: d2:ea:ff:e9:1c:52:a8:82:29:24:cd:50:75:72:32:c1:00:83: bf:14:c3:c6:bd:b0:0f:4f:83:86:ea:67:7a:8d:82:c6:42:4a: e5:73:4b:69:c2:96:9a:74:ea:5e:82:62:8c:a4:02:17:08:cf: f6:07:76:84:b5:91:b1:ce:79:4a:be:e5:43:5d:31:55:5e:4e: 38:42:cd:70:9b:22:c4:3e:ee:24:fa:ae:07:ae:75:f5:f9:b5: 05:53:58:bd:12:50:1f:68:5e:ff:8d:30:2d:61:85:97:5a:48: 0c:61:ab:ad:4c:95:67:32:c4:8c:3f:dd:9f:39:ed:9a:be:73: 50:53:20:de -----BEGIN CERTIFICATE----- MIIDzjCCAragAwIBAgIBAjANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTIwMDcyODA5MTIx MFoXDTI1MDcyNzA5MTIxMFoweDELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy MRMwEQYDVQQLDApQcm9kdWN0aW9uMRQwEgYDVQQDDAt0ZXN0IGNsaWVudDCCASIw DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALWFnupnp241vApgX90vuF2rH1aC GlWCHrp+BVn8lxF7c1nyYYQ72v8JuiEluThLdsGuLaB+ICPpIVDnuaOBNdfxOTyP 1TSCeuRoS/PxIztn6T7UlwGGjlL6oqdB6gOS/Pkbu55NsjJ4ftqMle/JU5cwNJ5c 0LMvRDMBKSO9uIIF9RL2ntJqb3QUEghuwoWIf6R89ed24ivowUS/HcfGtITES05W Y9yRsJFo0wdVwOOSreR1K6r0Z35/kUAiThFtXpe6muoRqBkfdHIrqY8FJAMRH5ys M0k3Q2DHC4d3AWSt9bRCxco4b/wNsd/3lOUU2bl/odoqUatN2jJcOltcDqECAwEA AaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0 ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFF4SSsSU6kCsFagUk2P5Ycg1iXmeMB8G A1UdIwQYMBaAFGOticQjExPR6wBNAQ4l414MnUHJMA0GCSqGSIb3DQEBCwUAA4IB AQBO812ZAJRXnqcZuJ7u8vkBnrcC5/6kic+hXwRORpi4qt6N9MJrcSUI9GR+mV4H 3UNDzwj35xHxeR16C9Oy8XCd2t3G96DiO2Qie3S4cJN0UaLEqj0VsbloIJ7smB2G TelCYUGSpwgSJ/N+PmpUHnYZ9bURTd4lImPveBdhPkzS6v/pHFKogikkzVB1cjLB AIO/FMPGvbAPT4OG6md6jYLGQkrlc0tpwpaadOpegmKMpAIXCM/2B3aEtZGxznlK vuVDXTFVXk44Qs1wmyLEPu4k+q4HrnX1+bUFU1i9ElAfaF7/jTAtYYWXWkgMYaut TJVnMsSMP92fOe2avnNQUyDe -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/signingCA/newcerts/03.pem000066400000000000000000000107001373244276700231670ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 3 (0x3) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Aug 20 00:00:00 2012 GMT Not After : Aug 21 00:00:00 2012 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=test client expired Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:b5:85:9e:ea:67:a7:6e:35:bc:0a:60:5f:dd:2f: b8:5d:ab:1f:56:82:1a:55:82:1e:ba:7e:05:59:fc: 97:11:7b:73:59:f2:61:84:3b:da:ff:09:ba:21:25: b9:38:4b:76:c1:ae:2d:a0:7e:20:23:e9:21:50:e7: b9:a3:81:35:d7:f1:39:3c:8f:d5:34:82:7a:e4:68: 4b:f3:f1:23:3b:67:e9:3e:d4:97:01:86:8e:52:fa: a2:a7:41:ea:03:92:fc:f9:1b:bb:9e:4d:b2:32:78: 7e:da:8c:95:ef:c9:53:97:30:34:9e:5c:d0:b3:2f: 44:33:01:29:23:bd:b8:82:05:f5:12:f6:9e:d2:6a: 6f:74:14:12:08:6e:c2:85:88:7f:a4:7c:f5:e7:76: e2:2b:e8:c1:44:bf:1d:c7:c6:b4:84:c4:4b:4e:56: 63:dc:91:b0:91:68:d3:07:55:c0:e3:92:ad:e4:75: 2b:aa:f4:67:7e:7f:91:40:22:4e:11:6d:5e:97:ba: 9a:ea:11:a8:19:1f:74:72:2b:a9:8f:05:24:03:11: 1f:9c:ac:33:49:37:43:60:c7:0b:87:77:01:64:ad: f5:b4:42:c5:ca:38:6f:fc:0d:b1:df:f7:94:e5:14: d9:b9:7f:a1:da:2a:51:ab:4d:da:32:5c:3a:5b:5c: 0e:a1 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 5E:12:4A:C4:94:EA:40:AC:15:A8:14:93:63:F9:61:C8:35:89:79:9E X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption b1:91:cd:ed:2f:8a:32:1f:90:7d:8f:5f:64:84:89:f9:9d:5c: 97:d6:d7:cd:08:ba:2d:8c:56:ca:f8:41:93:7a:4e:3e:d2:81: 57:e5:d4:3f:0c:3a:c8:f9:b1:5b:4c:8d:fc:cd:3c:d4:96:0a: 63:22:32:de:0e:c6:9c:f4:37:97:43:4b:aa:c9:e9:9d:85:4a: f4:92:8b:14:50:8e:17:a5:41:49:70:9b:ae:2d:6b:07:d5:33: 64:86:bc:95:b2:46:dc:d4:be:77:35:04:91:99:08:31:53:d8: 5c:5e:44:91:1e:90:3c:c3:6a:f9:fb:05:17:e9:16:3a:0d:ad: 5d:af:4e:6a:4f:f2:b6:6f:9a:1f:59:4d:11:c4:94:dd:b0:af: 3c:68:cb:cf:4d:3d:b0:88:97:2b:7b:cd:bf:20:c0:57:ab:f5: db:63:b7:7e:23:3c:dd:60:be:fb:20:e7:b6:14:30:c3:2f:09: a1:44:41:f1:bc:b9:75:4c:c3:5e:4c:5c:5c:a7:a9:67:58:a6: ed:de:2a:be:d9:28:03:ad:17:c0:de:aa:05:fc:8e:b7:cc:c1: bc:8d:12:06:62:83:6f:e7:9a:7c:a5:31:73:5f:75:31:ac:c7: b8:1b:c4:82:ea:c2:09:d6:d8:7f:27:6f:08:b9:13:e6:3a:60: e5:e3:a3:24 -----BEGIN CERTIFICATE----- MIID1zCCAr+gAwIBAgIBAzANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTEyMDgyMDAwMDAw MFoXDTEyMDgyMTAwMDAwMFowgYAxCzAJBgNVBAYTAkdCMRgwFgYDVQQIDA9Ob3R0 aW5naGFtc2hpcmUxEzARBgNVBAcMCk5vdHRpbmdoYW0xDzANBgNVBAoMBlNlcnZl cjETMBEGA1UECwwKUHJvZHVjdGlvbjEcMBoGA1UEAwwTdGVzdCBjbGllbnQgZXhw aXJlZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALWFnupnp241vApg X90vuF2rH1aCGlWCHrp+BVn8lxF7c1nyYYQ72v8JuiEluThLdsGuLaB+ICPpIVDn uaOBNdfxOTyP1TSCeuRoS/PxIztn6T7UlwGGjlL6oqdB6gOS/Pkbu55NsjJ4ftqM le/JU5cwNJ5c0LMvRDMBKSO9uIIF9RL2ntJqb3QUEghuwoWIf6R89ed24ivowUS/ HcfGtITES05WY9yRsJFo0wdVwOOSreR1K6r0Z35/kUAiThFtXpe6muoRqBkfdHIr qY8FJAMRH5ysM0k3Q2DHC4d3AWSt9bRCxco4b/wNsd/3lOUU2bl/odoqUatN2jJc OltcDqECAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNT TCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFF4SSsSU6kCsFagUk2P5 Ycg1iXmeMB8GA1UdIwQYMBaAFGOticQjExPR6wBNAQ4l414MnUHJMA0GCSqGSIb3 DQEBCwUAA4IBAQCxkc3tL4oyH5B9j19khIn5nVyX1tfNCLotjFbK+EGTek4+0oFX 5dQ/DDrI+bFbTI38zTzUlgpjIjLeDsac9DeXQ0uqyemdhUr0kosUUI4XpUFJcJuu LWsH1TNkhryVskbc1L53NQSRmQgxU9hcXkSRHpA8w2r5+wUX6RY6Da1dr05qT/K2 b5ofWU0RxJTdsK88aMvPTT2wiJcre82/IMBXq/XbY7d+IzzdYL77IOe2FDDDLwmh REHxvLl1TMNeTFxcp6lnWKbt3iq+2SgDrRfA3qoF/I63zMG8jRIGYoNv55p8pTFz X3UxrMe4G8SC6sIJ1th/J28IuRPmOmDl46Mk -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/signingCA/newcerts/04.pem000066400000000000000000000107001373244276700231700ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 4 (0x4) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Validity Not Before: Jul 28 09:12:11 2020 GMT Not After : Jul 27 09:12:11 2025 GMT Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=test client revoked Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:a4:22:2c:88:b3:4f:f2:a0:b0:18:7d:28:d8:b4: 69:72:a0:ad:90:f9:c4:1b:c1:f9:b1:e0:e5:87:02: 74:21:6d:ad:87:87:e2:6b:af:82:02:6f:e8:65:a9: 04:f8:05:a5:90:59:de:c9:26:41:a3:7b:dd:d6:91: 0f:6b:57:92:04:54:e6:a1:74:1c:af:38:b7:f9:e8: c8:fb:bb:ff:ac:23:58:77:17:3a:76:42:a6:0f:f1: dc:bc:76:7e:25:1b:8a:89:8a:5b:06:76:41:6a:29: 5c:72:27:e4:1b:68:c7:ca:3d:57:31:5e:9a:9d:5c: 88:c8:bc:d8:e6:bd:b5:be:91:88:e4:4e:8b:37:33: 13:6d:00:37:b4:12:02:da:1c:31:61:0e:e8:b5:0d: f2:f4:e2:46:55:d1:21:bf:ea:92:c3:8c:3d:16:0c: a4:e5:dd:d6:e5:f6:39:b5:4d:69:65:c0:fe:bf:1c: 33:23:b4:f8:94:40:28:47:e7:8f:59:06:31:72:4b: 6b:55:f2:7d:aa:c6:96:ff:1c:08:28:ab:82:b7:99: 22:1f:1c:08:54:d1:4c:f6:f2:79:06:77:da:58:63: 48:47:7f:13:6c:7f:eb:d3:06:1d:25:72:4b:04:d1: 2e:1d:76:a8:56:f5:59:bc:be:c7:78:6d:e2:1d:57: b2:f3 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 21:58:60:7A:B1:55:A8:CA:EF:2A:D2:0B:25:83:81:DB:E3:A8:7C:7B X509v3 Authority Key Identifier: keyid:63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 Signature Algorithm: sha256WithRSAEncryption ac:60:10:4d:cc:10:f8:71:5f:a2:94:20:d8:9e:8c:d9:fc:10: 4c:d7:b5:b7:57:8b:08:a5:97:50:24:27:38:47:e9:37:49:35: 92:07:fc:e2:75:37:4d:3c:b4:24:2c:62:da:6f:40:8a:55:d6: a3:bf:ef:a0:90:8d:4e:ee:51:c7:5a:30:cc:36:9f:8c:72:c7: 36:4c:c4:96:ce:bf:df:e9:58:5a:54:63:be:e5:9c:27:63:e6: 55:4e:2f:09:df:10:b2:7c:42:eb:f1:86:66:f2:07:ca:b3:e5: ca:14:58:34:ac:ac:4e:99:e4:37:c7:b1:8c:56:23:9a:5c:a8: fe:17:77:ec:ce:c8:77:25:35:b7:98:1c:90:25:bc:fc:5a:4b: 85:b0:96:55:ca:cb:83:bc:a1:2a:1a:f1:cb:73:e1:8d:4b:65: ca:86:1f:43:a5:f1:4a:86:d2:50:81:c3:c1:e6:c6:ed:15:0f: 01:2c:58:63:44:4e:17:c0:59:d1:cf:c8:cb:37:9c:9e:dc:e1: 83:10:90:9e:35:9d:43:23:f2:b9:1d:91:00:33:b4:eb:6a:9d: 5a:1c:e0:b8:6b:f0:dc:05:ae:15:f3:42:7f:0c:9a:bd:06:25: 75:79:53:ea:a8:9b:f5:4c:96:52:1a:85:91:a5:68:08:a5:f4: 32:ca:9d:58 -----BEGIN CERTIFICATE----- MIID1zCCAr+gAwIBAgIBBDANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTIwMDcyODA5MTIx MVoXDTI1MDcyNzA5MTIxMVowgYAxCzAJBgNVBAYTAkdCMRgwFgYDVQQIDA9Ob3R0 aW5naGFtc2hpcmUxEzARBgNVBAcMCk5vdHRpbmdoYW0xDzANBgNVBAoMBlNlcnZl cjETMBEGA1UECwwKUHJvZHVjdGlvbjEcMBoGA1UEAwwTdGVzdCBjbGllbnQgcmV2 b2tlZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKQiLIizT/KgsBh9 KNi0aXKgrZD5xBvB+bHg5YcCdCFtrYeH4muvggJv6GWpBPgFpZBZ3skmQaN73daR D2tXkgRU5qF0HK84t/noyPu7/6wjWHcXOnZCpg/x3Lx2fiUbiomKWwZ2QWopXHIn 5Btox8o9VzFemp1ciMi82Oa9tb6RiOROizczE20AN7QSAtocMWEO6LUN8vTiRlXR Ib/qksOMPRYMpOXd1uX2ObVNaWXA/r8cMyO0+JRAKEfnj1kGMXJLa1XyfarGlv8c CCirgreZIh8cCFTRTPbyeQZ32lhjSEd/E2x/69MGHSVySwTRLh12qFb1Wby+x3ht 4h1XsvMCAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNT TCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFCFYYHqxVajK7yrSCyWD gdvjqHx7MB8GA1UdIwQYMBaAFGOticQjExPR6wBNAQ4l414MnUHJMA0GCSqGSIb3 DQEBCwUAA4IBAQCsYBBNzBD4cV+ilCDYnozZ/BBM17W3V4sIpZdQJCc4R+k3STWS B/zidTdNPLQkLGLab0CKVdajv++gkI1O7lHHWjDMNp+Mcsc2TMSWzr/f6VhaVGO+ 5ZwnY+ZVTi8J3xCyfELr8YZm8gfKs+XKFFg0rKxOmeQ3x7GMViOaXKj+F3fszsh3 JTW3mByQJbz8WkuFsJZVysuDvKEqGvHLc+GNS2XKhh9DpfFKhtJQgcPB5sbtFQ8B LFhjRE4XwFnRz8jLN5ye3OGDEJCeNZ1DI/K5HZEAM7Trap1aHOC4a/DcBa4V80J/ DJq9BiV1eVPqqJv1TJZSGoWRpWgIpfQyyp1Y -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/signingCA/serial000066400000000000000000000000031373244276700216050ustar00rootroot0000000000000005 paho.mqtt.python-1.5.1/test/ssl/signingCA/serial.old000066400000000000000000000000031373244276700223620ustar00rootroot0000000000000004 paho.mqtt.python-1.5.1/test/ssl/test-alt-ca.crt000066400000000000000000000104461373244276700214050ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 2 (0x2) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA Validity Not Before: Jul 28 09:12:10 2020 GMT Not After : Jul 27 09:12:10 2025 GMT Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Alternative Signing CA Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:bd:c2:9f:2c:d2:a7:25:79:f0:3f:29:65:ac:d3: 8c:ea:72:d2:73:2d:1b:5b:e3:0c:a1:5a:40:f4:a9: 68:bc:a4:50:77:c9:08:75:12:a3:21:3d:a9:d6:dc: dc:08:b4:47:32:7e:ad:f4:87:de:48:fd:83:d1:b7: e4:ce:3b:8b:87:99:3c:fa:6b:0e:1c:70:71:6d:d9: b4:75:7c:6e:2a:03:cc:0e:bb:c7:8c:31:53:67:11: 2f:fd:97:c9:67:05:48:23:81:60:f5:94:94:af:61: 1c:a8:c1:4d:fe:2b:2e:f8:e6:bd:30:c2:52:ec:56: 7a:b7:64:d0:a2:bf:09:e4:d2:a3:c3:f1:f9:e7:12: 96:45:06:20:a2:fd:49:43:87:a7:0f:c1:c6:58:46: 9f:1d:9f:be:86:ce:49:de:c7:35:4d:fd:08:9a:61: 3f:ed:1f:cd:5c:55:77:4f:cc:0e:52:51:2a:7e:04: 4c:10:e1:79:88:9e:f6:8b:6b:bc:20:d2:6b:e9:c4: c6:94:bc:d8:06:57:a1:b6:b2:30:cd:0d:d3:27:b3: 9e:1b:ac:40:81:6a:f0:a3:f6:62:22:14:40:61:9d: 26:82:b1:aa:fa:0a:0a:45:54:7d:5d:02:59:70:e6: d2:f9:fc:45:58:83:10:2a:db:10:e3:7d:10:73:1b: d9:49 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: 3A:BA:37:57:E0:82:EB:BA:77:1B:50:07:A6:C9:22:EA:92:76:F9:1C X509v3 Authority Key Identifier: keyid:C7:BD:C0:22:65:FF:A7:97:A7:CB:9D:7E:44:E5:13:77:39:7D:BE:BA X509v3 Basic Constraints: CA:TRUE Signature Algorithm: sha256WithRSAEncryption 05:07:f6:5d:7d:2d:5e:35:07:82:1e:cd:06:e6:b6:4c:1b:03: b4:28:3e:16:22:0d:26:5f:f9:69:19:72:24:5a:fb:c6:cf:70: c8:a6:a6:19:8d:10:56:c4:d5:76:bb:38:93:e0:ff:d0:a0:81: 47:36:e7:b6:f5:bf:99:36:28:d1:db:59:c0:e9:84:95:0f:db: c0:84:86:9a:ef:78:ac:dd:83:6d:51:e8:ae:28:b4:f8:78:bb: 91:87:f5:35:21:fd:12:ff:41:33:7f:22:1e:16:f3:43:c9:97: e2:16:35:db:e8:c8:ee:5a:3e:d4:43:c1:90:52:12:7c:f7:7e: 18:ee:60:be:61:41:3a:aa:2d:99:f3:44:86:3c:fd:03:e1:a2: d8:e1:1c:49:b0:39:3e:8c:f6:38:00:4a:84:a5:54:98:ef:c0: 6d:2d:48:4a:13:fb:80:5f:58:a1:95:86:3a:a1:63:56:fe:23: 7f:db:c9:19:a5:22:cb:34:a9:10:cb:b4:95:9f:c9:c6:16:e0: e3:50:7a:29:60:b0:fe:c7:f5:c8:f9:c6:3b:82:a6:a8:d9:0c: 5b:aa:58:f2:31:c3:98:20:87:d8:a1:63:ad:52:ae:b2:85:57: 10:d5:75:9e:73:35:47:c5:22:26:1f:53:38:52:4d:fd:2e:16: 00:15:d4:da -----BEGIN CERTIFICATE----- MIIDpDCCAoygAwIBAgIBAjANBgkqhkiG9w0BAQsFADBtMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe Fw0yMDA3MjgwOTEyMTBaFw0yNTA3MjcwOTEyMTBaMGwxCzAJBgNVBAYTAkdCMRMw EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV BAsMB1Rlc3RpbmcxHzAdBgNVBAMMFkFsdGVybmF0aXZlIFNpZ25pbmcgQ0EwggEi MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC9wp8s0qclefA/KWWs04zqctJz LRtb4wyhWkD0qWi8pFB3yQh1EqMhPanW3NwItEcyfq30h95I/YPRt+TOO4uHmTz6 aw4ccHFt2bR1fG4qA8wOu8eMMVNnES/9l8lnBUgjgWD1lJSvYRyowU3+Ky745r0w wlLsVnq3ZNCivwnk0qPD8fnnEpZFBiCi/UlDh6cPwcZYRp8dn76GzknexzVN/Qia YT/tH81cVXdPzA5SUSp+BEwQ4XmInvaLa7wg0mvpxMaUvNgGV6G2sjDNDdMns54b rECBavCj9mIiFEBhnSaCsar6CgpFVH1dAllw5tL5/EVYgxAq2xDjfRBzG9lJAgMB AAGjUDBOMB0GA1UdDgQWBBQ6ujdX4ILruncbUAemySLqknb5HDAfBgNVHSMEGDAW gBTHvcAiZf+nl6fLnX5E5RN3OX2+ujAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEB CwUAA4IBAQAFB/ZdfS1eNQeCHs0G5rZMGwO0KD4WIg0mX/lpGXIkWvvGz3DIpqYZ jRBWxNV2uziT4P/QoIFHNue29b+ZNijR21nA6YSVD9vAhIaa73is3YNtUeiuKLT4 eLuRh/U1If0S/0EzfyIeFvNDyZfiFjXb6MjuWj7UQ8GQUhJ8934Y7mC+YUE6qi2Z 80SGPP0D4aLY4RxJsDk+jPY4AEqEpVSY78BtLUhKE/uAX1ihlYY6oWNW/iN/28kZ pSLLNKkQy7SVn8nGFuDjUHopYLD+x/XI+cY7gqao2QxbqljyMcOYIIfYoWOtUq6y hVcQ1XWeczVHxSImH1M4Uk39LhYAFdTa -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/test-alt-ca.key000066400000000000000000000032171373244276700214030ustar00rootroot00000000000000-----BEGIN RSA PRIVATE KEY----- MIIEpgIBAAKCAQEAvcKfLNKnJXnwPyllrNOM6nLScy0bW+MMoVpA9KlovKRQd8kI dRKjIT2p1tzcCLRHMn6t9IfeSP2D0bfkzjuLh5k8+msOHHBxbdm0dXxuKgPMDrvH jDFTZxEv/ZfJZwVII4Fg9ZSUr2EcqMFN/isu+Oa9MMJS7FZ6t2TQor8J5NKjw/H5 5xKWRQYgov1JQ4enD8HGWEafHZ++hs5J3sc1Tf0ImmE/7R/NXFV3T8wOUlEqfgRM EOF5iJ72i2u8INJr6cTGlLzYBlehtrIwzQ3TJ7OeG6xAgWrwo/ZiIhRAYZ0mgrGq +goKRVR9XQJZcObS+fxFWIMQKtsQ430QcxvZSQIDAQABAoIBAQCQQ4X/7aZlN28O lcpWuf5Hv0N/jKtgEB1qDdOULbcSs1j5uDxVxPWAMAEO+JnPhD8chHJ7lU/I7fNp XQT2RQ6u6DETsI/pzxJtETXAm/ikuH5KNThfvKBLmyWBBgR37ewKEjJEgdEIBCxl n5BLy0jKsaDjkNi6FIT3KA31rIc5Dhq72vb08ePkKhYN6DsIInY/qTT0z/ZOzSw2 3r/9juMWIfxxAf4d2QO7WtQbVhAaRGPU0dV4g/Xp03iq0SwJv0t92eFjHLCTKQUV 2WZ7K0NRcNwtlqTgWBj3BIl38IJC3w3baMl2QN+vgbfQZEarPFqfyPA39HDmz7HK m9NlRDSBAoGBAOyIbnQRTwHM9sEGQGXqxN2pKRNUDIOT3Hs9rMauXuf4+4ut2iXD fnNl5Gxr/N9E+y8JlygsINSretRcz+IPNWdU0BtHA8mieY4tozgMQghTTOGtOJbg 4kD/ycWiQpl52HjOeZyr/SlMUGSDM4UulJelFDwgplWS0dlqCtMSQecnAoGBAM1g ua8v0evTkcmKAL9BQwqqAs7QPtGOWT0EWPfyBCrxV4xIHfX9xqqWbay6fOpn00dz fi/XzBRE11ZPxVUUg8CxCzLM1BWLCDUVJqq2gsxTjsjFVSZ3m/Uc3ta4vSEiIVMj P+xGbxanSuyHdEfECDaVVxnR5g4knGjUTMM1pwIPAoGBAKHMWbHvvRnAOPKk8hxF UdFGy6A7GCxRUrrC35Mw6B7KRFex3s2CQtdxVaWM4PdhWmk8qDeEqBiSDH2D13gN azx52bkvBLpC9993/HR0fh7vzGF7eoBK6LoJvt4ANoqBvMA2jR3M0GoVl9CJpw5t ZJuvAn523xEeU4njbfAgRxB1AoGBAJ0kkk8SFtwLkPQVTMcKB2MEfIuD2Vz8Pxmp 1u04V6oH6cXjdFFBMR5bZWWRd3zfnlCAdR/kTTmBBwb6mHGl9b2deYUQJoKpU8lR +rkKVwBCOvEx1BpP0Jv20CaZSdUtSTRUt1dw+RTrQi/C4Nz8iJBDKlcOPKm7p5Wq Q2XmCnhPAoGBAI9jnZx0Tjvs7vHiBf/eEnlj0LRSiELVEmK/aZCo+VKrEpYBFubn jQla3tPPRi709WB3g7k7taMbPiOVypTWjo/hbfXqTI9QIDaWwCfqLlaohSjXKv7e fJyrBNaw4i9nDlJm8ncJABz3NwwJBXIRWUEjPlNvutGO92Smvzc1U5Ar -----END RSA PRIVATE KEY----- paho.mqtt.python-1.5.1/test/ssl/test-bad-root-ca.crt000066400000000000000000000025231373244276700223310ustar00rootroot00000000000000-----BEGIN CERTIFICATE----- MIIDwDCCAqigAwIBAgIUPom8FiJ7Gc6+2UdE/a8wWxttZ3IwDQYJKoZIhvcNAQEL BQAwcTELMAkGA1UEBhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcM BURlcmJ5MRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3Rpbmcx FDASBgNVBAMMC0JhZCBSb290IENBMB4XDTIwMDcyODA5MTIxMFoXDTMwMDcyNjA5 MTIxMFowcTELMAkGA1UEBhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNV BAcMBURlcmJ5MRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3Rp bmcxFDASBgNVBAMMC0JhZCBSb290IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A MIIBCgKCAQEA3Hh4kadQ46H4iHVSdXimBLkHkVrxuby/+PG5qLr3FiXnU8Q3XbBE hVacRJMtvsG+a8zDv7xthsCZlrhi8yvamWpvvYaVJJPsdpQ5ZrL5Ul8tqYJ9dJgD m6uC6fLfXYQiAgWAkc5p2MN/jWuVp5QTdl5/lbPtx/H03AP4IPuHMLxKu/HJ4WOC DMfkNA0/n8TlJM0VHQZeSLhxi/wUJbxXU/LGNmSBmb/Ryjf6BQvEqDkSicjYw27I Dw9zhiTkYj6EoSGTQ+9e/Z9MTMZWTP931j/83jDQJhTi0lS7fw0699vjtoYJ2vqE FUuFrg+C4JhV7bUZgNT4MuNaIUMJabbzawIDAQABo1AwTjAdBgNVHQ4EFgQUqb9z n8mhTvpSiCzWg7YlA7riIYAwHwYDVR0jBBgwFoAUqb9zn8mhTvpSiCzWg7YlA7ri IYAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAdrUdzuIiiM35IXTi ZoowONNAeOFefVGWXLPSuMJwbsT6Uy85cGFhdFNjKqykMnorrEeqzXtMWv6Zyr8t CjR2eATJiIUfm1o9LNZ8SdLigWBWfpdYRY+0AXnO+S1K7h+X9KpoHHT7nbzTyxiz E8cx+Vhjh0DZRe6VkIoG6JXEMdrvmWW9wTIrpqEAhBFKtS1TkPMBj7pUg8yEfk2I 4zCwZR6vD6hjPhL6/niAimypSrBjQHW4DRAwLUAeu1DWnJiSq2bPHhrPKUdJOhcq g6vPEPe6ffj+5oAoceSgz0LttsYK4GPPrYeDN6O5rl6T/2UjkFf/+mqUyecP4Pxz JOnyDg== -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/test-bad-root-ca.key000066400000000000000000000032171373244276700223320ustar00rootroot00000000000000-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA3Hh4kadQ46H4iHVSdXimBLkHkVrxuby/+PG5qLr3FiXnU8Q3 XbBEhVacRJMtvsG+a8zDv7xthsCZlrhi8yvamWpvvYaVJJPsdpQ5ZrL5Ul8tqYJ9 dJgDm6uC6fLfXYQiAgWAkc5p2MN/jWuVp5QTdl5/lbPtx/H03AP4IPuHMLxKu/HJ 4WOCDMfkNA0/n8TlJM0VHQZeSLhxi/wUJbxXU/LGNmSBmb/Ryjf6BQvEqDkSicjY w27IDw9zhiTkYj6EoSGTQ+9e/Z9MTMZWTP931j/83jDQJhTi0lS7fw0699vjtoYJ 2vqEFUuFrg+C4JhV7bUZgNT4MuNaIUMJabbzawIDAQABAoIBAQC6GLp0/81Ih9S4 ood6/t7sB576s9BsnoVQxgGYClE8kbwEuhCd9YaxIl1/iNhJN1LbvZjRxGSTJQm/ 7l4fsrmvW+d8DBjiKjakFROqu5G2VP6/IZVyEEqjYQ99GHQwhLMMD8bpzFkODl8h aVmGfXg8JyH8pEcmyfaMrJEKjiYcHJIXvVSck6H5vV1Gpqs+kGA10RNswnmk3Hlx 8dvWz+pPhhahiOeI5VvNGqNqxr2X/QSAdBYBCvz4NRXIdZb+8zeAYFuK0f/06N2i 3HgsJ5wbyAcYd1Kdxu2GlO3Xp8zT68Xm20LKAWHaGf+Za1tQrOr7LxINxcWpwceA 2wqs1jJxAoGBAPwHKOfzGM2TFvdniQg1/oLXT/kF0uy0tk4Ietuj4eeNRnVZjFAo l3JVFod5LhOl1fxy5U8vyeNl5atZV6ackt1P6z3ztMnstiU1HHh00KuQP836BaOP 1CNcFuJOk/tRlMkrPLRodto8ixgTHTGaNxa8i6v2jsO6KJTUeYF2/BVJAoGBAN/x /R+B60nVMqFW51Lo8P83z6vm5b4dPN4VEVxgy0jylWO2iwtaMN7pYZXEEZgUxSUk Ip2Tu2lb/JoIxfgUv2z5F5ZQNTOIcMiYkVlN2jrkbMg20Bm+ETJjeWHBPThufOy6 Fe99DjCZPLOwnkjCgfm+XLOmjOHDR6Q2qz2B6WcTAoGAOdN2ukmXzktKgLebxGuH GwRGEDAa5j7MeXkOn2ipw5Qxr2k9fYLixNPrGGhgfxeU0piWLqYbX3aYzMjyCINy Wx8kLZHGUHJklILsJmM/Ia42RY9xTccJeJd/lKtM3uQoDEREaGxzoL01eO+hyijF LQ1TysAGn7gN6aAaxO7FBikCgYEAtlJhbgFr+dRlQA1sj4eujVp27NEzQjCzmWs1 kywK1P0Kuv+m/DsVhqYjGLdkS5i9WJuuwvO/pOuLICz8YBkkMCgsF+h9J9NxXx83 VqmXflLybZ6SliK0BX4PGJMmsIbjlid6LFx37QEU9oZYl4wkHZvqBSkXkcZW0U7g 41adG5kCgYBiPypubN9RfY02F8RnjSqL8x1AiHuXgCmD2hLitb465a0Kkyvh25RY 0y+U8Xw/pSMu8JiPjyFUMeMDSq6SwBF123b9hWFjOOjNmvhW/n5vJ7Yjxy3QkMVO G0YrrbddMvVHNLP3DVrxiTXXf31F29fl1OqfiMN4eUCjA688WjV14Q== -----END RSA PRIVATE KEY----- paho.mqtt.python-1.5.1/test/ssl/test-ca.srl000066400000000000000000000000211373244276700206230ustar00rootroot00000000000000CDAE0E564A2891A9 paho.mqtt.python-1.5.1/test/ssl/test-fake-root-ca.crt000066400000000000000000000025061373244276700225120ustar00rootroot00000000000000-----BEGIN CERTIFICATE----- MIIDuDCCAqCgAwIBAgIUe49B4x+bcqcL+TkVVqSsR0cUMoUwDQYJKoZIhvcNAQEL BQAwbTELMAkGA1UEBhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcM BURlcmJ5MRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3Rpbmcx EDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjAwNzI4MDkxMjEwWhcNMzAwNzI2MDkxMjEw WjBtMQswCQYDVQQGEwJHQjETMBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwF RGVyYnkxFTATBgNVBAoMDFBhaG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQ MA4GA1UEAwwHUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB ALwdmfN6sTm66ynPE9zBZw1XsAnGC8InEOPIm1msBUPxTfJwvRf8nx/d7KcNML8b iFF0D5rtxCuBD+iOvgaceI0i7gO26NA+No9hXbOROk6+ye7hGRxDiiucE8lot+7C extOuZRHdXk6FwGx+M5Fzi1zyzCw9nzWxF1u3kBO6t/FHHYduA3qadY2T/kWBzb5 rsDDAAbvaHu1MQNO1hNdt6ffSf54mQS8jNr1mIzE5Fz6wZnfLhzafzBMMjWVhtQX Bb7hoXO7a1zZ+pYCpwiU/WNP7JkR49cyqd1rOP2fA9yj+ArhUYADxHMDfDnwOzHL wtO6FF2BEZ2QNylMuFP9it0CAwEAAaNQME4wHQYDVR0OBBYEFOuu0LJ5ALxAbHkY /wnXccwH+xbeMB8GA1UdIwQYMBaAFOuu0LJ5ALxAbHkY/wnXccwH+xbeMAwGA1Ud EwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBALbRQwMta94JBYp4h0U31GWhr3xS ua4emh16vWNjiCdFN/YfksEe53ryykMVRZU7KNzur025EsjQitCIpA4j/wdRXgFq Ha8zL7oHxCU7kBlFLDYYnNRifWVRwOczvKmvmrchpT89nnWfbHSr5W3I7rMVVAH1 QJIx9dJ87hD+1WmXtHp2aQrNUQKyhmABvsUIwinnL5kRGTLGMJrGgQOTejOg/Jn2 fYu2Rs0Z7/Gp7aPY9MAsAQZa12O/D5GFYMFDbZGM1ISndfreVI//T00OjCPLMUtA +REDMXpxZOOjQJZBu99+KAL4goLOwO7ZKLF/ny8SAVg8sgmOr7b9ClfP4Ek= -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/test-fake-root-ca.key000066400000000000000000000032131373244276700225060ustar00rootroot00000000000000-----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEAvB2Z83qxObrrKc8T3MFnDVewCcYLwicQ48ibWawFQ/FN8nC9 F/yfH93spw0wvxuIUXQPmu3EK4EP6I6+Bpx4jSLuA7bo0D42j2Fds5E6Tr7J7uEZ HEOKK5wTyWi37sJ7G065lEd1eToXAbH4zkXOLXPLMLD2fNbEXW7eQE7q38Ucdh24 Depp1jZP+RYHNvmuwMMABu9oe7UxA07WE123p99J/niZBLyM2vWYjMTkXPrBmd8u HNp/MEwyNZWG1BcFvuGhc7trXNn6lgKnCJT9Y0/smRHj1zKp3Ws4/Z8D3KP4CuFR gAPEcwN8OfA7McvC07oUXYERnZA3KUy4U/2K3QIDAQABAoIBADmMULmUsjz3+tMq f2gMXotNZRRIWvaFXvxgNW5EWsQDQRZG+QIqjT+Bc9FTDrOYJ6bLe66oyFeKvyQk 7us02QhMREYsoaJ7NdO9NJ4nco/+e+YxRK5J1y4qLD90YriPFHwxJELBbaWtaLZj DLuFzWJIR0PZDz73sNDohuNjgST9MJPiUJnoI2WQdWKJAlCgJUMjWTr5eVbZywxP VPbbHJKa0DykOR6UhDfpS/aPLu1RKIO6bjSGmhOE7afIsKCs05+iOU9QxJQGX9J6 Zj4hcDHnjFk7KyHW8MeOhnREmc3EhdURSvytSL3l8sZ4vjVlQcXJtDUXeMrKT94m mbzt5oECgYEA5948KwjrJkVjfJxjvBkjBOKjW9ZM64gPADi1nclzMw9hkWpF0Qra Yvc/MwnK2mYG4pgMyTAiXxUklgwTkPI99d7/cr0uR/TYdmgvPdcLdRT7eXWPnHhS o2RvQhHw2P6rY4TChGUQWaiuucmliDXp1Io8FqGyum5Y9pRc4LuPyGECgYEAz7Gm UsdQlYGhb9fBnif72PR/1g96ZzCRKWwrQ9RKKbYpIVpp/wMEiiJ20pwAZDusOl5l T9tbMySG41AndpycMJHA8jvKuSKILVqGub6cLvI09XjI2MsdVS91RGdiChkMNfbK NS73/ur8Enr4+8OKgFKDeA9/DF6Cg/TWNDnHY/0CgYAtcRSBqqHLQlYZGd1CA/sk /fXeDcXNc0DdXj/ZyJ1XKHCKuzUrnuDl/GbabdTfsJcw2XPICjLyR4aAEaXUBmW2 RhnyNrlXSNkTe5+mkvqf25jdWPjoRXyMoSZc4H8/R8n3GxG0OMpXiAOWTbqvU0Gc cesM1GvetbmhubnqIVgwgQKBgHHJcUcOvZ57O7frq777RuZQ5aygJD5ehFj+UyHB L7R0gUotn76/p4AKa7DtGOXRL4V26+h5VBjL3T6yTjyUhpmxcNUFXwZY3eSDISao QCcUOWF3AAqOFQ7zhjqorTS9DkyOXbAPgHzfvqRdTQWZ1sqA6lgfnUpoiPbEb4qD UTL9AoGASrXOr3MDDNVmLqAp8lXUAV/sNgTSg5qvndUFBzuJhrILTH44PA1s6DXD +p/BcwFCGKtqeE8192hGnhWdrL7RXhCSMhGe9nhKwOlDE2hviTbRY3QmLnYSYPyn EDACTZwg0RSM66CObAQIgqp8F4oifyJK3do/y+MfyCtC0PJnfpQ= -----END RSA PRIVATE KEY----- paho.mqtt.python-1.5.1/test/ssl/test-root-ca.crt000066400000000000000000000025061373244276700216060ustar00rootroot00000000000000-----BEGIN CERTIFICATE----- MIIDuDCCAqCgAwIBAgIUfktixcRWQfrifKAqkK/KyuylnZkwDQYJKoZIhvcNAQEL BQAwbTELMAkGA1UEBhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcM BURlcmJ5MRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3Rpbmcx EDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjAwNzI4MDkxMjEwWhcNMzAwNzI2MDkxMjEw WjBtMQswCQYDVQQGEwJHQjETMBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwF RGVyYnkxFTATBgNVBAoMDFBhaG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQ MA4GA1UEAwwHUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB ANvaqRfpEO9TFwwB/5syttx8Zaeyq+d0z0uyQuWPIWbp1iUrwTZTb7kwG/9HdNC0 t1KSwdb4Er9B/ycT65lUETlIE3MfzCu6nI/qiIC+yhsCBtdeVALfB2esdCQ+X2Ls jfavpsMDrbjrZ1fyFCYdK0Ka4F3YMyNYj75Bj0/DbUXsgGYL20Qe4uS2yNElQGqo 0mR21lDOhKAI0bVfrdafwfFZB5CIdx2e0kApwAQQOe3xgs3maTR5VQlIdFBApx0y afpJBW2XD/12QWKnOhObTw4QD3OdeXldE8gXrM4qZIrr8/zM/IIsUxSSMb2FIxMU HsMeILzvNuXjgx6fwROW5JECAwEAAaNQME4wHQYDVR0OBBYEFMe9wCJl/6eXp8ud fkTlE3c5fb66MB8GA1UdIwQYMBaAFMe9wCJl/6eXp8udfkTlE3c5fb66MAwGA1Ud EwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAIVn3TZjJNuoySnx8QJAwNPy9A+F oxUgYsjSKoagKc5Rk1czRwNawdeATb0HugT1oVrkbv71vrhBVNWSA9gtV46x9zoD HjxHjkd3owfOmW3VMPPqqBoKK0plmDQMEqB3j8+Pmvtjvl18BntAqWs2OyTLPqZV 0HNQ4bV1ArvwkE++8GYcuYfOU4ORxtPZFUKRc6ailf5Z9H4TEwS+BcOUZ8BaOYX5 5tyvvt7nnaF3v5fcnlX1nEvNJRwdOvo7+cLcOd4ehW8bBLiS2mEUDW/D712sSyId Xuoms4rmP66gCC29h72fj0aL6/PXxrDaZo+7MStB5tCkJK6kP58Elk64654= -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/test-root-ca.key000066400000000000000000000032171373244276700216060ustar00rootroot00000000000000-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA29qpF+kQ71MXDAH/mzK23Hxlp7Kr53TPS7JC5Y8hZunWJSvB NlNvuTAb/0d00LS3UpLB1vgSv0H/JxPrmVQROUgTcx/MK7qcj+qIgL7KGwIG115U At8HZ6x0JD5fYuyN9q+mwwOtuOtnV/IUJh0rQprgXdgzI1iPvkGPT8NtReyAZgvb RB7i5LbI0SVAaqjSZHbWUM6EoAjRtV+t1p/B8VkHkIh3HZ7SQCnABBA57fGCzeZp NHlVCUh0UECnHTJp+kkFbZcP/XZBYqc6E5tPDhAPc515eV0TyBeszipkiuvz/Mz8 gixTFJIxvYUjExQewx4gvO825eODHp/BE5bkkQIDAQABAoIBAC+HXfblU9vpQpo9 9FxA4ndYDUHrxm4LOqVKrFukTbxJ4Rm4E9UCxKxsUiEl+YMFDnyzbWRjzOm8AsUX 8V78ZZzUkB/bR/BML3yNX2U12cts7L2yjsbwIFGxXopXUZe5PBeQcaTHLs9DVNwW YXS76ZZElSy0iJmjk6+1zJ2Zyg3LZFxWTpSLu+bayTI0DDeurJr1/Icf0vjCsnRP zMkQ0RTQ1NXwrQEEYpKXPyKS+g6EpI7udvNdCjcyyBI6UhQrl9Ml/EIc/at1GOjz KO7b8rAurfTu5Ub642LbsvDeLoYCQr3e6DO6IaWn9qg0NcNLVtOBOheHVVN4o8up eu1lVoECgYEA+oDN9jbDw1KfmP0bATomHRvJrs0DopHTr2Rsv46gmwZX0eBTn2OL mz6+s+lw66iZ6d7lW7IfBVLSvpxwPM3wP9GxIMC1IW2V0r/2z413nnXhDxcGduks L7HYO59/T+T+/hYlKq1POuQuSC+peaVvx/h5vzQXEoPaBt7nrmVQbIUCgYEA4K2v mo6K9i6pwr8hQk1eWSzgMKx6L4Y6Ip+LRJAGxkGOaAOoSSs7xNQkCqAmO5jFi5IA zUuj7n9wqec7KSTyceDvgH/nksOTc7rmcbcN1atiWcYGRkBlUfyIxPB9s94kT2Ax d5WCEyIx9tmNEBGLARf52qeboc15q5V8sB4CK50CgYEA64b9n9jf+R8PRfX8VQwK V+YPm9XQ7CJ2SPuAMB93LCsrmP51QXCEC6RUA66iaEBu7nCPb8aq2gOEeIl4EgOD N03+X5Aw/cweSTgKZB1b8dZdlCWPA3C7BeEOMQkG1+S0R8wkh9rJmtJ+HYsKqoB8 +CTMu5TLeLIV5c3hQZyqoE0CgYEAqcEQ6InCXHatNMML8fhazK2nRZ9LQhT8X6SD qO3Y8Hofil8ZCw9rPS+7e3u851JqDyXlDTeVSGFpUjWu8UtFEt2Ml14MLUsvYUVZ T5mrDkFLMeD4ZKPK6cMP4xyBHSE99esL9Po1KRexAH0mo3lduRnQYXA5mmqQ/x8W 8kn6AdECgYBFRElkbB/WcU2Iu8mGDfPliOIS/qY/VOL1cVybAHbnyGbs0dfbPG3S ihAP+4kEKT44zy84E/5eyvwYf0yMHQTn8xAkrev6c+cCB4BbKhwFSv0lRHfXIFt+ REzDSMiV7H4P3pXKdtzPL7LZ6nFgdvk5s7b0u/Cpb+fQuPmSiIG2aQ== -----END RSA PRIVATE KEY----- paho.mqtt.python-1.5.1/test/ssl/test-signing-ca.crt000066400000000000000000000104121373244276700222540ustar00rootroot00000000000000Certificate: Data: Version: 3 (0x2) Serial Number: 1 (0x1) Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA Validity Not Before: Jul 28 09:12:10 2020 GMT Not After : Jul 27 09:12:10 2025 GMT Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:c2:33:17:27:8f:e6:b3:b3:96:d8:fc:cc:11:8d: 5e:da:3d:a5:8e:3a:14:c7:e6:38:80:25:e6:27:c4: cf:6f:3c:b8:18:4a:6e:53:ee:81:dc:c6:e2:4a:29: 18:d9:d3:d8:45:3f:19:2c:01:b5:61:ce:b9:f1:89: 9b:0b:0c:af:f2:38:05:2e:cf:e4:57:c5:9f:4f:fc: 42:a1:2f:cc:2a:59:fa:1a:4a:24:24:55:60:d3:25: d5:a7:0f:d8:5d:f3:9a:dc:d8:13:8c:37:ae:8d:27: bb:d2:2c:37:34:3e:11:16:02:46:03:b2:48:24:de: 5e:d0:65:63:cd:0d:af:58:48:13:dc:93:d0:52:84: fa:05:69:4c:09:69:da:00:c2:af:8a:00:4c:1c:c2: 1c:f5:8b:a9:f4:30:13:33:50:fd:6a:1e:8a:10:8d: cd:01:11:1b:cf:a3:30:80:4b:96:a3:b6:e1:ed:df: 6e:69:5f:26:ed:75:9e:04:3f:49:cd:c9:6f:4a:05: 6f:6d:45:09:09:a8:34:03:97:f2:77:ae:8e:96:7f: a8:52:7b:20:71:35:2d:11:17:52:cd:b1:b1:93:26: 2f:9a:17:c1:48:3e:15:99:85:db:c6:bd:c3:35:0f: fd:d1:d9:2a:63:2b:96:59:35:93:c1:cf:5c:e1:72: 3c:73 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: 63:AD:89:C4:23:13:13:D1:EB:00:4D:01:0E:25:E3:5E:0C:9D:41:C9 X509v3 Authority Key Identifier: keyid:C7:BD:C0:22:65:FF:A7:97:A7:CB:9D:7E:44:E5:13:77:39:7D:BE:BA X509v3 Basic Constraints: CA:TRUE Signature Algorithm: sha256WithRSAEncryption 18:5c:f3:6a:e2:82:d1:ba:ee:de:00:29:4e:b3:f7:87:46:1b: fa:7e:52:9d:87:d8:73:19:5b:38:7a:af:31:aa:4c:bd:fe:45: 95:25:03:48:15:d7:e5:38:4f:e3:39:93:99:10:b4:06:dc:5a: 87:af:22:b5:2f:82:da:ef:6c:b5:f3:9c:82:71:0f:f4:d0:65: 46:b7:23:b1:7d:51:8d:d7:7c:80:12:39:99:46:2b:d4:db:c7: 42:96:1a:b6:0f:b3:10:9e:ad:84:0e:87:38:e8:34:f8:04:3d: a2:fc:3d:24:1e:09:d6:63:52:82:e4:35:ae:39:5e:f9:82:a7: ac:23:87:0e:fb:2d:ae:08:da:2a:3f:51:ee:f6:85:3a:43:80: b0:f1:96:0c:fa:10:80:18:7b:75:14:70:09:48:fc:0c:38:ee: ab:e4:32:7d:80:77:a8:2a:63:15:c9:11:b7:a9:0c:77:7d:be: d6:a3:48:37:1e:56:33:13:71:e1:12:90:ce:95:72:68:ae:d5: 01:82:00:67:1b:ae:9d:93:5b:5d:c1:3d:6e:30:e5:e1:35:ac: 59:3b:eb:ef:ee:83:0b:eb:e5:ea:9c:62:29:8c:73:a3:b5:45: 45:e8:53:ea:b8:48:16:7e:f8:c5:af:4b:89:b5:1b:94:a5:85: d9:d5:f4:13 -----BEGIN CERTIFICATE----- MIIDmDCCAoCgAwIBAgIBATANBgkqhkiG9w0BAQsFADBtMQswCQYDVQQGEwJHQjET MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe Fw0yMDA3MjgwOTEyMTBaFw0yNTA3MjcwOTEyMTBaMGAxCzAJBgNVBAYTAkdCMRMw EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV BAsMB1Rlc3RpbmcxEzARBgNVBAMMClNpZ25pbmcgQ0EwggEiMA0GCSqGSIb3DQEB AQUAA4IBDwAwggEKAoIBAQDCMxcnj+azs5bY/MwRjV7aPaWOOhTH5jiAJeYnxM9v PLgYSm5T7oHcxuJKKRjZ09hFPxksAbVhzrnxiZsLDK/yOAUuz+RXxZ9P/EKhL8wq WfoaSiQkVWDTJdWnD9hd85rc2BOMN66NJ7vSLDc0PhEWAkYDskgk3l7QZWPNDa9Y SBPck9BShPoFaUwJadoAwq+KAEwcwhz1i6n0MBMzUP1qHooQjc0BERvPozCAS5aj tuHt325pXybtdZ4EP0nNyW9KBW9tRQkJqDQDl/J3ro6Wf6hSeyBxNS0RF1LNsbGT Ji+aF8FIPhWZhdvGvcM1D/3R2SpjK5ZZNZPBz1zhcjxzAgMBAAGjUDBOMB0GA1Ud DgQWBBRjrYnEIxMT0esATQEOJeNeDJ1ByTAfBgNVHSMEGDAWgBTHvcAiZf+nl6fL nX5E5RN3OX2+ujAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAYXPNq 4oLRuu7eAClOs/eHRhv6flKdh9hzGVs4eq8xqky9/kWVJQNIFdflOE/jOZOZELQG 3FqHryK1L4La72y185yCcQ/00GVGtyOxfVGN13yAEjmZRivU28dClhq2D7MQnq2E Doc46DT4BD2i/D0kHgnWY1KC5DWuOV75gqesI4cO+y2uCNoqP1Hu9oU6Q4Cw8ZYM +hCAGHt1FHAJSPwMOO6r5DJ9gHeoKmMVyRG3qQx3fb7Wo0g3HlYzE3HhEpDOlXJo rtUBggBnG66dk1tdwT1uMOXhNaxZO+vv7oML6+XqnGIpjHOjtUVF6FPquEgWfvjF r0uJtRuUpYXZ1fQT -----END CERTIFICATE----- paho.mqtt.python-1.5.1/test/ssl/test-signing-ca.csr000066400000000000000000000017711373244276700222630ustar00rootroot00000000000000-----BEGIN CERTIFICATE REQUEST----- MIICtTCCAZ0CAQAwcDELMAkGA1UEBhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUx DjAMBgNVBAcMBURlcmJ5MRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsM B1Rlc3RpbmcxEzARBgNVBAMMClNpZ25pbmcgQ0EwggEiMA0GCSqGSIb3DQEBAQUA A4IBDwAwggEKAoIBAQDCMxcnj+azs5bY/MwRjV7aPaWOOhTH5jiAJeYnxM9vPLgY Sm5T7oHcxuJKKRjZ09hFPxksAbVhzrnxiZsLDK/yOAUuz+RXxZ9P/EKhL8wqWfoa SiQkVWDTJdWnD9hd85rc2BOMN66NJ7vSLDc0PhEWAkYDskgk3l7QZWPNDa9YSBPc k9BShPoFaUwJadoAwq+KAEwcwhz1i6n0MBMzUP1qHooQjc0BERvPozCAS5ajtuHt 325pXybtdZ4EP0nNyW9KBW9tRQkJqDQDl/J3ro6Wf6hSeyBxNS0RF1LNsbGTJi+a F8FIPhWZhdvGvcM1D/3R2SpjK5ZZNZPBz1zhcjxzAgMBAAGgADANBgkqhkiG9w0B AQsFAAOCAQEAMU8s9pBSLFS5x/G4KO6bM8Ym9RBJJZatlJu/hg/Z2qYxcCjueGWr ureTKdsX+6Mir3upL7BMeBmazLW1Efnr3ZFpE3ZBIw1nW580V0uxjwninmSclax1 WwPP68thxEExDDCy5jtjSX685s3cutLNhCHSxPkPVwfVAxJxjJ1XYrenrfWhgtUc T8GNWBamnUn8eJKiRvPy+kg93XX4ZgAkrtj/3Pyzfg19n8XZvAXkYx/KjMnpnPI4 xXJMdvXJtzdKYnGuRRxJ2oq69xRoiYTaQRjF4DeU+3krfAWoV24xQI2nHEeXOs5g RUff1KcIXCu/nKD4rjCZ5iJofn6W4XZBTQ== -----END CERTIFICATE REQUEST----- paho.mqtt.python-1.5.1/test/ssl/test-signing-ca.key000066400000000000000000000032171373244276700222610ustar00rootroot00000000000000-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEAwjMXJ4/ms7OW2PzMEY1e2j2ljjoUx+Y4gCXmJ8TPbzy4GEpu U+6B3MbiSikY2dPYRT8ZLAG1Yc658YmbCwyv8jgFLs/kV8WfT/xCoS/MKln6Gkok JFVg0yXVpw/YXfOa3NgTjDeujSe70iw3ND4RFgJGA7JIJN5e0GVjzQ2vWEgT3JPQ UoT6BWlMCWnaAMKvigBMHMIc9Yup9DATM1D9ah6KEI3NAREbz6MwgEuWo7bh7d9u aV8m7XWeBD9JzclvSgVvbUUJCag0A5fyd66Oln+oUnsgcTUtERdSzbGxkyYvmhfB SD4VmYXbxr3DNQ/90dkqYyuWWTWTwc9c4XI8cwIDAQABAoIBABBJKI/wyXAYh3X6 /UIbkPDMaq3awRNigyp8AykioCK7/NRMqaPwRIO3ShLeD291DJYCDKJcIlHpfD59 Q7tRfQ/bEtQyKvwRXqLejNfnoj+K/CZoQU+quUv7yEcSVRrL6xjKJhmEMec0hdPC UX7YFaa62hRFRzeQTnM7jXsMwr+sZkW0uKm08Me5X7qMsU0V00N1B0yUcHmTGz07 aRFwIeLnboQd6tiNzCf+CNuETSRWL9jdbU8YtgNm6EnyWWZv46bu2rISHpuYKDsY HxpH3jGLWoWGtyKYB/SY99MDJ/UGVAboRsawAbp2xb0eKw9pH4wiTCllJBbAMORO AHVw1UECgYEA7Uw8Dg4ArvBkyst+PSPRnhnT68/9VupkXmUVaEcaj1L3HoJZ6E+Z 0IXkVcYKXtawi2olNqZcAusM98RkDjDAzDGytSSRrtsnXPRnXRccvvE0AuvYuNZk ownddv4FpGic05zexyqvQIV826CFcArEKRA/SdRV7Q3Hqpo1RPyUINcCgYEA0YFM SH1E1F30Imjwpnf/lanrCWatzrTod+MCho0ihor7YhMG2lSmZjiAlbfHVfRedR1h PkIsQ91J6+RwIX4LhVbPHJ3PRKziSswZYLlN+DJzs4UiAFLvWV7Ai+HK13+Tvn5T ir73JpH2XAJD3kVNvic+kWMs+Zo6gPrv8zco4cUCgYEAxIfs/R7vxfNnJuYeaXiu 9Sgi8hzSjxeVhPBnKHQrNSTbcjM3T0YN+DvL/pYEpMNeeDizFW32qpwNo27OB0qt gvBuN8RPu+fZ1Ay/RsQLlMCj+P9oAL3fn4BeIV0FQ0M5D7HOeFmLx/5GiIeLvF3O VMwV/omTmL9e7JbHI5mk/QUCgYBBmBDxNT9imlQAngiSpkmAa2XqWJqceGm8d3fn 9rJTm5ofV8OyggRjRteDiLnBgLQ+SMeUfZVsXhFx6ODuq48h3U8VL5egcdyb/JEJ hpsR1YICN/GwVkcYHSF96mDe3dO9NcIkU6wACH0wy4jCQ8KWgaUGUh3XvGEK1wZf iOqk3QKBgQDXEKurTR8TrtGc3ZHGaD+LO1VHU/WEQov753k9X101BMyU60NlpTSo QNZlw1i9ZR4wWZRx0ku5r/bdkHAFw2XbjgKU13/z9eprHEG7Xr6/7SULeensEpE8 DnY3r51CAIBsYOqQKVUc//ecqdg/LRpEQkJWz0DPl+u1Cf+kAkLmfg== -----END RSA PRIVATE KEY----- paho.mqtt.python-1.5.1/tests/000077500000000000000000000000001373244276700161325ustar00rootroot00000000000000paho.mqtt.python-1.5.1/tests/test_client.py000066400000000000000000000264201373244276700210250ustar00rootroot00000000000000import os import sys import time import inspect import unicodedata import pytest import paho.mqtt.client as client # From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder cmd_subfolder = os.path.realpath( os.path.abspath( os.path.join( os.path.split( inspect.getfile(inspect.currentframe()))[0], '..', 'test'))) if cmd_subfolder not in sys.path: sys.path.insert(0, cmd_subfolder) import paho_test # Import test fixture from testsupport.broker import fake_broker @pytest.mark.parametrize("proto_ver", [ (client.MQTTv31), (client.MQTTv311), ]) class Test_connect(object): """ Tests on connect/disconnect behaviour of the client """ def test_01_con_discon_success(self, proto_ver, fake_broker): mqttc = client.Client( "01-con-discon-success", protocol=proto_ver) def on_connect(mqttc, obj, flags, rc): assert rc == 0 mqttc.disconnect() mqttc.on_connect = on_connect mqttc.connect_async("localhost", 1888) mqttc.loop_start() try: fake_broker.start() connect_packet = paho_test.gen_connect( "01-con-discon-success", keepalive=60, proto_ver=proto_ver) packet_in = fake_broker.receive_packet(1000) assert packet_in # Check connection was not closed assert packet_in == connect_packet connack_packet = paho_test.gen_connack(rc=0) count = fake_broker.send_packet(connack_packet) assert count # Check connection was not closed assert count == len(connack_packet) disconnect_packet = paho_test.gen_disconnect() packet_in = fake_broker.receive_packet(1000) assert packet_in # Check connection was not closed assert packet_in == disconnect_packet finally: mqttc.loop_stop() packet_in = fake_broker.receive_packet(1) assert not packet_in # Check connection is closed def test_01_con_failure_rc(self, proto_ver, fake_broker): mqttc = client.Client( "01-con-failure-rc", protocol=proto_ver) def on_connect(mqttc, obj, flags, rc): assert rc == 1 mqttc.on_connect = on_connect mqttc.connect_async("localhost", 1888) mqttc.loop_start() try: fake_broker.start() connect_packet = paho_test.gen_connect( "01-con-failure-rc", keepalive=60, proto_ver=proto_ver) packet_in = fake_broker.receive_packet(1000) assert packet_in # Check connection was not closed assert packet_in == connect_packet connack_packet = paho_test.gen_connack(rc=1) count = fake_broker.send_packet(connack_packet) assert count # Check connection was not closed assert count == len(connack_packet) packet_in = fake_broker.receive_packet(1) assert not packet_in # Check connection is closed finally: mqttc.loop_stop() class TestPublishBroker2Client(object): def test_invalid_utf8_topic(self, fake_broker): mqttc = client.Client("client-id") def on_message(client, userdata, msg): with pytest.raises(UnicodeDecodeError): msg.topic client.disconnect() mqttc.on_message = on_message mqttc.connect_async("localhost", 1888) mqttc.loop_start() try: fake_broker.start() connect_packet = paho_test.gen_connect("client-id") packet_in = fake_broker.receive_packet(len(connect_packet)) assert packet_in # Check connection was not closed assert packet_in == connect_packet connack_packet = paho_test.gen_connack(rc=0) count = fake_broker.send_packet(connack_packet) assert count # Check connection was not closed assert count == len(connack_packet) publish_packet = paho_test.gen_publish(b"\xff", qos=0) count = fake_broker.send_packet(publish_packet) assert count # Check connection was not closed assert count == len(publish_packet) disconnect_packet = paho_test.gen_disconnect() packet_in = fake_broker.receive_packet(len(disconnect_packet)) assert packet_in # Check connection was not closed assert packet_in == disconnect_packet finally: mqttc.loop_stop() packet_in = fake_broker.receive_packet(1) assert not packet_in # Check connection is closed def test_valid_utf8_topic_recv(self, fake_broker): mqttc = client.Client("client-id") # It should be non-ascii multi-bytes character topic = unicodedata.lookup('SNOWMAN') def on_message(client, userdata, msg): assert msg.topic == topic client.disconnect() mqttc.on_message = on_message mqttc.connect_async("localhost", 1888) mqttc.loop_start() try: fake_broker.start() connect_packet = paho_test.gen_connect("client-id") packet_in = fake_broker.receive_packet(len(connect_packet)) assert packet_in # Check connection was not closed assert packet_in == connect_packet connack_packet = paho_test.gen_connack(rc=0) count = fake_broker.send_packet(connack_packet) assert count # Check connection was not closed assert count == len(connack_packet) publish_packet = paho_test.gen_publish( topic.encode('utf-8'), qos=0 ) count = fake_broker.send_packet(publish_packet) assert count # Check connection was not closed assert count == len(publish_packet) disconnect_packet = paho_test.gen_disconnect() packet_in = fake_broker.receive_packet(len(disconnect_packet)) assert packet_in # Check connection was not closed assert packet_in == disconnect_packet finally: mqttc.loop_stop() packet_in = fake_broker.receive_packet(1) assert not packet_in # Check connection is closed def test_valid_utf8_topic_publish(self, fake_broker): mqttc = client.Client("client-id") # It should be non-ascii multi-bytes character topic = unicodedata.lookup('SNOWMAN') mqttc.connect_async("localhost", 1888) mqttc.loop_start() try: fake_broker.start() connect_packet = paho_test.gen_connect("client-id") packet_in = fake_broker.receive_packet(len(connect_packet)) assert packet_in # Check connection was not closed assert packet_in == connect_packet connack_packet = paho_test.gen_connack(rc=0) count = fake_broker.send_packet(connack_packet) assert count # Check connection was not closed assert count == len(connack_packet) mqttc.publish(topic, None, 0) # Small sleep needed to avoid connection reset. time.sleep(0.3) publish_packet = paho_test.gen_publish( topic.encode('utf-8'), qos=0 ) packet_in = fake_broker.receive_packet(len(publish_packet)) assert packet_in # Check connection was not closed assert packet_in == publish_packet mqttc.disconnect() disconnect_packet = paho_test.gen_disconnect() packet_in = fake_broker.receive_packet(len(disconnect_packet)) assert packet_in # Check connection was not closed assert packet_in == disconnect_packet finally: mqttc.loop_stop() packet_in = fake_broker.receive_packet(1) assert not packet_in # Check connection is closed def test_message_callback(self, fake_broker): mqttc = client.Client("client-id") userdata = { 'on_message': 0, 'callback1': 0, 'callback2': 0, } mqttc.user_data_set(userdata) def on_message(client, userdata, msg): assert msg.topic == 'topic/value' userdata['on_message'] += 1 def callback1(client, userdata, msg): assert msg.topic == 'topic/callback/1' userdata['callback1'] += 1 def callback2(client, userdata, msg): assert msg.topic in ('topic/callback/3', 'topic/callback/1') userdata['callback2'] += 1 mqttc.on_message = on_message mqttc.message_callback_add('topic/callback/1', callback1) mqttc.message_callback_add('topic/callback/+', callback2) mqttc.connect_async("localhost", 1888) mqttc.loop_start() try: fake_broker.start() connect_packet = paho_test.gen_connect("client-id") packet_in = fake_broker.receive_packet(len(connect_packet)) assert packet_in # Check connection was not closed assert packet_in == connect_packet connack_packet = paho_test.gen_connack(rc=0) count = fake_broker.send_packet(connack_packet) assert count # Check connection was not closed assert count == len(connack_packet) publish_packet = paho_test.gen_publish(b"topic/value", qos=1, mid=1) count = fake_broker.send_packet(publish_packet) assert count # Check connection was not closed assert count == len(publish_packet) publish_packet = paho_test.gen_publish(b"topic/callback/1", qos=1, mid=2) count = fake_broker.send_packet(publish_packet) assert count # Check connection was not closed assert count == len(publish_packet) publish_packet = paho_test.gen_publish(b"topic/callback/3", qos=1, mid=3) count = fake_broker.send_packet(publish_packet) assert count # Check connection was not closed assert count == len(publish_packet) puback_packet = paho_test.gen_puback(mid=1) packet_in = fake_broker.receive_packet(len(puback_packet)) assert packet_in # Check connection was not closed assert packet_in == puback_packet puback_packet = paho_test.gen_puback(mid=2) packet_in = fake_broker.receive_packet(len(puback_packet)) assert packet_in # Check connection was not closed assert packet_in == puback_packet puback_packet = paho_test.gen_puback(mid=3) packet_in = fake_broker.receive_packet(len(puback_packet)) assert packet_in # Check connection was not closed assert packet_in == puback_packet mqttc.disconnect() disconnect_packet = paho_test.gen_disconnect() packet_in = fake_broker.receive_packet(len(disconnect_packet)) assert packet_in # Check connection was not closed assert packet_in == disconnect_packet finally: mqttc.loop_stop() packet_in = fake_broker.receive_packet(1) assert not packet_in # Check connection is closed assert userdata['on_message'] == 1 assert userdata['callback1'] == 1 assert userdata['callback2'] == 2 paho.mqtt.python-1.5.1/tests/test_matcher.py000066400000000000000000000017561373244276700211770ustar00rootroot00000000000000import pytest import paho.mqtt.client as client class Test_client_function(object): """ Tests on topic_matches_sub function in the client module """ @pytest.mark.parametrize("sub,topic", [ ("foo/bar", "foo/bar"), ("foo/+", "foo/bar"), ("foo/+/baz", "foo/bar/baz"), ("foo/+/#", "foo/bar/baz"), ("A/B/+/#", "A/B/B/C"), ("#", "foo/bar/baz"), ("#", "/foo/bar"), ("/#", "/foo/bar"), ("$SYS/bar", "$SYS/bar"), ]) def test_matching(self, sub, topic): assert client.topic_matches_sub(sub, topic) @pytest.mark.parametrize("sub,topic", [ ("test/6/#", "test/3"), ("foo/bar", "foo"), ("foo/+", "foo/bar/baz"), ("foo/+/baz", "foo/bar/bar"), ("foo/+/#", "fo2/bar/baz"), ("/#", "foo/bar"), ("#", "$SYS/bar"), ("$BOB/bar", "$SYS/bar"), ]) def test_not_matching(self, sub, topic): assert not client.topic_matches_sub(sub, topic) paho.mqtt.python-1.5.1/tests/test_mqttv5.py000066400000000000000000001570031373244276700210110ustar00rootroot00000000000000""" ******************************************************************* Copyright (c) 2013, 2019 IBM Corp. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v1.0 which accompany this distribution. The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. Contributors: Ian Craggs - initial implementation and/or documentation ******************************************************************* """ import unittest import time import threading import getopt import sys import logging import traceback import paho.mqtt from paho.mqtt.properties import Properties from paho.mqtt.reasoncodes import ReasonCodes from paho.mqtt.subscribeoptions import SubscribeOptions from paho.mqtt.packettypes import PacketTypes import paho.mqtt.client class Callbacks: def __init__(self): self.messages = [] self.publisheds = [] self.subscribeds = [] self.unsubscribeds = [] self.disconnecteds = [] self.connecteds = [] def __str__(self): return str(self.messages) + str(self.messagedicts) + str(self.publisheds) + \ str(self.subscribeds) + \ str(self.unsubscribeds) + str(self.disconnects) def clear(self): self.__init__() def on_connect(self, client, userdata, flags, reasonCode, properties): self.connecteds.append({"userdata": userdata, "flags": flags, "reasonCode": reasonCode, "properties": properties}) def wait(self, alist, timeout=2): interval = 0.2 total = 0 while len(alist) == 0 and total < timeout: time.sleep(interval) total += interval return alist.pop(0) # if len(alist) > 0 else None def wait_connected(self): return self.wait(self.connecteds) def on_disconnect(self, client, userdata, reasonCode, properties=None): self.disconnecteds.append( {"reasonCode": reasonCode, "properties": properties}) def wait_disconnected(self): return self.wait(self.disconnecteds) def on_message(self, client, userdata, message): self.messages.append({"userdata": userdata, "message": message}) def published(self, client, userdata, msgid): self.publisheds.append(msgid) def wait_published(self): return self.wait(self.publisheds) def on_subscribe(self, client, userdata, mid, reasonCodes, properties): self.subscribeds.append({"mid": mid, "userdata": userdata, "properties": properties, "reasonCodes": reasonCodes}) def wait_subscribed(self): return self.wait(self.subscribeds) def unsubscribed(self, client, userdata, mid, properties, reasonCodes): self.unsubscribeds.append({"mid": mid, "userdata": userdata, "properties": properties, "reasonCodes": reasonCodes}) def wait_unsubscribed(self): return self.wait(self.unsubscribeds) def on_log(self, client, userdata, level, buf): print(buf) def register(self, client): client.on_connect = self.on_connect client.on_subscribe = self.on_subscribe client.on_publish = self.published client.on_unsubscribe = self.unsubscribed client.on_message = self.on_message client.on_disconnect = self.on_disconnect client.on_log = self.on_log def cleanRetained(port): callback = Callbacks() curclient = paho.mqtt.client.Client("clean retained".encode("utf-8"), protocol=paho.mqtt.client.MQTTv5) curclient.loop_start() callback.register(curclient) curclient.connect(host="localhost", port=port) response = callback.wait_connected() curclient.subscribe("#", options=SubscribeOptions(qos=0)) response = callback.wait_subscribed() # wait for retained messages to arrive time.sleep(1) for message in callback.messages: logging.info("deleting retained message for topic", message["message"]) curclient.publish(message["message"].topic, b"", 0, retain=True) curclient.disconnect() curclient.loop_stop() time.sleep(.1) def cleanup(port): # clean all client state print("clean up starting") clientids = ("aclient", "bclient") for clientid in clientids: curclient = paho.mqtt.client.Client(clientid.encode( "utf-8"), protocol=paho.mqtt.client.MQTTv5) curclient.loop_start() curclient.connect(host="localhost", port=port, clean_start=True) time.sleep(.1) curclient.disconnect() time.sleep(.1) curclient.loop_stop() # clean retained messages cleanRetained(port) print("clean up finished") class Test(unittest.TestCase): @classmethod def setUpClass(cls): global callback, callback2, aclient, bclient sys.path.append("paho.mqtt.testing/interoperability/") try: import mqtt.brokers except ImportError: raise unittest.SkipTest("paho.mqtt.testing not present.") cls._test_broker = threading.Thread( target=mqtt.brokers.run, kwargs={ "config": ["listener 0"], }, ) cls._test_broker.daemon = True cls._test_broker.start() # Wait a bit for TCP server to bind to an address time.sleep(0.5) # Hack to find the port used by the test broker... cls._test_broker_port = mqtt.brokers.listeners.TCPListeners.server.socket.getsockname()[1] setData() cleanup(cls._test_broker_port) callback = Callbacks() callback2 = Callbacks() #aclient = mqtt_client.Client(b"\xEF\xBB\xBF" + "myclientid".encode("utf-8")) #aclient = mqtt_client.Client("myclientid".encode("utf-8")) aclient = paho.mqtt.client.Client("aclient".encode( "utf-8"), protocol=paho.mqtt.client.MQTTv5) callback.register(aclient) bclient = paho.mqtt.client.Client("bclient".encode( "utf-8"), protocol=paho.mqtt.client.MQTTv5) callback2.register(bclient) @classmethod def tearDownClass(cls): # Another hack to stop the test broker... we rely on fact that it use a sockserver.TCPServer import mqtt.brokers mqtt.brokers.listeners.TCPListeners.server.shutdown() cls._test_broker.join(5) def waitfor(self, queue, depth, limit): total = 0 while len(queue) < depth and total < limit: interval = .5 total += interval time.sleep(interval) def test_basic(self): aclient.connect(host="localhost", port=self._test_broker_port) aclient.loop_start() response = callback.wait_connected() self.assertEqual(response["reasonCode"].getName(), "Success") aclient.subscribe(topics[0], options=SubscribeOptions(qos=2)) response = callback.wait_subscribed() self.assertEqual(response["reasonCodes"][0].getName(), "Granted QoS 2") aclient.publish(topics[0], b"qos 0") aclient.publish(topics[0], b"qos 1", 1) aclient.publish(topics[0], b"qos 2", 2) i = 0 while len(callback.messages) < 3 and i < 10: time.sleep(.2) i += 1 self.assertEqual(len(callback.messages), 3) aclient.disconnect() callback.clear() aclient.loop_stop() def test_retained_message(self): qos0topic = "fromb/qos 0" qos1topic = "fromb/qos 1" qos2topic = "fromb/qos2" wildcardtopic = "fromb/+" publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.UserProperty = ("a", "2") publish_properties.UserProperty = ("c", "3") # retained messages callback.clear() aclient.connect(host="localhost", port=self._test_broker_port) aclient.loop_start() response = callback.wait_connected() aclient.publish(topics[1], b"qos 0", 0, retain=True, properties=publish_properties) aclient.publish(topics[2], b"qos 1", 1, retain=True, properties=publish_properties) aclient.publish(topics[3], b"qos 2", 2, retain=True, properties=publish_properties) # wait until those messages are published time.sleep(1) aclient.subscribe(wildtopics[5], options=SubscribeOptions(qos=2)) response = callback.wait_subscribed() self.assertEqual(response["reasonCodes"][0].getName(), "Granted QoS 2") time.sleep(1) aclient.disconnect() aclient.loop_stop() self.assertEqual(len(callback.messages), 3) userprops = callback.messages[0]["message"].properties.UserProperty self.assertTrue(userprops in [[("a", "2"), ("c", "3")], [ ("c", "3"), ("a", "2")]], userprops) userprops = callback.messages[1]["message"].properties.UserProperty self.assertTrue(userprops in [[("a", "2"), ("c", "3")], [ ("c", "3"), ("a", "2")]], userprops) userprops = callback.messages[2]["message"].properties.UserProperty self.assertTrue(userprops in [[("a", "2"), ("c", "3")], [ ("c", "3"), ("a", "2")]], userprops) qoss = [callback.messages[i]["message"].qos for i in range(3)] self.assertTrue(1 in qoss and 2 in qoss and 0 in qoss, qoss) cleanRetained(self._test_broker_port) def test_will_message(self): # will messages and keep alive callback.clear() callback2.clear() self.assertEqual(len(callback2.messages), 0, callback2.messages) will_properties = Properties(PacketTypes.WILLMESSAGE) will_properties.WillDelayInterval = 0 # this is the default anyway will_properties.UserProperty = ("a", "2") will_properties.UserProperty = ("c", "3") aclient.will_set(topics[2], payload=b"will message", properties=will_properties) aclient.connect(host="localhost", port=self._test_broker_port, keepalive=2) aclient.loop_start() response = callback.wait_connected() bclient.connect(host="localhost", port=self._test_broker_port) bclient.loop_start() response = callback2.wait_connected() bclient.subscribe(topics[2], qos=2) response = callback2.wait_subscribed() self.assertEqual(response["reasonCodes"][0].getName(), "Granted QoS 2") # keep alive timeout ought to be triggered so the will message is received aclient.loop_stop() # so that pings aren't sent self.waitfor(callback2.messages, 1, 10) bclient.disconnect() bclient.loop_stop() # should have the will message self.assertEqual(len(callback2.messages), 1, callback2.messages) props = callback2.messages[0]["message"].properties self.assertEqual(props.UserProperty, [("a", "2"), ("c", "3")]) def test_zero_length_clientid(self): logging.info("Zero length clientid test starting") callback0 = Callbacks() client0 = paho.mqtt.client.Client(protocol=paho.mqtt.client.MQTTv5) callback0.register(client0) client0.loop_start() # should not be rejected client0.connect(host="localhost", port=self._test_broker_port, clean_start=False) response = callback0.wait_connected() self.assertEqual(response["reasonCode"].getName(), "Success") self.assertTrue( len(response["properties"].AssignedClientIdentifier) > 0) client0.disconnect() client0.loop_stop() client0 = paho.mqtt.client.Client(protocol=paho.mqtt.client.MQTTv5) callback0.register(client0) client0.loop_start() client0.connect(host="localhost", port=self._test_broker_port) # should work response = callback0.wait_connected() self.assertEqual(response["reasonCode"].getName(), "Success") self.assertTrue( len(response["properties"].AssignedClientIdentifier) > 0) client0.disconnect() client0.loop_stop() # when we supply a client id, we should not get one assigned client0 = paho.mqtt.client.Client( "client0", protocol=paho.mqtt.client.MQTTv5) callback0.register(client0) client0.loop_start() client0.connect(host="localhost", port=self._test_broker_port) # should work response = callback0.wait_connected() self.assertEqual(response["reasonCode"].getName(), "Success") self.assertFalse( hasattr(response["properties"], "AssignedClientIdentifier")) client0.disconnect() client0.loop_stop() def test_offline_message_queueing(self): # message queueing for offline clients cleanRetained(self._test_broker_port) ocallback = Callbacks() clientid = "offline message queueing".encode("utf-8") oclient = paho.mqtt.client.Client( clientid, protocol=paho.mqtt.client.MQTTv5) ocallback.register(oclient) connect_properties = Properties(PacketTypes.CONNECT) connect_properties.SessionExpiryInterval = 99999 oclient.loop_start() oclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) response = ocallback.wait_connected() oclient.subscribe(wildtopics[5], qos=2) response = ocallback.wait_subscribed() oclient.disconnect() oclient.loop_stop() bclient.loop_start() bclient.connect(host="localhost", port=self._test_broker_port) response = callback2.wait_connected() bclient.publish(topics[1], b"qos 0", 0) bclient.publish(topics[2], b"qos 1", 1) bclient.publish(topics[3], b"qos 2", 2) time.sleep(2) bclient.disconnect() bclient.loop_stop() oclient = paho.mqtt.client.Client( clientid, protocol=paho.mqtt.client.MQTTv5) ocallback.register(oclient) oclient.loop_start() oclient.connect(host="localhost", port=self._test_broker_port, clean_start=False) response = ocallback.wait_connected() time.sleep(2) oclient.disconnect() oclient.loop_stop() self.assertTrue(len(ocallback.messages) in [ 2, 3], len(ocallback.messages)) logging.info("This server %s queueing QoS 0 messages for offline clients" % ("is" if len(ocallback.messages) == 3 else "is not")) def test_overlapping_subscriptions(self): # overlapping subscriptions. When there is more than one matching subscription for the same client for a topic, # the server may send back one message with the highest QoS of any matching subscription, or one message for # each subscription with a matching QoS. ocallback = Callbacks() clientid = "overlapping subscriptions".encode("utf-8") oclient = paho.mqtt.client.Client( clientid, protocol=paho.mqtt.client.MQTTv5) ocallback.register(oclient) oclient.loop_start() oclient.connect(host="localhost", port=self._test_broker_port) ocallback.wait_connected() oclient.subscribe([(wildtopics[6], SubscribeOptions(qos=2)), (wildtopics[0], SubscribeOptions(qos=1))]) ocallback.wait_subscribed() oclient.publish(topics[3], b"overlapping topic filters", 2) ocallback.wait_published() time.sleep(1) self.assertTrue(len(ocallback.messages) in [1, 2], ocallback.messages) if len(ocallback.messages) == 1: logging.info( "This server is publishing one message for all matching overlapping subscriptions, not one for each.") self.assertEqual( ocallback.messages[0]["message"].qos, 2, ocallback.messages[0]["message"].qos) else: logging.info( "This server is publishing one message per each matching overlapping subscription.") self.assertTrue((ocallback.messages[0]["message"].qos == 2 and ocallback.messages[1]["message"].qos == 1) or (ocallback.messages[0]["message"].qos == 1 and ocallback.messages[1]["message"].qos == 2), callback.messages) oclient.disconnect() oclient.loop_stop() ocallback.clear() def test_subscribe_failure(self): # Subscribe failure. A new feature of MQTT 3.1.1 is the ability to send back negative reponses to subscribe # requests. One way of doing this is to subscribe to a topic which is not allowed to be subscribed to. logging.info("Subscribe failure test starting") ocallback = Callbacks() clientid = "subscribe failure".encode("utf-8") oclient = paho.mqtt.client.Client( clientid, protocol=paho.mqtt.client.MQTTv5) ocallback.register(oclient) oclient.loop_start() oclient.connect(host="localhost", port=self._test_broker_port) ocallback.wait_connected() oclient.subscribe(nosubscribe_topics[0], qos=2) response = ocallback.wait_subscribed() self.assertEqual(response["reasonCodes"][0].getName(), "Unspecified error", "return code should be 0x80 %s" % response["reasonCodes"][0].getName()) oclient.disconnect() oclient.loop_stop() def test_unsubscribe(self): callback2.clear() bclient.connect(host="localhost", port=self._test_broker_port) bclient.loop_start() callback2.wait_connected() bclient.subscribe(topics[0], qos=2) callback2.wait_subscribed() bclient.subscribe(topics[1], qos=2) callback2.wait_subscribed() bclient.subscribe(topics[2], qos=2) callback2.wait_subscribed() time.sleep(1) # wait for any retained messages, hopefully # Unsubscribe from one topic bclient.unsubscribe(topics[0]) callback2.wait_unsubscribed() callback2.clear() # if there were any retained messsages aclient.connect(host="localhost", port=self._test_broker_port) aclient.loop_start() callback.wait_connected() aclient.publish(topics[0], b"topic 0 - unsubscribed", 1, retain=False) aclient.publish(topics[1], b"topic 1", 1, retain=False) aclient.publish(topics[2], b"topic 2", 1, retain=False) time.sleep(2) bclient.disconnect() bclient.loop_stop() aclient.disconnect() aclient.loop_stop() self.assertEqual(len(callback2.messages), 2, callback2.messages) def new_client(self, clientid): callback = Callbacks() client = paho.mqtt.client.Client(clientid.encode( "utf-8"), protocol=paho.mqtt.client.MQTTv5) callback.register(client) client.loop_start() return client, callback def test_session_expiry(self): # no session expiry property == never expire connect_properties = Properties(PacketTypes.CONNECT) connect_properties.SessionExpiryInterval = 0 # expire immediately clientid = "session expiry" eclient, ecallback = self.new_client(clientid) eclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = ecallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) eclient.subscribe(topics[0], qos=2) ecallback.wait_subscribed() eclient.disconnect() ecallback.wait_disconnected() eclient.loop_stop() fclient, fcallback = self.new_client(clientid) # session should immediately expire fclient.connect_async(host="localhost", port=self._test_broker_port, clean_start=False, properties=connect_properties) connack = fcallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) fclient.disconnect() fcallback.wait_disconnected() connect_properties.SessionExpiryInterval = 5 eclient, ecallback = self.new_client(clientid) eclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = ecallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) eclient.subscribe(topics[0], qos=2) ecallback.wait_subscribed() eclient.disconnect() ecallback.wait_disconnected() eclient.loop_stop() time.sleep(2) # session should still exist fclient, fcallback = self.new_client(clientid) fclient.connect(host="localhost", port=self._test_broker_port, clean_start=False, properties=connect_properties) connack = fcallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], True) fclient.disconnect() fcallback.wait_disconnected() fclient.loop_stop() time.sleep(6) # session should not exist fclient, fcallback = self.new_client(clientid) fclient.connect(host="localhost", port=self._test_broker_port, clean_start=False, properties=connect_properties) connack = fcallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) fclient.disconnect() fcallback.wait_disconnected() fclient.loop_stop() eclient, ecallback = self.new_client(clientid) connect_properties.SessionExpiryInterval = 1 connack = eclient.connect( host="localhost", port=self._test_broker_port, properties=connect_properties) connack = ecallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) eclient.subscribe(topics[0], qos=2) ecallback.wait_subscribed() disconnect_properties = Properties(PacketTypes.DISCONNECT) disconnect_properties.SessionExpiryInterval = 5 eclient.disconnect(properties=disconnect_properties) ecallback.wait_disconnected() eclient.loop_stop() time.sleep(3) # session should still exist as we changed the expiry interval on disconnect fclient, fcallback = self.new_client(clientid) fclient.connect(host="localhost", port=self._test_broker_port, clean_start=False, properties=connect_properties) connack = fcallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], True) disconnect_properties.SessionExpiryInterval = 0 fclient.disconnect(properties=disconnect_properties) fcallback.wait_disconnected() fclient.loop_stop() # session should immediately expire fclient, fcallback = self.new_client(clientid) fclient.connect(host="localhost", port=self._test_broker_port, clean_start=False, properties=connect_properties) connack = fcallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) fclient.disconnect() fcallback.wait_disconnected() fclient.loop_stop() fclient.loop_stop() eclient.loop_stop() def test_user_properties(self): clientid = "user properties" uclient, ucallback = self.new_client(clientid) uclient.loop_start() uclient.connect(host="localhost", port=self._test_broker_port) ucallback.wait_connected() uclient.subscribe(topics[0], qos=2) ucallback.wait_subscribed() publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.UserProperty = ("a", "2") publish_properties.UserProperty = ("c", "3") uclient.publish(topics[0], b"", 0, retain=False, properties=publish_properties) uclient.publish(topics[0], b"", 1, retain=False, properties=publish_properties) uclient.publish(topics[0], b"", 2, retain=False, properties=publish_properties) count = 0 while len(ucallback.messages) < 3 and count < 50: time.sleep(.1) count += 1 uclient.disconnect() ucallback.wait_disconnected() uclient.loop_stop() self.assertEqual(len(ucallback.messages), 3, ucallback.messages) userprops = ucallback.messages[0]["message"].properties.UserProperty self.assertTrue(userprops in [[("a", "2"), ("c", "3")], [ ("c", "3"), ("a", "2")]], userprops) userprops = ucallback.messages[1]["message"].properties.UserProperty self.assertTrue(userprops in [[("a", "2"), ("c", "3")], [ ("c", "3"), ("a", "2")]], userprops) userprops = ucallback.messages[2]["message"].properties.UserProperty self.assertTrue(userprops in [[("a", "2"), ("c", "3")], [ ("c", "3"), ("a", "2")]], userprops) qoss = [ucallback.messages[i]["message"].qos for i in range(3)] self.assertTrue(1 in qoss and 2 in qoss and 0 in qoss, qoss) def test_payload_format(self): clientid = "payload format" pclient, pcallback = self.new_client(clientid) pclient.loop_start() pclient.connect_async(host="localhost", port=self._test_broker_port) response = pcallback.wait_connected() pclient.subscribe(topics[0], qos=2) response = pcallback.wait_subscribed() publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.PayloadFormatIndicator = 1 publish_properties.ContentType = "My name" info = pclient.publish( topics[0], b"qos 0", 0, retain=False, properties=publish_properties) info.wait_for_publish() info = pclient.publish( topics[0], b"qos 1", 1, retain=False, properties=publish_properties) info.wait_for_publish() info = pclient.publish( topics[0], b"qos 2", 2, retain=False, properties=publish_properties) info.wait_for_publish() count = 0 while len(pcallback.messages) < 3 and count < 50: time.sleep(.1) count += 1 pclient.disconnect() pcallback.wait_disconnected() pclient.loop_stop() self.assertEqual(len(pcallback.messages), 3, pcallback.messages) props = pcallback.messages[0]["message"].properties self.assertEqual(props.ContentType, "My name", props.ContentType) self.assertEqual(props.PayloadFormatIndicator, 1, props.PayloadFormatIndicator) props = pcallback.messages[1]["message"].properties self.assertEqual(props.ContentType, "My name", props.ContentType) self.assertEqual(props.PayloadFormatIndicator, 1, props.PayloadFormatIndicator) props = pcallback.messages[2]["message"].properties self.assertEqual(props.ContentType, "My name", props.ContentType) self.assertEqual(props.PayloadFormatIndicator, 1, props.PayloadFormatIndicator) qoss = [pcallback.messages[i]["message"].qos for i in range(3)] self.assertTrue(1 in qoss and 2 in qoss and 0 in qoss, qoss) def test_message_expiry(self): clientid = "message expiry" connect_properties = Properties(PacketTypes.CONNECT) connect_properties.SessionExpiryInterval = 99999 lbclient, lbcallback = self.new_client(clientid+" b") lbclient.loop_start() lbclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) response = lbcallback.wait_connected() lbclient.subscribe(topics[0], qos=2) response = lbcallback.wait_subscribed() disconnect_properties = Properties(PacketTypes.DISCONNECT) disconnect_properties.SessionExpiryInterval = 999999999 lbclient.disconnect(properties=disconnect_properties) lbcallback.wait_disconnected() lbclient.loop_stop() laclient, lacallback = self.new_client(clientid+" a") laclient.loop_start() laclient.connect(host="localhost", port=self._test_broker_port) publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.MessageExpiryInterval = 1 laclient.publish(topics[0], b"qos 1 - expire", 1, retain=False, properties=publish_properties) laclient.publish(topics[0], b"qos 2 - expire", 2, retain=False, properties=publish_properties) publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.MessageExpiryInterval = 6 laclient.publish(topics[0], b"qos 1 - don't expire", 1, retain=False, properties=publish_properties) laclient.publish(topics[0], b"qos 2 - don't expire", 2, retain=False, properties=publish_properties) time.sleep(3) lbclient, lbcallback = self.new_client(clientid+" b") lbclient.loop_start() lbclient.connect(host="localhost", port=self._test_broker_port, clean_start=False) lbcallback.wait_connected() self.waitfor(lbcallback.messages, 1, 3) time.sleep(1) self.assertEqual(len(lbcallback.messages), 2, lbcallback.messages) self.assertTrue(lbcallback.messages[0]["message"].properties.MessageExpiryInterval < 6, lbcallback.messages[0]["message"].properties.MessageExpiryInterval) self.assertTrue(lbcallback.messages[1]["message"].properties.MessageExpiryInterval < 6, lbcallback.messages[1]["message"].properties.MessageExpiryInterval) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() lbclient.disconnect() lbcallback.wait_disconnected() lbclient.loop_stop() def test_subscribe_options(self): # noLocal clientid = 'subscribe options - noLocal' laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) lacallback.wait_connected() laclient.loop_start() laclient.subscribe( topics[0], options=SubscribeOptions(qos=2, noLocal=True)) lacallback.wait_subscribed() lbclient, lbcallback = self.new_client(clientid+" b") lbclient.connect(host="localhost", port=self._test_broker_port) lbcallback.wait_connected() lbclient.loop_start() lbclient.subscribe( topics[0], options=SubscribeOptions(qos=2, noLocal=True)) lbcallback.wait_subscribed() laclient.publish(topics[0], b"noLocal test", 1, retain=False) self.waitfor(lbcallback.messages, 1, 3) time.sleep(1) self.assertEqual(lacallback.messages, [], lacallback.messages) self.assertEqual(len(lbcallback.messages), 1, lbcallback.messages) laclient.disconnect() lacallback.wait_disconnected() lbclient.disconnect() lbcallback.wait_disconnected() laclient.loop_stop() lbclient.loop_stop() # retainAsPublished clientid = 'subscribe options - retain as published' laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) lacallback.wait_connected() laclient.subscribe(topics[0], options=SubscribeOptions( qos=2, retainAsPublished=True)) lacallback.wait_subscribed() self.waitfor(lacallback.subscribeds, 1, 3) laclient.publish( topics[0], b"retain as published false", 1, retain=False) laclient.publish( topics[0], b"retain as published true", 1, retain=True) self.waitfor(lacallback.messages, 2, 3) time.sleep(1) self.assertEqual(len(lacallback.messages), 2, lacallback.messages) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() self.assertEqual(lacallback.messages[0]["message"].retain, False) self.assertEqual(lacallback.messages[1]["message"].retain, True) # retainHandling clientid = 'subscribe options - retain handling' laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) lacallback.wait_connected() laclient.publish(topics[1], b"qos 0", 0, retain=True) laclient.publish(topics[2], b"qos 1", 1, retain=True) laclient.publish(topics[3], b"qos 2", 2, retain=True) time.sleep(1) # retain handling 1 only gives us retained messages on a new subscription laclient.subscribe( wildtopics[5], options=SubscribeOptions(2, retainHandling=1)) lacallback.wait_subscribed() self.assertEqual(len(lacallback.messages), 3) qoss = [lacallback.messages[i]["message"].qos for i in range(3)] self.assertTrue(1 in qoss and 2 in qoss and 0 in qoss, qoss) lacallback.clear() laclient.subscribe( wildtopics[5], options=SubscribeOptions(2, retainHandling=1)) lacallback.wait_subscribed() time.sleep(1) self.assertEqual(len(lacallback.messages), 0) # remove that subscription properties = Properties(PacketTypes.UNSUBSCRIBE) properties.UserProperty = ("a", "2") properties.UserProperty = ("c", "3") laclient.unsubscribe(wildtopics[5], properties) response = lacallback.wait_unsubscribed() # check that we really did remove that subscription laclient.subscribe( wildtopics[5], options=SubscribeOptions(2, retainHandling=1)) lacallback.wait_subscribed() self.assertEqual(len(lacallback.messages), 3) qoss = [lacallback.messages[i]["message"].qos for i in range(3)] self.assertTrue(1 in qoss and 2 in qoss and 0 in qoss, qoss) lacallback.clear() laclient.subscribe( wildtopics[5], options=SubscribeOptions(2, retainHandling=1)) lacallback.wait_subscribed() time.sleep(1) self.assertEqual(len(lacallback.messages), 0) # remove that subscription properties = Properties(PacketTypes.UNSUBSCRIBE) properties.UserProperty = ("a", "2") properties.UserProperty = ("c", "3") laclient.unsubscribe(wildtopics[5], properties) response = lacallback.wait_unsubscribed() lacallback.clear() laclient.subscribe( wildtopics[5], options=SubscribeOptions(2, retainHandling=2)) lacallback.wait_subscribed() self.assertEqual(len(lacallback.messages), 0) laclient.subscribe( wildtopics[5], options=SubscribeOptions(2, retainHandling=2)) lacallback.wait_subscribed() self.assertEqual(len(lacallback.messages), 0) # remove that subscription laclient.unsubscribe(wildtopics[5]) response = lacallback.wait_unsubscribed() laclient.subscribe( wildtopics[5], options=SubscribeOptions(2, retainHandling=0)) lacallback.wait_subscribed() self.assertEqual(len(lacallback.messages), 3) qoss = [lacallback.messages[i]["message"].qos for i in range(3)] self.assertTrue(1 in qoss and 2 in qoss and 0 in qoss, qoss) lacallback.clear() laclient.subscribe( wildtopics[5], options=SubscribeOptions(2, retainHandling=0)) time.sleep(1) self.assertEqual(len(lacallback.messages), 3) qoss = [lacallback.messages[i]["message"].qos for i in range(3)] self.assertTrue(1 in qoss and 2 in qoss and 0 in qoss, qoss) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() cleanRetained(self._test_broker_port) def test_subscription_identifiers(self): clientid = 'subscription identifiers' laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) lacallback.wait_connected() laclient.loop_start() sub_properties = Properties(PacketTypes.SUBSCRIBE) sub_properties.SubscriptionIdentifier = 456789 laclient.subscribe(topics[0], qos=2, properties=sub_properties) lacallback.wait_subscribed() lbclient, lbcallback = self.new_client(clientid+" b") lbclient.connect(host="localhost", port=self._test_broker_port) lbcallback.wait_connected() lbclient.loop_start() sub_properties = Properties(PacketTypes.SUBSCRIBE) sub_properties.SubscriptionIdentifier = 2 lbclient.subscribe(topics[0], qos=2, properties=sub_properties) lbcallback.wait_subscribed() sub_properties.clear() sub_properties.SubscriptionIdentifier = 3 lbclient.subscribe(topics[0]+"/#", qos=2, properties=sub_properties) lbclient.publish(topics[0], b"sub identifier test", 1, retain=False) self.waitfor(lacallback.messages, 1, 3) self.assertEqual(len(lacallback.messages), 1, lacallback.messages) self.assertEqual(lacallback.messages[0]["message"].properties.SubscriptionIdentifier[0], 456789, lacallback.messages[0]["message"].properties.SubscriptionIdentifier) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() self.waitfor(lbcallback.messages, 1, 3) self.assertEqual(len(lbcallback.messages), 1, lbcallback.messages) expected_subsids = set([2, 3]) received_subsids = set( lbcallback.messages[0]["message"].properties.SubscriptionIdentifier) self.assertEqual(received_subsids, expected_subsids, received_subsids) lbclient.disconnect() lbcallback.wait_disconnected() lbclient.loop_stop() def test_request_response(self): clientid = 'request response' laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) lacallback.wait_connected() laclient.loop_start() lbclient, lbcallback = self.new_client(clientid+" b") lbclient.connect(host="localhost", port=self._test_broker_port) lbcallback.wait_connected() lbclient.loop_start() laclient.subscribe( topics[0], options=SubscribeOptions(2, noLocal=True)) lacallback.wait_subscribed() lbclient.subscribe( topics[0], options=SubscribeOptions(2, noLocal=True)) lbcallback.wait_subscribed() publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.ResponseTopic = topics[0] publish_properties.CorrelationData = b"334" # client a is the requester laclient.publish(topics[0], b"request", 1, properties=publish_properties) # client b is the responder self.waitfor(lbcallback.messages, 1, 3) self.assertEqual(len(lbcallback.messages), 1, lbcallback.messages) self.assertEqual(lbcallback.messages[0]["message"].properties.ResponseTopic, topics[0], lbcallback.messages[0]["message"].properties) self.assertEqual(lbcallback.messages[0]["message"].properties.CorrelationData, b"334", lbcallback.messages[0]["message"].properties) lbclient.publish(lbcallback.messages[0]["message"].properties.ResponseTopic, b"response", 1, properties=lbcallback.messages[0]["message"].properties) # client a gets the response self.waitfor(lacallback.messages, 1, 3) self.assertEqual(len(lacallback.messages), 1, lacallback.messages) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() lbclient.disconnect() lbcallback.wait_disconnected() lbclient.loop_stop() def test_client_topic_alias(self): clientid = 'client topic alias' # no server side topic aliases allowed laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) connack = lacallback.wait_connected() laclient.loop_start() publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.TopicAlias = 0 # topic alias 0 not allowed laclient.publish(topics[0], "topic alias 0", 1, properties=publish_properties) # should get back a disconnect with Topic alias invalid lacallback.wait_disconnected() laclient.loop_stop() connect_properties = Properties(PacketTypes.CONNECT) connect_properties.TopicAliasMaximum = 0 # server topic aliases not allowed connect_properties.SessionExpiryInterval = 99999 laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = lacallback.wait_connected() clientTopicAliasMaximum = 0 if hasattr(connack["properties"], "TopicAliasMaximum"): clientTopicAliasMaximum = connack["properties"].TopicAliasMaximum if clientTopicAliasMaximum == 0: laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() return laclient.subscribe(topics[0], qos=2) lacallback.wait_subscribed() publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.TopicAlias = 1 laclient.publish(topics[0], b"topic alias 1", 1, properties=publish_properties) self.waitfor(lacallback.messages, 1, 3) self.assertEqual(len(lacallback.messages), 1, lacallback.messages) laclient.publish("", b"topic alias 2", 1, properties=publish_properties) self.waitfor(lacallback.messages, 2, 3) self.assertEqual(len(lacallback.messages), 2, lacallback.messages) laclient.disconnect() # should get rid of the topic aliases but not subscriptions lacallback.wait_disconnected() laclient.loop_stop() # check aliases have been deleted laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port, clean_start=False, properties=connect_properties) laclient.publish(topics[0], b"topic alias 3", 1) self.waitfor(lacallback.messages, 1, 3) self.assertEqual(len(lacallback.messages), 1, lacallback.messages) publish_properties = Properties(PacketTypes.PUBLISH) publish_properties.TopicAlias = 1 laclient.publish("", b"topic alias 4", 1, properties=publish_properties) # should get back a disconnect with Topic alias invalid lacallback.wait_disconnected() laclient.loop_stop() def test_server_topic_alias(self): clientid = 'server topic alias' serverTopicAliasMaximum = 1 # server topic alias allowed connect_properties = Properties(PacketTypes.CONNECT) connect_properties.TopicAliasMaximum = serverTopicAliasMaximum laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = lacallback.wait_connected() laclient.loop_start() clientTopicAliasMaximum = 0 if hasattr(connack["properties"], "TopicAliasMaximum"): clientTopicAliasMaximum = connack["properties"].TopicAliasMaximum laclient.subscribe(topics[0], qos=2) lacallback.wait_subscribed() for qos in range(3): laclient.publish(topics[0], b"topic alias 1", qos) self.waitfor(lacallback.messages, 3, 3) self.assertEqual(len(lacallback.messages), 3, lacallback.messages) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() # first message should set the topic alias self.assertTrue(hasattr( lacallback.messages[0]["message"].properties, "TopicAlias"), lacallback.messages[0]["message"].properties) topicalias = lacallback.messages[0]["message"].properties.TopicAlias self.assertTrue(topicalias > 0) self.assertEqual(lacallback.messages[0]["message"].topic, topics[0]) self.assertEqual( lacallback.messages[1]["message"].properties.TopicAlias, topicalias) self.assertEqual(lacallback.messages[1]["message"].topic, "") self.assertEqual( lacallback.messages[2]["message"].properties.TopicAlias, topicalias) self.assertEqual(lacallback.messages[2]["message"].topic, "") serverTopicAliasMaximum = 0 # no server topic alias allowed connect_properties = Properties(PacketTypes.CONNECT) # connect_properties.TopicAliasMaximum = serverTopicAliasMaximum # default is 0 laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = lacallback.wait_connected() laclient.loop_start() clientTopicAliasMaximum = 0 if hasattr(connack["properties"], "TopicAliasMaximum"): clientTopicAliasMaximum = connack["properties"].TopicAliasMaximum laclient.subscribe(topics[0], qos=2) lacallback.wait_subscribed() for qos in range(3): laclient.publish(topics[0], b"topic alias 2", qos) self.waitfor(lacallback.messages, 3, 3) self.assertEqual(len(lacallback.messages), 3, lacallback.messages) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() # No topic aliases self.assertFalse(hasattr( lacallback.messages[0]["message"].properties, "TopicAlias"), lacallback.messages[0]["message"].properties) self.assertFalse(hasattr( lacallback.messages[1]["message"].properties, "TopicAlias"), lacallback.messages[1]["message"].properties) self.assertFalse(hasattr( lacallback.messages[2]["message"].properties, "TopicAlias"), lacallback.messages[2]["message"].properties) serverTopicAliasMaximum = 0 # no server topic alias allowed connect_properties = Properties(PacketTypes.CONNECT) connect_properties.TopicAliasMaximum = serverTopicAliasMaximum # default is 0 laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = lacallback.wait_connected() laclient.loop_start() clientTopicAliasMaximum = 0 if hasattr(connack["properties"], "TopicAliasMaximum"): clientTopicAliasMaximum = connack["properties"].TopicAliasMaximum laclient.subscribe(topics[0], qos=2) lacallback.wait_subscribed() for qos in range(3): laclient.publish(topics[0], b"topic alias 3", qos) self.waitfor(lacallback.messages, 3, 3) self.assertEqual(len(lacallback.messages), 3, lacallback.messages) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() # No topic aliases self.assertFalse(hasattr( lacallback.messages[0]["message"].properties, "TopicAlias"), lacallback.messages[0]["message"].properties) self.assertFalse(hasattr( lacallback.messages[1]["message"].properties, "TopicAlias"), lacallback.messages[1]["message"].properties) self.assertFalse(hasattr( lacallback.messages[2]["message"].properties, "TopicAlias"), lacallback.messages[2]["message"].properties) def test_maximum_packet_size(self): clientid = 'maximum packet size' # 1. server max packet size laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) connack = lacallback.wait_connected() laclient.loop_start() serverMaximumPacketSize = 2**28-1 if hasattr(connack["properties"], "MaximumPacketSize"): serverMaximumPacketSize = connack["properties"].MaximumPacketSize if serverMaximumPacketSize < 65535: # publish bigger packet than server can accept payload = b"."*serverMaximumPacketSize laclient.publish(topics[0], payload, 0) # should get back a disconnect with packet size too big response = lacallback.wait_disconnected() self.assertEqual(len(lacallback.disconnecteds), 0, lacallback.disconnecteds) self.assertEqual(response["reasonCode"].getName(), "Packet too large", response["reasonCode"].getName()) else: laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() # 1. client max packet size maximumPacketSize = 64 # max packet size we want to receive connect_properties = Properties(PacketTypes.CONNECT) connect_properties.MaximumPacketSize = maximumPacketSize laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = lacallback.wait_connected() laclient.loop_start() serverMaximumPacketSize = 2**28-1 if hasattr(connack["properties"], "MaximumPacketSize"): serverMaximumPacketSize = connack["properties"].MaximumPacketSize laclient.subscribe(topics[0], qos=2) response = lacallback.wait_subscribed() # send a small enough packet, should get this one back payload = b"."*(int(maximumPacketSize/2)) laclient.publish(topics[0], payload, 0) self.waitfor(lacallback.messages, 1, 3) self.assertEqual(len(lacallback.messages), 1, lacallback.messages) # send a packet too big to receive payload = b"."*maximumPacketSize laclient.publish(topics[0], payload, 1) self.waitfor(lacallback.messages, 2, 3) self.assertEqual(len(lacallback.messages), 1, lacallback.messages) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() """ def test_server_keep_alive(self): clientid = 'server keep alive' laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) connack = lacallback.wait_connected() laclient.loop_start() self.assertTrue(hasattr(connack["properties"], "ServerKeepAlive")) self.assertEqual(connack["properties"].ServerKeepAlive, 60) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() """ def test_will_delay(self): # the will message should be received earlier than the session expiry clientid = 'will delay' will_properties = Properties(PacketTypes.WILLMESSAGE) connect_properties = Properties(PacketTypes.CONNECT) # set the will delay and session expiry to the same value - # then both should occur at the same time will_properties.WillDelayInterval = 3 # in seconds connect_properties.SessionExpiryInterval = 5 laclient, lacallback = self.new_client(clientid+" a") laclient.will_set( topics[0], payload=b"test_will_delay will message", properties=will_properties) laclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = lacallback.wait_connected() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) laclient.loop_start() lbclient, lbcallback = self.new_client(clientid+" b") lbclient.connect(host="localhost", port=self._test_broker_port, properties=connect_properties) connack = lbcallback.wait_connected() lbclient.loop_start() # subscribe to will message topic lbclient.subscribe(topics[0], qos=2) lbcallback.wait_subscribed() # abort client a and wait for the will message laclient.loop_stop() laclient.socket().close() start = time.time() while lbcallback.messages == []: time.sleep(.1) duration = time.time() - start self.assertAlmostEqual(duration, 4, delta=1) self.assertEqual(lbcallback.messages[0]["message"].topic, topics[0]) self.assertEqual( lbcallback.messages[0]["message"].payload, b"test_will_delay will message") lbclient.disconnect() lbcallback.wait_disconnected() lbclient.loop_stop() def test_shared_subscriptions(self): clientid = 'shared subscriptions' shared_sub_topic = '$share/sharename/' + topic_prefix + 'x' shared_pub_topic = topic_prefix + 'x' laclient, lacallback = self.new_client(clientid+" a") laclient.connect(host="localhost", port=self._test_broker_port) connack = lacallback.wait_connected() laclient.loop_start() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) laclient.subscribe( [(shared_sub_topic, SubscribeOptions(2)), (topics[0], SubscribeOptions(2))]) response = lacallback.wait_subscribed() lbclient, lbcallback = self.new_client(clientid+" b") lbclient.connect(host="localhost", port=self._test_broker_port) connack = lbcallback.wait_connected() lbclient.loop_start() self.assertEqual(connack["reasonCode"].getName(), "Success") self.assertEqual(connack["flags"]["session present"], False) lbclient.subscribe( [(shared_sub_topic, SubscribeOptions(2)), (topics[0], 2)]) response = lbcallback.wait_subscribed() lacallback.clear() lbcallback.clear() count = 1 for i in range(count): lbclient.publish(topics[0], "message "+str(i), 0) j = 0 while len(lacallback.messages) + len(lbcallback.messages) < 2*count and j < 20: time.sleep(.1) j += 1 time.sleep(1) self.assertEqual(len(lacallback.messages), count) self.assertEqual(len(lbcallback.messages), count) lacallback.clear() lbcallback.clear() for i in range(count): lbclient.publish(shared_pub_topic, "message "+str(i), 0) j = 0 while len(lacallback.messages) + len(lbcallback.messages) < count and j < 20: time.sleep(.1) j += 1 time.sleep(1) # Each message should only be received once self.assertEqual(len(lacallback.messages) + len(lbcallback.messages), count) laclient.disconnect() lacallback.wait_disconnected() laclient.loop_stop() lbclient.disconnect() lbcallback.wait_disconnected() lbclient.loop_stop() def setData(): global topics, wildtopics, nosubscribe_topics, topic_prefix topics = ("TopicA", "TopicA/B", "Topic/C", "TopicA/C", "/TopicA") wildtopics = ("TopicA/+", "+/C", "#", "/#", "/+", "+/+", "TopicA/#") nosubscribe_topics = ("test/nosubscribe",) topic_prefix = "paho.mqtt.client.mqttv5/" paho.mqtt.python-1.5.1/tests/test_websocket_integration.py000066400000000000000000000205261373244276700241410ustar00rootroot00000000000000import base64 import re import hashlib from collections import OrderedDict from six.moves import socketserver import pytest import paho.mqtt.client as client from paho.mqtt.client import WebsocketConnectionError from testsupport.broker import fake_websocket_broker @pytest.fixture def init_response_headers(): # "Normal" websocket response from server response_headers = OrderedDict([ ("Upgrade", "websocket"), ("Connection", "Upgrade"), ("Sec-WebSocket-Accept", "testwebsocketkey"), ("Sec-WebSocket-Protocol", "chat"), ]) return response_headers def get_websocket_response(response_headers): """ Takes headers and constructs HTTP response 'HTTP/1.1 101 Switching Protocols' is the headers for the response, as expected in client.py """ response = "\r\n".join([ "HTTP/1.1 101 Switching Protocols", "\r\n".join("{}: {}".format(i, j) for i, j in response_headers.items()), "\r\n", ]).encode("utf8") return response @pytest.mark.parametrize("proto_ver,proto_name", [ (client.MQTTv31, "MQIsdp"), (client.MQTTv311, "MQTT"), ]) class TestInvalidWebsocketResponse(object): def test_unexpected_response(self, proto_ver, proto_name, fake_websocket_broker): """ Server responds with a valid code, but it's not what the client expected """ mqttc = client.Client( "test_unexpected_response", protocol=proto_ver, transport="websockets" ) class WebsocketHandler(socketserver.BaseRequestHandler): def handle(_self): # Respond with data passed in to serve() _self.request.sendall("200 OK".encode("utf8")) with fake_websocket_broker.serve(WebsocketHandler): with pytest.raises(WebsocketConnectionError) as exc: mqttc.connect("localhost", 1888, keepalive=10) assert str(exc.value) == "WebSocket handshake error" @pytest.mark.parametrize("proto_ver,proto_name", [ (client.MQTTv31, "MQIsdp"), (client.MQTTv311, "MQTT"), ]) class TestBadWebsocketHeaders(object): """ Testing for basic functionality in checking for headers """ def _get_basic_handler(self, response_headers): """ Get a basic BaseRequestHandler which returns the information in self._response_headers """ response = get_websocket_response(response_headers) class WebsocketHandler(socketserver.BaseRequestHandler): def handle(_self): self.data = _self.request.recv(1024).strip() print("Received '{:s}'".format(self.data.decode("utf8"))) # Respond with data passed in to serve() _self.request.sendall(response) return WebsocketHandler def test_no_upgrade(self, proto_ver, proto_name, fake_websocket_broker, init_response_headers): """ Server doesn't respond with 'connection: upgrade' """ mqttc = client.Client( "test_no_upgrade", protocol=proto_ver, transport="websockets" ) init_response_headers["Connection"] = "bad" response = self._get_basic_handler(init_response_headers) with fake_websocket_broker.serve(response): with pytest.raises(WebsocketConnectionError) as exc: mqttc.connect("localhost", 1888, keepalive=10) assert str(exc.value) == "WebSocket handshake error, connection not upgraded" def test_bad_secret_key(self, proto_ver, proto_name, fake_websocket_broker, init_response_headers): """ Server doesn't give anything after connection: upgrade """ mqttc = client.Client( "test_bad_secret_key", protocol=proto_ver, transport="websockets" ) response = self._get_basic_handler(init_response_headers) with fake_websocket_broker.serve(response): with pytest.raises(WebsocketConnectionError) as exc: mqttc.connect("localhost", 1888, keepalive=10) assert str(exc.value) == "WebSocket handshake error, invalid secret key" @pytest.mark.parametrize("proto_ver,proto_name", [ (client.MQTTv31, "MQIsdp"), (client.MQTTv311, "MQTT"), ]) class TestValidHeaders(object): """ Testing for functionality in request/response headers """ def _get_callback_handler(self, response_headers, check_request=None): """ Get a basic BaseRequestHandler which returns the information in self._response_headers """ class WebsocketHandler(socketserver.BaseRequestHandler): def handle(_self): self.data = _self.request.recv(1024).strip() print("Received '{:s}'".format(self.data.decode("utf8"))) decoded = self.data.decode("utf8") if check_request is not None: check_request(decoded) # Create server hash GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" key = re.search("sec-websocket-key: ([A-Za-z0-9+/=]*)", decoded, re.IGNORECASE).group(1) to_hash = "{:s}{:s}".format(key, GUID) hashed = hashlib.sha1(to_hash.encode("utf8")) encoded = base64.b64encode(hashed.digest()).decode("utf8") response_headers["Sec-WebSocket-Accept"] = encoded # Respond with the correct hash response = get_websocket_response(response_headers) _self.request.sendall(response) return WebsocketHandler def test_successful_connection(self, proto_ver, proto_name, fake_websocket_broker, init_response_headers): """ Connect successfully, on correct path """ mqttc = client.Client( "test_successful_connection", protocol=proto_ver, transport="websockets" ) response = self._get_callback_handler(init_response_headers) with fake_websocket_broker.serve(response): mqttc.connect("localhost", 1888, keepalive=10) mqttc.disconnect() @pytest.mark.parametrize("mqtt_path", [ "/mqtt" "/special", None, ]) def test_correct_path(self, proto_ver, proto_name, fake_websocket_broker, mqtt_path, init_response_headers): """ Make sure it can connect on user specified paths """ mqttc = client.Client( "test_correct_path", protocol=proto_ver, transport="websockets" ) mqttc.ws_set_options( path=mqtt_path, ) def check_path_correct(decoded): # Make sure it connects to the right path if mqtt_path: assert re.search("GET {:s} HTTP/1.1".format(mqtt_path), decoded, re.IGNORECASE) is not None response = self._get_callback_handler( init_response_headers, check_request=check_path_correct, ) with fake_websocket_broker.serve(response): mqttc.connect("localhost", 1888, keepalive=10) mqttc.disconnect() @pytest.mark.parametrize("auth_headers", [ {"Authorization": "test123"}, {"Authorization": "test123", "auth2": "abcdef"}, # Won't be checked, but make sure it still works even if the user passes it None, ]) def test_correct_auth(self, proto_ver, proto_name, fake_websocket_broker, auth_headers, init_response_headers): """ Make sure it sends the right auth headers """ mqttc = client.Client( "test_correct_path", protocol=proto_ver, transport="websockets" ) mqttc.ws_set_options( headers=auth_headers, ) def check_headers_used(decoded): # Make sure it connects to the right path if auth_headers: for h in auth_headers: assert re.search("{:s}: {:s}".format(h, auth_headers[h]), decoded, re.IGNORECASE) is not None response = self._get_callback_handler( init_response_headers, check_request=check_headers_used, ) with fake_websocket_broker.serve(response): mqttc.connect("localhost", 1888, keepalive=10) mqttc.disconnect() paho.mqtt.python-1.5.1/tests/test_websockets.py000066400000000000000000000041571373244276700217230ustar00rootroot00000000000000import socket import sys if sys.version_info < (3, 0): from mock import Mock else: from unittest.mock import Mock import pytest from paho.mqtt.client import WebsocketWrapper, WebsocketConnectionError class TestHeaders(object): """ Make sure headers are used correctly """ def test_normal_headers(self): """ Normal headers as specified in RFC 6455 """ response = [ "HTTP/1.1 101 Switching Protocols", "Upgrade: websocket", "Connection: Upgrade", "Sec-WebSocket-Accept: badreturnvalue=", "Sec-WebSocket-Protocol: chat", "\r\n", ] def iter_response(): for i in "\r\n".join(response).encode("utf8"): yield i for i in "\r\n".encode("utf8"): yield i it = iter_response() def fakerecv(*args): if sys.version_info < (3, 0): return next(it) else: return bytes([next(it)]) mocksock = Mock( spec_set=socket.socket, recv=fakerecv, send=Mock(), ) wargs = { "host": "testhost.com", "port": 1234, "path": "/mqtt", "extra_headers": None, "is_ssl": True, "socket": mocksock, } with pytest.raises(WebsocketConnectionError) as exc: WebsocketWrapper(**wargs) # We're not creating the response hash properly so it should raise this # error assert str(exc.value) == "WebSocket handshake error, invalid secret key" expected_sent = [i.format(**wargs) for i in [ "GET {path:s} HTTP/1.1", "Host: {host:s}", "Upgrade: websocket", "Connection: Upgrade", "Sec-Websocket-Protocol: mqtt", "Sec-Websocket-Version: 13", "Origin: https://{host:s}:{port:d}", ]] # Only sends the header once assert mocksock.send.call_count == 1 for i in expected_sent: assert i in mocksock.send.call_args[0][0].decode("utf8") paho.mqtt.python-1.5.1/tests/testsupport/000077500000000000000000000000001373244276700205465ustar00rootroot00000000000000paho.mqtt.python-1.5.1/tests/testsupport/__init__.py000066400000000000000000000000001373244276700226450ustar00rootroot00000000000000paho.mqtt.python-1.5.1/tests/testsupport/broker.py000066400000000000000000000047631373244276700224160ustar00rootroot00000000000000import socket from six.moves import socketserver import threading import contextlib import pytest class FakeBroker: def __init__(self): # Bind to "localhost" for maximum performance, as described in: # http://docs.python.org/howto/sockets.html#ipc sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.settimeout(30) sock.bind(("localhost", 1888)) sock.listen(1) self._sock = sock self._conn = None def start(self): if self._sock is None: raise ValueError('Socket is not open') (conn, address) = self._sock.accept() conn.settimeout(10) self._conn = conn def finish(self): if self._conn is not None: self._conn.close() self._conn = None if self._sock is not None: self._sock.close() self._sock = None def receive_packet(self, num_bytes): if self._conn is None: raise ValueError('Connection is not open') packet_in = self._conn.recv(num_bytes) return packet_in def send_packet(self, packet_out): if self._conn is None: raise ValueError('Connection is not open') count = self._conn.send(packet_out) return count @pytest.fixture def fake_broker(): # print('Setup broker') broker = FakeBroker() yield broker # print('Teardown broker') broker.finish() class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): pass class FakeWebsocketBroker(threading.Thread): def __init__(self): super(FakeWebsocketBroker, self).__init__() self.host = "localhost" self.port = 1888 self._server = None self._running = True self.handler_cls = False @contextlib.contextmanager def serve(self, tcphandler): self._server = ThreadedTCPServer((self.host, self.port), tcphandler) try: self.start() if not self._running: raise RuntimeError("Error starting server") yield finally: if self._server: self._server.shutdown() self._server.server_close() def run(self): self._running = True self._server.serve_forever() @pytest.fixture def fake_websocket_broker(): socketserver.TCPServer.allow_reuse_address = True broker = FakeWebsocketBroker() yield broker paho.mqtt.python-1.5.1/tox.ini000066400000000000000000000011651373244276700163060ustar00rootroot00000000000000[tox] envlist = py{27,35,36,37,38} [testenv:py27] setenv = EXCLUDE = --exclude=./.*,./examples/loop_asyncio.py,*/MQTTV5.py,*/MQTTV311.py [testenv] whitelist_externals = echo make deps = -rrequirements.txt flake8 commands = # $EXCLUDE is defined above in testenv:py27 as a workaround for Python 2 # which does not support asyncio and type hints flake8 . --count --select=E9,F63,F7,F822,F823 --show-source --statistics {env:EXCLUDE:} python setup.py test make -C test test # TODO (cclauss) Fix up all these undefined names flake8 . --count --exit-zero --select=F821 --show-source --statistics