libp2p.security.noise package

Subpackages

Submodules

libp2p.security.noise.exceptions module

exception libp2p.security.noise.exceptions.HandshakeHasNotFinished

Bases: NoiseFailure

exception libp2p.security.noise.exceptions.InvalidSignature

Bases: NoiseFailure

exception libp2p.security.noise.exceptions.NoiseFailure

Bases: HandshakeFailure

exception libp2p.security.noise.exceptions.NoiseStateError

Bases: NoiseFailure

Raised when anything goes wrong in the noise state in noiseprotocol package.

exception libp2p.security.noise.exceptions.PeerIDMismatchesPubkey

Bases: NoiseFailure

libp2p.security.noise.io module

class libp2p.security.noise.io.BaseNoiseMsgReadWriter(conn: IRawConnection, noise_state: NoiseConnection)

Bases: EncryptedMsgReadWriter

The base implementation of noise message reader/writer.

encrypt and decrypt are not implemented here, which should be implemented by the subclasses.

async close() None
noise_state: NoiseConnection
prefix: bytes = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
async read_msg(prefix_encoded: bool = False) bytes
read_writer: MsgReadWriteCloser
async write_msg(data: bytes, prefix_encoded: bool = False) None
class libp2p.security.noise.io.NoiseHandshakeReadWriter(conn: IRawConnection, noise_state: NoiseConnection)

Bases: BaseNoiseMsgReadWriter

decrypt(data: bytes) bytes
encrypt(data: bytes) bytes
class libp2p.security.noise.io.NoisePacketReadWriter(read_write_closer: ReadWriteCloser)

Bases: FixedSizeLenMsgReadWriter

size_len_bytes: int = 2
class libp2p.security.noise.io.NoiseTransportReadWriter(conn: IRawConnection, noise_state: NoiseConnection)

Bases: BaseNoiseMsgReadWriter

decrypt(data: bytes) bytes
encrypt(data: bytes) bytes

libp2p.security.noise.messages module

class libp2p.security.noise.messages.NoiseHandshakePayload(id_pubkey: libp2p.crypto.keys.PublicKey, id_sig: bytes, early_data: bytes = None)

Bases: object

classmethod deserialize(protobuf_bytes: bytes) NoiseHandshakePayload
early_data: bytes = None
id_pubkey: PublicKey
id_sig: bytes
serialize() bytes
libp2p.security.noise.messages.make_data_to_be_signed(noise_static_pubkey: PublicKey) bytes
libp2p.security.noise.messages.make_handshake_payload_sig(id_privkey: PrivateKey, noise_static_pubkey: PublicKey) bytes
libp2p.security.noise.messages.verify_handshake_payload_sig(payload: NoiseHandshakePayload, noise_static_pubkey: PublicKey) bool
Verify if the signature
  1. is composed of the data SIGNED_DATA_PREFIX`++`noise_static_pubkey and

  2. signed by the private key corresponding to id_pubkey

libp2p.security.noise.patterns module

class libp2p.security.noise.patterns.BasePattern

Bases: IPattern

create_noise_state() NoiseConnection
early_data: bytes
libp2p_privkey: PrivateKey
local_peer: ID
make_handshake_payload() NoiseHandshakePayload
noise_static_key: PrivateKey
protocol_name: bytes
class libp2p.security.noise.patterns.IPattern

Bases: ABC

abstract async handshake_inbound(conn: IRawConnection) ISecureConn
abstract async handshake_outbound(conn: IRawConnection, remote_peer: ID) ISecureConn
class libp2p.security.noise.patterns.PatternXX(local_peer: ID, libp2p_privkey: PrivateKey, noise_static_key: PrivateKey, early_data: bytes | None = None)

Bases: BasePattern

async handshake_inbound(conn: IRawConnection) ISecureConn
async handshake_outbound(conn: IRawConnection, remote_peer: ID) ISecureConn

libp2p.security.noise.transport module

class libp2p.security.noise.transport.Transport(libp2p_keypair: KeyPair, noise_privkey: PrivateKey | None = None, early_data: bytes | None = None, with_noise_pipes: bool = False)

Bases: ISecureTransport

early_data: bytes
get_pattern() IPattern
libp2p_privkey: PrivateKey
local_peer: ID
noise_privkey: PrivateKey
async secure_inbound(conn: IRawConnection) ISecureConn

Secure the connection, either locally or by communicating with opposing node via conn, for an inbound connection (i.e. we are not the initiator)

Returns:

secure connection object (that implements secure_conn_interface)

async secure_outbound(conn: IRawConnection, peer_id: ID) ISecureConn

Secure the connection, either locally or by communicating with opposing node via conn, for an inbound connection (i.e. we are the initiator)

Returns:

secure connection object (that implements secure_conn_interface)

with_noise_pipes: bool

Module contents