Selaa lähdekoodia

Enable supression of Crypto Warning

Oz N Tiram 8 vuotta sitten
vanhempi
commit
97b69292c5
5 muutettua tiedostoa jossa 33 lisäystä ja 12 poistoa
  1. 8 5
      pwman/__init__.py
  2. 16 2
      pwman/ui/cli.py
  3. 7 1
      pwman/ui/win.py
  4. 1 1
      pwman/util/config.py
  5. 1 3
      pwman/util/crypto_engine.py

+ 8 - 5
pwman/__init__.py

@@ -70,6 +70,7 @@ def which(cmd):  # pragma: no cover
             return cmd
     return ''
 
+
 config_dir = os.path.expanduser("~/.pwman")
 
 
@@ -106,10 +107,12 @@ def set_xsel(configp, OSX):
         configp.set_value("Global", "xsel", pbcopypath)
 
 
-def set_win_colors(config):  # pragma: no cover
-    if sys.platform.startswith('win'):
-        colorama.init()
-
+#def set_win_colors(config):  # pragma: no cover
+#    try:
+#        if sys.platform.startswith('win'):
+#            colorama.init()
+#   except ImportError:  # when installing colorama is still not there
+#        pass
 
 def set_umask(configp):
     umask = configp.get_value("Global", "umask")
@@ -129,7 +132,7 @@ def get_conf_options(args, OSX):
     if not xselpath:  # pragma: no cover
         set_xsel(configp, OSX)
 
-    set_win_colors(configp)
+    #set_win_colors(configp)
     set_db(args, configp)
     set_umask(configp)
     dburi = configp.get_value("Database", "dburi")

+ 16 - 2
pwman/ui/cli.py

@@ -19,8 +19,12 @@
 # pylint: disable=I0011
 
 from __future__ import print_function
-import sys
+
 import cmd
+import os
+import sys
+
+
 if sys.version_info.major > 2:
     raw_input = input
 
@@ -38,7 +42,7 @@ from pwman.ui.tools import CLICallback
 from pwman.data import factory
 from pwman.exchange.importer import Importer
 from pwman.util.crypto_engine import CryptoEngine
-
+from pwman.util.crypto_engine import AES
 
 class PwmanCli(cmd.Cmd, BaseCommands):
     """
@@ -95,6 +99,16 @@ def main():
     PwmanCli, OSX = get_ui_platform(sys.platform)
     xselpath, dbtype, config = get_conf_options(args, OSX)
     dburi = config.get_value('Database', 'dburi')
+
+    if os.path.join("Crypto", "Cipher") not in AES.__file__:  # we are using built in AES.py
+        import colorama
+        if config.get_value('Crypto', 'supress_warning').lower() != 'yes':
+            print("{}WARNING: You are not using PyCrypto!!!\n"
+                  "WARNING: You should install PyCrypto for better security and "
+                  "perfomance\nWARNING: You can supress this warning by editing "
+                  "pwman config file.{}".format(colorama.Fore.RED,
+                                                colorama.Style.RESET_ALL))
+
     print(dburi)
     dbver = get_db_version(config, args)
     CryptoEngine.get()

+ 7 - 1
pwman/ui/win.py

@@ -21,18 +21,24 @@
 # ============================================================================
 """
 from __future__ import print_function
-import time
 import ctypes
 import os
+import time
+
 try:
     import msvcrt
 except ImportError:
     pass
 
+import colorama
+
 from pwman.ui.cli import PwmanCli
 from pwman.util.crypto_engine import CryptoEngine
 
 
+colorama.init()
+
+
 def heardEnterWin():
     c = msvcrt.kbhit()
     if c == 1:

+ 1 - 1
pwman/util/config.py

@@ -39,7 +39,7 @@ default_config = {'Global': {'umask': '0100', 'colors': 'yes',
                                                           'pwman.db')},
                   'Readline': {'history': os.path.join(config_dir,
                                                        'history')},
-                  'Crypto': {'warning': 'yes'},
+                  'Crypto': {'supress_warning': 'no'},
                   }
 
 if 'win' in sys.platform:

+ 1 - 3
pwman/util/crypto_engine.py

@@ -37,9 +37,7 @@ except ImportError:
     # or embeded devices where compilation is a bit harder
     from pwman.util.crypto import AES
     from pwman.util.crypto.pypbkdf2 import PBKDF2
-    print("WARNING: You are not using PyCrypto!!!")
-    print("WARNING: You should install PyCrypto for better security and perfomance")
-    print("WARNING: You can supress this warning by editing pwman config file.")
+
 
 from pwman.util.callback import Callback