Skip to main content

KeyNub License Dongle — Python binding

keynub-licdongle is a thin ctypes wrapper over the native keynub_licdongle core — no protocol or crypto logic in Python. Pure Python (no compiler needed at install); the native library is bundled per platform. Works on Windows, Linux, and macOS with no drivers.

Install

pip install keynub-licdongle

Use

import keynub_licdongle as kn

with kn.LicenseDongleContext() as ctx:
    for d in ctx.enumerate():
        print(d.serial, d.path)

    dongle = ctx.open()                    # first attached dongle (or open(serial=...))
    print(dongle.get_serial())

    result = dongle.verify_genuine()       # cert chain + live challenge-response
    print("genuine:", result.is_genuine)

    with dongle.open_session() as session:  # ECDH -> HKDF -> AES-256-GCM
        license = session.read_record("license")            # read role

        # Developer/provisioning tools elevate to the write role:
        session.authorize_write(master_key_der)
        session.write_record("license", new_bytes)

        # App-data envelope encryption — unusable without a genuine dongle:
        blob = session.app_encrypt(kn.Scope.DEVICE, plaintext)
        assert session.app_decrypt(blob) == plaintext
  • LicenseDongleContext — enumerate / open / logging (a context manager).
  • Dongle — get_info, get_serial, verify_genuine, open_session.
  • Session — records, counters, app-crypto, authorize_write.
  • Failures raise LicenseDongleError (with a .status); common cases have subclasses (NotGenuineError, WriteAuthorizationRequiredError, RecordNotFoundError, …).
  • read_record / write_record accept a progress callback (TransferProgress) -> bool; return False to cancel (raises OperationCancelledError).

Native library resolution

The binding loads, in order: $KEYNUB_LICDONGLE_LIBRARY (explicit path), the bundled keynub_licdongle/_libs/<lib>, a copy next to the package, then the system search path. Linux additionally needs the shipped udev rule (a permission rule, not a driver).

licd-tool — the command line

Installing the wheel also installs licd-tool, which drives the same production core an application would. Useful for licence issuance, for support ("what is this dongle and is it genuine?"), and for reproducing what an application sees without the application.

licd-tool list                                   # attached dongles
licd-tool info                                   # firmware, storage, provisioning state
licd-tool --trust-root ca.der verify             # prove it is genuine

# Anything inside a session needs --trust-root; anything that writes needs the
# developer master key.
licd-tool --trust-root ca.der records list
licd-tool --trust-root ca.der --master-key mk.der records write license lic.bin
licd-tool --trust-root ca.der records read license -o lic.bin
licd-tool --trust-root ca.der counter read

# Envelope-encrypt data so it only decrypts with a dongle attached.
licd-tool --trust-root ca.der appcrypto encrypt assets.bin -o assets.enc --scope developer
licd-tool --trust-root ca.der appcrypto decrypt assets.enc -o assets.bin

--json makes every command emit machine-readable output on stdout, so it drops into a licence-issuing script. Irreversible operations refuse to run without --yes: incrementing a monotonic counter cannot be undone, and records erase --all wipes the dongle. Record writes are read back and compared before the tool reports success, because a silent truncation would otherwise surface at the customer.

Factory provisioning is deliberately not in this tool — it lives with the CA in the firmware repo's tools/provision, is vendor-internal, and has irreversible steps.

Security

Read docs/integration-security.md before writing your licensing check. verify_genuine() proves a genuine dongle is attached; it cannot stop an attacker from patching your application or pointing KEYNUB_LICDONGLE_LIBRARY at a fake library. Branch on a boolean and you will be bypassed — put dongle-derived data (app_encrypt/app_decrypt) on the path your application actually needs.

License

Apache-2.0 — see LICENSE, NOTICE, and THIRD-PARTY-NOTICES.txt (all three ship inside the wheel, under .dist-info/licenses/). The bundled native statically links Mbed TLS (Apache-2.0 elected) and hidapi (BSD-style elected); no GPL terms apply.

Metadata

Release files for keynub-licdongle 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keynub-licdongle 1.1.1
File Size Uploaded
keynub_licdongle-1.1.1.tar.gz 31.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for keynub-licdongle 1.1.1
File
keynub_licdongle-1.1.1-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details
keynub_licdongle-1.1.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
keynub_licdongle-1.1.1-py3-none-win32.whl Python 3 none Windows x86-32 Details
keynub_licdongle-1.1.1-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details
keynub_licdongle-1.1.1-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details
keynub_licdongle-1.1.1-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details

Total release size: 834.3 kB

Release files / keynub_licdongle-1.1.1.tar.gz

Download URL keynub_licdongle-1.1.1.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
686d5b1cb589c82057064cbdfafd9d2ab030c2c753bd97a189ce0e8c6a9c2b86
BLAKE2b-256 checksum
How to use checksums
0d90f8c78c7da5ba1c47a46b1fbe81816e5e2ec600cb6d57deb3654b51137720
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / keynub_licdongle-1.1.1-py3-none-win_arm64.whl

Download URL keynub_licdongle-1.1.1-py3-none-win_arm64.whl
Size 103.1 kB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
3862b5e62736855dd0a3022cebf8f080cac58fc5ab7a281330cdca91075772b9
BLAKE2b-256 checksum
How to use checksums
2192390f7b49ce895a2c051c05759efd6f2068bdcf56c81f63325c6d377faa3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / keynub_licdongle-1.1.1-py3-none-win_amd64.whl

Download URL keynub_licdongle-1.1.1-py3-none-win_amd64.whl
Size 109.5 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
c0d68863d5d3471f205ca16d03da6470c747006e0222c0cd74346e98173eb661
BLAKE2b-256 checksum
How to use checksums
870efee83839a0aee1c334236e86224b2321a52062c76e625e1c8469d78a50fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / keynub_licdongle-1.1.1-py3-none-win32.whl

Download URL keynub_licdongle-1.1.1-py3-none-win32.whl
Size 90.0 kB
Tags Python 3 Windows x86-32
SHA-256 checksum
How to use checksums
aea33ea3b1c6dd356a8484d94191bce06cf0f7f62e161350ea2b2e638b8beb65
BLAKE2b-256 checksum
How to use checksums
8be273720bd103bd6e21677ced0ad06c55f7188c1f7d24075160472097ac94a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / keynub_licdongle-1.1.1-py3-none-manylinux_2_28_x86_64.whl

Download URL keynub_licdongle-1.1.1-py3-none-manylinux_2_28_x86_64.whl
Size 140.9 kB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
0c469836ad6a30f8e2fffa234c1b6d96a9b0b33ee415c1a107dc571908ad86d5
BLAKE2b-256 checksum
How to use checksums
688a7e4465ba369cb508c89abe9b760acc42b60b972736d105054d9e9fd07c9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / keynub_licdongle-1.1.1-py3-none-manylinux_2_28_aarch64.whl

Download URL keynub_licdongle-1.1.1-py3-none-manylinux_2_28_aarch64.whl
Size 139.8 kB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
df9a9bf26cb4fdf7a74a849b69448c82ebfe83907e211ac33f1005dcbb36190a
BLAKE2b-256 checksum
How to use checksums
592def123b4239fa54c7d08a8ac2de563a5130cc543727ada0f96dbc5c37a4fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / keynub_licdongle-1.1.1-py3-none-macosx_11_0_universal2.whl

Download URL keynub_licdongle-1.1.1-py3-none-macosx_11_0_universal2.whl
Size 219.4 kB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
287b233d809ced916b33724e131cac7cfa0eb8c4b4ece928b348a37ffd710a47
BLAKE2b-256 checksum
How to use checksums
39ba24e0d8b4ad658a238b5b9bde7ca75f5aca8b213939adb58b3c8072697e2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

1.1.1 This release

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page