From 9470d7866fc23eb1808472f435e2ea56cf220c8e Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Sun, 23 Apr 2017 19:55:58 +0300 Subject: [PATCH] Fix rsa_aes in stacked transport We have tricky situation here. Somehow postponed packets goes /before/ IV, and client get wrong IV setted up. Likely this happens because packets from client goes to the rpyc protocol processor before KEX complete, and response also goes before KEX complete. Because client initiate KEX by itself, there is no reason for any racy logic on the server end. So we'll just wait until something came to us, generate IV, and send in right order. --- pupy/network/lib/transports/rsa_aes.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pupy/network/lib/transports/rsa_aes.py b/pupy/network/lib/transports/rsa_aes.py index fb742248..015a74f0 100644 --- a/pupy/network/lib/transports/rsa_aes.py +++ b/pupy/network/lib/transports/rsa_aes.py @@ -43,10 +43,6 @@ class RSA_AESTransport(BasePupyTransport): self.size_to_read=None self.first_block=b"" - def on_connect(self): - self.downstream.write(self._iv_enc) # send IV - logging.debug("IV sent to Client") - def upstream_recv(self, data): try: cleartext=data.peek() @@ -133,7 +129,6 @@ class RSA_AESClient(RSA_AESTransport): logging.debug("IV sent to Server") - class RSA_AESServer(RSA_AESTransport): privkey=None privkey_path=None @@ -166,6 +161,9 @@ class RSA_AESServer(RSA_AESTransport): self.enc_cipher = NewAESCipher(self.aes_key, self._iv_enc) logging.debug("client AES key received && decrypted from RSA private key") + self.downstream.write(self._iv_enc) # send IV + logging.debug("IV sent to Client") + for f, args in self.post_handshake_callbacks: f(*args) self.post_handshake_callbacks=[] @@ -179,4 +177,3 @@ class RSA_AESServer(RSA_AESTransport): self.post_handshake_callbacks.append((self.upstream_recv, (data,))) return super(RSA_AESServer, self).upstream_recv(data) -