Supply local priv and pub key when upgrading to a secure transport

This commit is contained in:
Alex Stokes 2019-08-02 21:55:37 -07:00
parent 7942b7eaa7
commit 9e18d7561d
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086
3 changed files with 10 additions and 4 deletions

View File

@ -99,8 +99,11 @@ def initialize_default_swarm(
# TODO parse muxer and sec to pass into TransportUpgrader
muxer = muxer_opt or ["mplex/6.7.0"]
private_key_bytes = private_key.export_key("DER")
public_key_bytes = private_key.publickey().export_key("DER")
security_transports_by_protocol = sec_opt or {
TProtocol("insecure/1.0.0"): InsecureTransport(private_key_bytes)
TProtocol("insecure/1.0.0"): InsecureTransport(
private_key_bytes, public_key_bytes
)
}
upgrader = TransportUpgrader(security_transports_by_protocol, muxer)

View File

@ -8,6 +8,6 @@ class BaseSecureTransport(ISecureTransport):
is only meant to be used in clases that derive from it.
"""
def __init__(self, local_private_key: bytes) -> None:
def __init__(self, local_private_key: bytes, local_public_key: bytes) -> None:
self.local_private_key = local_private_key
self.local_peer = ID.from_privkey(local_private_key)
self.local_peer = ID.from_pubkey(local_public_key)

View File

@ -10,7 +10,10 @@ from libp2p.security.secure_conn_interface import ISecureConn
class SimpleSecurityTransport(BaseSecureTransport):
key_phrase: str
def __init__(self, key_phrase: str) -> None:
def __init__(
self, local_private_key: bytes, local_public_key: bytes, key_phrase: str
) -> None:
super().__init__(local_private_key, local_public_key)
self.key_phrase = key_phrase
async def secure_inbound(self, conn: IRawConnection) -> ISecureConn: