|
1 |
| -import pybase64 |
2 | 1 | import json
|
3 | 2 | import ssl
|
4 | 3 | from threading import Event
|
5 | 4 | from typing import Union, Optional, Callable
|
6 | 5 |
|
7 |
| -import pgpy |
| 6 | +import pybase64 |
| 7 | +from Cryptodome.PublicKey import RSA |
8 | 8 | from ovos_bus_client import Message as MycroftMessage, MessageBusClient as OVOSBusClient
|
9 | 9 | from ovos_bus_client.session import Session
|
| 10 | +from ovos_utils.fakebus import FakeBus |
| 11 | +from ovos_utils.log import LOG |
10 | 12 | from pyee import EventEmitter
|
11 | 13 | from websocket import ABNF
|
12 | 14 | from websocket import WebSocketApp, WebSocketConnectionClosedException
|
|
17 | 19 | from hivemind_bus_client.serialization import get_bitstring, decode_bitstring
|
18 | 20 | from hivemind_bus_client.util import serialize_message, \
|
19 | 21 | encrypt_as_json, decrypt_from_json, encrypt_bin, decrypt_bin
|
20 |
| -from ovos_utils.log import LOG |
21 |
| -from ovos_utils.fakebus import FakeBus |
| 22 | +from poorman_handshake.asymmetric.utils import encrypt_RSA, load_RSA_key, sign_RSA |
22 | 23 |
|
23 | 24 |
|
24 | 25 | class BinaryDataCallbacks:
|
@@ -492,24 +493,15 @@ def wait_for_payload_response(self, message: Union[MycroftMessage, HiveMessage],
|
492 | 493 | self.emit(message)
|
493 | 494 | return waiter.wait(timeout)
|
494 | 495 |
|
495 |
| - # targeted messages for nodes, assymetric encryption |
| 496 | + # targeted messages for nodes, asymmetric encryption |
496 | 497 | def emit_intercom(self, message: Union[MycroftMessage, HiveMessage],
|
497 |
| - pubkey: Union[str, pgpy.PGPKey]): |
498 |
| - |
499 |
| - if isinstance(pubkey, str): |
500 |
| - pubkey, _ = pgpy.PGPKey.from_blob(pubkey) |
501 |
| - assert isinstance(pubkey, pgpy.PGPKey) |
502 |
| - |
503 |
| - txt = message.serialize() |
| 498 | + pubkey: Union[str, bytes, RSA.RsaKey]): |
504 | 499 |
|
505 |
| - text_message = pgpy.PGPMessage.new(txt) |
506 |
| - encrypted_message = pubkey.encrypt(text_message) |
| 500 | + encrypted_message = encrypt_RSA(pubkey, message.serialize()) |
507 | 501 |
|
508 | 502 | # sign message
|
509 |
| - with open(self.identity.private_key, "r") as f: |
510 |
| - private_key = pgpy.PGPKey.from_blob(f.read()) |
511 |
| - # the bitwise OR operator '|' is used to add a signature to a PGPMessage. |
512 |
| - encrypted_message |= private_key.sign(encrypted_message, |
513 |
| - intended_recipients=[pubkey]) |
| 503 | + private_key = load_RSA_key(self.identity.private_key) |
| 504 | + signature = sign_RSA(private_key, encrypted_message) |
514 | 505 |
|
515 |
| - self.emit(HiveMessage(HiveMessageType.INTERCOM, payload={"ciphertext": str(encrypted_message)})) |
| 506 | + self.emit(HiveMessage(HiveMessageType.INTERCOM, payload={"ciphertext": pybase64.b64encode(encrypted_message), |
| 507 | + "signature": pybase64.b64encode(signature)})) |
0 commit comments