Skip to content

Commit

Permalink
fix: INTERCOM messages RSA
Browse files Browse the repository at this point in the history
these were still using the removed pgpy
  • Loading branch information
JarbasAl committed Jan 1, 2025
1 parent 44fbad8 commit 15810a1
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hivemind_core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from enum import Enum, IntEnum
from typing import Union, List, Optional, Callable

import pgpy
from ovos_bus_client import MessageBusClient
from ovos_bus_client.message import Message
from ovos_bus_client.session import Session
from ovos_utils.fakebus import FakeBus
from ovos_utils.log import LOG
from poorman_handshake import HandShake, PasswordHandShake
from poorman_handshake.asymmetric.utils import verify_RSA, decrypt_RSA, encrypt_RSA, load_RSA_key

from hivemind_bus_client.identity import NodeIdentity
from hivemind_bus_client.message import HiveMessage, HiveMessageType, HiveMindBinaryPayloadType
Expand Down Expand Up @@ -671,12 +671,17 @@ def handle_intercom_message(
pload = message.payload
if isinstance(pload, dict) and "ciphertext" in pload:
try:
message_from_blob = pgpy.PGPMessage.from_blob(pload["ciphertext"])
from binascii import unhexlify
ciphertext = unhexlify(pload["ciphertext"])
signature = unhexlify(pload["signature"])

with open(self.identity.private_key, "r") as f:
private_key = pgpy.PGPKey.from_blob(f.read())
# TODO - allow verifying, we need to store trusted pubkeys before this can be done
#pub = ""
#verified = verify_RSA(pub, ciphertext, signature)

decrypted: str = private_key.decrypt(message_from_blob)
private_key = load_RSA_key(self.identity.private_key)

decrypted: str = decrypt_RSA(private_key, ciphertext).decode("utf-8")
message._payload = HiveMessage.deserialize(decrypted)
except:
if k:
Expand Down

0 comments on commit 15810a1

Please sign in to comment.