comparison src/plugins/plugin_sec_otr.py @ 1137:768f1f1ef12c

plugin otr: priv_key is better than getPrivKey here, as it should not be None + fixed private key encryption/decryption
author Goffi <goffi@goffi.org>
date Mon, 25 Aug 2014 21:32:29 +0200
parents ea2bbdf5b541
children 7fcafc3206b1
comparison
equal deleted inserted replaced
1136:ea2bbdf5b541 1137:768f1f1ef12c
128 log.debug(u"loadPrivkey") 128 log.debug(u"loadPrivkey")
129 return self.client.otr_priv_key 129 return self.client.otr_priv_key
130 130
131 def savePrivkey(self): 131 def savePrivkey(self):
132 log.debug(u"savePrivkey") 132 log.debug(u"savePrivkey")
133 priv_key = self.getPrivkey().serializePrivateKey() 133 if self.privkey is None:
134 raise exceptions.InternalError(_("Save is called but privkey is None !"))
135 priv_key = self.privkey.serializePrivateKey().encode('hex')
134 d = self.host.memory.encryptValue(priv_key, self.client.profile) 136 d = self.host.memory.encryptValue(priv_key, self.client.profile)
135 def save_encrypted_key(encrypted_priv_key): 137 def save_encrypted_key(encrypted_priv_key):
136 self.client.otr_data[PRIVATE_KEY] = encrypted_priv_key 138 self.client.otr_data[PRIVATE_KEY] = encrypted_priv_key
137 d.addCallback(save_encrypted_key) 139 d.addCallback(save_encrypted_key)
138 140
191 client.otr_data = persistent.PersistentBinaryDict(NS_OTR, profile) 193 client.otr_data = persistent.PersistentBinaryDict(NS_OTR, profile)
192 yield client.otr_data.load() 194 yield client.otr_data.load()
193 encrypted_priv_key = client.otr_data.get(PRIVATE_KEY, None) 195 encrypted_priv_key = client.otr_data.get(PRIVATE_KEY, None)
194 if encrypted_priv_key is not None: 196 if encrypted_priv_key is not None:
195 priv_key = yield self.host.memory.decryptValue(encrypted_priv_key, profile) 197 priv_key = yield self.host.memory.decryptValue(encrypted_priv_key, profile)
196 client.otr_priv_key = potr.crypt.PK.parsePrivateKey(priv_key)[0] 198 client.otr_priv_key = potr.crypt.PK.parsePrivateKey(priv_key.decode('hex'))[0]
197 else: 199 else:
198 client.otr_priv_key = None 200 client.otr_priv_key = None
199 201
200 def _startRefresh(self, menu_data, profile): 202 def _startRefresh(self, menu_data, profile):
201 """Start or refresh an OTR session 203 """Start or refresh an OTR session