Skip to main content

Angaza Nexus backend libraries for managing PAYG devices

Project description

Nexus Python

This repository contains server-side code for managing devices using Nexus protocols, including Nexus Keycode.

Learn more about about Angaza Nexus here!

Installation

Nexus Keycode will be available on PyPI. Installation will be as simple as:

pip install nexus-keycode

This package comes with a full suite of unit tests, which you can run like so:

nose2

Versioning

Package Version

This package uses a form of semantic versioning. The version number is comprised of three components: MAJOR.MINOR.PATCH

Major version numbers represent breaking internal API changes. You may need to modify your code to accomodate these changes. Minor version numbers represent feature additions or changes that do not break the library's API, and are fully backward compatible. Patch version numbers represent bug fixes or minor changes that do not add additional functionality.

The package version is independent of the Nexus System Version that the package supports.

Usage

Generate keycodes for the full and small keypad protocols.

Full Protocol

Add Credit

secret_key = b"\xde\xad\xbe\xef" * 4
message = FullMessage.add_credit(
    id_=42, hours=24 * 7, secret_key=secret_key
).to_keycode()
# outputs *599 791 493 194 43#

Set Credit

message = FullMessage.set_credit(
    id_=43, hours=24 * 10, secret_key=secret_key
).to_keycode()
# outputs *682 070 357 093 12#

Unlock

message = FullMessage.unlock(id_=44, secret_key=secret_key).to_keycode()
# outputs *578 396 697 305 45#

Wipe

message = FullMessage.wipe_state(
    id_=45, flags=FullMessageWipeFlags.WIPE_IDS_ALL, secret_key=secret_key
).to_keycode()
# outputs *356 107 776 307 38#

Enabled/Disabled Test

message = FactoryFullMessage.oqc_test().to_keycode()
# outputs *577 043 3#

Factory Test

message = FactoryFullMessage.allow_test().to_keycode()
# outputs *406 498 3#

Display PAYG ID

message = FactoryFullMessage.display_payg_id().to_keycode()
# outputs *634 776 5#

Nexus Channel Origin Commands

These commands are accepted by Nexus Channel "Controller" devices using the "Full Protocol". Typically, these are used to manage the secured link state of "Controller" and "Accessory" devices.

See also: protocols/channel_origin_commands.py

Create Nexus Channel Secured Link

from nexus_keycode.protocols.full import FactoryFullMessage
from nexus_keycode.protocols.channel_origin_commands import ChannelOriginAction

message = FactoryFullMessage.passthrough_channel_origin_command(
	ChannelOriginAction.LINK_ACCESSORY_MODE_3,
    controller_command_count=5,
    accessory_command_count=2,
    accessory_sym_key=b"\xAB" * 16,
    controller_sym_key=b"\xCD" * 16,
)
message.to_keycode()
# outputs *817 307 500 565 772#

Delete Nexus Channel Secured Link (All Accessory Links)

from nexus_keycode.protocols.full import FactoryFullMessage
from nexus_keycode.protocols.channel_origin_commands import ChannelOriginAction

message = FactoryFullMessage.passthrough_channel_origin_command(
	ChannelOriginAction.UNLINK_ALL_ACCESSORIES,
    controller_command_count=7,
    controller_sym_key=b"\xCD" * 16,
)

message.to_keycode()
# outputs *810 023 592 81#

Small Protocol

Add Credit

SECRET_KEY = b"\xde\xad\xbe\xef" * 4
AddCreditSmallMessage(id_=42, days=7, secret_key=secret_key).to_keycode()
# outputs 135 242 422 455 244

Set Credit

SetCreditSmallMessage(id_=44, days=10, secret_key=secret_key).to_keycode()
# outputs 142 522 332 234 533

Unlock

UnlockSmallMessage(id_=45, secret_key=secret_key).to_keycode()
# outputs 152 323 254 454 322

Wipe Message IDs

MaintenanceSmallMessage(type_=MaintenanceSmallMessageType.WIPE_IDS_ALL, secret_key=secret_key).to_keycode()
# outputs 122 324 235 545 545

Wipe Custom "Restricted Flag"

CustomCommandSmallMessage(id_=46, type_=CustomCommandSmallMessageType.WIPE_RESTRICTED_FLAG, secret_key=secret_key).to_keycode()
# outputs 154 545 254 542 523

Set Credit + Wipe Custom "Restricted Flag"

# Creating a message of this type *may* lead to a 'message ID collision',
# meaning the message cannot be unambiguously interpreted by the unit
# (it might be mistaken for a different message if entered into the unit).
# If this occurs, an `ExtendedSmallMessageIdInvalidError` error will be raised.
# Typically incrementing the ID by 1 and creating the message again will
# succeed.

In [25]: ExtendedSmallMessage(id_=50, days=84, type_=ExtendedSmallMessageType.SET_CREDIT_WIPE_RESTRICTED_FLAG, secret_key=secret_key).to_keycode()
# raises `ExtendedSmallMessageIdInvalidError: ID 50 yields MAC collision, next valid ID is 51.`

In [26]: ExtendedSmallMessage(id_=51, days=84, type_=ExtendedSmallMessageType.SET_CREDIT_WIPE_RESTRICTED_FLAG, secret_key=secret_key).to_keycode()
# outputs 145 545 244 442 435

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nexus_keycode-1.5.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

nexus_keycode-1.5.1-py2.py3-none-any.whl (32.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nexus_keycode-1.5.1.tar.gz.

File metadata

  • Download URL: nexus_keycode-1.5.1.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/1.4.0 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.9

File hashes

Hashes for nexus_keycode-1.5.1.tar.gz
Algorithm Hash digest
SHA256 e0db086a4a731486cd0fdfe61cc3bbadf063649c681239c31e043e2d7ab03840
MD5 3e6973f4f6b75af0075b3f2a75eb805a
BLAKE2b-256 2d19d6b08a7c7f88bb16405026fcb0edff0535e4ba504546f7fec13d1ec87753

See more details on using hashes here.

File details

Details for the file nexus_keycode-1.5.1-py2.py3-none-any.whl.

File metadata

  • Download URL: nexus_keycode-1.5.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/1.4.0 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.9

File hashes

Hashes for nexus_keycode-1.5.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f17bfcb4a545ffd79166f997d075549913264636c9e266a0879614faafe7975f
MD5 54609179a379a29cdbb75a56f67da2c5
BLAKE2b-256 2ecbcb855df528300243bec7198a841f6062cfb224ce1e273895ff4ca30c3107

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page