Newer
Older
Copyright (C) 2010-2020 Cr@ns <roots@crans.org>
Authors : Daniel Stan <daniel.stan@crans.org>
Vincent Le Gallic <legallic@crans.org>
Alexandre Iooss <erdnaxe@crans.org>
SPDX-License-Identifier: GPL-3.0-or-later
"""
import subprocess
import logging
# Local logger
log = logging.getLogger(__name__)
log.info("Decrypting using GnuPG")
with gpg.Context() as c:
plaintext, _, _ = c.decrypt(ciphertext.encode("utf-8"))
return plaintext.decode("utf-8")
def encrypt(content: str, keys: []) -> str:
log.info("Encrypting using GnuPG")
with gpg.Context() as c:
c.armor = True
cipher, _, _ = c.encrypt(content.encode("utf-8"), keys)
return cipher.decode("utf-8")
full_command = ['gpg', '--recv-keys', fpr]
log.info("Running `%s`" % " ".join(full_command))
return subprocess.run(full_command)
Return true if can be trusted and we can encrypt
log.info("Checking %s key with email %s" % (key.fpr, email))
if not key.can_encrypt:
log.debug("Cannot encrypt for key %s" % key.fpr)
return False
for uid in key.uids:
if email == uid.email and not uid.revoked and not uid.invalid \
and uid.validity >= gpg.constants.validity.FULL:
return True
log.debug("No trusted valid uid were found for this key")
"""
log.info("Getting key corresponding to %s" % fpr)
with gpg.Context() as c: