I'm having trouble unencoding some data I get from a socket connection through messagepack, and consequentially unencrypting it. I get the string in from a Ruby on Rails web application in UTF-8 and use messagepack to bundle it all up and send it over to a python service using sockets. The other data comes across fine: strings, numbers, arrays etc. But my encrypted password is wrecked.
https://github.com/msgpack/msgpack/issues/15 this discussion suggested forcing ascii which i did in the rails code as well as here in python. If i force ascii in ruby and do nothing inpython i get junk in the string but i have the correct unencrypted password at the end. If i try to force ascii in my python script i get a decoding error
while 1:
buf = clientsocket.recv(1024)
unpacker.feed(buf)
for obj in unpacker:
print obj #works great! => ['3', [['really long url', [87987234, 'gobbledyguck of password']]]]
#key.decrypt(obj[1][0][1][1]) roughly gives "YD3zt�(-�½ï¿½ï¿½=you suck"
print key.decrypt(obj[1][0][1][1].decode('ascii'))
encryption is done using public/private keys (Crypto.PublicKey RSA in Python, openssl in ruby). i can decrypt and encrypt fine within each script (not sending it over the socket via messagepack)
any thoughts at all?
EDIT:
after some experimentation and a bit of thought, i realized that the fact that password comes out just fine is interesting. the issue is the extra junk at the beginning of the string. I just don't know where it comes from... or whether its safe to truncate it.