mirror of
https://github.com/simple-login/app.git
synced 2025-02-24 15:53:22 +08:00
use pgpy as fallback for gpg
This commit is contained in:
parent
6c816d51d6
commit
0307793666
1 changed files with 9 additions and 20 deletions
|
@ -420,27 +420,16 @@ def prepare_pgp_message(orig_msg: Message, pgp_fingerprint: str, public_key: str
|
||||||
second.add_header("Content-Disposition", 'inline; filename="encrypted.asc"')
|
second.add_header("Content-Disposition", 'inline; filename="encrypted.asc"')
|
||||||
|
|
||||||
# encrypt original message
|
# encrypt original message
|
||||||
# ABTest between pgpy and python-gnupg
|
# use pgpy as fallback
|
||||||
x = random.randint(0, 9)
|
try:
|
||||||
if x >= 5:
|
encrypted_data = pgp_utils.encrypt_file(
|
||||||
LOG.d("encrypt using python-gnupg")
|
BytesIO(orig_msg.as_bytes()), pgp_fingerprint
|
||||||
try:
|
|
||||||
encrypted_data = pgp_utils.encrypt_file(
|
|
||||||
BytesIO(orig_msg.as_bytes()), pgp_fingerprint
|
|
||||||
)
|
|
||||||
second.set_payload(encrypted_data)
|
|
||||||
except PGPException:
|
|
||||||
LOG.exception("Cannot encrypt using python-gnupg, use pgpy")
|
|
||||||
encrypted_data = pgp_utils.encrypt_file_with_pgpy(
|
|
||||||
orig_msg.as_bytes(), public_key
|
|
||||||
)
|
|
||||||
second.set_payload(str(encrypted_data))
|
|
||||||
else:
|
|
||||||
LOG.d("encrypt using pgpy")
|
|
||||||
encrypted_data = pgp_utils.encrypt_file_with_pgpy(
|
|
||||||
orig_msg.as_bytes(), public_key
|
|
||||||
)
|
)
|
||||||
second.set_payload(str(encrypted_data))
|
second.set_payload(encrypted_data)
|
||||||
|
except PGPException:
|
||||||
|
LOG.exception("Cannot encrypt using python-gnupg, use pgpy")
|
||||||
|
encrypted = pgp_utils.encrypt_file_with_pgpy(orig_msg.as_bytes(), public_key)
|
||||||
|
second.set_payload(str(encrypted))
|
||||||
|
|
||||||
msg.attach(second)
|
msg.attach(second)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue