libp2p.security.secio package

Subpackages

Submodules

libp2p.security.secio.exceptions module

exception libp2p.security.secio.exceptions.IncompatibleChoices

Bases: SecioException

exception libp2p.security.secio.exceptions.InconsistentNonce

Bases: SecioException

exception libp2p.security.secio.exceptions.InvalidSignatureOnExchange

Bases: SecioException

exception libp2p.security.secio.exceptions.PeerMismatchException

Bases: SecioException

exception libp2p.security.secio.exceptions.SecioException

Bases: HandshakeFailure

exception libp2p.security.secio.exceptions.SedesException

Bases: SecioException

exception libp2p.security.secio.exceptions.SelfEncryption

Bases: SecioException

Raised to indicate that a host is attempting to encrypt communications with itself.

libp2p.security.secio.transport module

class libp2p.security.secio.transport.EncryptionParameters

Bases: object

cipher_type: str
curve_type: str
ephemeral_public_key: PublicKey
hash_type: str
permanent_public_key: PublicKey
class libp2p.security.secio.transport.Proposal(nonce: bytes, public_key: PublicKey, exchanges: str = 'P-256', ciphers: str = 'AES-128', hashes: str = 'SHA256')

Bases: object

Represents the set of session parameters one peer in a pair of peers attempting to negotiate a secio channel prefers.

calculate_peer_id() ID
ciphers: str = 'AES-128'
classmethod deserialize(protobuf_bytes: bytes) Proposal
exchanges: str = 'P-256'
hashes: str = 'SHA256'
nonce: bytes
public_key: PublicKey
serialize() bytes
class libp2p.security.secio.transport.SecioMsgReadWriter(local_encryption_parameters: EncryptionParameters, remote_encryption_parameters: EncryptionParameters, read_writer: SecioPacketReadWriter)

Bases: EncryptedMsgReadWriter

async close() None
decrypt(data: bytes) bytes
encrypt(data: bytes) bytes
async read_msg() bytes
read_writer: SecioPacketReadWriter
async write_msg(msg: bytes) None
class libp2p.security.secio.transport.SecioPacketReadWriter(read_write_closer: ReadWriteCloser)

Bases: FixedSizeLenMsgReadWriter

size_len_bytes: int = 4
class libp2p.security.secio.transport.SessionParameters

Bases: object

local_encryption_parameters: EncryptionParameters
local_peer: ID
order: int
remote_encryption_parameters: EncryptionParameters
remote_peer: ID
shared_key: bytes
class libp2p.security.secio.transport.Transport(local_key_pair: ~libp2p.crypto.keys.KeyPair, secure_bytes_provider: ~typing.Callable[[int], bytes] = <function default_secure_bytes_provider>)

Bases: BaseSecureTransport

Provide a security upgrader for a IRawConnection, following the secio protocol defined in the libp2p specs.

get_nonce() bytes
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 libp2p.security.secio.transport.create_secure_session(local_nonce: bytes, local_peer: ID, local_private_key: PrivateKey, conn: IRawConnection, remote_peer: ID | None = None) ISecureConn

Attempt the initial secio handshake with the remote peer.

If successful, return an object that provides secure communication to the remote_peer. Raise SecioException when conn closed. Raise InconsistentNonce when handshake failed

Module contents