Skip to content

Commit bcc809e

Browse files
authored
Merge pull request #52 from JarbasHiveMind/release-0.2.0a1
Release 0.2.0a1
2 parents a15d7a2 + 1ef6782 commit bcc809e

File tree

11 files changed

+707
-119
lines changed

11 files changed

+707
-119
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Changelog
22

3-
## [0.1.6a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.1.6a1) (2025-01-01)
3+
## [0.2.0a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.2.0a1) (2025-01-03)
44

5-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.1.5...0.1.6a1)
5+
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.1.6...0.2.0a1)
66

77
**Merged pull requests:**
88

9-
- fix: dont leak session data / implement client HELLO [\#48](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/48) ([JarbasAl](https://github.com/JarbasAl))
9+
- feat:add chacha20 cipher + z85 encoding [\#50](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/50) ([JarbasAl](https://github.com/JarbasAl))
1010

1111

1212

hivemind_bus_client/client.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
from hivemind_bus_client.message import HiveMessage, HiveMessageType
1818
from hivemind_bus_client.serialization import HiveMindBinaryPayloadType
1919
from hivemind_bus_client.serialization import get_bitstring, decode_bitstring
20-
from hivemind_bus_client.util import serialize_message, \
21-
encrypt_as_json, decrypt_from_json, encrypt_bin, decrypt_bin
20+
from hivemind_bus_client.util import serialize_message
21+
from hivemind_bus_client.encryption import (encrypt_as_json, decrypt_from_json, encrypt_bin, decrypt_bin,
22+
SupportedEncodings, SupportedCiphers)
2223
from poorman_handshake.asymmetric.utils import encrypt_RSA, load_RSA_key, sign_RSA
2324

2425

@@ -104,6 +105,8 @@ def __init__(self, key: Optional[str] = None,
104105
internal_bus: Optional[OVOSBusClient] = None,
105106
bin_callbacks: BinaryDataCallbacks = BinaryDataCallbacks()):
106107
self.bin_callbacks = bin_callbacks
108+
self.json_encoding = SupportedEncodings.JSON_HEX # server defaults before it was made configurable
109+
self.cipher = SupportedCiphers.AES_GCM # server defaults before it was made configurable
107110

108111
self.identity = identity or None
109112
self._password = password
@@ -271,11 +274,12 @@ def on_message(self, *args):
271274
if self.crypto_key:
272275
# handle binary encryption
273276
if isinstance(message, bytes):
274-
message = decrypt_bin(self.crypto_key, message)
277+
message = decrypt_bin(self.crypto_key, message, cipher=self.cipher)
275278
# handle json encryption
276279
elif "ciphertext" in message:
277280
# LOG.debug(f"got encrypted message: {len(message)}")
278-
message = decrypt_from_json(self.crypto_key, message)
281+
message = decrypt_from_json(self.crypto_key, message,
282+
cipher=self.cipher, encoding=self.json_encoding)
279283
else:
280284
LOG.debug("Message was unencrypted")
281285

@@ -367,14 +371,15 @@ def emit(self, message: Union[MycroftMessage, HiveMessage],
367371
binary_type=binary_type,
368372
hivemeta=message.metadata)
369373
if self.crypto_key:
370-
ws_payload = encrypt_bin(self.crypto_key, bitstr.bytes)
374+
ws_payload = encrypt_bin(self.crypto_key, bitstr.bytes, cipher=self.cipher)
371375
else:
372376
ws_payload = bitstr.bytes
373377
self.client.send(ws_payload, ABNF.OPCODE_BINARY)
374378
else:
375379
ws_payload = serialize_message(message)
376380
if self.crypto_key:
377-
ws_payload = encrypt_as_json(self.crypto_key, ws_payload)
381+
ws_payload = encrypt_as_json(self.crypto_key, ws_payload,
382+
cipher=self.cipher, encoding=self.json_encoding)
378383
self.client.send(ws_payload)
379384

380385
except WebSocketConnectionClosedException:

0 commit comments

Comments
 (0)