mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
run lint and fix errors, except mypy
This commit is contained in:
@ -1,13 +1,24 @@
|
||||
from typing import Optional
|
||||
from typing import (
|
||||
Optional,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.security.secure_conn_interface import (
|
||||
ISecureConn,
|
||||
)
|
||||
|
||||
|
||||
class BaseSession(ISecureConn):
|
||||
"""``BaseSession`` is not fully instantiated from its abstract classes as
|
||||
it is only meant to be used in clases that derive from it."""
|
||||
"""
|
||||
``BaseSession`` is not fully instantiated from its abstract classes as
|
||||
it is only meant to be used in clases that derive from it.
|
||||
"""
|
||||
|
||||
local_peer: ID
|
||||
local_private_key: PrivateKey
|
||||
|
||||
@ -1,9 +1,17 @@
|
||||
import secrets
|
||||
from typing import Callable
|
||||
from typing import (
|
||||
Callable,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import KeyPair
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.security.secure_transport_interface import (
|
||||
ISecureTransport,
|
||||
)
|
||||
|
||||
|
||||
def default_secure_bytes_provider(n: int) -> bytes:
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
from libp2p.exceptions import BaseLibp2pError
|
||||
from libp2p.exceptions import (
|
||||
BaseLibp2pError,
|
||||
)
|
||||
|
||||
|
||||
class HandshakeFailure(BaseLibp2pError):
|
||||
|
||||
@ -2,12 +2,13 @@
|
||||
# source: libp2p/security/insecure/pb/plaintext.proto
|
||||
|
||||
import sys
|
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||
|
||||
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1"))
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
from google.protobuf import descriptor_pb2
|
||||
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
@ -17,62 +18,89 @@ from libp2p.crypto.pb import crypto_pb2 as libp2p_dot_crypto_dot_pb_dot_crypto__
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
name='libp2p/security/insecure/pb/plaintext.proto',
|
||||
package='plaintext.pb',
|
||||
syntax='proto2',
|
||||
serialized_pb=_b('\n+libp2p/security/insecure/pb/plaintext.proto\x12\x0cplaintext.pb\x1a\x1dlibp2p/crypto/pb/crypto.proto\"<\n\x08\x45xchange\x12\n\n\x02id\x18\x01 \x01(\x0c\x12$\n\x06pubkey\x18\x02 \x01(\x0b\x32\x14.crypto.pb.PublicKey')
|
||||
,
|
||||
dependencies=[libp2p_dot_crypto_dot_pb_dot_crypto__pb2.DESCRIPTOR,])
|
||||
|
||||
|
||||
name="libp2p/security/insecure/pb/plaintext.proto",
|
||||
package="plaintext.pb",
|
||||
syntax="proto2",
|
||||
serialized_pb=_b(
|
||||
'\n+libp2p/security/insecure/pb/plaintext.proto\x12\x0cplaintext.pb\x1a\x1dlibp2p/crypto/pb/crypto.proto"<\n\x08\x45xchange\x12\n\n\x02id\x18\x01 \x01(\x0c\x12$\n\x06pubkey\x18\x02 \x01(\x0b\x32\x14.crypto.pb.PublicKey'
|
||||
),
|
||||
dependencies=[
|
||||
libp2p_dot_crypto_dot_pb_dot_crypto__pb2.DESCRIPTOR,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
_EXCHANGE = _descriptor.Descriptor(
|
||||
name='Exchange',
|
||||
full_name='plaintext.pb.Exchange',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='id', full_name='plaintext.pb.Exchange.id', index=0,
|
||||
number=1, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='pubkey', full_name='plaintext.pb.Exchange.pubkey', index=1,
|
||||
number=2, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=92,
|
||||
serialized_end=152,
|
||||
name="Exchange",
|
||||
full_name="plaintext.pb.Exchange",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="id",
|
||||
full_name="plaintext.pb.Exchange.id",
|
||||
index=0,
|
||||
number=1,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="pubkey",
|
||||
full_name="plaintext.pb.Exchange.pubkey",
|
||||
index=1,
|
||||
number=2,
|
||||
type=11,
|
||||
cpp_type=10,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=None,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=92,
|
||||
serialized_end=152,
|
||||
)
|
||||
|
||||
_EXCHANGE.fields_by_name['pubkey'].message_type = libp2p_dot_crypto_dot_pb_dot_crypto__pb2._PUBLICKEY
|
||||
DESCRIPTOR.message_types_by_name['Exchange'] = _EXCHANGE
|
||||
_EXCHANGE.fields_by_name[
|
||||
"pubkey"
|
||||
].message_type = libp2p_dot_crypto_dot_pb_dot_crypto__pb2._PUBLICKEY
|
||||
DESCRIPTOR.message_types_by_name["Exchange"] = _EXCHANGE
|
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||
|
||||
Exchange = _reflection.GeneratedProtocolMessageType('Exchange', (_message.Message,), dict(
|
||||
DESCRIPTOR = _EXCHANGE,
|
||||
__module__ = 'libp2p.security.insecure.pb.plaintext_pb2'
|
||||
# @@protoc_insertion_point(class_scope:plaintext.pb.Exchange)
|
||||
))
|
||||
Exchange = _reflection.GeneratedProtocolMessageType(
|
||||
"Exchange",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
DESCRIPTOR=_EXCHANGE,
|
||||
__module__="libp2p.security.insecure.pb.plaintext_pb2"
|
||||
# @@protoc_insertion_point(class_scope:plaintext.pb.Exchange)
|
||||
),
|
||||
)
|
||||
_sym_db.RegisterMessage(Exchange)
|
||||
|
||||
|
||||
|
||||
@ -20,26 +20,35 @@ from typing_extensions import (
|
||||
Literal as typing_extensions___Literal,
|
||||
)
|
||||
|
||||
|
||||
class Exchange(google___protobuf___message___Message):
|
||||
DESCRIPTOR: google___protobuf___descriptor___Descriptor = ...
|
||||
id = ... # type: bytes
|
||||
id = ... # type: bytes
|
||||
|
||||
@property
|
||||
def pubkey(self) -> libp2p___crypto___pb___crypto_pb2___PublicKey: ...
|
||||
|
||||
def __init__(self,
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
id : typing___Optional[bytes] = None,
|
||||
pubkey : typing___Optional[libp2p___crypto___pb___crypto_pb2___PublicKey] = None,
|
||||
) -> None: ...
|
||||
id: typing___Optional[bytes] = None,
|
||||
pubkey: typing___Optional[libp2p___crypto___pb___crypto_pb2___PublicKey] = None,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def FromString(cls, s: bytes) -> Exchange: ...
|
||||
def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
if sys.version_info >= (3,):
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"id",u"pubkey"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"id",u"pubkey"]) -> None: ...
|
||||
def HasField(
|
||||
self, field_name: typing_extensions___Literal["id", "pubkey"]
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self, field_name: typing_extensions___Literal["id", "pubkey"]
|
||||
) -> None: ...
|
||||
else:
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"id",b"id",u"pubkey",b"pubkey"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"id",b"id",u"pubkey",b"pubkey"]) -> None: ...
|
||||
def HasField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal["id", b"id", "pubkey", b"pubkey"],
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal["id", b"id", "pubkey", b"pubkey"],
|
||||
) -> None: ...
|
||||
|
||||
@ -1,21 +1,52 @@
|
||||
from libp2p.crypto.exceptions import MissingDeserializerError
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.crypto.pb import crypto_pb2
|
||||
from libp2p.crypto.serialization import deserialize_public_key
|
||||
from libp2p.io.abc import ReadWriteCloser
|
||||
from libp2p.io.msgio import VarIntLengthMsgReadWriter
|
||||
from libp2p.network.connection.exceptions import RawConnError
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.base_session import BaseSession
|
||||
from libp2p.security.base_transport import BaseSecureTransport
|
||||
from libp2p.security.exceptions import HandshakeFailure
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p.crypto.exceptions import (
|
||||
MissingDeserializerError,
|
||||
)
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
from libp2p.crypto.pb import (
|
||||
crypto_pb2,
|
||||
)
|
||||
from libp2p.crypto.serialization import (
|
||||
deserialize_public_key,
|
||||
)
|
||||
from libp2p.io.abc import (
|
||||
ReadWriteCloser,
|
||||
)
|
||||
from libp2p.io.msgio import (
|
||||
VarIntLengthMsgReadWriter,
|
||||
)
|
||||
from libp2p.network.connection.exceptions import (
|
||||
RawConnError,
|
||||
)
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.security.base_session import (
|
||||
BaseSession,
|
||||
)
|
||||
from libp2p.security.base_transport import (
|
||||
BaseSecureTransport,
|
||||
)
|
||||
from libp2p.security.exceptions import (
|
||||
HandshakeFailure,
|
||||
)
|
||||
from libp2p.security.secure_conn_interface import (
|
||||
ISecureConn,
|
||||
)
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
from .pb import plaintext_pb2
|
||||
from .pb import (
|
||||
plaintext_pb2,
|
||||
)
|
||||
|
||||
# Reference: https://github.com/libp2p/go-libp2p-core/blob/master/sec/insecure/insecure.go
|
||||
# Reference: https://github.com/libp2p/go-libp2p-core/blob/master/sec/insecure/insecure.go # noqa: E501
|
||||
|
||||
|
||||
PLAINTEXT_PROTOCOL_ID = TProtocol("/plaintext/2.0.0")
|
||||
@ -120,9 +151,10 @@ async def run_handshake(
|
||||
|
||||
|
||||
class InsecureTransport(BaseSecureTransport):
|
||||
"""``InsecureTransport`` provides the "identity" upgrader for a
|
||||
``IRawConnection``, i.e. the upgraded transport does not add any additional
|
||||
security."""
|
||||
"""
|
||||
Provides the "identity" upgrader for a ``IRawConnection``, i.e. the upgraded
|
||||
transport does not add any additional security.
|
||||
"""
|
||||
|
||||
async def secure_inbound(self, conn: IRawConnection) -> ISecureConn:
|
||||
"""
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
from libp2p.security.exceptions import HandshakeFailure
|
||||
from libp2p.security.exceptions import (
|
||||
HandshakeFailure,
|
||||
)
|
||||
|
||||
|
||||
class NoiseFailure(HandshakeFailure):
|
||||
@ -14,8 +16,10 @@ class InvalidSignature(NoiseFailure):
|
||||
|
||||
|
||||
class NoiseStateError(NoiseFailure):
|
||||
"""Raised when anything goes wrong in the noise state in `noiseprotocol`
|
||||
package."""
|
||||
"""
|
||||
Raised when anything goes wrong in the noise state in `noiseprotocol`
|
||||
package.
|
||||
"""
|
||||
|
||||
|
||||
class PeerIDMismatchesPubkey(NoiseFailure):
|
||||
|
||||
@ -1,10 +1,20 @@
|
||||
from typing import cast
|
||||
from typing import (
|
||||
cast,
|
||||
)
|
||||
|
||||
from noise.connection import NoiseConnection as NoiseState
|
||||
|
||||
from libp2p.io.abc import EncryptedMsgReadWriter, MsgReadWriteCloser, ReadWriteCloser
|
||||
from libp2p.io.msgio import FixedSizeLenMsgReadWriter
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.io.abc import (
|
||||
EncryptedMsgReadWriter,
|
||||
MsgReadWriteCloser,
|
||||
ReadWriteCloser,
|
||||
)
|
||||
from libp2p.io.msgio import (
|
||||
FixedSizeLenMsgReadWriter,
|
||||
)
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
|
||||
SIZE_NOISE_MESSAGE_LEN = 2
|
||||
MAX_NOISE_MESSAGE_LEN = 2 ** (8 * SIZE_NOISE_MESSAGE_LEN) - 1
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import (
|
||||
dataclass,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.crypto.serialization import deserialize_public_key
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
from libp2p.crypto.serialization import (
|
||||
deserialize_public_key,
|
||||
)
|
||||
|
||||
from .pb import noise_pb2 as noise_pb
|
||||
|
||||
|
||||
@ -1,16 +1,34 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives import (
|
||||
serialization,
|
||||
)
|
||||
from noise.backends.default.keypairs import KeyPair as NoiseKeyPair
|
||||
from noise.connection import Keypair as NoiseKeypairEnum
|
||||
from noise.connection import NoiseConnection as NoiseState
|
||||
|
||||
from libp2p.crypto.ed25519 import Ed25519PublicKey
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.security.secure_session import SecureSession
|
||||
from libp2p.crypto.ed25519 import (
|
||||
Ed25519PublicKey,
|
||||
)
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.security.secure_conn_interface import (
|
||||
ISecureConn,
|
||||
)
|
||||
from libp2p.security.secure_session import (
|
||||
SecureSession,
|
||||
)
|
||||
|
||||
from .exceptions import (
|
||||
HandshakeHasNotFinished,
|
||||
@ -18,7 +36,10 @@ from .exceptions import (
|
||||
NoiseStateError,
|
||||
PeerIDMismatchesPubkey,
|
||||
)
|
||||
from .io import NoiseHandshakeReadWriter, NoiseTransportReadWriter
|
||||
from .io import (
|
||||
NoiseHandshakeReadWriter,
|
||||
NoiseTransportReadWriter,
|
||||
)
|
||||
from .messages import (
|
||||
NoiseHandshakePayload,
|
||||
make_handshake_payload_sig,
|
||||
@ -95,8 +116,8 @@ class PatternXX(BasePattern):
|
||||
if handshake_state.rs is None:
|
||||
raise NoiseStateError(
|
||||
"something is wrong in the underlying noise `handshake_state`: "
|
||||
"we received and consumed msg#3, which should have included the"
|
||||
" remote static public key, but it is not present in the handshake_state"
|
||||
"we received and consumed msg#3, which should have included the "
|
||||
"remote static public key, but it is not present in the handshake_state"
|
||||
)
|
||||
remote_pubkey = self._get_pubkey_from_noise_keypair(handshake_state.rs)
|
||||
|
||||
@ -139,8 +160,8 @@ class PatternXX(BasePattern):
|
||||
if handshake_state.rs is None:
|
||||
raise NoiseStateError(
|
||||
"something is wrong in the underlying noise `handshake_state`: "
|
||||
"we received and consumed msg#3, which should have included the"
|
||||
" remote static public key, but it is not present in the handshake_state"
|
||||
"we received and consumed msg#3, which should have included the "
|
||||
"remote static public key, but it is not present in the handshake_state"
|
||||
)
|
||||
remote_pubkey = self._get_pubkey_from_noise_keypair(handshake_state.rs)
|
||||
|
||||
|
||||
@ -2,81 +2,114 @@
|
||||
# source: libp2p/security/noise/pb/noise.proto
|
||||
|
||||
import sys
|
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||
|
||||
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1"))
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
from google.protobuf import descriptor_pb2
|
||||
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
name='libp2p/security/noise/pb/noise.proto',
|
||||
package='pb',
|
||||
syntax='proto3',
|
||||
serialized_pb=_b('\n$libp2p/security/noise/pb/noise.proto\x12\x02pb\"Q\n\x15NoiseHandshakePayload\x12\x14\n\x0cidentity_key\x18\x01 \x01(\x0c\x12\x14\n\x0cidentity_sig\x18\x02 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c\x62\x06proto3')
|
||||
name="libp2p/security/noise/pb/noise.proto",
|
||||
package="pb",
|
||||
syntax="proto3",
|
||||
serialized_pb=_b(
|
||||
'\n$libp2p/security/noise/pb/noise.proto\x12\x02pb"Q\n\x15NoiseHandshakePayload\x12\x14\n\x0cidentity_key\x18\x01 \x01(\x0c\x12\x14\n\x0cidentity_sig\x18\x02 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c\x62\x06proto3'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
_NOISEHANDSHAKEPAYLOAD = _descriptor.Descriptor(
|
||||
name='NoiseHandshakePayload',
|
||||
full_name='pb.NoiseHandshakePayload',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='identity_key', full_name='pb.NoiseHandshakePayload.identity_key', index=0,
|
||||
number=1, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='identity_sig', full_name='pb.NoiseHandshakePayload.identity_sig', index=1,
|
||||
number=2, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='data', full_name='pb.NoiseHandshakePayload.data', index=2,
|
||||
number=3, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=44,
|
||||
serialized_end=125,
|
||||
name="NoiseHandshakePayload",
|
||||
full_name="pb.NoiseHandshakePayload",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="identity_key",
|
||||
full_name="pb.NoiseHandshakePayload.identity_key",
|
||||
index=0,
|
||||
number=1,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="identity_sig",
|
||||
full_name="pb.NoiseHandshakePayload.identity_sig",
|
||||
index=1,
|
||||
number=2,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="data",
|
||||
full_name="pb.NoiseHandshakePayload.data",
|
||||
index=2,
|
||||
number=3,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto3",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=44,
|
||||
serialized_end=125,
|
||||
)
|
||||
|
||||
DESCRIPTOR.message_types_by_name['NoiseHandshakePayload'] = _NOISEHANDSHAKEPAYLOAD
|
||||
DESCRIPTOR.message_types_by_name["NoiseHandshakePayload"] = _NOISEHANDSHAKEPAYLOAD
|
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||
|
||||
NoiseHandshakePayload = _reflection.GeneratedProtocolMessageType('NoiseHandshakePayload', (_message.Message,), dict(
|
||||
DESCRIPTOR = _NOISEHANDSHAKEPAYLOAD,
|
||||
__module__ = 'libp2p.security.noise.pb.noise_pb2'
|
||||
# @@protoc_insertion_point(class_scope:pb.NoiseHandshakePayload)
|
||||
))
|
||||
NoiseHandshakePayload = _reflection.GeneratedProtocolMessageType(
|
||||
"NoiseHandshakePayload",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
DESCRIPTOR=_NOISEHANDSHAKEPAYLOAD,
|
||||
__module__="libp2p.security.noise.pb.noise_pb2"
|
||||
# @@protoc_insertion_point(class_scope:pb.NoiseHandshakePayload)
|
||||
),
|
||||
)
|
||||
_sym_db.RegisterMessage(NoiseHandshakePayload)
|
||||
|
||||
|
||||
|
||||
@ -16,24 +16,39 @@ from typing_extensions import (
|
||||
Literal as typing_extensions___Literal,
|
||||
)
|
||||
|
||||
|
||||
class NoiseHandshakePayload(google___protobuf___message___Message):
|
||||
DESCRIPTOR: google___protobuf___descriptor___Descriptor = ...
|
||||
identity_key = ... # type: bytes
|
||||
identity_sig = ... # type: bytes
|
||||
data = ... # type: bytes
|
||||
identity_key = ... # type: bytes
|
||||
identity_sig = ... # type: bytes
|
||||
data = ... # type: bytes
|
||||
|
||||
def __init__(self,
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
identity_key : typing___Optional[bytes] = None,
|
||||
identity_sig : typing___Optional[bytes] = None,
|
||||
data : typing___Optional[bytes] = None,
|
||||
) -> None: ...
|
||||
identity_key: typing___Optional[bytes] = None,
|
||||
identity_sig: typing___Optional[bytes] = None,
|
||||
data: typing___Optional[bytes] = None,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def FromString(cls, s: bytes) -> NoiseHandshakePayload: ...
|
||||
def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
if sys.version_info >= (3,):
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"data",u"identity_key",u"identity_sig"]) -> None: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"data", "identity_key", "identity_sig"
|
||||
],
|
||||
) -> None: ...
|
||||
else:
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"data",b"data",u"identity_key",b"identity_key",u"identity_sig",b"identity_sig"]) -> None: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"data",
|
||||
b"data",
|
||||
"identity_key",
|
||||
b"identity_key",
|
||||
"identity_sig",
|
||||
b"identity_sig",
|
||||
],
|
||||
) -> None: ...
|
||||
|
||||
@ -1,11 +1,27 @@
|
||||
from libp2p.crypto.keys import KeyPair, PrivateKey
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
PrivateKey,
|
||||
)
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.security.secure_conn_interface import (
|
||||
ISecureConn,
|
||||
)
|
||||
from libp2p.security.secure_transport_interface import (
|
||||
ISecureTransport,
|
||||
)
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
from .patterns import IPattern, PatternXX
|
||||
from .patterns import (
|
||||
IPattern,
|
||||
PatternXX,
|
||||
)
|
||||
|
||||
PROTOCOL_ID = TProtocol("/noise")
|
||||
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
from libp2p.security.exceptions import HandshakeFailure
|
||||
from libp2p.security.exceptions import (
|
||||
HandshakeFailure,
|
||||
)
|
||||
|
||||
|
||||
class SecioException(HandshakeFailure):
|
||||
@ -6,10 +8,10 @@ class SecioException(HandshakeFailure):
|
||||
|
||||
|
||||
class SelfEncryption(SecioException):
|
||||
"""Raised to indicate that a host is attempting to encrypt communications
|
||||
with itself."""
|
||||
|
||||
pass
|
||||
"""
|
||||
Raised to indicate that a host is attempting to encrypt communications
|
||||
with itself.
|
||||
"""
|
||||
|
||||
|
||||
class PeerMismatchException(SecioException):
|
||||
|
||||
@ -13,4 +13,4 @@ message Propose {
|
||||
message Exchange {
|
||||
optional bytes ephemeral_public_key = 1;
|
||||
optional bytes signature = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,143 +1,221 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: libp2p/security/secio/pb/spipe.proto
|
||||
|
||||
import sys
|
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||
|
||||
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1"))
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
name='libp2p/security/secio/pb/spipe.proto',
|
||||
package='spipe.pb',
|
||||
syntax='proto2',
|
||||
serialized_options=None,
|
||||
serialized_pb=_b('\n$libp2p/security/secio/pb/spipe.proto\x12\x08spipe.pb\"_\n\x07Propose\x12\x0c\n\x04rand\x18\x01 \x01(\x0c\x12\x12\n\npublic_key\x18\x02 \x01(\x0c\x12\x11\n\texchanges\x18\x03 \x01(\t\x12\x0f\n\x07\x63iphers\x18\x04 \x01(\t\x12\x0e\n\x06hashes\x18\x05 \x01(\t\";\n\x08\x45xchange\x12\x1c\n\x14\x65phemeral_public_key\x18\x01 \x01(\x0c\x12\x11\n\tsignature\x18\x02 \x01(\x0c')
|
||||
name="libp2p/security/secio/pb/spipe.proto",
|
||||
package="spipe.pb",
|
||||
syntax="proto2",
|
||||
serialized_options=None,
|
||||
serialized_pb=_b(
|
||||
'\n$libp2p/security/secio/pb/spipe.proto\x12\x08spipe.pb"_\n\x07Propose\x12\x0c\n\x04rand\x18\x01 \x01(\x0c\x12\x12\n\npublic_key\x18\x02 \x01(\x0c\x12\x11\n\texchanges\x18\x03 \x01(\t\x12\x0f\n\x07\x63iphers\x18\x04 \x01(\t\x12\x0e\n\x06hashes\x18\x05 \x01(\t";\n\x08\x45xchange\x12\x1c\n\x14\x65phemeral_public_key\x18\x01 \x01(\x0c\x12\x11\n\tsignature\x18\x02 \x01(\x0c'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
_PROPOSE = _descriptor.Descriptor(
|
||||
name='Propose',
|
||||
full_name='spipe.pb.Propose',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='rand', full_name='spipe.pb.Propose.rand', index=0,
|
||||
number=1, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='public_key', full_name='spipe.pb.Propose.public_key', index=1,
|
||||
number=2, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='exchanges', full_name='spipe.pb.Propose.exchanges', index=2,
|
||||
number=3, type=9, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='ciphers', full_name='spipe.pb.Propose.ciphers', index=3,
|
||||
number=4, type=9, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='hashes', full_name='spipe.pb.Propose.hashes', index=4,
|
||||
number=5, type=9, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=50,
|
||||
serialized_end=145,
|
||||
name="Propose",
|
||||
full_name="spipe.pb.Propose",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="rand",
|
||||
full_name="spipe.pb.Propose.rand",
|
||||
index=0,
|
||||
number=1,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="public_key",
|
||||
full_name="spipe.pb.Propose.public_key",
|
||||
index=1,
|
||||
number=2,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="exchanges",
|
||||
full_name="spipe.pb.Propose.exchanges",
|
||||
index=2,
|
||||
number=3,
|
||||
type=9,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b("").decode("utf-8"),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="ciphers",
|
||||
full_name="spipe.pb.Propose.ciphers",
|
||||
index=3,
|
||||
number=4,
|
||||
type=9,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b("").decode("utf-8"),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="hashes",
|
||||
full_name="spipe.pb.Propose.hashes",
|
||||
index=4,
|
||||
number=5,
|
||||
type=9,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b("").decode("utf-8"),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=50,
|
||||
serialized_end=145,
|
||||
)
|
||||
|
||||
|
||||
_EXCHANGE = _descriptor.Descriptor(
|
||||
name='Exchange',
|
||||
full_name='spipe.pb.Exchange',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='ephemeral_public_key', full_name='spipe.pb.Exchange.ephemeral_public_key', index=0,
|
||||
number=1, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='signature', full_name='spipe.pb.Exchange.signature', index=1,
|
||||
number=2, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=147,
|
||||
serialized_end=206,
|
||||
name="Exchange",
|
||||
full_name="spipe.pb.Exchange",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="ephemeral_public_key",
|
||||
full_name="spipe.pb.Exchange.ephemeral_public_key",
|
||||
index=0,
|
||||
number=1,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="signature",
|
||||
full_name="spipe.pb.Exchange.signature",
|
||||
index=1,
|
||||
number=2,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=147,
|
||||
serialized_end=206,
|
||||
)
|
||||
|
||||
DESCRIPTOR.message_types_by_name['Propose'] = _PROPOSE
|
||||
DESCRIPTOR.message_types_by_name['Exchange'] = _EXCHANGE
|
||||
DESCRIPTOR.message_types_by_name["Propose"] = _PROPOSE
|
||||
DESCRIPTOR.message_types_by_name["Exchange"] = _EXCHANGE
|
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||
|
||||
Propose = _reflection.GeneratedProtocolMessageType('Propose', (_message.Message,), {
|
||||
'DESCRIPTOR' : _PROPOSE,
|
||||
'__module__' : 'libp2p.security.secio.pb.spipe_pb2'
|
||||
# @@protoc_insertion_point(class_scope:spipe.pb.Propose)
|
||||
})
|
||||
Propose = _reflection.GeneratedProtocolMessageType(
|
||||
"Propose",
|
||||
(_message.Message,),
|
||||
{
|
||||
"DESCRIPTOR": _PROPOSE,
|
||||
"__module__": "libp2p.security.secio.pb.spipe_pb2"
|
||||
# @@protoc_insertion_point(class_scope:spipe.pb.Propose)
|
||||
},
|
||||
)
|
||||
_sym_db.RegisterMessage(Propose)
|
||||
|
||||
Exchange = _reflection.GeneratedProtocolMessageType('Exchange', (_message.Message,), {
|
||||
'DESCRIPTOR' : _EXCHANGE,
|
||||
'__module__' : 'libp2p.security.secio.pb.spipe_pb2'
|
||||
# @@protoc_insertion_point(class_scope:spipe.pb.Exchange)
|
||||
})
|
||||
Exchange = _reflection.GeneratedProtocolMessageType(
|
||||
"Exchange",
|
||||
(_message.Message,),
|
||||
{
|
||||
"DESCRIPTOR": _EXCHANGE,
|
||||
"__module__": "libp2p.security.secio.pb.spipe_pb2"
|
||||
# @@protoc_insertion_point(class_scope:spipe.pb.Exchange)
|
||||
},
|
||||
)
|
||||
_sym_db.RegisterMessage(Exchange)
|
||||
|
||||
|
||||
|
||||
@ -17,51 +17,116 @@ from typing_extensions import (
|
||||
Literal as typing_extensions___Literal,
|
||||
)
|
||||
|
||||
|
||||
class Propose(google___protobuf___message___Message):
|
||||
DESCRIPTOR: google___protobuf___descriptor___Descriptor = ...
|
||||
rand = ... # type: bytes
|
||||
public_key = ... # type: bytes
|
||||
exchanges = ... # type: typing___Text
|
||||
ciphers = ... # type: typing___Text
|
||||
hashes = ... # type: typing___Text
|
||||
rand = ... # type: bytes
|
||||
public_key = ... # type: bytes
|
||||
exchanges = ... # type: typing___Text
|
||||
ciphers = ... # type: typing___Text
|
||||
hashes = ... # type: typing___Text
|
||||
|
||||
def __init__(self,
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
rand : typing___Optional[bytes] = None,
|
||||
public_key : typing___Optional[bytes] = None,
|
||||
exchanges : typing___Optional[typing___Text] = None,
|
||||
ciphers : typing___Optional[typing___Text] = None,
|
||||
hashes : typing___Optional[typing___Text] = None,
|
||||
) -> None: ...
|
||||
rand: typing___Optional[bytes] = None,
|
||||
public_key: typing___Optional[bytes] = None,
|
||||
exchanges: typing___Optional[typing___Text] = None,
|
||||
ciphers: typing___Optional[typing___Text] = None,
|
||||
hashes: typing___Optional[typing___Text] = None,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def FromString(cls, s: bytes) -> Propose: ...
|
||||
def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
if sys.version_info >= (3,):
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"ciphers",u"exchanges",u"hashes",u"public_key",u"rand"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"ciphers",u"exchanges",u"hashes",u"public_key",u"rand"]) -> None: ...
|
||||
def HasField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"ciphers", "exchanges", "hashes", "public_key", "rand"
|
||||
],
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"ciphers", "exchanges", "hashes", "public_key", "rand"
|
||||
],
|
||||
) -> None: ...
|
||||
else:
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"ciphers",b"ciphers",u"exchanges",b"exchanges",u"hashes",b"hashes",u"public_key",b"public_key",u"rand",b"rand"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"ciphers",b"ciphers",u"exchanges",b"exchanges",u"hashes",b"hashes",u"public_key",b"public_key",u"rand",b"rand"]) -> None: ...
|
||||
def HasField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"ciphers",
|
||||
b"ciphers",
|
||||
"exchanges",
|
||||
b"exchanges",
|
||||
"hashes",
|
||||
b"hashes",
|
||||
"public_key",
|
||||
b"public_key",
|
||||
"rand",
|
||||
b"rand",
|
||||
],
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"ciphers",
|
||||
b"ciphers",
|
||||
"exchanges",
|
||||
b"exchanges",
|
||||
"hashes",
|
||||
b"hashes",
|
||||
"public_key",
|
||||
b"public_key",
|
||||
"rand",
|
||||
b"rand",
|
||||
],
|
||||
) -> None: ...
|
||||
|
||||
class Exchange(google___protobuf___message___Message):
|
||||
DESCRIPTOR: google___protobuf___descriptor___Descriptor = ...
|
||||
ephemeral_public_key = ... # type: bytes
|
||||
signature = ... # type: bytes
|
||||
ephemeral_public_key = ... # type: bytes
|
||||
signature = ... # type: bytes
|
||||
|
||||
def __init__(self,
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
ephemeral_public_key : typing___Optional[bytes] = None,
|
||||
signature : typing___Optional[bytes] = None,
|
||||
) -> None: ...
|
||||
ephemeral_public_key: typing___Optional[bytes] = None,
|
||||
signature: typing___Optional[bytes] = None,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def FromString(cls, s: bytes) -> Exchange: ...
|
||||
def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
if sys.version_info >= (3,):
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"ephemeral_public_key",u"signature"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"ephemeral_public_key",u"signature"]) -> None: ...
|
||||
def HasField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"ephemeral_public_key", "signature"
|
||||
],
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"ephemeral_public_key", "signature"
|
||||
],
|
||||
) -> None: ...
|
||||
else:
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"ephemeral_public_key",b"ephemeral_public_key",u"signature",b"signature"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"ephemeral_public_key",b"ephemeral_public_key",u"signature",b"signature"]) -> None: ...
|
||||
def HasField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"ephemeral_public_key",
|
||||
b"ephemeral_public_key",
|
||||
"signature",
|
||||
b"signature",
|
||||
],
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"ephemeral_public_key",
|
||||
b"ephemeral_public_key",
|
||||
"signature",
|
||||
b"signature",
|
||||
],
|
||||
) -> None: ...
|
||||
|
||||
@ -1,31 +1,66 @@
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import (
|
||||
dataclass,
|
||||
)
|
||||
import itertools
|
||||
from typing import Optional, Tuple
|
||||
from typing import (
|
||||
Optional,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
import multihash
|
||||
|
||||
from libp2p.crypto.authenticated_encryption import (
|
||||
EncryptionParameters as AuthenticatedEncryptionParameters,
|
||||
)
|
||||
from libp2p.crypto.authenticated_encryption import (
|
||||
InvalidMACException,
|
||||
)
|
||||
from libp2p.crypto.authenticated_encryption import (
|
||||
initialize_pair as initialize_pair_for_encryption,
|
||||
)
|
||||
from libp2p.crypto.authenticated_encryption import InvalidMACException
|
||||
from libp2p.crypto.authenticated_encryption import MacAndCipher as Encrypter
|
||||
from libp2p.crypto.ecc import ECCPublicKey
|
||||
from libp2p.crypto.exceptions import MissingDeserializerError
|
||||
from libp2p.crypto.key_exchange import create_ephemeral_key_pair
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.crypto.serialization import deserialize_public_key
|
||||
from libp2p.io.abc import EncryptedMsgReadWriter
|
||||
from libp2p.io.exceptions import DecryptionFailedException, IOException
|
||||
from libp2p.io.msgio import FixedSizeLenMsgReadWriter
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.crypto.ecc import (
|
||||
ECCPublicKey,
|
||||
)
|
||||
from libp2p.crypto.exceptions import (
|
||||
MissingDeserializerError,
|
||||
)
|
||||
from libp2p.crypto.key_exchange import (
|
||||
create_ephemeral_key_pair,
|
||||
)
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
from libp2p.crypto.serialization import (
|
||||
deserialize_public_key,
|
||||
)
|
||||
from libp2p.io.abc import (
|
||||
EncryptedMsgReadWriter,
|
||||
)
|
||||
from libp2p.io.exceptions import (
|
||||
DecryptionFailedException,
|
||||
IOException,
|
||||
)
|
||||
from libp2p.io.msgio import (
|
||||
FixedSizeLenMsgReadWriter,
|
||||
)
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
from libp2p.peer.id import ID as PeerID
|
||||
from libp2p.security.base_transport import BaseSecureTransport
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.security.secure_session import SecureSession
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p.security.base_transport import (
|
||||
BaseSecureTransport,
|
||||
)
|
||||
from libp2p.security.secure_conn_interface import (
|
||||
ISecureConn,
|
||||
)
|
||||
from libp2p.security.secure_session import (
|
||||
SecureSession,
|
||||
)
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
from .exceptions import (
|
||||
IncompatibleChoices,
|
||||
@ -36,7 +71,10 @@ from .exceptions import (
|
||||
SedesException,
|
||||
SelfEncryption,
|
||||
)
|
||||
from .pb.spipe_pb2 import Exchange, Propose
|
||||
from .pb.spipe_pb2 import (
|
||||
Exchange,
|
||||
Propose,
|
||||
)
|
||||
|
||||
ID = TProtocol("/secio/1.0.0")
|
||||
|
||||
@ -101,8 +139,10 @@ class SecioMsgReadWriter(EncryptedMsgReadWriter):
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Proposal:
|
||||
"""A ``Proposal`` represents the set of session parameters one peer in a
|
||||
pair of peers attempting to negotiate a `secio` channel prefers."""
|
||||
"""
|
||||
Represents the set of session parameters one peer in a
|
||||
pair of peers attempting to negotiate a `secio` channel prefers.
|
||||
"""
|
||||
|
||||
nonce: bytes
|
||||
public_key: PublicKey
|
||||
@ -401,8 +441,10 @@ async def create_secure_session(
|
||||
|
||||
|
||||
class Transport(BaseSecureTransport):
|
||||
"""``Transport`` provides a security upgrader for a ``IRawConnection``,
|
||||
following the `secio` protocol defined in the libp2p specs."""
|
||||
"""
|
||||
Provide a security upgrader for a ``IRawConnection``,
|
||||
following the `secio` protocol defined in the libp2p specs.
|
||||
"""
|
||||
|
||||
def get_nonce(self) -> bytes:
|
||||
return self.secure_bytes_provider(NONCE_SIZE)
|
||||
|
||||
@ -1,13 +1,22 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
|
||||
"""
|
||||
Represents a secured connection object, which includes a connection and details about the security
|
||||
involved in the secured connection
|
||||
Represents a secured connection object, which includes a connection and details about
|
||||
the security involved in the secured connection
|
||||
|
||||
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
|
||||
"""
|
||||
|
||||
@ -1,9 +1,18 @@
|
||||
import io
|
||||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.io.abc import EncryptedMsgReadWriter
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.base_session import BaseSession
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
from libp2p.io.abc import (
|
||||
EncryptedMsgReadWriter,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.security.base_session import (
|
||||
BaseSession,
|
||||
)
|
||||
|
||||
|
||||
class SecureSession(BaseSession):
|
||||
@ -39,7 +48,7 @@ class SecureSession(BaseSession):
|
||||
|
||||
def _drain(self, n: int) -> bytes:
|
||||
if self.low_watermark == self.high_watermark:
|
||||
return bytes()
|
||||
return b""
|
||||
|
||||
data = self.buf.getbuffer()[self.low_watermark : self.high_watermark]
|
||||
|
||||
@ -61,7 +70,7 @@ class SecureSession(BaseSession):
|
||||
|
||||
async def read(self, n: int = None) -> bytes:
|
||||
if n == 0:
|
||||
return bytes()
|
||||
return b""
|
||||
|
||||
data_from_buffer = self._drain(n)
|
||||
if len(data_from_buffer) > 0:
|
||||
|
||||
@ -1,9 +1,17 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.security.secure_conn_interface import (
|
||||
ISecureConn,
|
||||
)
|
||||
|
||||
"""
|
||||
Transport that is used to secure a connection. This transport is
|
||||
|
||||
@ -1,20 +1,41 @@
|
||||
from abc import ABC
|
||||
from collections import OrderedDict
|
||||
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.protocol_muxer.multiselect import Multiselect
|
||||
from libp2p.protocol_muxer.multiselect_client import MultiselectClient
|
||||
from libp2p.protocol_muxer.multiselect_communicator import MultiselectCommunicator
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
from libp2p.transport.typing import TSecurityOptions
|
||||
from libp2p.typing import TProtocol
|
||||
from abc import (
|
||||
ABC,
|
||||
)
|
||||
from collections import (
|
||||
OrderedDict,
|
||||
)
|
||||
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.protocol_muxer.multiselect import (
|
||||
Multiselect,
|
||||
)
|
||||
from libp2p.protocol_muxer.multiselect_client import (
|
||||
MultiselectClient,
|
||||
)
|
||||
from libp2p.protocol_muxer.multiselect_communicator import (
|
||||
MultiselectCommunicator,
|
||||
)
|
||||
from libp2p.security.secure_conn_interface import (
|
||||
ISecureConn,
|
||||
)
|
||||
from libp2p.security.secure_transport_interface import (
|
||||
ISecureTransport,
|
||||
)
|
||||
from libp2p.transport.typing import (
|
||||
TSecurityOptions,
|
||||
)
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
"""
|
||||
Represents a secured connection object, which includes a connection and details about the security
|
||||
involved in the secured connection
|
||||
Represents a secured connection object, which includes a connection and details about
|
||||
the security involved in the secured connection
|
||||
|
||||
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user