skimpax / fbxosctrl

Shell tool to control some Freebox OS stuff: wifi, reboot...
GNU General Public License v3.0
29 stars 10 forks source link

HMAC problem ? #2

Closed ravelou closed 10 years ago

ravelou commented 10 years ago

This is the code I get when I try to set the Wifi off :

>>> setWifiOff
>>> _setWifiStatus
>>> _login
>>> isRegistered
>>> hasRegistrationParams
>>> _loadRegistrationParams: file: fbxosctrl_registration.txt
>>> getRegistrationStatus
>>> hasRegistrationParams
http://mafreebox.freebox.fr/api/v1/login/authorize/1
GET url: http://mafreebox.freebox.fr/api/v1/login/authorize/1
GET response: {"success":true,"result":{"status":"granted","challenge":"rF7pTgHX8flUZ9TFqa6+Yr\/+0N0yCO3M","password_salt":"KpDAqdZIgRdDX7IXKqkFccT4taWFZ8+Y"}}
GET url: http://mafreebox.freebox.fr/api/v1/login/
GET response: {"success":true,"result":{"logged_in":false,"challenge":"rF7pTgHX8flUZ9TFqa6+Yr\/+0N0yCO3M","password_salt":"KpDAqdZIgRdDX7IXKqkFccT4taWFZ8+Y"}}
challenge: rF7pTgHX8flUZ9TFqa6+Yr/+0N0yCO3M, apptoken: a4a7K0S5iPwboVUaWmfalFd3/pHoYYawljcAvhHzRBn3dZD9gM6rAX5lMXZRElZI
Traceback (most recent call last):
  File "fbxosctrl.py", line 467, in <module>
    rc = cli.cmdExec(sys.argv[1:])
  File "fbxosctrl.py", line 454, in cmdExec
    return self.dispatch(argsdict.keys())
  File "fbxosctrl.py", line 461, in dispatch
    return self.cmdCallbacks.get(cmd, self.parser.print_help)()
  File "fbxosctrl.py", line 397, in setWifiOff
    return self._setWifiStatus(False)
  File "fbxosctrl.py", line 212, in _setWifiStatus
    self._login()
  File "fbxosctrl.py", line 159, in _login
    h = hmac.new(apptoken, key, sha1)
  File "/volume1/@appstore/python/lib/python2.7/hmac.py", line 133, in new
    return HMAC(key, msg, digestmod)
  File "/volume1/@appstore/python/lib/python2.7/hmac.py", line 72, in __init__
    self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode
skimpax commented 10 years ago

Hi, Can you indicate which linux distribution and version you are using to launch the script?

ravelou commented 10 years ago

I'm on a synology server ds211+.

HomeServeur> uname --all
Linux HomeServeur 2.6.32.12 #4458 Thu Mar 6 14:16:04 CST 2014 armv5tel GNU/Linux
ravelou commented 10 years ago

My mistake, I reopen the issue

ravelou commented 10 years ago

Hello,

I've found the solution. It is a known bug described on python website http://bugs.python.org/issue5285. I've changed the hmac.py code on line 72

if type(key) == unicode:
    key = key.encode()

And it works ! I close the issue.

skimpax commented 10 years ago

Thanks for the update. I have included the fix in v1.03.