]> git.datanom.net - securemail.git/blobdiff - user.py
Make backwards compatible with nacl 1.0.x
[securemail.git] / user.py
diff --git a/user.py b/user.py
index fd3d39724e34770b1a0551a5b8797688789f9619..7c1632e71129e5db64aaacca827b9312a16a3130 100644 (file)
--- a/user.py
+++ b/user.py
@@ -21,7 +21,6 @@ import pickle
 from db import DBInterface as DBI
 from cryptonize import Cryptonize
 from nacl.public import PublicKey
-from nacl import __version__ as NACL_VERSION
 
 class NoSuchUser(Exception):
     pass
@@ -38,13 +37,7 @@ class User:
 
     def store(self, key):
         crypto = Cryptonize()
-        if NACL_VERSION < "1.1.0":
-            from nacl.utils import random
-            from nacl.public import SecretBox
-            nonce = random(SecretBox.NONCE_SIZE)
-            cipher = crypto.symmetric_encrypt(key, pickle.dumps(self), nonce)
-        else:
-            cipher = crypto.symmetric_encrypt(key, pickle.dumps(self))
+        cipher = crypto.symmetric_encrypt(key, pickle.dumps(self))
         DBI.store_user(crypto.generate_hash(key), cipher)
 
     def load(self, key):
@@ -127,7 +120,7 @@ if __name__ == '__main__':
             for attr, value in u.__dict__.items():
                 print ('{0}: {1}'.format(attr, value))
             print ('{0} - {1} - {2}'.format(u.name, u.email, u.pubkeys))
-        from nacl.public import Box
+#        from nacl.public import Box
         c = Cryptonize()
         keypair1 = c.get_key_pair()
         keypair2 = c.get_key_pair()
@@ -135,11 +128,13 @@ if __name__ == '__main__':
             u.add_pubkey('test', keypair2[1])
         except KeyError:
             u.update_pubkey('test', keypair2[1])
-        bob_box = Box(keypair1[0], u.get_pubkey('test'))
+#        bob_box = Box(keypair1[0], u.get_pubkey('test'))
         message = "Kill all humans æøåÅØÆ"
-        encrypted = bob_box.encrypt(message.encode())
-        alice_box = Box(keypair2[0], keypair1[1])
-        plaintext = alice_box.decrypt(encrypted)
+#        encrypted = bob_box.encrypt(message.encode())
+        encrypted = c.asymmetric_encrypt(keypair1[0], u.get_pubkey('test'), message)
+#        alice_box = Box(keypair2[0], keypair1[1])
+#        plaintext = alice_box.decrypt(encrypted)
+        plaintext = c.asymmetric_decrypt(keypair2[0], keypair1[1], encrypted)
         print (plaintext.decode())
 #        c = Cryptonize()
 #        key = 'æselØre' #c.get_random_key()
This page took 0.030273 seconds and 5 git commands to generate.