From 78cc2dad9c34d1a86f5dfed71b0a2fc29c695478 Mon Sep 17 00:00:00 2001 From: kaeff Date: Tue, 8 Sep 2015 14:50:16 +0200 Subject: =?UTF-8?q?Revert=20"Kill=20SoledadQuerier=20with=20=F0=9F=94=A5?= =?UTF-8?q?=F0=9F=94=A5=F0=9F=94=A5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7deaefb939c833d65fd499aacb35502d6de1ac7e. --- ...soledad_search_key_masterkey_retrieval_mixin.py | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py (limited to 'service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py') diff --git a/service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py b/service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py new file mode 100644 index 00000000..8a912bc2 --- /dev/null +++ b/service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py @@ -0,0 +1,35 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +from pixelated.adapter.soledad.soledad_facade_mixin import SoledadDbFacadeMixin +import os +import base64 + + +class SoledadSearchIndexMasterkeyRetrievalMixin(SoledadDbFacadeMixin, object): + + def get_index_masterkey(self): + deferred = self.get_search_index_masterkey() + deferred.addCallback(self._ensure_masterkey_exists) + return deferred + + def _ensure_masterkey_exists(self, result): + index_key_doc = result[0] if result else None + + if not index_key_doc: + new_index_key = os.urandom(64) # 32 for encryption, 32 for hmac + self.create_doc(dict(type='index_key', value=base64.encodestring(new_index_key))) + return new_index_key + return base64.decodestring(index_key_doc.content['value']) -- cgit v1.2.3