mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 04:41:28 +02:00
remove pgp debugging code
This commit is contained in:
parent
1abebe8067
commit
a2254cfdf8
@ -17,6 +17,10 @@ class PGPException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class IncorrectPassphrasePGPException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def load_public_key(public_key: str) -> str:
|
def load_public_key(public_key: str) -> str:
|
||||||
"""Load a public key into keyring and return the fingerprint. If error, raise Exception"""
|
"""Load a public key into keyring and return the fingerprint. If error, raise Exception"""
|
||||||
import_result = gpg.import_keys(public_key)
|
import_result = gpg.import_keys(public_key)
|
||||||
@ -26,6 +30,30 @@ def load_public_key(public_key: str) -> str:
|
|||||||
raise PGPException("Cannot load key") from e
|
raise PGPException("Cannot load key") from e
|
||||||
|
|
||||||
|
|
||||||
|
def load_public_key_and_check(public_key: str) -> str:
|
||||||
|
"""Same as load_public_key but will try an encryption using the new key.
|
||||||
|
If the encryption fails, remove the newly created fingerprint.
|
||||||
|
Return the fingerprint
|
||||||
|
"""
|
||||||
|
import_result = gpg.import_keys(public_key)
|
||||||
|
try:
|
||||||
|
fingerprint = import_result.fingerprints[0]
|
||||||
|
except Exception as e:
|
||||||
|
raise PGPException("Cannot load key") from e
|
||||||
|
else:
|
||||||
|
dummy_data = BytesIO(b"test")
|
||||||
|
r = gpg.encrypt_file(dummy_data, fingerprint)
|
||||||
|
if not r.ok:
|
||||||
|
# remove the fingerprint
|
||||||
|
gpg.delete_keys([fingerprint])
|
||||||
|
if r.GPG_ERROR_CODES == {11: "incorrect passphrase"}:
|
||||||
|
LOG.warning("Incorrect passphrase")
|
||||||
|
raise IncorrectPassphrasePGPException()
|
||||||
|
raise PGPException("Encryption fails with the key")
|
||||||
|
|
||||||
|
return fingerprint
|
||||||
|
|
||||||
|
|
||||||
def hard_exit():
|
def hard_exit():
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
LOG.warning("kill pid %s", pid)
|
LOG.warning("kill pid %s", pid)
|
||||||
@ -61,12 +89,6 @@ def encrypt_file(data: BytesIO, fingerprint: str) -> str:
|
|||||||
r = gpg.encrypt_file(data, fingerprint, always_trust=True)
|
r = gpg.encrypt_file(data, fingerprint, always_trust=True)
|
||||||
|
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
# save the data for debugging
|
raise PGPException(f"Cannot encrypt, status: {r.status}")
|
||||||
data.seek(0)
|
|
||||||
file_path = f"/tmp/{random_string(10)}.eml"
|
|
||||||
with open(file_path, "wb") as f:
|
|
||||||
f.write(data.getbuffer())
|
|
||||||
|
|
||||||
raise PGPException(f"Cannot encrypt, status: {r.status}, {file_path}")
|
|
||||||
|
|
||||||
return str(r)
|
return str(r)
|
||||||
|
Loading…
Reference in New Issue
Block a user