Verify the remote pubkey and peer_id

- Add `from_bytes` in RSAPublicKey and Secp256k1PublicKey
- Add `pubkey_from_protobuf` to parse pubkey from protobuf
- Verify key and peer_id in `InsecureSession.run_handshake`
This commit is contained in:
mhchia
2019-08-20 23:54:33 +08:00
parent ef476e555b
commit 921bfb65cc
5 changed files with 62 additions and 6 deletions

View File

@ -11,6 +11,11 @@ class RSAPublicKey(PublicKey):
def to_bytes(self) -> bytes:
return self.impl.export_key("DER")
@classmethod
def from_bytes(cls, key_bytes: bytes) -> "RSAPublicKey":
rsakey = RSA.import_key(key_bytes)
return cls(rsakey)
def get_type(self) -> KeyType:
return KeyType.RSA
@ -30,6 +35,11 @@ class RSAPrivateKey(PrivateKey):
def to_bytes(self) -> bytes:
return self.impl.export_key("DER")
@classmethod
def from_bytes(cls, key_bytes: bytes) -> "RSAPrivateKey":
rsakey = RSA.import_key(key_bytes)
return cls(rsakey)
def get_type(self) -> KeyType:
return KeyType.RSA