diff --git a/shadowsocks/obfsplugin/auth_chain.py b/shadowsocks/obfsplugin/auth_chain.py index ff0a812..c23a883 100644 --- a/shadowsocks/obfsplugin/auth_chain.py +++ b/shadowsocks/obfsplugin/auth_chain.py @@ -336,34 +336,35 @@ class auth_chain_a(auth_base): return data def pack_auth_data(self, auth_data, buf): - if len(buf) == 0: - return b'' - if len(buf) > 400: - rnd_len = struct.unpack(' 4: mac_key = self.user_key + struct.pack('= 8192 or length < 7: + data_len = struct.unpack('= 4096: self.raw_trans = True self.recv_buf = b'' raise Exception('client_post_decrypt data error') - if length > len(self.recv_buf): + + if length + 4 > len(self.recv_buf): break - if hmac.new(mac_key, self.recv_buf[:length - 4], self.hashfunc).digest()[:4] != self.recv_buf[length - 4:length]: + server_hash = hmac.new(mac_key, self.recv_buf[:length + 2], self.hashfunc).digest() + if server_hash[:2] != self.recv_buf[length + 2 : length + 4]: + logging.info('%s: checksum error, data %s' % (self.no_compatible_method, binascii.hexlify(self.recv_buf[:length]))) self.raw_trans = True self.recv_buf = b'' raise Exception('client_post_decrypt data uncorrect checksum') + pos = 2 + if data_len > 0 and rand_len > 0: + pos = 2 + self.rnd_start_pos(rand_len, self.random_server) + out_buf += self.encryptor.decrypt(self.recv_buf[pos : data_len + pos]) + self.last_server_hash = server_hash + if self.recv_id == 1: + self.server_info.tcp_mss = out_buf[:2] + out_buf = out_buf[2:] self.recv_id = (self.recv_id + 1) & 0xFFFFFFFF - pos = common.ord(self.recv_buf[4]) - if pos < 255: - pos += 4 - else: - pos = struct.unpack('