Mercurial > libervia-backend
comparison src/memory/sqlite.py @ 1065:9378c80e3408
memory (sqlite): fixes upgrade to database v2
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 12 Jun 2014 15:56:41 +0200 |
parents | 5f7f913c05ac |
children | 1baa116501fa |
comparison
equal
deleted
inserted
replaced
1064:7ee9d9db67b9 | 1065:9378c80e3408 |
---|---|
762 xmpp_pass_path = ('Connection', 'Password') | 762 xmpp_pass_path = ('Connection', 'Password') |
763 | 763 |
764 def encrypt_values(values): | 764 def encrypt_values(values): |
765 ret = [] | 765 ret = [] |
766 list_ = [] | 766 list_ = [] |
767 | |
768 def prepare_queries(result, xmpp_password): | |
769 try: | |
770 id_ = result[0][0] | |
771 except IndexError: | |
772 log.error("Profile of id %d is referenced in 'param_ind' but it doesn't exist!" % profile_id) | |
773 return | |
774 | |
775 sat_password = xmpp_password | |
776 d1 = PasswordHasher.hash(sat_password) | |
777 personal_key = BlockCipher.getRandomKey(base64=True) | |
778 d2 = BlockCipher.encrypt(sat_password, personal_key) | |
779 d3 = BlockCipher.encrypt(personal_key, xmpp_password) | |
780 | |
781 def gotValues(res): | |
782 sat_cipher, personal_cipher, xmpp_cipher = res[0][1], res[1][1], res[2][1] | |
783 ret.append("INSERT INTO param_ind(category,name,profile_id,value) VALUES ('%s','%s',%s,'%s')" % | |
784 (C.PROFILE_PASS_PATH[0], C.PROFILE_PASS_PATH[1], id_, sat_cipher)) | |
785 | |
786 ret.append("INSERT INTO private_ind(namespace,key,profile_id,value) VALUES ('%s','%s',%s,'%s')" % | |
787 (C.MEMORY_CRYPTO_NAMESPACE, C.MEMORY_CRYPTO_KEY, id_, personal_cipher)) | |
788 | |
789 ret.append("REPLACE INTO param_ind(category,name,profile_id,value) VALUES ('%s','%s',%s,'%s')" % | |
790 (xmpp_pass_path[0], xmpp_pass_path[1], id_, xmpp_cipher)) | |
791 | |
792 return defer.DeferredList([d1, d2, d3]).addCallback(gotValues) | |
793 | |
767 for profile_id, xmpp_password in values: | 794 for profile_id, xmpp_password in values: |
768 def prepare_queries(result): | |
769 try: | |
770 id_ = result[0][0] | |
771 except IndexError: | |
772 log.error("Profile of id %d is referenced in 'param_ind' but it doesn't exist!" % profile_id) | |
773 return | |
774 | |
775 sat_password = xmpp_password | |
776 d1 = PasswordHasher.hash(sat_password) | |
777 personal_key = BlockCipher.getRandomKey(base64=True) | |
778 d2 = BlockCipher.encrypt(sat_password, personal_key) | |
779 d3 = BlockCipher.encrypt(personal_key, xmpp_password) | |
780 | |
781 def gotValues(res): | |
782 sat_cipher, personal_cipher, xmpp_cipher = res[0][1], res[1][1], res[2][1] | |
783 ret.append("INSERT INTO param_ind(category,name,profile_id,value) VALUES ('%s','%s',%s,'%s')" % | |
784 (C.PROFILE_PASS_PATH[0], C.PROFILE_PASS_PATH[1], id_, sat_cipher)) | |
785 | |
786 ret.append("INSERT INTO private_ind(namespace,key,profile_id,value) VALUES ('%s','%s',%s,'%s')" % | |
787 (C.MEMORY_CRYPTO_NAMESPACE, C.MEMORY_CRYPTO_KEY, id_, personal_cipher)) | |
788 | |
789 ret.append("REPLACE INTO param_ind(category,name,profile_id,value) VALUES ('%s','%s',%s,'%s')" % | |
790 (xmpp_pass_path[0], xmpp_pass_path[1], id_, xmpp_cipher)) | |
791 | |
792 return defer.DeferredList([d1, d2, d3]).addCallback(gotValues) | |
793 | |
794 d = self.dbpool.runQuery("SELECT id FROM profiles WHERE id=?", (profile_id,)) | 795 d = self.dbpool.runQuery("SELECT id FROM profiles WHERE id=?", (profile_id,)) |
795 d.addCallback(prepare_queries) | 796 d.addCallback(prepare_queries, xmpp_password) |
796 list_.append(d) | 797 list_.append(d) |
797 | 798 |
798 d_list = defer.DeferredList(list_) | 799 d_list = defer.DeferredList(list_) |
799 d_list.addCallback(lambda dummy: ret) | 800 d_list.addCallback(lambda dummy: ret) |
800 return d_list | 801 return d_list |