kpdyer / fteproxy

programmable proxy for censorship circumvention
https://fteproxy.org/
Apache License 2.0
149 stars 21 forks source link

--key cli argument not working #189

Open yefkov opened 5 years ago

yefkov commented 5 years ago
Traceback (most recent call last):
  File "/root/fteproxy-master/fteproxy/cli.py", line 84, in run
    FTEMain.do_server(self)
  File "/root/fteproxy-master/fteproxy/cli.py", line 164, in do_server
    FTEMain.init_DfaEncoder(self, language)
  File "/root/fteproxy-master/fteproxy/cli.py", line 141, in init_DfaEncoder
    fixed_slice, K1, K2)
  File "/usr/local/lib/python2.7/dist-packages/fte/encoder.py", line 55, in __new__
    dfa, fixed_slice, K1, K2)
  File "/usr/local/lib/python2.7/dist-packages/fte/encoder.py", line 73, in __init__
    self._encrypter = fte.encrypter.Encrypter(K1, K2)
  File "/usr/local/lib/python2.7/dist-packages/fte/encrypter.py", line 79, in __init__
    raise InvalidKeyLengthError('each key must be 16 bytes long.')
InvalidKeyLengthError: each key must be 16 bytes long.
ERROR: FTEMain terminated unexpectedly: each key must be 16 bytes long.

in cli.py

class setConfValue(argparse.Action):
def __call__(self, parser, namespace, values, options_string):
.....
if self.dest is "key":
                if len(self.dest) != 64:
                    fteproxy.warn('Invalid key length: ' + str(len(self.dest))
                                  + ', should be 64')
                    sys.exit(1)
                try:
                    values = self.dest.decode('hex')
                except:
                    fteproxy.warn('Invalid key format, must contain only 0-9a-fA-F')
sys.exit(1)

Wrong use of "is" operator. We want to check value equality (==) not identity equality (is). Wrong use of "dest" attribute. len(self.dest) is always 3. The actual key value contains in "values" argument. self.dest.decode('hex') - not sure what exactly returns decode('hex') for text "key" but it's definetly not the right key.

kpdyer commented 5 years ago

Confirmed that this is indeed a problem. Thanks for reporting it! Looks like there aren't any tests that cover --key, either.

This project is mostly unmaintained but I'd be happy to review a pull request if you submit one.