Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BjarniRunar committed Aug 3, 2017
2 parents c9b0240 + c0ec2ae commit 1a1f622
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
22 changes: 18 additions & 4 deletions mailpile/crypto/gpgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# For details on type 20 compromisation, see
# https://lists.gnupg.org/pipermail/gnupg-announce/2003q4/000160.html

ENTROPY_LOCK = threading.Lock()

class GnuPGEventUpdater:
"""
Expand Down Expand Up @@ -1372,7 +1373,7 @@ def chat(self, gpg_args, callback, *args, **kwargs):
self.debug('Running %s' % ' '.join(gpg_args))
self.event.update_args(gpg_args)
proc = Popen(gpg_args, stdin=PIPE, stdout=PIPE, stderr=PIPE,
bufsize=0)
bufsize=0, long_running=True)

return callback(proc, *args, **kwargs)
finally:
Expand Down Expand Up @@ -1616,6 +1617,7 @@ def on_complete(self, name, callback):

class GnuPGBaseKeyGenerator(GnuPGExpectScript):
"""This is a background thread which generates a new PGP key."""
AWAITING_LOCK = 'Pending keygen'
KEY_SETUP = 'Key Setup'
GATHER_ENTROPY = 'Creating key'
CREATED_KEY = 'Created key'
Expand All @@ -1629,19 +1631,31 @@ class GnuPGBaseKeyGenerator(GnuPGExpectScript):
'passphrase': 'mailpile'}
DESCRIPTION = _('Creating a %(bits)s bit GnuPG key')
RUNNING_STATES = (GnuPGExpectScript.RUNNING_STATES +
[KEY_SETUP, GATHER_ENTROPY, HAVE_KEY])
[AWAITING_LOCK, KEY_SETUP, GATHER_ENTROPY, HAVE_KEY])

failed = property(lambda self: (not self.running and
not self.generated_key))

def __init__(self, *args, **kwargs):
GnuPGExpectScript.__init__(self, *args, **kwargs)
super(GnuPGBaseKeyGenerator, self).__init__(*args, **kwargs)
self.generated_key = None

def in_state(self, state):
if state == self.HAVE_KEY:
self.generated_key = self.before.strip().split()[-1]

def run(self):
# In order to minimize risk of timeout during key generation (due to
# lack of entropy), we serialize them here using a global lock
self.set_state(self.AWAITING_LOCK)
self.event.message = _('Waiting to generate a %d bit GnuPG key.'
% self.variables['bits'])
with ENTROPY_LOCK:
self.event.data['keygen_gotlock'] = 1
self.event.message = _('Generating new %d bit PGP key.'
% self.variables['bits'])
super(GnuPGBaseKeyGenerator, self).run()


class GnuPG14KeyGenerator(GnuPGBaseKeyGenerator):
"""This is the GnuPG 1.4x specific PGP key generation script."""
Expand All @@ -1661,7 +1675,7 @@ class GnuPG14KeyGenerator(GnuPGBaseKeyGenerator):
('GET_LINE keygen.comment', '%(comment)s', -1, None),
('GET_HIDDEN passphrase', '%(passphrase)s', -1, None),
('GOT_IT', None, -1, B.GATHER_ENTROPY),
('KEY_CREATED', None, 1800, B.CREATED_KEY),
('KEY_CREATED', None, 7200, B.CREATED_KEY),
('\n', None, -1, B.HAVE_KEY)]

def gpg_args(self):
Expand Down
2 changes: 0 additions & 2 deletions mailpile/plugins/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,6 @@ def _create_new_key(self, vcard, keytype):
'comment': ''
}
event = Event(source=self,
message=_('Generating new %d bit PGP key. '
'This may take some time!') % bits,
flags=Event.INCOMPLETE,
data={'keygen_started': int(time.time()),
'profile_id': random_uid},
Expand Down
8 changes: 8 additions & 0 deletions shared-data/default-theme/html/jsapi/ui/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,23 @@ EventLog.subscribe('.*(Add|Edit)Profile', function(ev) {
$icon.removeClass('unconfigured');
$icon.removeClass('icon-clock').removeClass('icon-lock-open');
$icon.addClass('configured').addClass('icon-lock-closed');
ev.timeout = 60000; // Keep completed notification up for 1 minute
}
else {
$icon.removeClass('configured');
$icon.removeClass('icon-lock-open').removeClass('icon-lock-closed');
$icon.addClass('unconfigured').addClass('icon-clock');
if (ev.data.keygen_gotlock > 0) {
ev.action_url = '/page/entropy/';
ev.action_cls = 'auto-modal';
ev.action_text = '{{_("learn more")|escapejs}}';
ev.message2 = '{{_("This may take some time!")|escapejs}}';
}
}
Mailpile.notification(ev);
}
});

EventLog.subscribe('.*mail_source.*', function(ev) {
//
// Mail source notifications behave differently depending on which
Expand Down
31 changes: 31 additions & 0 deletions shared-data/default-theme/html/page/entropy/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "layouts/" + render_mode + "-tall.html" %}
{% block title %}{{_("Increasing Entropy")}}{% endblock %}
{% block content %}
<div class="content-normal" style="max-width: 46em;">

<h1><span class="icon-robot"></span>
{{_("Increasing Entropy")}}
</h1>
<p>
{{_("Mailpile needs true random numbers to generate good encryption keys.")}}
</p>
<p>
{{_("Although your computer may be powerful, it may still have hard time finding enough randomness when generating keys.")}}
{{_("The technical term used to describe the source of randomness is Entropy!")}}
</p>
<p>
{{_("On the machine that is running Mailpile you can do a few things to increase the Entropy:")}}
<br>
<ul class="list" style="margin-left: 2em; list-style: disc">
<li>{{_("Move the mouse.")}}</li>
<li>{{_("Perform other activity which requires using the keyboard.")}}</li>
<li>{{_("Start a process that utilizes the disk(s).")}}</li>
<li>{{_("Browse the internet.")}}</li>
</ul>
</p>
<p>
{{_("Because the computer cannot predict human activity these actions help the computer generate random numbers.")}}
</p>

</div>
{% endblock %}

0 comments on commit 1a1f622

Please sign in to comment.