Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid accidentally exporting all pub keys #4009

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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