Skip to content

Commit 3635055

Browse files
committed
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>
1 parent 98f1ba4 commit 3635055

7 files changed

Lines changed: 258 additions & 258 deletions

File tree

alot/commands/envelope.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from alot.errors import GPGProblem
1616
from alot import buffers
1717
from alot import commands
18-
from alot import crypto
18+
#from alot import crypto
1919
from alot.commands import Command, registerCommand
2020
from alot.commands import globals
2121
from alot.commands.utils import get_keys
@@ -482,18 +482,18 @@ def apply(self, ui):
482482
envelope.sign = sign
483483

484484
# try to find key if hint given as parameter
485-
if sign:
486-
if len(self.keyid) > 0:
487-
keyid = str(' '.join(self.keyid))
488-
try:
489-
key = crypto.get_key(keyid, validate=True, sign=True)
490-
except GPGProblem, e:
491-
envelope.sign = False
492-
ui.notify(e.message, priority='error')
493-
return
494-
envelope.sign_key = key
495-
else:
496-
envelope.sign_key = None
485+
# if sign:
486+
# if len(self.keyid) > 0:
487+
# keyid = str(' '.join(self.keyid))
488+
# try:
489+
# key = crypto.get_key(keyid, validate=True, sign=True)
490+
# except GPGProblem, e:
491+
# envelope.sign = False
492+
# ui.notify(e.message, priority='error')
493+
# return
494+
# envelope.sign_key = key
495+
# else:
496+
envelope.sign_key = None
497497

498498
# reload buffer
499499
ui.current_buffer.rebuild()
@@ -532,12 +532,12 @@ def __init__(self, action=None, keyids=None, **kwargs):
532532
def apply(self, ui):
533533
envelope = ui.current_buffer.envelope
534534
if self.action == 'rmencrypt':
535-
try:
536-
for keyid in self.encrypt_keys:
537-
tmp_key = crypto.get_key(keyid)
538-
del envelope.encrypt_keys[crypto.hash_key(tmp_key)]
539-
except GPGProblem as e:
540-
ui.notify(e.message, priority='error')
535+
# try:
536+
# for keyid in self.encrypt_keys:
537+
# tmp_key = crypto.get_key(keyid)
538+
# del envelope.encrypt_keys[crypto.hash_key(tmp_key)]
539+
# except GPGProblem as e:
540+
# ui.notify(e.message, priority='error')
541541
if not envelope.encrypt_keys:
542542
envelope.encrypt = False
543543
ui.current_buffer.rebuild()

alot/commands/utils.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from twisted.internet.defer import inlineCallbacks, returnValue
55

66
from alot.errors import GPGProblem, GPGCode
7-
from alot import crypto
7+
#from alot import crypto
88

99

1010
@inlineCallbacks
@@ -24,23 +24,23 @@ def get_keys(ui, encrypt_keyids, block_error=False):
2424
2525
"""
2626
keys = {}
27-
for keyid in encrypt_keyids:
28-
try:
29-
key = crypto.get_key(keyid, validate=True, encrypt=True)
30-
except GPGProblem as e:
31-
if e.code == GPGCode.AMBIGUOUS_NAME:
32-
possible_keys = crypto.list_keys(hint=keyid)
33-
tmp_choices = [k.uids[0].uid for k in possible_keys]
34-
choices = {str(len(tmp_choices) - x): tmp_choices[x]
35-
for x in range(0, len(tmp_choices))}
36-
keyid = yield ui.choice("ambiguous keyid! Which " +
37-
"key do you want to use?",
38-
choices, cancel=None)
39-
if keyid:
40-
encrypt_keyids.append(keyid)
41-
continue
42-
else:
43-
ui.notify(e.message, priority='error', block=block_error)
44-
continue
45-
keys[crypto.hash_key(key)] = key
27+
# for keyid in encrypt_keyids:
28+
# try:
29+
# key = crypto.get_key(keyid, validate=True, encrypt=True)
30+
# except GPGProblem as e:
31+
# if e.code == GPGCode.AMBIGUOUS_NAME:
32+
# possible_keys = crypto.list_keys(hint=keyid)
33+
# tmp_choices = [k.uids[0].uid for k in possible_keys]
34+
# choices = {str(len(tmp_choices) - x): tmp_choices[x]
35+
# for x in range(0, len(tmp_choices))}
36+
# keyid = yield ui.choice("ambiguous keyid! Which " +
37+
# "key do you want to use?",
38+
# choices, cancel=None)
39+
# if keyid:
40+
# encrypt_keyids.append(keyid)
41+
# continue
42+
# else:
43+
# ui.notify(e.message, priority='error', block=block_error)
44+
# continue
45+
# keys[crypto.hash_key(key)] = key
4646
returnValue(keys)

alot/completion.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import logging
88
import argparse
99

10-
import alot.crypto as crypto
10+
#import alot.crypto as crypto
1111
import alot.commands as commands
1212
from alot.buffers import EnvelopeBuffer
1313
from alot.settings import settings
@@ -320,8 +320,8 @@ def __init__(self, dbman, mode, currentbuffer=None):
320320
self._contactscompleter = ContactsCompleter(abooks)
321321
self._pathcompleter = PathCompleter()
322322
self._accountscompleter = AccountCompleter()
323-
self._secretkeyscompleter = CryptoKeyCompleter(private=True)
324-
self._publickeyscompleter = CryptoKeyCompleter(private=False)
323+
# self._secretkeyscompleter = CryptoKeyCompleter(private=True)
324+
# self._publickeyscompleter = CryptoKeyCompleter(private=False)
325325

326326
def complete(self, line, pos):
327327
# remember how many preceding space characters we see until the command
@@ -534,19 +534,19 @@ def prep(path):
534534
return map(prep, glob.glob(deescape(prefix) + '*'))
535535

536536

537-
class CryptoKeyCompleter(StringlistCompleter):
538-
"""completion for gpg keys"""
539-
540-
def __init__(self, private=False):
541-
"""
542-
:param private: return private keys
543-
:type private: bool
544-
"""
545-
keys = crypto.list_keys(private=private)
546-
resultlist = []
547-
for k in keys:
548-
for s in k.subkeys:
549-
resultlist.append(s.keyid)
550-
for u in k.uids:
551-
resultlist.append(u.email)
552-
StringlistCompleter.__init__(self, resultlist, match_anywhere=True)
537+
#class CryptoKeyCompleter(StringlistCompleter):
538+
# """completion for gpg keys"""
539+
#
540+
# def __init__(self, private=False):
541+
# """
542+
# :param private: return private keys
543+
# :type private: bool
544+
# """
545+
# keys = crypto.list_keys(private=private)
546+
# resultlist = []
547+
# for k in keys:
548+
# for s in k.subkeys:
549+
# resultlist.append(s.keyid)
550+
# for u in k.uids:
551+
# resultlist.append(u.email)
552+
# StringlistCompleter.__init__(self, resultlist, match_anywhere=True)

alot/db/envelope.py

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from alot import __version__
1414
import logging
1515
import alot.helper as helper
16-
import alot.crypto as crypto
17-
import gpgme
16+
#import alot.crypto as crypto
17+
#import gpgme
1818
from alot.settings import settings
1919
from alot.errors import GPGProblem, GPGCode
2020

@@ -184,78 +184,78 @@ def construct_mail(self):
184184
else:
185185
inner_msg = textpart
186186

187-
if self.sign:
188-
plaintext = helper.email_as_string(inner_msg)
189-
logging.debug('signing plaintext: ' + plaintext)
190-
191-
try:
192-
signatures, signature_str = crypto.detached_signature_for(
193-
plaintext, self.sign_key)
194-
if len(signatures) != 1:
195-
raise GPGProblem("Could not sign message (GPGME "
196-
"did not return a signature)",
197-
code=GPGCode.KEY_CANNOT_SIGN)
198-
except gpgme.GpgmeError as e:
199-
if e.code == gpgme.ERR_BAD_PASSPHRASE:
200-
# If GPG_AGENT_INFO is unset or empty, the user just does
201-
# not have gpg-agent running (properly).
202-
if os.environ.get('GPG_AGENT_INFO', '').strip() == '':
203-
msg = "Got invalid passphrase and GPG_AGENT_INFO\
204-
not set. Please set up gpg-agent."
205-
raise GPGProblem(msg, code=GPGCode.BAD_PASSPHRASE)
206-
else:
207-
raise GPGProblem("Bad passphrase. Is gpg-agent "
208-
"running?",
209-
code=GPGCode.BAD_PASSPHRASE)
210-
raise GPGProblem(str(e), code=GPGCode.KEY_CANNOT_SIGN)
211-
212-
micalg = crypto.RFC3156_micalg_from_algo(signatures[0].hash_algo)
213-
unencrypted_msg = MIMEMultipart('signed', micalg=micalg,
214-
protocol='application/pgp-signature')
215-
216-
# wrap signature in MIMEcontainter
217-
stype = 'pgp-signature; name="signature.asc"'
218-
signature_mime = MIMEApplication(_data=signature_str,
219-
_subtype=stype,
220-
_encoder=encode_7or8bit)
221-
signature_mime['Content-Description'] = 'signature'
222-
signature_mime.set_charset('us-ascii')
223-
224-
# add signed message and signature to outer message
225-
unencrypted_msg.attach(inner_msg)
226-
unencrypted_msg.attach(signature_mime)
227-
unencrypted_msg['Content-Disposition'] = 'inline'
228-
else:
229-
unencrypted_msg = inner_msg
230-
231-
if self.encrypt:
232-
plaintext = helper.email_as_string(unencrypted_msg)
233-
logging.debug('encrypting plaintext: ' + plaintext)
234-
235-
try:
236-
encrypted_str = crypto.encrypt(plaintext,
237-
self.encrypt_keys.values())
238-
except gpgme.GpgmeError as e:
239-
raise GPGProblem(str(e), code=GPGCode.KEY_CANNOT_ENCRYPT)
240-
241-
outer_msg = MIMEMultipart('encrypted',
242-
protocol='application/pgp-encrypted')
243-
244-
version_str = 'Version: 1'
245-
encryption_mime = MIMEApplication(_data=version_str,
246-
_subtype='pgp-encrypted',
247-
_encoder=encode_7or8bit)
248-
encryption_mime.set_charset('us-ascii')
249-
250-
encrypted_mime = MIMEApplication(_data=encrypted_str,
251-
_subtype='octet-stream',
252-
_encoder=encode_7or8bit)
253-
encrypted_mime.set_charset('us-ascii')
254-
outer_msg.attach(encryption_mime)
255-
outer_msg.attach(encrypted_mime)
256-
257-
else:
258-
outer_msg = unencrypted_msg
187+
# if self.sign:
188+
# plaintext = helper.email_as_string(inner_msg)
189+
# logging.debug('signing plaintext: ' + plaintext)
190+
#
191+
# try:
192+
# signatures, signature_str = crypto.detached_signature_for(
193+
# plaintext, self.sign_key)
194+
# if len(signatures) != 1:
195+
# raise GPGProblem("Could not sign message (GPGME "
196+
# "did not return a signature)",
197+
# code=GPGCode.KEY_CANNOT_SIGN)
198+
# except gpgme.GpgmeError as e:
199+
# if e.code == gpgme.ERR_BAD_PASSPHRASE:
200+
# # If GPG_AGENT_INFO is unset or empty, the user just does
201+
# # not have gpg-agent running (properly).
202+
# if os.environ.get('GPG_AGENT_INFO', '').strip() == '':
203+
# msg = "Got invalid passphrase and GPG_AGENT_INFO\
204+
# not set. Please set up gpg-agent."
205+
# raise GPGProblem(msg, code=GPGCode.BAD_PASSPHRASE)
206+
# else:
207+
# raise GPGProblem("Bad passphrase. Is gpg-agent "
208+
# "running?",
209+
# code=GPGCode.BAD_PASSPHRASE)
210+
# raise GPGProblem(str(e), code=GPGCode.KEY_CANNOT_SIGN)
211+
#
212+
# micalg = crypto.RFC3156_micalg_from_algo(signatures[0].hash_algo)
213+
# unencrypted_msg = MIMEMultipart('signed', micalg=micalg,
214+
# protocol='application/pgp-signature')
215+
#
216+
# # wrap signature in MIMEcontainter
217+
# stype = 'pgp-signature; name="signature.asc"'
218+
# signature_mime = MIMEApplication(_data=signature_str,
219+
# _subtype=stype,
220+
# _encoder=encode_7or8bit)
221+
# signature_mime['Content-Description'] = 'signature'
222+
# signature_mime.set_charset('us-ascii')
223+
#
224+
# # add signed message and signature to outer message
225+
# unencrypted_msg.attach(inner_msg)
226+
# unencrypted_msg.attach(signature_mime)
227+
# unencrypted_msg['Content-Disposition'] = 'inline'
228+
# else:
229+
unencrypted_msg = inner_msg
230+
231+
# if self.encrypt:
232+
# plaintext = helper.email_as_string(unencrypted_msg)
233+
# logging.debug('encrypting plaintext: ' + plaintext)
234+
#
235+
# try:
236+
# encrypted_str = crypto.encrypt(plaintext,
237+
# self.encrypt_keys.values())
238+
# except gpgme.GpgmeError as e:
239+
# raise GPGProblem(str(e), code=GPGCode.KEY_CANNOT_ENCRYPT)
240+
#
241+
# outer_msg = MIMEMultipart('encrypted',
242+
# protocol='application/pgp-encrypted')
243+
#
244+
# version_str = 'Version: 1'
245+
# encryption_mime = MIMEApplication(_data=version_str,
246+
# _subtype='pgp-encrypted',
247+
# _encoder=encode_7or8bit)
248+
# encryption_mime.set_charset('us-ascii')
249+
#
250+
# encrypted_mime = MIMEApplication(_data=encrypted_str,
251+
# _subtype='octet-stream',
252+
# _encoder=encode_7or8bit)
253+
# encrypted_mime.set_charset('us-ascii')
254+
# outer_msg.attach(encryption_mime)
255+
# outer_msg.attach(encrypted_mime)
256+
#
257+
# else:
258+
outer_msg = unencrypted_msg
259259

260260
headers = self.headers.copy()
261261
# add Message-ID

0 commit comments

Comments
 (0)