pyrad icon indicating copy to clipboard operation
pyrad copied to clipboard

Stop string decode errors on encrypted values by treating them as bytestrings

Open jeamland opened this issue 13 years ago • 3 comments

jeamland avatar Apr 16 '12 06:04 jeamland

I'm not sure what the problem is that you are trying to fix; I have not seen any decode errors so far.

In order for me to understand the problem you are running into and to prove that this change fixes that please add one or more tests that demonstrate the bug and the fix.

wichert avatar Apr 16 '12 08:04 wichert

So when running the example/server.py script (which required my commenting out the include directives since the files referenced weren't around), I then ran radtest from the freeradius package like so:

> radtest username password 127.0.0.1 0 Kah3choteereethiejeimaeziecumi

This results in the following:

Received an authentication request
Attributes: 
Message-Authenticator: ['.!5\x8fyd\xa9\xddNga\xb5\xdb\xfb\xff\xc7']
User-Name: [u'username']
Traceback (most recent call last):
  File "server.py", line 73, in <module>
    srv.Run()
  File "server.py", line 27, in Run
    self._ProcessInput(fdo)
  File "/private/tmp/pyrad/pyrad/server.py", line 221, in _ProcessInput
    self._HandleAuthPacket(pkt)
  File "server.py", line 48, in _HandleAuthPacket
    print "%s: %s" % (attr, pkt[attr])
  File "/private/tmp/pyrad/pyrad/packet.py", line 173, in __getitem__
    res.append(self._DecodeValue(attr, v))
  File "/private/tmp/pyrad/pyrad/packet.py", line 114, in _DecodeValue
    return tools.DecodeAttr(attr.type, value)
  File "/private/tmp/pyrad/pyrad/tools.py", line 79, in DecodeAttr
    return DecodeString(value)
  File "/private/tmp/pyrad/pyrad/tools.py", line 43, in DecodeString
    return str.decode('utf-8')
  File "/Users/benno/.virtualenvs/rad/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in position 0: invalid start byte

When looking at the dictionaries used by freeradius (dictionary.rfc2865), I found that the User-Password attribute had an encrypt=1 setting, so I made the assumption that this should be treated as bytes rather than a unicode string.

jeamland avatar Apr 17 '12 00:04 jeamland

ATTRIBUTE User-Password 2 string encrypt=1

I have get this problem,Can I delete “ encrypt=1”?

jamiesun avatar Sep 05 '12 09:09 jamiesun