libp2p.security package

Subpackages

Submodules

libp2p.security.base_session module

class libp2p.security.base_session.BaseSession(*, local_peer: ID, local_private_key: PrivateKey, remote_peer: ID, remote_permanent_pubkey: PublicKey, is_initiator: bool)

Bases: ISecureConn

BaseSession is not fully instantiated from its abstract classes as it is only meant to be used in clases that derive from it.

get_local_peer() ID
get_local_private_key() PrivateKey
get_remote_peer() ID
get_remote_public_key() PublicKey | None
local_peer: ID
local_private_key: PrivateKey
remote_peer: ID
remote_permanent_pubkey: PublicKey

libp2p.security.base_transport module

class libp2p.security.base_transport.BaseSecureTransport(local_key_pair: ~libp2p.crypto.keys.KeyPair, secure_bytes_provider: ~typing.Callable[[int], bytes] = <function default_secure_bytes_provider>)

Bases: ISecureTransport

BaseSecureTransport is not fully instantiated from its abstract classes as it is only meant to be used in clases that derive from it.

Clients can provide a strategy to get cryptographically secure bytes of a given length. A default implementation is provided using the secrets module from the standard library.

libp2p.security.base_transport.default_secure_bytes_provider(n: int) bytes

libp2p.security.exceptions module

exception libp2p.security.exceptions.HandshakeFailure

Bases: BaseLibp2pError

libp2p.security.secure_conn_interface module

class libp2p.security.secure_conn_interface.AbstractSecureConn

Bases: ABC

abstract get_local_peer() ID
abstract get_local_private_key() PrivateKey
abstract get_remote_peer() ID
abstract get_remote_public_key() PublicKey
class libp2p.security.secure_conn_interface.ISecureConn

Bases: AbstractSecureConn, IRawConnection

libp2p.security.secure_session module

class libp2p.security.secure_session.SecureSession(*, local_peer: ID, local_private_key: PrivateKey, remote_peer: ID, remote_permanent_pubkey: PublicKey, is_initiator: bool, conn: EncryptedMsgReadWriter)

Bases: BaseSession

buf: BytesIO
async close() None
high_watermark: int
low_watermark: int
async read(n: int | None = None) bytes
async write(data: bytes) None

libp2p.security.secure_transport_interface module

class libp2p.security.secure_transport_interface.ISecureTransport

Bases: ABC

abstract 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)

abstract 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)

libp2p.security.security_multistream module

class libp2p.security.security_multistream.SecurityMultistream(secure_transports_by_protocol: Mapping[TProtocol, ISecureTransport])

Bases: ABC

SSMuxer is a multistream stream security transport multiplexer.

Go implementation: github.com/libp2p/go-conn-security-multistream/ssms.go

add_transport(protocol: TProtocol, transport: ISecureTransport) None

Add a protocol and its corresponding transport to multistream- select(multiselect). The order that a protocol is added is exactly the precedence it is negotiated in multiselect.

Parameters:
  • protocol – the protocol name, which is negotiated in multiselect.

  • transport – the corresponding transportation to the protocol.

multiselect: Multiselect
multiselect_client: MultiselectClient
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)

async select_transport(conn: IRawConnection, is_initiator: bool) ISecureTransport

Select a transport that both us and the node on the other end of conn support and agree on.

Parameters:
  • conn – conn to choose a transport over

  • is_initiator – true if we are the initiator, false otherwise

Returns:

selected secure transport

transports: OrderedDict[TProtocol, ISecureTransport]

Module contents