pylibsdm


Namepylibsdm JSON
Version 1.0.0a0.dev2 PyPI version JSON
download
home_pagehttps://codeberg.org/Bergblau/pylibsdm
SummaryPython library for handling Secure Dynamic Messaging (SDM) of NFC cards like the NTAG 424 DNA
upload_time2023-07-02 19:15:15
maintainer
docs_urlNone
authorDominik George
requires_python>=3.9,<4.0
licenseApache-2.0
keywords nfc ntag424
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--
SPDX-FileCopyrightText: © 2023 Dominik George <nik@velocitux.com>

SPDX-License-Identifier: LGPL-2.0-or-later
-->

# pylibsdm - NFC Secure Dynamic Messaging with Python

pylibsdm is a Python library (SDK) for handling Secure Dynamic Messaging (SDM)
of NFC cards with Python.

Secure Dynamic Messaging is a technology that adds security features to
NFC tags using standard mechanisms. While standard NFC data (so-called
NDEF messages, e.g. texts, URLs, etc.) can be written to any compatible
tag, SUN-capable tags can cryptographically sign and optionally also
encrypt parts of the data, which can then still be read by any standard
NFC reader.

## Features

* Card management / configuration
  * Configuration of NDEF file settings (mirrors, offsets, used keys,…)
  * Configuration of NDEF file data (URL)
  * Provisioning of keys
* Backend implementation for SUN (Secure Unique NFC)
  * Decryption and validation of SDM data (mirrors)
  * Validation of information from URI parameters

## Supported tags

* [NTAG 424 DNA](https://www.nxp.com/products/rfid-nfc/nfc-hf/ntag-for-tags-and-labels/ntag-424-dna-424-dna-tagtamper-advanced-security-and-privacy-for-trusted-iot-applications:NTAG424DNA)
  ([specification](https://www.nxp.com/docs/en/application-note/AN12196.pdf))

## Installation and usage

`pylibsdm` is shipped as a standard Python library and cann be installed
from PyPI:

```sh
pip install "pylibsdm[cli]"
```

The `cli` extra installs the `sdmutil` command-line utility, which can
be used as a stand-alone tool to handle tags.

### Usage as a library in own code

The following examples show how to use `pylibsdm` within custom
applications. It can, as such, be seen as an SDK for writing SUN-capable
applications.

#### Configuring a tag in code

We will configure a tag for the following behaviour:

 * Change app keys 1 and 2 to our own keys
 * Configure write access to NDEF data to need authentication with app key 1
 * Configure SDM to encrypt and sign data with key 2
 * Mirror encrypted PICC data (UID and read counter)
 * Mirror a CMAC for validation

```python
from pylibsdm.tag.ntag424dna import Tag

# We need a working tag object from nfcpy
nfc_tag = ...

# Configure the SDM tag object for communication
sdm_tag = Tag(nfc_tag)

# Set current master app key nr 0 for authentication
sdm_tag.set_key(0, b"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff")

# Change app keys 1 and 2 for later use
sdm_tag.change_key(1, 16 * b"\xaa")
sdm_tag.change_key(2, 16 * b"\xaa")

# Configure attributes for mirroring
file_option = FileOption(sdm_enabled=True, comm_mode=CommMode.PLAIN)
sdm_options = SDMOptions(
    uid=True,
    read_ctr=True,
    read_ctr_limit=False,
    enc_file_data=False,
    tt_status=False,
    ascii_encoding=True,
)

# We configure free reading access of NDEF, writing data is limited to app key 1,
#  and changing file settings to the master app key 0
access_rights = AccessRights(
    read=AccessCondition.FREE_ACCESS,
    write=AccessCondition.1,
    read_write=AccessCondition.KEY_1,
    change=AccessCondition.KEY_0,
)
# When reading the NDEF message, app key 2 is used for
sdm_acceess_rights = SDMAccessRights(
    file_read=AccessCondition.KEY_2,
    meta_read=AccessCondition.KEY_2,
    ctr_ret=AccessCondition.KEY_2,
)

# Aggregate options and offsets in NDEF data
file_settings = FileSettings(
    file_option=file_option,
    access_rights=access_rights,
    sdm_options=sdm_options,
    sdm_access_rights=sdm_acceess_rights,
    picc_data_offset=32,
    mac_offset=67,
    mac_input_offset=67,
)
sdm_tag.change_file_settings(2, file_settings)
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://codeberg.org/Bergblau/pylibsdm",
    "name": "pylibsdm",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "nfc,ntag424",
    "author": "Dominik George",
    "author_email": "nik@naturalnet.de",
    "download_url": "https://files.pythonhosted.org/packages/46/ae/5ba908011bab782f5be29ec928eedfb6ccf63349c2588d6e233c0e6f2b11/pylibsdm-1.0.0a0.dev2.tar.gz",
    "platform": null,
    "description": "<!--\nSPDX-FileCopyrightText: \u00a9 2023 Dominik George <nik@velocitux.com>\n\nSPDX-License-Identifier: LGPL-2.0-or-later\n-->\n\n# pylibsdm - NFC Secure Dynamic Messaging with Python\n\npylibsdm is a Python library (SDK) for handling Secure Dynamic Messaging (SDM)\nof NFC cards with Python.\n\nSecure Dynamic Messaging is a technology that adds security features to\nNFC tags using standard mechanisms. While standard NFC data (so-called\nNDEF messages, e.g. texts, URLs, etc.) can be written to any compatible\ntag, SUN-capable tags can cryptographically sign and optionally also\nencrypt parts of the data, which can then still be read by any standard\nNFC reader.\n\n## Features\n\n* Card management / configuration\n  * Configuration of NDEF file settings (mirrors, offsets, used keys,\u2026)\n  * Configuration of NDEF file data (URL)\n  * Provisioning of keys\n* Backend implementation for SUN (Secure Unique NFC)\n  * Decryption and validation of SDM data (mirrors)\n  * Validation of information from URI parameters\n\n## Supported tags\n\n* [NTAG 424 DNA](https://www.nxp.com/products/rfid-nfc/nfc-hf/ntag-for-tags-and-labels/ntag-424-dna-424-dna-tagtamper-advanced-security-and-privacy-for-trusted-iot-applications:NTAG424DNA)\n  ([specification](https://www.nxp.com/docs/en/application-note/AN12196.pdf))\n\n## Installation and usage\n\n`pylibsdm` is shipped as a standard Python library and cann be installed\nfrom PyPI:\n\n```sh\npip install \"pylibsdm[cli]\"\n```\n\nThe `cli` extra installs the `sdmutil` command-line utility, which can\nbe used as a stand-alone tool to handle tags.\n\n### Usage as a library in own code\n\nThe following examples show how to use `pylibsdm` within custom\napplications. It can, as such, be seen as an SDK for writing SUN-capable\napplications.\n\n#### Configuring a tag in code\n\nWe will configure a tag for the following behaviour:\n\n * Change app keys 1 and 2 to our own keys\n * Configure write access to NDEF data to need authentication with app key 1\n * Configure SDM to encrypt and sign data with key 2\n * Mirror encrypted PICC data (UID and read counter)\n * Mirror a CMAC for validation\n\n```python\nfrom pylibsdm.tag.ntag424dna import Tag\n\n# We need a working tag object from nfcpy\nnfc_tag = ...\n\n# Configure the SDM tag object for communication\nsdm_tag = Tag(nfc_tag)\n\n# Set current master app key nr 0 for authentication\nsdm_tag.set_key(0, b\"\\x00\\x11\\x22\\x33\\x44\\x55\\x66\\x77\\x88\\x99\\xaa\\xbb\\xcc\\xdd\\xee\\xff\")\n\n# Change app keys 1 and 2 for later use\nsdm_tag.change_key(1, 16 * b\"\\xaa\")\nsdm_tag.change_key(2, 16 * b\"\\xaa\")\n\n# Configure attributes for mirroring\nfile_option = FileOption(sdm_enabled=True, comm_mode=CommMode.PLAIN)\nsdm_options = SDMOptions(\n    uid=True,\n    read_ctr=True,\n    read_ctr_limit=False,\n    enc_file_data=False,\n    tt_status=False,\n    ascii_encoding=True,\n)\n\n# We configure free reading access of NDEF, writing data is limited to app key 1,\n#  and changing file settings to the master app key 0\naccess_rights = AccessRights(\n    read=AccessCondition.FREE_ACCESS,\n    write=AccessCondition.1,\n    read_write=AccessCondition.KEY_1,\n    change=AccessCondition.KEY_0,\n)\n# When reading the NDEF message, app key 2 is used for\nsdm_acceess_rights = SDMAccessRights(\n    file_read=AccessCondition.KEY_2,\n    meta_read=AccessCondition.KEY_2,\n    ctr_ret=AccessCondition.KEY_2,\n)\n\n# Aggregate options and offsets in NDEF data\nfile_settings = FileSettings(\n    file_option=file_option,\n    access_rights=access_rights,\n    sdm_options=sdm_options,\n    sdm_access_rights=sdm_acceess_rights,\n    picc_data_offset=32,\n    mac_offset=67,\n    mac_input_offset=67,\n)\nsdm_tag.change_file_settings(2, file_settings)\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python library for handling Secure Dynamic Messaging (SDM) of NFC cards like the NTAG 424 DNA",
    "version": "1.0.0a0.dev2",
    "project_urls": {
        "Homepage": "https://codeberg.org/Bergblau/pylibsdm",
        "Repository": "https://codeberg.org/Bergblau/pylibsdm"
    },
    "split_keywords": [
        "nfc",
        "ntag424"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "47d55e9fb6fdc91e6feb515c51f6fed4a18e4a6e78693fd49d2ef5c516c2da32",
                "md5": "1d12b466313cf9537e441d6392f1e41c",
                "sha256": "c5fe71439378f1acafb1d1f41365d90373d251aa2d045ca6ecda8988a2514879"
            },
            "downloads": -1,
            "filename": "pylibsdm-1.0.0a0.dev2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1d12b466313cf9537e441d6392f1e41c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 36142,
            "upload_time": "2023-07-02T19:15:14",
            "upload_time_iso_8601": "2023-07-02T19:15:14.305939Z",
            "url": "https://files.pythonhosted.org/packages/47/d5/5e9fb6fdc91e6feb515c51f6fed4a18e4a6e78693fd49d2ef5c516c2da32/pylibsdm-1.0.0a0.dev2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46ae5ba908011bab782f5be29ec928eedfb6ccf63349c2588d6e233c0e6f2b11",
                "md5": "27bf38721557749e6668a4f7c1c7ba92",
                "sha256": "7035d8e858c5aac458db6416b16fb4867cbf13e0fa490e534e6cab997e0362dd"
            },
            "downloads": -1,
            "filename": "pylibsdm-1.0.0a0.dev2.tar.gz",
            "has_sig": false,
            "md5_digest": "27bf38721557749e6668a4f7c1c7ba92",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 24818,
            "upload_time": "2023-07-02T19:15:15",
            "upload_time_iso_8601": "2023-07-02T19:15:15.879485Z",
            "url": "https://files.pythonhosted.org/packages/46/ae/5ba908011bab782f5be29ec928eedfb6ccf63349c2588d6e233c0e6f2b11/pylibsdm-1.0.0a0.dev2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-02 19:15:15",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": true,
    "codeberg_user": "Bergblau",
    "codeberg_project": "pylibsdm",
    "lcname": "pylibsdm"
}
        
Elapsed time: 0.08500s