olm: Save and restore the olm account keys.

This commit is contained in:
poljar (Damir Jelić) 2018-03-22 12:07:22 +01:00
parent 357c76edcc
commit 823cc1bf28
3 changed files with 21 additions and 2 deletions

View file

@ -170,6 +170,21 @@ class Olm():
with open(path, "rb") as f:
pickle = f.read()
account = Account.from_pickle(pickle)
return cls(server, account)
return cls(account)
except OlmAccountError as error:
raise EncryptionError(error)
@encrypt_enabled
def to_session_dir(self, server):
# type: (Server) -> None
account_file_name = "{}_{}.account".format(server.user,
server.device_id)
session_path = server.get_session_path()
path = os.path.join(session_path, account_file_name)
try:
with open(path, "wb") as f:
pickle = self.account.pickle()
f.write(pickle)
except OlmAccountError as error:
raise EncryptionError(error)

View file

@ -89,6 +89,7 @@ class MatrixLoginEvent(MatrixEvent):
if not self.server.olm:
self.server.create_olm()
self.server.store_olm()
self.server.sync()

View file

@ -158,7 +158,10 @@ class MatrixServer:
server=self.name,
device=self.device_id)
W.prnt(self.server_buffer, message)
self.olm = Olm(self)
self.olm = Olm()
def store_olm(self):
self.olm.to_session_dir(self)
def _create_options(self, config_file):
options = [