Skip to content

Commit 183bf9f

Browse files
committed
Avoid looping on encrypted secret decryption failure (#213)
1 parent df0fda4 commit 183bf9f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

emailproxy.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2023 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__version__ = '2023-11-18' # ISO 8601 (YYYY-MM-DD)
9+
__version__ = '2023-12-18' # ISO 8601 (YYYY-MM-DD)
1010
__package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only
1111

1212
import abc
@@ -340,10 +340,10 @@ def save(store_id, config_dict):
340340

341341

342342
class AWSSecretsManagerCacheStore(CacheStore):
343-
# noinspection PyGlobalUndefined,PyPackageRequirements
344343
@staticmethod
345344
def _get_boto3_client(store_id):
346345
try:
346+
# noinspection PyGlobalUndefined
347347
global boto3, botocore
348348
import boto3
349349
import botocore.exceptions
@@ -752,7 +752,11 @@ def get_account_with_catch_all_fallback(option):
752752
try:
753753
# if both secret values are present we use the unencrypted version (as it may have been user-edited)
754754
if client_secret_encrypted and not client_secret:
755-
client_secret = cryptographer.decrypt(client_secret_encrypted)
755+
try:
756+
client_secret = cryptographer.decrypt(client_secret_encrypted)
757+
except InvalidToken as e: # needed to avoid looping as we don't remove secrets on decryption failure
758+
Log.error('Invalid password to decrypt', username, 'secret - aborting login:', Log.error_string(e))
759+
return False, '%s: Login failed - the password for account %s is incorrect' % (APP_NAME, username)
756760

757761
if access_token or refresh_token: # if possible, refresh the existing token(s)
758762
if not access_token or access_token_expiry - current_time < TOKEN_EXPIRY_MARGIN:
@@ -2270,7 +2274,9 @@ class App:
22702274
"""Manage the menu bar icon, server loading, authorisation and notifications, and start the main proxy thread"""
22712275

22722276
def __init__(self, args=None):
2273-
global CONFIG_FILE_PATH, CACHE_STORE, EXITING, prompt_toolkit
2277+
# noinspection PyGlobalUndefined
2278+
global prompt_toolkit
2279+
global CONFIG_FILE_PATH, CACHE_STORE, EXITING
22742280
EXITING = False # needed to allow restarting when imported from parent scripts (or an interpreter)
22752281

22762282
parser = argparse.ArgumentParser(description='%s: transparently add OAuth 2.0 support to IMAP/POP/SMTP client '

0 commit comments

Comments
 (0)