Registry / auth-security / noiseprotocol

noiseprotocol

JSON →
library0.3.1pypypiunverified

The `noiseprotocol` library provides a Python implementation of the Noise Protocol Framework (Revision 5), a widely used framework for building secure cryptographic protocols. It focuses on offering a robust and flexible API for performing handshakes and secure transport of data, supporting various handshake patterns and cipher suites. The current version is 0.3.1, and releases are infrequent, reflecting the stability of the underlying protocol.

pip install noiseprotocol
INSTALL
IMPORT
SIG · NOISEPROTOCOL
N
noiseprotocol
auth-securitypythonv0.3.1
Install
2.4s avg
Import
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 34.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 35MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HandshakeState
from noise.handshake import HandshakeState
from noise.handshake import HandshakeState
KeyPair
from noise.keypair import KeyPair
Noise
from noise import Noise

This example demonstrates a basic Noise Protocol handshake using the IK pattern, followed by secure transport of a message. It sets up an initiator and a responder, performs the handshake by exchanging messages, and then uses the resulting transport states to encrypt and decrypt a payload.

import secrets from noiseprotocol.constants import HandshakePattern, CipherSuite, NoiseConnectionRole from noiseprotocol.handshake import HandshakeState, Keypair # 1. Define static keys (can be pre-shared or generated once) initiator_static_key = Keypair(private=secrets.token_bytes(32)) responder_static_key = Keypair(private=secrets.token_bytes(32)) # 2. Setup Initiator initiator_hs = HandshakeState( role=NoiseConnectionRole.INITIATOR, pattern=HandshakePattern.IK, static_key=initiator_static_key, remote_static_key=responder_static_key.public, # Initiator knows Responder's public key cipher_suite=CipherSuite.AESGCM256_SHA256_X25519 ) initiator_hs.initialize() # 3. Setup Responder responder_hs = HandshakeState( role=NoiseConnectionRole.RESPONDER, pattern=HandshakePattern.IK, static_key=responder_static_key, cipher_suite=CipherSuite.AESGCM256_SHA256_X25519 ) responder_hs.initialize() # 4. Perform Handshake (simplified for example, messages would be sent over network) # Initiator sends first message message_initiator_to_responder, _ = initiator_hs.write_message(b"") # Responder receives message _, post_handshake_state_responder = responder_hs.read_message(message_initiator_to_responder) # Responder sends second message message_responder_to_initiator, _ = responder_hs.write_message(b"") # Initiator receives message _, post_handshake_state_initiator = initiator_hs.read_message(message_responder_to_initiator) # Handshake complete, now use post_handshake_state for transport if post_handshake_state_initiator and post_handshake_state_responder: plaintext = b"Hello, secure world!" ciphertext = post_handshake_state_initiator.write_message(plaintext) decrypted = post_handshake_state_responder.read_message(ciphertext) assert plaintext == decrypted print("Handshake and transport successful!") else: print("Handshake failed.")
Debug
Known issues
gotchaMismatch in HandshakePattern or CipherSuite between Initiator and Responder will prevent a successful handshake. Both sides must agree on these parameters.
fix
Ensure the `HandshakePattern` and `CipherSuite` provided to `HandshakeState` are identical for both the initiator and responder.
affects: All versions
gotchaKeypair management is crucial. Static private keys must be kept secret and ideally persisted for consistent peer identification. Ephemeral keys are generated per handshake.
fix
Do not regenerate static private keys for every connection. Securely store and load them. For testing, `secrets.token_bytes(32)` is acceptable, but for production, use a secure key generation and storage mechanism.
affects: All versions
gotchaThe library expects byte-like objects for all message payloads and key material. Passing strings directly without encoding will result in `TypeError`.
fix
Always encode strings to bytes (e.g., `"hello".encode('utf-8')`) before passing them to `write_message` or using them in key material.
affects: All versions
gotchaThe `read_message` and `write_message` methods return a tuple of `(payload, next_state)`. It's critical to use the `next_state` for subsequent message processing or transport, as the handshake state evolves.
fix
Always capture and use the `next_state` returned by these methods. For example, `_, post_handshake_state = responder_hs.read_message(...)` where `post_handshake_state` becomes your transport state.
affects: All versions
Upgrade
Version history
0.3.1latest on PyPI · released Mar 3, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
32 hits · last 30 days
node
28
Amazon
1
OpenAI (training)
1
Resources
noiseprotocol — pip install noiseprotocol · libregistry