From c07178f43a492aa7f2fbc6244a07feb989ae049d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 11 Aug 2022 06:48:35 +0530 Subject: [PATCH] Avoid transmitting the currently un-needed enc_proto --- docs/rc_protocol.rst | 1 - kitty/remote_control.py | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/rc_protocol.rst b/docs/rc_protocol.rst index beab33a28..3d49c7870 100644 --- a/docs/rc_protocol.rst +++ b/docs/rc_protocol.rst @@ -65,7 +65,6 @@ command is created and transmitted that contains the fields: "iv": "base85 encoded IV", "tag": "base85 encoded AEAD tag", "pubkey": "base85 encoded ECDH public key of sender", - "enc_proto": "The first field from KITTY_PUBLIC_KEY, currently always 1", "encrypted": "The original command encrypted and base85 encoded" } diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 17c9ebb4e..2e02c601f 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -48,7 +48,7 @@ def parse_cmd(serialized_cmd: str, encryption_key: EllipticCurveKey) -> Dict[str return {} pcmd.pop('password', None) if 'encrypted' in pcmd: - if pcmd.get('enc_proto') != RC_ENCRYPTION_PROTOCOL_VERSION: + if pcmd.get('enc_proto', '1') != RC_ENCRYPTION_PROTOCOL_VERSION: log_error(f'Ignoring encrypted rc command with unsupported protocol: {pcmd.get("enc_proto")}') return {} pubkey = pcmd.get('pubkey', '') @@ -353,10 +353,13 @@ class CommandEncrypter: cmd['password'] = self.password raw = json.dumps(cmd).encode('utf-8') encrypted = encrypter.add_data_to_be_encrypted(raw, True) - return { + ans = { 'version': version, 'iv': encode_as_base85(encrypter.iv), 'tag': encode_as_base85(encrypter.tag), - 'pubkey': encode_as_base85(self.pubkey), 'encrypted': encode_as_base85(encrypted), 'enc_proto': self.encryption_version + 'pubkey': encode_as_base85(self.pubkey), 'encrypted': encode_as_base85(encrypted), } + if self.encryption_version != '1': + ans['enc_proto'] = self.encryption_version + return ans def adjust_response_timeout_for_password(self, response_timeout: float) -> float: return max(response_timeout, 120)