Permalink
Browse files

remove all references to crypto, gpgme and gnupg

Alot *requires* gpgme, which isn't so bad, but there is no gpgme
equivalent for users of GnuPG v2.1 (aka "Modern"). Installing gpgme
support implies using a version of GnuPG prior to v2.1.

And since there are backwards-incompatible changes to the keyring format
in GnuPG v2.1, it is a pretty bad idea to have pre-2.1 versions of GnuPG
installed alongside v2.1.

What's a email reader to do? Why, comment out a couple hundred lines of
code, of course!

This totally shitty hack removes (all?) references to any crypto or
gpg-related operations, including the build-time check for gpgme. Seems
to work for me until GnuPG v2.1 has some sort of gpgme support some day
in the future.

Signed-off-by: Michael Turquette <mturquette@deferred.io>
  • Loading branch information...
mturquette committed Jun 24, 2016
1 parent 98f1ba4 commit 3635055f9527e1bf0140dabac77f2a161d4f89b8
Showing with 258 additions and 258 deletions.
  1. +19 −19 alot/commands/envelope.py
  2. +20 −20 alot/commands/utils.py
  3. +19 −19 alot/completion.py
  4. +74 −74 alot/db/envelope.py
  5. +119 −119 alot/db/utils.py
  6. +6 −5 alot/settings/checks.py
  7. +1 −2 setup.py
View
@@ -15,7 +15,7 @@
from alot.errors import GPGProblem
from alot import buffers
from alot import commands
from alot import crypto
#from alot import crypto
from alot.commands import Command, registerCommand
from alot.commands import globals
from alot.commands.utils import get_keys
@@ -482,18 +482,18 @@ def apply(self, ui):
envelope.sign = sign
# try to find key if hint given as parameter
if sign:
if len(self.keyid) > 0:
keyid = str(' '.join(self.keyid))
try:
key = crypto.get_key(keyid, validate=True, sign=True)
except GPGProblem, e:
envelope.sign = False
ui.notify(e.message, priority='error')
return
envelope.sign_key = key
else:
envelope.sign_key = None
# if sign:
# if len(self.keyid) > 0:
# keyid = str(' '.join(self.keyid))
# try:
# key = crypto.get_key(keyid, validate=True, sign=True)
# except GPGProblem, e:
# envelope.sign = False
# ui.notify(e.message, priority='error')
# return
# envelope.sign_key = key
# else:
envelope.sign_key = None
# reload buffer
ui.current_buffer.rebuild()
@@ -532,12 +532,12 @@ def __init__(self, action=None, keyids=None, **kwargs):
def apply(self, ui):
envelope = ui.current_buffer.envelope
if self.action == 'rmencrypt':
try:
for keyid in self.encrypt_keys:
tmp_key = crypto.get_key(keyid)
del envelope.encrypt_keys[crypto.hash_key(tmp_key)]
except GPGProblem as e:
ui.notify(e.message, priority='error')
# try:
# for keyid in self.encrypt_keys:
# tmp_key = crypto.get_key(keyid)
# del envelope.encrypt_keys[crypto.hash_key(tmp_key)]
# except GPGProblem as e:
# ui.notify(e.message, priority='error')
if not envelope.encrypt_keys:
envelope.encrypt = False
ui.current_buffer.rebuild()
View
@@ -4,7 +4,7 @@
from twisted.internet.defer import inlineCallbacks, returnValue
from alot.errors import GPGProblem, GPGCode
from alot import crypto
#from alot import crypto
@inlineCallbacks
@@ -24,23 +24,23 @@ def get_keys(ui, encrypt_keyids, block_error=False):
"""
keys = {}
for keyid in encrypt_keyids:
try:
key = crypto.get_key(keyid, validate=True, encrypt=True)
except GPGProblem as e:
if e.code == GPGCode.AMBIGUOUS_NAME:
possible_keys = crypto.list_keys(hint=keyid)
tmp_choices = [k.uids[0].uid for k in possible_keys]
choices = {str(len(tmp_choices) - x): tmp_choices[x]
for x in range(0, len(tmp_choices))}
keyid = yield ui.choice("ambiguous keyid! Which " +
"key do you want to use?",
choices, cancel=None)
if keyid:
encrypt_keyids.append(keyid)
continue
else:
ui.notify(e.message, priority='error', block=block_error)
continue
keys[crypto.hash_key(key)] = key
# for keyid in encrypt_keyids:
# try:
# key = crypto.get_key(keyid, validate=True, encrypt=True)
# except GPGProblem as e:
# if e.code == GPGCode.AMBIGUOUS_NAME:
# possible_keys = crypto.list_keys(hint=keyid)
# tmp_choices = [k.uids[0].uid for k in possible_keys]
# choices = {str(len(tmp_choices) - x): tmp_choices[x]
# for x in range(0, len(tmp_choices))}
# keyid = yield ui.choice("ambiguous keyid! Which " +
# "key do you want to use?",
# choices, cancel=None)
# if keyid:
# encrypt_keyids.append(keyid)
# continue
# else:
# ui.notify(e.message, priority='error', block=block_error)
# continue
# keys[crypto.hash_key(key)] = key
returnValue(keys)
View
@@ -7,7 +7,7 @@
import logging
import argparse
import alot.crypto as crypto
#import alot.crypto as crypto
import alot.commands as commands
from alot.buffers import EnvelopeBuffer
from alot.settings import settings
@@ -320,8 +320,8 @@ def __init__(self, dbman, mode, currentbuffer=None):
self._contactscompleter = ContactsCompleter(abooks)
self._pathcompleter = PathCompleter()
self._accountscompleter = AccountCompleter()
self._secretkeyscompleter = CryptoKeyCompleter(private=True)
self._publickeyscompleter = CryptoKeyCompleter(private=False)
# self._secretkeyscompleter = CryptoKeyCompleter(private=True)
# self._publickeyscompleter = CryptoKeyCompleter(private=False)
def complete(self, line, pos):
# remember how many preceding space characters we see until the command
@@ -534,19 +534,19 @@ def prep(path):
return map(prep, glob.glob(deescape(prefix) + '*'))
class CryptoKeyCompleter(StringlistCompleter):
"""completion for gpg keys"""
def __init__(self, private=False):
"""
:param private: return private keys
:type private: bool
"""
keys = crypto.list_keys(private=private)
resultlist = []
for k in keys:
for s in k.subkeys:
resultlist.append(s.keyid)
for u in k.uids:
resultlist.append(u.email)
StringlistCompleter.__init__(self, resultlist, match_anywhere=True)
#class CryptoKeyCompleter(StringlistCompleter):
# """completion for gpg keys"""
#
# def __init__(self, private=False):
# """
# :param private: return private keys
# :type private: bool
# """
# keys = crypto.list_keys(private=private)
# resultlist = []
# for k in keys:
# for s in k.subkeys:
# resultlist.append(s.keyid)
# for u in k.uids:
# resultlist.append(u.email)
# StringlistCompleter.__init__(self, resultlist, match_anywhere=True)
View
@@ -13,8 +13,8 @@
from alot import __version__
import logging
import alot.helper as helper
import alot.crypto as crypto
import gpgme
#import alot.crypto as crypto
#import gpgme
from alot.settings import settings
from alot.errors import GPGProblem, GPGCode
@@ -184,78 +184,78 @@ def construct_mail(self):
else:
inner_msg = textpart
if self.sign:
plaintext = helper.email_as_string(inner_msg)
logging.debug('signing plaintext: ' + plaintext)
try:
signatures, signature_str = crypto.detached_signature_for(
plaintext, self.sign_key)
if len(signatures) != 1:
raise GPGProblem("Could not sign message (GPGME "
"did not return a signature)",
code=GPGCode.KEY_CANNOT_SIGN)
except gpgme.GpgmeError as e:
if e.code == gpgme.ERR_BAD_PASSPHRASE:
# If GPG_AGENT_INFO is unset or empty, the user just does
# not have gpg-agent running (properly).
if os.environ.get('GPG_AGENT_INFO', '').strip() == '':
msg = "Got invalid passphrase and GPG_AGENT_INFO\
not set. Please set up gpg-agent."
raise GPGProblem(msg, code=GPGCode.BAD_PASSPHRASE)
else:
raise GPGProblem("Bad passphrase. Is gpg-agent "
"running?",
code=GPGCode.BAD_PASSPHRASE)
raise GPGProblem(str(e), code=GPGCode.KEY_CANNOT_SIGN)
micalg = crypto.RFC3156_micalg_from_algo(signatures[0].hash_algo)
unencrypted_msg = MIMEMultipart('signed', micalg=micalg,
protocol='application/pgp-signature')
# wrap signature in MIMEcontainter
stype = 'pgp-signature; name="signature.asc"'
signature_mime = MIMEApplication(_data=signature_str,
_subtype=stype,
_encoder=encode_7or8bit)
signature_mime['Content-Description'] = 'signature'
signature_mime.set_charset('us-ascii')
# add signed message and signature to outer message
unencrypted_msg.attach(inner_msg)
unencrypted_msg.attach(signature_mime)
unencrypted_msg['Content-Disposition'] = 'inline'
else:
unencrypted_msg = inner_msg
if self.encrypt:
plaintext = helper.email_as_string(unencrypted_msg)
logging.debug('encrypting plaintext: ' + plaintext)
try:
encrypted_str = crypto.encrypt(plaintext,
self.encrypt_keys.values())
except gpgme.GpgmeError as e:
raise GPGProblem(str(e), code=GPGCode.KEY_CANNOT_ENCRYPT)
outer_msg = MIMEMultipart('encrypted',
protocol='application/pgp-encrypted')
version_str = 'Version: 1'
encryption_mime = MIMEApplication(_data=version_str,
_subtype='pgp-encrypted',
_encoder=encode_7or8bit)
encryption_mime.set_charset('us-ascii')
encrypted_mime = MIMEApplication(_data=encrypted_str,
_subtype='octet-stream',
_encoder=encode_7or8bit)
encrypted_mime.set_charset('us-ascii')
outer_msg.attach(encryption_mime)
outer_msg.attach(encrypted_mime)
else:
outer_msg = unencrypted_msg
# if self.sign:
# plaintext = helper.email_as_string(inner_msg)
# logging.debug('signing plaintext: ' + plaintext)
#
# try:
# signatures, signature_str = crypto.detached_signature_for(
# plaintext, self.sign_key)
# if len(signatures) != 1:
# raise GPGProblem("Could not sign message (GPGME "
# "did not return a signature)",
# code=GPGCode.KEY_CANNOT_SIGN)
# except gpgme.GpgmeError as e:
# if e.code == gpgme.ERR_BAD_PASSPHRASE:
# # If GPG_AGENT_INFO is unset or empty, the user just does
# # not have gpg-agent running (properly).
# if os.environ.get('GPG_AGENT_INFO', '').strip() == '':
# msg = "Got invalid passphrase and GPG_AGENT_INFO\
# not set. Please set up gpg-agent."
# raise GPGProblem(msg, code=GPGCode.BAD_PASSPHRASE)
# else:
# raise GPGProblem("Bad passphrase. Is gpg-agent "
# "running?",
# code=GPGCode.BAD_PASSPHRASE)
# raise GPGProblem(str(e), code=GPGCode.KEY_CANNOT_SIGN)
#
# micalg = crypto.RFC3156_micalg_from_algo(signatures[0].hash_algo)
# unencrypted_msg = MIMEMultipart('signed', micalg=micalg,
# protocol='application/pgp-signature')
#
# # wrap signature in MIMEcontainter
# stype = 'pgp-signature; name="signature.asc"'
# signature_mime = MIMEApplication(_data=signature_str,
# _subtype=stype,
# _encoder=encode_7or8bit)
# signature_mime['Content-Description'] = 'signature'
# signature_mime.set_charset('us-ascii')
#
# # add signed message and signature to outer message
# unencrypted_msg.attach(inner_msg)
# unencrypted_msg.attach(signature_mime)
# unencrypted_msg['Content-Disposition'] = 'inline'
# else:
unencrypted_msg = inner_msg
# if self.encrypt:
# plaintext = helper.email_as_string(unencrypted_msg)
# logging.debug('encrypting plaintext: ' + plaintext)
#
# try:
# encrypted_str = crypto.encrypt(plaintext,
# self.encrypt_keys.values())
# except gpgme.GpgmeError as e:
# raise GPGProblem(str(e), code=GPGCode.KEY_CANNOT_ENCRYPT)
#
# outer_msg = MIMEMultipart('encrypted',
# protocol='application/pgp-encrypted')
#
# version_str = 'Version: 1'
# encryption_mime = MIMEApplication(_data=version_str,
# _subtype='pgp-encrypted',
# _encoder=encode_7or8bit)
# encryption_mime.set_charset('us-ascii')
#
# encrypted_mime = MIMEApplication(_data=encrypted_str,
# _subtype='octet-stream',
# _encoder=encode_7or8bit)
# encrypted_mime.set_charset('us-ascii')
# outer_msg.attach(encryption_mime)
# outer_msg.attach(encrypted_mime)
#
# else:
outer_msg = unencrypted_msg
headers = self.headers.copy()
# add Message-ID
Oops, something went wrong.

0 comments on commit 3635055

Please sign in to comment.