Skip to content

Commit

Permalink
Rename CryptoUtil Redis keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmol committed Apr 8, 2020
1 parent 07e4708 commit 5aca092
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions securedrop/crypto_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class CryptoUtil:
# to set an expiration date.
DEFAULT_KEY_EXPIRATION_DATE = '0'

REDIS_SOURCE_FINGERPRINT_HASH = "sd/crypto-util/source-fingerprints"
REDIS_SOURCE_KEY_HASH = "sd/crypto-util/source-keys"
REDIS_FINGERPRINT_HASH = "sd/crypto-util/fingerprints"
REDIS_KEY_HASH = "sd/crypto-util/keys"

def __init__(self,
scrypt_params,
Expand Down Expand Up @@ -230,23 +230,23 @@ def delete_reply_keypair(self, source_filesystem_id):
temp_gpg = gnupg.GPG(binary='gpg2', homedir=self.gpg_key_dir)
# The subkeys keyword argument deletes both secret and public keys.
temp_gpg.delete_keys(key, secret=True, subkeys=True)
self.redis.hdel(self.REDIS_SOURCE_KEY_HASH, self.get_fingerprint(source_filesystem_id))
self.redis.hdel(self.REDIS_SOURCE_FINGERPRINT_HASH, source_filesystem_id)
self.redis.hdel(self.REDIS_KEY_HASH, self.get_fingerprint(source_filesystem_id))
self.redis.hdel(self.REDIS_FINGERPRINT_HASH, source_filesystem_id)

def get_fingerprint(self, name):
"""
Returns the fingerprint of the GPG key for the given name.
The supplied name is usually a source filesystem ID.
"""
fingerprint = self.redis.hget(self.REDIS_SOURCE_FINGERPRINT_HASH, name)
fingerprint = self.redis.hget(self.REDIS_FINGERPRINT_HASH, name)
if fingerprint:
return fingerprint

for key in self.gpg.list_keys():
for uid in key['uids']:
if name in uid:
self.redis.hset(self.REDIS_SOURCE_FINGERPRINT_HASH, name, key['fingerprint'])
self.redis.hset(self.REDIS_FINGERPRINT_HASH, name, key['fingerprint'])
return key['fingerprint']

return None
Expand All @@ -261,12 +261,12 @@ def get_pubkey(self, name):
if not fingerprint:
return None

key = self.redis.hget(self.REDIS_SOURCE_KEY_HASH, fingerprint)
key = self.redis.hget(self.REDIS_KEY_HASH, fingerprint)
if key:
return key

key = self.gpg.export_keys(fingerprint)
self.redis.hset(self.REDIS_SOURCE_KEY_HASH, fingerprint, key)
self.redis.hset(self.REDIS_KEY_HASH, fingerprint, key)
return key

def encrypt(self, plaintext, fingerprints, output=None):
Expand Down

0 comments on commit 5aca092

Please sign in to comment.