Commit d8bf566d authored by Philipp Hörist's avatar Philipp Hörist

[openpgp] Add GPGME backend

parent a2622aa6
This diff is collapsed.
......@@ -31,7 +31,7 @@ if log.getEffectiveLevel() == logging.DEBUG:
KeyringItem = namedtuple('KeyringItem', 'jid keyid fingerprint')
class PGPContext(gnupg.GPG):
class PythonGnuPG(gnupg.GPG):
def __init__(self, jid, gnupghome):
gnupg.GPG.__init__(
self, gpgbinary='gpg', gnupghome=str(gnupghome))
......
......@@ -93,12 +93,6 @@ class KeyWizard(Gtk.Assistant):
elif self.get_current_page() == Page.SUCCESS:
self._activate_encryption()
def _on_error(self, error_text):
log.info('Show Error page')
page = self.get_nth_page(Page.ERROR)
page.set_text(error_text)
self.set_current_page(Page.ERROR)
def _on_cancel(self, widget):
self.destroy()
......@@ -168,22 +162,23 @@ class NewKeyPage(RequestPage):
thread.start()
def worker(self):
error = None
text = None
try:
self._con.get_module('OpenPGP').generate_key()
except Exception as e:
error = e
else:
self._con.get_module('OpenPGP').get_own_key_details()
self._con.get_module('OpenPGP').set_public_key()
self._con.get_module('OpenPGP').request_keylist()
GLib.idle_add(self.finished, error)
except Exception as error:
text = str(error)
GLib.idle_add(self.finished, text)
def finished(self, error):
if error is None:
self._assistant.set_current_page(Page.SUCCESS)
self._con.get_module('OpenPGP').get_own_key_details()
self._con.get_module('OpenPGP').set_public_key()
self._con.get_module('OpenPGP').request_keylist()
else:
log.error(error)
error_page = self._assistant.get_nth_page(Page.ERROR)
error_page.set_text(error)
self._assistant.set_current_page(Page.ERROR)
......@@ -229,7 +224,7 @@ class SuccessfulPage(Gtk.Box):
class ErrorPage(Gtk.Box):
type_ = Gtk.AssistantPageType.SUMMARY
title = _('Registration failed')
title = _('Setup failed')
complete = True
def __init__(self):
......
......@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with OpenPGP Gajim Plugin. If not, see <http://www.gnu.org/licenses/>.
import sys
import time
import logging
from pathlib import Path
......@@ -44,7 +45,11 @@ from openpgp.modules.util import DecryptionFailed
from openpgp.modules.util import prepare_stanza
from openpgp.modules.key_store import PGPContacts
from openpgp.backend.sql import Storage
from openpgp.backend.pygpg import PGPContext
if sys.platform == 'win32':
from openpgp.backend.pygpg import PythonGnuPG as PGPBackend
else:
from openpgp.backend.gpgme import GPGME as PGPBackend
log = logging.getLogger('gajim.p.openpgp')
......@@ -84,9 +89,9 @@ class OpenPGP(BaseModule):
own_bare_jid = self.own_jid.getBare()
path = Path(configpaths.get('MY_DATA')) / 'openpgp' / own_bare_jid
if not path.exists():
path.mkdir(parents=True)
path.mkdir(mode=0o700, parents=True)
self._pgp = PGPContext(self.own_jid, path)
self._pgp = PGPBackend(self.own_jid, path)
self._storage = Storage(path)
self._contacts = PGPContacts(self._pgp, self._storage)
self._fingerprint, self._date = self.get_own_key_details()
......@@ -223,7 +228,14 @@ class OpenPGP(BaseModule):
if not any(map(self.own_jid.bareMatch, recipients)):
log.warning('to attr not valid')
log.warning(payload)
log.warning(str(payload))
return
keys = self._contacts.get_keys(properties.jid.bare)
fingerprints = [key.fingerprint for key in keys]
if fingerprint not in fingerprints:
log.warning('Invalid fingerprint on message: %s', fingerprint)
log.warning('Expected: %s', fingerprints)
return
log.info('Received OpenPGP message from: %s', properties.jid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment