{ "info": { "author": "Matthias L. Jugel", "author_email": "matthias.jugel@ubirch.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# ubirch-protocol for python\n\nThis is an implementation of the [ubirch-protocol](https://github.com/ubirch/ubirch-protocol)\nfor [Python 3](https://www.python.org/). Please see [ubirch-protocol](https://github.com/ubirch/ubirch-protocol)\nfor details.\n\nThe library consists of three parts which can be used individually:\n\n* `ubirch.API` - a python layer covering the ubirch backend REST API\n* `ubirch.Protocol` - the protocol compiler which packages messages and handles signing and verification\n* `ubirch.KeyStore` - a simple key store based on [pyjks](https://pypi.org/project/pyjks/) to store keys and certificates\n\n> the [ubirch](https://ubirch.com) protocol uses the [Ed25519](https://ed25519.cr.yp.to/) signature scheme by default.\n \n## Usage\n\nInstall the library: `pip install ubirch-protocol`\n \n### Creating keypair and messages\n\n```python\nimport ubirch\nfrom ubirch.ubirch_protocol import CHAINED\nfrom uuid import UUID\nimport binascii\n\n# create a keystore for the device keypair\nkeystore = ubirch.KeyStore(\"demo-device.jks\", \"keystore\")\n\n# create a UUID that identifies the device and load or create a keypair\nuuid = UUID(hex=\"575A5601FD744F8EB6AEEF592CDEE12C\")\nif not keystore.exists_signing_key(uuid):\n keystore.create_ed25519_keypair(uuid)\n\n# implement the _sign method on the ubirch.Protocol to use the just created\n# keys to sign the message and add methods to save and load the last signature\nclass ProtocolImpl(ubirch.Protocol):\n def _sign(self, uuid: UUID, message: bytes) -> bytes:\n return keystore.find_signing_key(uuid).sign(message) \n\nproto = ProtocolImpl(CHAINED)\nprint(binascii.hexlify(proto.message_chained(uuid, 0x00, [1, 2, 3])))\nprint(binascii.hexlify(proto.message_chained(uuid, 0x00, [4, 5, 6])))\n```\n \n### Sending messages using the ubirch API\n\nPlease see [test-protocol.py](examples/test-protocol.py) for a comprehensive example, how to create a device and\nsend data. Below is a snipped that will send two chained messages, using the generic key/value payload.\n\nYou will need an authentication token for the ubirch backend. Feel free to [contact us](https://ubirch.com), \nself on-bording is on it's way!\n\n```python\nimport ubirch\nimport uuid\nimport binascii\nfrom datetime import datetime\n\nuuid = uuid.uuid4()\nproto = ubirch.Protocol()\napi = ubirch.API()\n\n# message 1\nmsg = proto.message_chained(uuid, 0x53, {'ts': int(datetime.utcnow().timestamp()), 'v': 99})\n\nprint(binascii.hexlify(msg))\nr = api.send(msg)\nprint(\"{}: {}\".format(r.status_code, r.content))\n\n# message 2 (chained to message 1)\nmsg = proto.message_chained(uuid, 0x53, {\"ts\": int(datetime.utcnow().timestamp()), \"v\": 100})\nprint(binascii.hexlify(msg))\nr = api.send(msg)\nprint(\"{}: {}\".format(r.status_code, r.content))\n```\n\n### Verification of received message\n\n```python\nimport ubirch\nimport hashlib\n\nfrom ed25519 import VerifyingKey\nfrom uuid import UUID\nfrom ubirch.ubirch_protocol import SIGNED\n\nremote_uuid = UUID(hex=\"6eac4d0b-16e6-4508-8c46-22e7451ea5a1\")\nremote_vk = VerifyingKey(\"b12a906051f102881bbb487ee8264aa05d8d0fcc51218f2a47f562ceb9b0d068\", encoding='hex')\n# a random signed ubirch-protocol message\nkeystore = ubirch.KeyStore(\"demo-device.jks\", \"keystore\")\nkeystore.insert_ed25519_verifying_key(remote_uuid, remote_vk)\n\n\nclass ProtocolImpl(ubirch.Protocol):\n def _verify(self, uuid: UUID, message: bytes, signature: bytes) -> dict:\n hash = hashlib.sha512(message).digest()\n return keystore.find_verifying_key(uuid).verify(signature, hash)\n\n\nproto = ProtocolImpl(SIGNED)\n\nmessage = bytes.fromhex(\n \"9512b06eac4d0b16e645088c4622e7451ea5a1ccef01da0040578a5b22ceb3e1\"\n \"d0d0f8947c098010133b44d3b1d2ab398758ffed11507b607ed37dbbe006f645\"\n \"f0ed0fdbeb1b48bb50fd71d832340ce024d5a0e21c0ebc8e0e\")\nprint(proto.message_verify(message))\n```\n\n### Existing keys\n\nIn case you create a key pair from our demo website, use the following code to insert it into the key store:\n\n```python\nimport ubirch\nimport ed25519\nimport uuid\n\nhwDeviceId = uuid.uuid4()\nkeystore = ubirch.KeyStore(\"demo-device.jks\", \"keystore\")\nkey_encoded = input(\"paste the encoded private key here:\")\nsk = ed25519.SigningKey(key_encoded, encoding='hex')\nvk = sk.get_verifying_key() \n\nkeystore.insert_ed25519_keypair(hwDeviceId, vk, sk)\n```\n\n### Running the example\n\n```bash\npython3 -m venv venv3\n. venv3/bin/activate\npip install -r requirements.txt\npip install ubirch-protocol\nPYTHONPATH=. python3 examples/test-protocol.py\n```\n\nAt the first launch the script generates a random UUID for your device and you will be asked\nabout the authentication token and the device group. You can safely ignore the device group, just press Enter.\nThe script creates a file `demo-device.ini` which is loaded upon running the script again. If\nyou need to change anything edit that file.\n\nThe script goes through a number of steps:\n\n1. checks the existence of the device and deletes the device if it exists\n2. registers the device with the backend\n3. generates a new identity for that device and stores it in the key store\n4. registers the new identity with the backend\n5. sends two consecutive chained messages to the backend\n\n### Example: Web-of-Trust\n\n#### Before First Execution\n\n```bash\npython3 -m venv venv3\npip install -r requirements.txt\n```\n\n#### Running The Example\n\n```bash\n. venv3/bin/activate\nPYTHONPATH=. python3 examples/test-web-of-trust.py\n```\n\nDuring first launch the script generates key pairs for two users. Each user has one device and key pairs are created for \nthese, too. All key pairs are stored in `test-web-of-trust.jks` while the association of users, their device and the \nrespective key pair is stored in `demo-web-of-trust.ini`. In consecutive runs no new key pairs are generated and instead\nthe ones referenced in `demo-web-of-trust.ini` are used.\n\nThe script always uploads all public keys, followed by creating and uploading a web-of-trust and searching all public \nkeys trusted by `deviceA`. This search is repeated with different parameters. The results are then printed onto the\nterminal.\n\nThe web-of-trust created looks as follows (trust knows a direction; always bidirectional in this example):\n\n```\ndeviceA <--trustLevel=100--> user1 <--trustLevel=50--> user2 <--trustLevel=100--> deviceB\n```\n\nThe first search for all trusted keys is for a minimum trust of 50 and a depth of 3 resulting in the the following keys\nbeing found:\n\n* user1\n* user2\n* deviceB\n\nThe second search increases the minimum trust to 60 resulting in:\n\n* user1\n\nAnd the third search is with a minimum trust of 50 again while the depth is now 2 resulting in:\n\n* user1\n* user2\n\n\n### Testing\n\nUnit tests are added to test the functionality of all objects provided in this library.\n\n```bash\npip install -r requirements.test.txt\npython3 -m pytest tests\n``` \n# License", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ubirch/ubirch-protocol-python", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "ubirch-protocol", "package_url": "https://pypi.org/project/ubirch-protocol/", "platform": "", "project_url": "https://pypi.org/project/ubirch-protocol/", "project_urls": { "Homepage": "https://github.com/ubirch/ubirch-protocol-python" }, "release_url": "https://pypi.org/project/ubirch-protocol/2.1.0/", "requires_dist": null, "requires_python": "", "summary": "A ubirch-protocol implementation for python.", "version": "2.1.0" }, "last_serial": 5678112, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "998d3e9f0dd68f878b97156649c55303", "sha256": "0331ec3f20885e368ccf22647d28bb8d0b2fb781a817b11fb17ab3f967424479" }, "downloads": -1, "filename": "ubirch-protocol-1.0.0.tar.gz", "has_sig": false, "md5_digest": "998d3e9f0dd68f878b97156649c55303", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9290, "upload_time": "2018-08-10T17:13:31", "url": "https://files.pythonhosted.org/packages/9b/4c/82021c147d13419b39f6b395e8879a337ad7db87afed26bb73187544f9d8/ubirch-protocol-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "c7a3caea4a7a88c5d2ddcda7b052f87d", "sha256": "d6d1e13844deee7514db4c4c612e9a2182b5747638f278b9a1429981ed1b8699" }, "downloads": -1, "filename": "ubirch-protocol-1.0.1.tar.gz", "has_sig": false, "md5_digest": "c7a3caea4a7a88c5d2ddcda7b052f87d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10110, "upload_time": "2018-08-17T22:19:45", "url": "https://files.pythonhosted.org/packages/48/e6/65af1c10f89dba66cfa66b1eb8da0c879c7271253bbc35a430ed7ab58af2/ubirch-protocol-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "045f6379612a3266ee6d10eb9fcdd365", "sha256": "ecd263368378ee4727a28b9ade36535c4d659256a8336c39bbba5c3b2b786ebc" }, "downloads": -1, "filename": "ubirch-protocol-1.0.2.tar.gz", "has_sig": false, "md5_digest": "045f6379612a3266ee6d10eb9fcdd365", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10216, "upload_time": "2018-08-18T10:34:50", "url": "https://files.pythonhosted.org/packages/4a/b6/88d1e96e4533420ed2b799fa92a4e402d360e03b21285ce91a9bb7b4fe41/ubirch-protocol-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "b417cba7767dab09cf2e747d03cc63e6", "sha256": "615ed8adcacbbb96e7a21dc6e46de0796f7052da9956f91f57d6c9c17aec6e9f" }, "downloads": -1, "filename": "ubirch-protocol-1.0.3.tar.gz", "has_sig": false, "md5_digest": "b417cba7767dab09cf2e747d03cc63e6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10214, "upload_time": "2018-09-07T15:33:00", "url": "https://files.pythonhosted.org/packages/38/2c/b784b05997d806b3e916b327e8cb4795fa7c4b1884dadbd8e3b73a1b77d6/ubirch-protocol-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "142a285fedd8f501b2b839a1c54d0994", "sha256": "2cea72e1c327be01ded7b4578098b9494e8f023e8aff443308ef3d3b0fc83490" }, "downloads": -1, "filename": "ubirch-protocol-1.0.4.tar.gz", "has_sig": false, "md5_digest": "142a285fedd8f501b2b839a1c54d0994", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10216, "upload_time": "2018-09-07T15:42:01", "url": "https://files.pythonhosted.org/packages/5f/cc/cfb09c55ff6141dd1bcabf28bf888cb445eb4342a8ad4f96c1d51fafdc97/ubirch-protocol-1.0.4.tar.gz" } ], "1.0.5": [ { "comment_text": "", "digests": { "md5": "abe7cd3676dbbed08bb77d0da7f2226d", "sha256": "d34d07e59926680cef4fe3e12a169f641fd68186f7ab101bae262b301ff3f357" }, "downloads": -1, "filename": "ubirch-protocol-1.0.5.tar.gz", "has_sig": false, "md5_digest": "abe7cd3676dbbed08bb77d0da7f2226d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10232, "upload_time": "2018-09-07T15:48:37", "url": "https://files.pythonhosted.org/packages/8e/2e/6ba684100e1ea37afd1834e4ef946ed5484f6e86e038d0cf7c43bf14b18d/ubirch-protocol-1.0.5.tar.gz" } ], "1.0.7": [ { "comment_text": "", "digests": { "md5": "8b4550507d7563d4e3b0d5e42172ffbe", "sha256": "d4d3c3a67590ef46b9f81f872817da46d3da7d989b389569a42e2982998b67b0" }, "downloads": -1, "filename": "ubirch_protocol-1.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "8b4550507d7563d4e3b0d5e42172ffbe", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 15089, "upload_time": "2018-10-10T10:08:11", "url": "https://files.pythonhosted.org/packages/c5/3c/245e19f70053913793038de8d05310e59e3b298ee2a696889172aea4181a/ubirch_protocol-1.0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6499b70bdeecde8961b05e19a8f46545", "sha256": "5bb18eb307eb53728cc51cebd270b14e956e17305a7fe672a32a1aabcc65aff8" }, "downloads": -1, "filename": "ubirch-protocol-1.0.7.tar.gz", "has_sig": false, "md5_digest": "6499b70bdeecde8961b05e19a8f46545", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11614, "upload_time": "2018-10-10T10:08:12", "url": "https://files.pythonhosted.org/packages/67/3a/74033097a67c1a6705142a478d23d998d1162095eef25594e5a8ee53a07f/ubirch-protocol-1.0.7.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "e223023dfd8d3dd6eb2c938aaf7f9ddb", "sha256": "c129a686b480144ac34626159575fe211cb4d6d0f1772dff9a5a26c19d626ea1" }, "downloads": -1, "filename": "ubirch-protocol-2.0.0.tar.gz", "has_sig": false, "md5_digest": "e223023dfd8d3dd6eb2c938aaf7f9ddb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11813, "upload_time": "2019-02-11T19:00:47", "url": "https://files.pythonhosted.org/packages/df/27/4f356edb301bc268e5b7f462c1c4a964e2c9d765aeb1515de4a8a1cad4ea/ubirch-protocol-2.0.0.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "269277563d033c4930e93b16b809ed22", "sha256": "63eac218fe5605a887b8de4a76cef27ae60db12b62bbdb2f2420d33086153add" }, "downloads": -1, "filename": "ubirch-protocol-2.0.1.tar.gz", "has_sig": false, "md5_digest": "269277563d033c4930e93b16b809ed22", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11873, "upload_time": "2019-05-03T10:56:19", "url": "https://files.pythonhosted.org/packages/2f/dd/cf1cba76bcef4a896f5f1a7e7eb03ae4161420517cdf5f9d06352aaac0ee/ubirch-protocol-2.0.1.tar.gz" } ], "2.1.0": [ { "comment_text": "", "digests": { "md5": "d9caec9baee8cf1b91888de0e401808d", "sha256": "6d81ca3605cbfc81946b5a21e05d90d736341ecc95a99892cffe146cec9a14e6" }, "downloads": -1, "filename": "ubirch-protocol-2.1.0.tar.gz", "has_sig": false, "md5_digest": "d9caec9baee8cf1b91888de0e401808d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11619, "upload_time": "2019-08-14T16:36:03", "url": "https://files.pythonhosted.org/packages/b2/b3/14744abdf446db6ad5f3e7c45747fa147684a69f145afa5e0f18d49208d9/ubirch-protocol-2.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d9caec9baee8cf1b91888de0e401808d", "sha256": "6d81ca3605cbfc81946b5a21e05d90d736341ecc95a99892cffe146cec9a14e6" }, "downloads": -1, "filename": "ubirch-protocol-2.1.0.tar.gz", "has_sig": false, "md5_digest": "d9caec9baee8cf1b91888de0e401808d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11619, "upload_time": "2019-08-14T16:36:03", "url": "https://files.pythonhosted.org/packages/b2/b3/14744abdf446db6ad5f3e7c45747fa147684a69f145afa5e0f18d49208d9/ubirch-protocol-2.1.0.tar.gz" } ] }