Przeglądaj źródła

- merge changes from secure listing branch to start up script.
- add dummy classes ...

oz123 11 lat temu
rodzic
commit
971dbdfae7
2 zmienionych plików z 58 dodań i 34 usunięć
  1. 10 6
      pwman/ui/cli.py
  2. 48 28
      scripts/pwman3

+ 10 - 6
pwman/ui/cli.py

@@ -594,9 +594,8 @@ class PwmanCli(cmd.Cmd):
 
     def help_open(self):
         self.usage("open <ID>")
-        print "Launch default browser with 'xdg-open url',\n\
-the url must contain http:// or https://."
-
+        print "Launch default browser with 'xdg-open url',\n\"
+              + "the url must contain http:// or https://."
     def help_o(self):
         self.help_open()
 
@@ -738,7 +737,9 @@ pwman> n {'leetify':False, 'numerics':True}"""
         self.prompt = "pwman> "
 
 
-
+class PwmanCliNew(PwmanCli):
+    pass
+    
 class PwmanCliMac(PwmanCli):
     """
     inherit from PwmanCli, override the right functions...
@@ -781,8 +782,8 @@ class PwmanCliMac(PwmanCli):
     ##
     def help_open(self):
         self.usage("open <ID>")
-        print "Launch default browser with 'open url',\n\
-the url must contain http:// or https://."
+        print "Launch default browser with 'open url',\n\"
+              + "the url must contain http:// or https://."
 
     def help_o(self):
         self.help_open()
@@ -794,6 +795,9 @@ the url must contain http:// or https://."
     def help_cp(self):
         self.help_copy()
 
+class PwmanCliMacNew(PwmanCliMac):
+    pass
+    
 _defaultwidth = 10
 
 def getonechar(question, width=_defaultwidth):

+ 48 - 28
scripts/pwman3

@@ -21,50 +21,47 @@
 #============================================================================
 import os
 import os.path
-import subprocess as sp
 
 _saveconfig = True
 
 import argparse
 
 
-parser = argparse.ArgumentParser(description='pwman3 - a command line password'\
-+'manager.')
-parser.add_argument('-c','--config', dest='cfile',
+parser = argparse.ArgumentParser(description='pwman3 - a command line password'
+                                 + ' manager.')
+parser.add_argument('-c', '--config', dest='cfile',
                     default=os.path.expanduser("~/.pwman/config"),
-                    help='cofiguretion file to read')
-parser.add_argument('-d', '--database', dest='dbase',
-                    default=os.path.expanduser("~/.pwman/pwman.db"))
+                    help='cofiguration file to read')
+parser.add_argument('-d', '--database', dest='dbase')
 
-parser.add_argument('-e', '--encryption', dest="algo", default="Blowfish",
-                help="Possible options are: AES, ARC2, ARC4, "\
-                +"Blowfish(default) CAST, DES, DES3, IDEA, RC5")
+parser.add_argument('-e', '--encryption', dest="algo",
+                    help="Possible options are: AES(default), ARC2, ARC4, "
+                    + "Blowfish, CAST, DES, DES3, IDEA, RC5")
 
-parser.add_argument('-t','--test',  help="Run pwman from current directory \
+parser.add_argument('-t', '--test',  help="Run pwman from current directory \
 without installation", action="store_true")
 args = parser.parse_args()
 
+import sys
 if args.test:
-    import sys
-    sys.path.insert(0,os.getcwd())
+    sys.path.insert(0, os.getcwd())
 
 from pwman.util.crypto import CryptoEngine
-import getopt
-import sys
 
 if 'darwin' in sys.platform:
     from pwman.ui.cli import PwmanCliMac as PwmanCli
+    from pwman.ui.cli import PwmanCliMacNew as PwmanCliNew
     OSX = True
 else:
     from pwman.ui.cli import PwmanCli
+    from pwman.ui.cli import PwmanCliNew
     OSX = False
 
 
 import pwman.util.config as config
 import pwman.data.factory
 
-config_file=args.cfile
-
+config_file = args.cfile
 
 
 def which(cmd):
@@ -86,43 +83,65 @@ try:
     # set cls_timout to negative number (e.g. -1) to disable
     default_config = {'Global': {'umask': '0100', 'colors': 'yes',
                                  'cls_timeout': '5'
-                                },
+                                 },
                       'Database': {'type': 'SQLite',
                                    'filename': os.path.join(config_dir,
                                                             "pwman.db")},
-                      'Encryption': {'algorithm': 'Blowfish'},
+                      'Encryption': {'algorithm': 'AES'},
                       'Readline': {'history': os.path.join(config_dir,
                                                            "history")}
                       }
-    
+
     config.set_defaults(default_config)
-    
+
     if os.path.exists(config_file):
         config.load(config_file)
         xselpath = config.get_value("Global", "xselpath")
-    elif not OSX :
+    elif not OSX:
         xselpath = which("xsel")
         config.set_value("Global", "xsel", xselpath)
     elif OSX:
         pbcopypath = which("pbcopy")
         config.set_value("Global", "xsel", pbcopypath)
 
-    if args.dbase !=  config.get_value('Database', "filename"):
+    if args.dbase:
         config.set_value("Database", "filename", args.dbase)
         _saveconfig = False
-    if args.algo != "Blowfish":
+    if args.algo:
             config.set_value("Encryption", "algorithm", args.algo)
             _saveconfig = False
-
     # set umask before creating/opening any files
     umask = int(config.get_value("Global", "umask"))
     os.umask(umask)
 
     enc = CryptoEngine.get()
-    
+
     dbtype = config.get_value("Database", "type")
-    db = pwman.data.factory.create(dbtype)
-    cli = PwmanCli(db, xselpath)
+    # if it is done here, we could do the following:
+    # if db.ver == 0.4 :
+    #     db = pwman.data.factory.create(dbtyp, new_version)
+    # else:
+    #     we use the old code untouched ... insecure, but
+    #     keeps backwards compatibility ...
+    # if the database file exists check it's version
+    # else: force version 0.4
+    if os.path.exists(config.get_value("Database", "filename")):
+        dbver = pwman.data.factory.check_db_version(dbtype)
+        dbver = float(dbver.strip("\'"))
+    else:
+        dbver = 0.4
+    # the method create could create an old instance that
+    # accepts cPickle object or new style instance that
+    # accepts only strings.
+    # The user should be STRONGLY Prompted to CONVERT the
+    # database to the new format using a command line tool.
+    # version 0.5 pwman will depreciate that old and insecure
+    # code ...
+    db = pwman.data.factory.create(dbtype, dbver)
+    if dbver >= 0.4:
+        cli = PwmanCliNew(db, xselpath)
+    elif dbver < 0.4:
+        cli = PwmanCli(db, xselpath)
 except SystemExit, e:
     sys.exit(e)
 except Exception, e:
@@ -141,3 +160,4 @@ finally:
     except Exception, e:
         print "Error: %s" % (e)
         sys.exit(-1)
+