Skip to main content

USMP - Unified Secure Multi-transport Protocol. Secure, encrypted device communication for ESP32, Arduino and IoT.

Project description

USMP - Unified Secure Multi-transport Protocol

Secure, encrypted communication for ESP32, Arduino, and IoT devices.

USMP sits between raw sockets (no security) and full TLS/DTLS (too heavy for microcontrollers) - giving any constrained device a fully encrypted, mutually authenticated session in three function calls.

pip install usmp

What it gives you

  • Mutual authentication - both device and server verify each other via HMAC-SHA256 + PSK
  • Forward secrecy - X25519 ephemeral key exchange, new keys every session
  • Encryption - AES-256-GCM, mandatory, no plaintext mode
  • Replay protection - monotonic sequence numbers
  • Multiple Transports - Production-ready support for both TCP and UDP streams.

Quickstart

Server

import asyncio
from usmp import USMPServer, USMPSession, USMPProtocol, ConnectionClosedError

# Initialize server
server = USMPServer(host="0.0.0.0", port=9000, psk=b"your-psk-here", protocol=USMPProtocol.TCP)

@server.on_session
async def handle(session: USMPSession):
    print(f"Device connected: {session.device_id}")
    try:
        while True:
            data = await session.recv()
            print(f"RX: {data}")
            await session.send(b"got it")
    except ConnectionClosedError:
        print(f"Device disconnected: {session.device_id}")

async def main():
    await server.serve()

if __name__ == "__main__":
    asyncio.run(main())

Client (Python)

import asyncio
from usmp import USMPClient, USMPProtocol

async def main():
    # Initialize client
    client = USMPClient(host="127.0.0.1", port=9000, psk=b"your-psk-here", protocol=USMPProtocol.TCP)
    await client.connect()
    
    await client.send(b"hello")
    reply = await client.recv()
    print(f"RX: {reply}")
    
    await client.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

Client (Arduino ESP32)

#include <USMP.h>

USMPClient usmp("your-psk-here");

void setup() {
    // Connect using TCP or UDP
    usmp.begin(USMP::TCP("192.168.1.100").wifi("SSID", "password"));
    usmp.send("hello from esp32");
}

void loop() {
    usmp.maintain(); // keepalive + reconnect

    if (usmp.available()) {
        Serial.println(usmp.read());
    }
}

Protocol overview

Device                        Server
  |                              |
  |-- HELLO (device_id, pub_C) -->|
  |<- CHALLENGE (nonce, pub_S) ---|
  |-- HELLO_ACK (HMAC) ---------->|
  |<- SESSION_OK (session_id) ----|
  |                              |
  |== AES-256-GCM encrypted ======|

4-step handshake, then every frame is AES-256-GCM encrypted with a session key derived via X25519 + HKDF-SHA256.

Installation

pip install usmp

Requires Python 3.11+.

ESP32 / Arduino library

The Arduino library and ESP-IDF component are available directly through their respective package registries:

  • ESP-IDF Component: Add as a dependency by running idf.py add-dependency "metaloomlabs/usmp" in your project directory.
  • Arduino Library: Import the packaged release ZIP archive usmp-X.Y.Z-arduino.zip via SketchInclude LibraryAdd .ZIP Library...

USMP™ • Developed by Metaloom

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

usmp-0.5.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usmp-0.5.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file usmp-0.5.1.tar.gz.

File metadata

  • Download URL: usmp-0.5.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for usmp-0.5.1.tar.gz
Algorithm Hash digest
SHA256 780b7fbc467b2c748780ff1d96367f70bbc12def8daaf1dbeed85e42d4a54bb1
MD5 42c2918da50b51b1fe2e6cd302209d24
BLAKE2b-256 a1b54a5bd36d72e071c285e6bef34b1d3615591b5873c55d3d64d6fc4e64312c

See more details on using hashes here.

File details

Details for the file usmp-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: usmp-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for usmp-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 275959d34d58b1e8d385a6cc24836c6fd86a0d31c64b2bb6f0292ef4a746e6d0
MD5 e088859009a00756562784b57846990d
BLAKE2b-256 ab27c06b6735119b39266351a3f01add96d3ff623a8b3ada5143fabe3d93d4e1

See more details on using hashes here.

Supported by

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