Browse Source

revert encrypt.py

new obfs header
dev
breakwa11 9 years ago
parent
commit
61959945c3
  1. 17
      shadowsocks/common.py
  2. 4
      shadowsocks/encrypt.py
  3. 2
      shadowsocks/tcprelay.py

17
shadowsocks/common.py

@ -21,7 +21,7 @@ from __future__ import absolute_import, division, print_function, \
import socket import socket
import struct import struct
import logging import logging
import binascii
def compat_ord(s): def compat_ord(s):
if type(s) == int: if type(s) == int:
@ -160,6 +160,21 @@ def pre_parse_header(data):
'encryption method') 'encryption method')
return None return None
data = data[rand_data_size + 3:] data = data[rand_data_size + 3:]
elif datatype == 0x88:
if len(data) <= 7 + 7:
return None
data_size = struct.unpack('>H', data[1:3])[0]
ogn_data = data
data = data[:data_size]
crc = binascii.crc32(data) & 0xffffffff
if crc != 0xffffffff:
logging.warn('uncorrect CRC32, maybe wrong password or '
'encryption method')
return None
start_pos = 3 + ord(data[3])
data = data[start_pos:-4]
if data_size < len(ogn_data):
data += ogn_data[data_size:]
return data return data
def parse_header(data): def parse_header(data):

4
shadowsocks/encrypt.py

@ -21,7 +21,6 @@ import os
import sys import sys
import hashlib import hashlib
import logging import logging
import random
from shadowsocks import common from shadowsocks import common
from shadowsocks.crypto import rc4_md5, openssl, sodium, table from shadowsocks.crypto import rc4_md5, openssl, sodium, table
@ -35,10 +34,7 @@ method_supported.update(table.ciphers)
def random_string(length): def random_string(length):
try:
return os.urandom(length) return os.urandom(length)
except (AttributeError, NotImplementedError):
return ''.join(chr(random.randrange(255)) for _ in range(length))
cached_keys = {} cached_keys = {}

2
shadowsocks/tcprelay.py

@ -341,6 +341,8 @@ class TCPRelayHandler(object):
logging.error('unknown command %d', cmd) logging.error('unknown command %d', cmd)
self.destroy() self.destroy()
return return
if False and ord(data[0]) != 0x88: # force new header
raise Exception('can not parse header')
data = pre_parse_header(data) data = pre_parse_header(data)
if data is None: if data is None:
raise Exception('can not parse header') raise Exception('can not parse header')

Loading…
Cancel
Save