3.0.ipv8.messaging.anonymization.crypto ======================================= .. py:module:: 3.0.ipv8.messaging.anonymization.crypto Exceptions ---------- .. autoapisummary:: 3.0.ipv8.messaging.anonymization.crypto.CryptoException Classes ------- .. autoapisummary:: 3.0.ipv8.messaging.anonymization.crypto.SessionKeys 3.0.ipv8.messaging.anonymization.crypto.CryptoEndpoint 3.0.ipv8.messaging.anonymization.crypto.PythonCryptoEndpoint 3.0.ipv8.messaging.anonymization.crypto.TunnelCrypto Module Contents --------------- .. py:class:: SessionKeys Session keys to communicate between hops. .. py:attribute:: key_forward :type: bytes .. py:attribute:: key_backward :type: bytes .. py:attribute:: salt_forward :type: bytes .. py:attribute:: salt_backward :type: bytes .. py:attribute:: salt_explicit_forward :type: int .. py:attribute:: salt_explicit_backward :type: int .. py:exception:: CryptoException Bases: :py:obj:`Exception` Exception for when anything goes wrong with sessions, encoding, and decoding. .. py:class:: CryptoEndpoint UDP endpoint capable of sending/relaying/exiting CellPayloads. .. py:attribute:: settings :type: 3.0.ipv8.messaging.anonymization.community.TunnelSettings | None :value: None .. py:attribute:: prefix .. py:attribute:: circuits :type: dict[int, 3.0.ipv8.messaging.anonymization.tunnel.Circuit] .. py:attribute:: relays :type: dict[int, 3.0.ipv8.messaging.anonymization.tunnel.RelayRoute] .. py:attribute:: exit_sockets :type: dict[int, 3.0.ipv8.messaging.anonymization.exit_socket.TunnelExitSocket] .. py:attribute:: logger .. py:method:: setup_tunnels(tunnel_community: 3.0.ipv8.messaging.anonymization.community.TunnelCommunity, settings: 3.0.ipv8.messaging.anonymization.community.TunnelSettings) -> None :abstractmethod: Set up the TunnelCommunity. .. py:method:: send_cell(target_addr: ipv8.types.Address, cell: 3.0.ipv8.messaging.anonymization.payload.CellPayload) -> None :abstractmethod: Send the given payload directly to the given peer with the appropriate encryption rules. .. py:class:: PythonCryptoEndpoint(endpoint: ipv8.types.Endpoint) Bases: :py:obj:`CryptoEndpoint`, :py:obj:`3.0.ipv8.messaging.interfaces.endpoint.EndpointListener` UDP endpoint capable of sending/relaying/exiting CellPayloads. .. py:attribute:: tunnel_community :type: 3.0.ipv8.messaging.anonymization.community.TunnelCommunity | None :value: None .. py:method:: setup_tunnels(tunnel_community: 3.0.ipv8.messaging.anonymization.community.TunnelCommunity, settings: 3.0.ipv8.messaging.anonymization.community.TunnelSettings) -> None Set up the TunnelCommunity. .. py:property:: max_relay_early :type: int Return the maximum number of relay_early cells that are allowed to pass a relay. .. py:method:: on_packet(packet: tuple[ipv8.types.Address, bytes], warn_unknown: bool = True) -> None Callback for when data is received on this endpoint. .. py:method:: send_cell(target_addr: ipv8.types.Address, cell: 3.0.ipv8.messaging.anonymization.payload.CellPayload) -> None Send the given payload directly to the given peer with the appropriate encryption rules. .. py:method:: process_cell(source_address: ipv8.types.Address, data: bytes) -> None Process incoming raw data, assumed to be a cell, originating from a given address. .. py:method:: relay_cell(cell: 3.0.ipv8.messaging.anonymization.payload.CellPayload) -> None Forward the given cell, which contains the information needed for its own relaying. .. py:method:: outgoing_crypto(cell: 3.0.ipv8.messaging.anonymization.payload.CellPayload) -> 3.0.ipv8.messaging.anonymization.payload.CellPayload | None Encrypt a CellPayload using the SessionKeys currently available in the routing table. .. py:method:: incoming_crypto(cell: 3.0.ipv8.messaging.anonymization.payload.CellPayload) -> 3.0.ipv8.messaging.anonymization.payload.CellPayload | None Decrypt a CellPayload using the SessionKeys currently available in the routing table. .. py:method:: encrypt_cell(cell: 3.0.ipv8.messaging.anonymization.payload.CellPayload, direction: int, *hops: 3.0.ipv8.messaging.anonymization.tunnel.Hop) -> None Encrypt a given cell. :raises CryptoException: if encryption failed. .. py:method:: decrypt_cell(cell: 3.0.ipv8.messaging.anonymization.payload.CellPayload, direction: int, *hops: 3.0.ipv8.messaging.anonymization.tunnel.Hop) -> None Decrypt a given cell. :raises CryptoException: if decryption failed. .. py:class:: TunnelCrypto Bases: :py:obj:`3.0.ipv8.keyvault.crypto.ECCrypto` Add Diffie-Hellman key establishment logic to ECCrypto. .. py:method:: initialize(key: 3.0.ipv8.keyvault.crypto.LibNaCLPK) -> None Make this ECCrypto fit for key establishment based on the given public key. .. py:method:: is_key_compatible(key: 3.0.ipv8.types.PublicKey) -> bool Whether the given key is a ``LibNaCLPK`` instance. .. py:method:: generate_diffie_secret() -> tuple[3.0.ipv8.keyvault.private.libnaclkey.LibNaCLSK, 3.0.ipv8.keyvault.crypto.LibNaCLPK] Create a new private-public keypair. .. py:method:: generate_diffie_shared_secret(dh_received: bytes, key: 3.0.ipv8.keyvault.crypto.LibNaCLPK | None = None) -> tuple[bytes, 3.0.ipv8.keyvault.crypto.LibNaCLPK, bytes] Generate the shared secret from the received string and the given key. .. py:method:: verify_and_generate_shared_secret(dh_secret: 3.0.ipv8.keyvault.private.libnaclkey.LibNaCLSK, dh_received: bytes, auth: bytes, b: bytes) -> bytes Generate the shared secret based on the response to the shared string and our own key. .. py:method:: generate_session_keys(shared_secret: bytes) -> SessionKeys Generate new session keys based on the shared secret. .. py:method:: encrypt_str(content: bytes, keys: SessionKeys, direction: int) -> bytes :staticmethod: Encrypt content using the given key, salt, and incremental session salt. .. py:method:: decrypt_str(content: bytes, keys: SessionKeys, direction: int) -> bytes :staticmethod: Decrypt the given content using a key and salt.