Skip to content

Commit

Permalink
Merge pull request #4009 from freedomofpress/fix-source-key-export
Browse files Browse the repository at this point in the history
avoid accidentally exporting all pub keys
  • Loading branch information
redshiftzero authored Jan 7, 2019
2 parents a1c2e2a + 7109aff commit 445aa0a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion securedrop/crypto_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ def getkey(self, name):

def export_pubkey(self, name):
fingerprint = self.getkey(name)
return self.gpg.export_keys(fingerprint)
if fingerprint:
return self.gpg.export_keys(fingerprint)
else:
return None

def encrypt(self, plaintext, fingerprints, output=None):
# Verify the output path
Expand Down
16 changes: 16 additions & 0 deletions securedrop/tests/test_crypto_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,19 @@ def test_delete_reply_keypair_no_key(source_app):
def test_getkey(source_app, test_source):
assert (source_app.crypto_util.getkey(test_source['filesystem_id'])
is not None)

# check that a non-existent key returns None
assert source_app.crypto_util.getkey('x' * 50) is None


def test_export_pubkey(source_app, test_source):
begin_pgp = '-----BEGIN PGP PUBLIC KEY BLOCK----'

# check that a filesystem_id exports the pubkey
exported = source_app.crypto_util.export_pubkey(
test_source['filesystem_id'])
assert exported.startswith(begin_pgp)

# check that a non-existent identifer exports None
exported = source_app.crypto_util.export_pubkey('x' * 50)
assert exported is None

0 comments on commit 445aa0a

Please sign in to comment.