Human password exception handing

pull/539/head
Kieran Prasch 2018-11-09 07:22:50 -08:00
parent 377c96c410
commit 1ad5e98648
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
3 changed files with 16 additions and 12 deletions

View File

@ -32,8 +32,3 @@ DEFAULT_CONFIG_ROOT = APP_DIR.user_data_dir
# Static Seednodes
SeednodeMetadata = namedtuple('seednode', ['checksum_address', 'rest_host', 'rest_port'])
SEEDNODES = tuple()
# CLI
NUCYPHER_SENTRY_ENDPOINT = "https://d8af7c4d692e4692a455328a280d845e@sentry.io/1310685"
KEYRING_PASSPHRASE_ENVVAR_KEY = 'NUCYPHER_KEYRING_PASSPHRASE'

View File

@ -359,6 +359,9 @@ class NucypherKeyring:
class KeyringLocked(KeyringError):
pass
class InvalidPassphrase(KeyringError):
pass
def __init__(self,
account: str,
keyring_root: str = None,
@ -567,7 +570,10 @@ class NucypherKeyring:
returning the corresponding Keyring instance.
"""
cls.validate_passphrase(passphrase)
failures = cls.validate_passphrase(passphrase)
if failures:
raise cls.InvalidPassphrase(", ".join(failures)) # TODO: Ensure this scope is seperable from the scope containing the passphrase
if not any((wallet, encrypting, tls)):
raise ValueError('Either "encrypting", "wallet", or "tls" must be True '
'to generate new keys, or set "no_keys" to True to skip generation.')
@ -662,12 +668,18 @@ class NucypherKeyring:
@staticmethod
def validate_passphrase(passphrase: str) -> bool:
"""Validate a passphrase and return True or raise an error with a failure reason"""
"""
Validate a passphrase and return True or raise an error with a failure reason.
NOTICE: Do not raise inside this function.
"""
rules = (
(bool(passphrase), 'Passphrase must not be blank.'),
(len(passphrase) >= 16, 'Passphrase is too short, must be >= 16 chars.'),
)
failures = list()
for rule, failure_message in rules:
if not rule:
raise ValueError(failure_message)
return True
failures.append(failure_message)
return True if not failures else failures

View File

@ -20,8 +20,6 @@ from sentry_sdk import Client, capture_exception, add_breadcrumb
from twisted.logger import ILogObserver
from zope.interface import provider
from nucypher.config.constants import NUCYPHER_SENTRY_ENDPOINT
@provider(ILogObserver)
def simpleObserver(event):
@ -32,7 +30,6 @@ def simpleObserver(event):
def logToSentry(event):
client = Client(dsn=NUCYPHER_SENTRY_ENDPOINT)
# Handle Logs
if not event.get('isError') or 'failure' not in event: