From 1b999a1206528e27c777967024a4d6638ba33843 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 2 Sep 2012 15:29:37 -0400 Subject: [PATCH] Finish lazy-importing of py-bcrypt and pycrypto in config.__init__ --- earwigbot/commands/crypt.py | 2 -- earwigbot/config/__init__.py | 12 ++++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/earwigbot/commands/crypt.py b/earwigbot/commands/crypt.py index 92f458c..2072743 100644 --- a/earwigbot/commands/crypt.py +++ b/earwigbot/commands/crypt.py @@ -22,8 +22,6 @@ import hashlib -from Crypto.Cipher import Blowfish - from earwigbot import importer from earwigbot.commands import Command diff --git a/earwigbot/config/__init__.py b/earwigbot/config/__init__.py index 911a496..b89d310 100644 --- a/earwigbot/config/__init__.py +++ b/earwigbot/config/__init__.py @@ -282,10 +282,18 @@ class BotConfig(object): self._setup_logging() if self.is_encrypted(): if not self._decryption_cipher: + try: + blowfish_new = Blowfish.new + hashpw = bcrypt.hashpw + except ImportError: + url1 = "http://www.mindrot.org/projects/py-bcrypt" + url2 = "https://www.dlitz.net/software/pycrypto/" + e = "Encryption requires the 'py-bcrypt' and 'pycrypto' packages: {0}, {1}" + raise NoConfigError(e.format(url1, url2)) key = getpass("Enter key to decrypt bot passwords: ") - self._decryption_cipher = Blowfish.new(sha256(key).digest()) + self._decryption_cipher = blowfish_new(sha256(key).digest()) signature = self.metadata["signature"] - if bcrypt.hashpw(key, signature) != signature: + if hashpw(key, signature) != signature: raise RuntimeError("Incorrect password.") for node, nodes in self._decryptable_nodes: self._decrypt(node, nodes)