diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-12-08 20:18:46 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-12-08 20:18:46 +0000 |
commit | b250e05d84d6f914289a13e92285d1190c64636b (patch) | |
tree | 6c07671f36f9931000fc4dca64697004ffedb66d /lib/thandy/keys.py | |
parent | ec54f74b76b766474b375378aa5a7b752b8cf26c (diff) |
Make encrypted data format handle unicode.
git-svn-id: file:///home/or/svnrepo/updater/trunk@17523 55e972cd-5a19-0410-ae62-a4d7a52db4cd
Diffstat (limited to 'lib/thandy/keys.py')
-rw-r--r-- | lib/thandy/keys.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/thandy/keys.py b/lib/thandy/keys.py index aa9bbc8..56273e8 100644 --- a/lib/thandy/keys.py +++ b/lib/thandy/keys.py @@ -279,9 +279,14 @@ def encryptSecret(secret, password, difficulty=0x80): # D -- 32 bytes; SHA256 hash of (salt|secret|salt). # # This format leaks the secret length, obviously. + # + # If the secret started out in unicode, we encode it using UTF-8 + # and prepend the string "utf-8:" before we begin encryption. assert 0 <= difficulty < 256 salt = os.urandom(SALTLEN)+chr(difficulty) key = secretToKey(salt, password) + if isinstance(secret, unicode): + secret = "utf-8:"+secret.encode("utf-8") d_obj = Crypto.Hash.SHA256.new() d_obj.update(salt) @@ -340,6 +345,9 @@ def decryptSecret(encrypted, password): if d.digest() != hash: raise thandy.BadPassword() + if secret.startswith("utf-8:"): + secret = secret[6:].decode("utf-8") + return secret class KeyStore(thandy.formats.KeyDB): |