Ejemplo n.º 1
0
 def test_get(self):
     old_engine = CryptoEngine.get()
     self.assertIsInstance(old_engine, CryptoEngineOld)
     CryptoEngine._instance = None
     new_engine = CryptoEngine.get(dbver=0.5)
     self.assertIsInstance(new_engine, CryptoEngine)
     self.assertFalse(isinstance(new_engine, CryptoEngineOld))
     CryptoEngine._instance = None
     old_engine = CryptoEngine.get()
    def __init__(self):
        config.set_defaults(default_config)
        enc = CryptoEngine.get(dbver=0.4)
        enc.callback = DummyCallback4()
        self.enc1 = copy.copy(enc)
        enc = CryptoEngine.get(dbver=0.5)
        enc.callback = DummyCallback4()
        self.enc2 = copy.copy(enc)

        self.db1 = SQLiteDatabaseNewForm('konverter-v0.4.db', dbformat=0.4)
        self.db2 = SQLiteDatabaseNewForm('konverter-v0.5.db', dbformat=0.5)
        assert self.enc1 is not self.enc2
Ejemplo n.º 3
0
    def run(self):
        global AUTHENTICATED, TAGS, DB

        OSX = False
        sys.argv = []

        args = parser_options().parse_args()
        xselpath, dbtype = get_conf_options(args, OSX)
        dbver = 0.5
        DB = pwman.data.factory.create(dbtype, dbver)
        DB.open(dbver=0.5)
        print(dir(DB))
        CryptoEngine.get(dbver=0.5)
        print(pwman.config._conf)
        debug(True)
        run(port=9030)
Ejemplo n.º 4
0
 def get_user_password(self):
     """
     get the databases password from the user
     """
     enc = CryptoEngine.get()
     newkey = enc.changepassword()
     return self.savekey(newkey)
Ejemplo n.º 5
0
 def changepassword(self):
     """
     Change the databases password.
     """
     enc = CryptoEngine.get()
     newkey = enc.changepassword()
     return self.savekey(newkey)
Ejemplo n.º 6
0
 def do_tags(self, arg):
     enc = CryptoEngine.get()
     if not enc.alive():
         enc._getcipher()
     print ("Tags: \n",)
     t = self._tags(enc)
     print ('\n'.join(t))
Ejemplo n.º 7
0
def forget():
    global AUTHENTICATED
    AUTHENTICATED = False
    enc = CryptoEngine.get()
    enc.forget()

    redirect('/auth')
Ejemplo n.º 8
0
Archivo: cli.py Proyecto: hbrunn/pwman3
    def __init__(self, db, hasxsel, callback):
        """
        initialize CLI interface, set up the DB
        connecion, see if we have xsel ...
        """
        cmd.Cmd.__init__(self)
        self.intro = "%s %s (c) visit: %s" % (pwman.appname, pwman.version, pwman.website)
        self._historyfile = config.get_value("Readline", "history")
        self.hasxsel = hasxsel
        try:
            enc = CryptoEngine.get()
            enc._callback = callback()
            self._db = db
            #  this cascades down all the way to setting the database key
            self._db.open()
        except Exception as e:  # pragma: no cover
            self.error(e)
            sys.exit(1)

        try:
            readline.read_history_file(self._historyfile)
        except IOError as e:  # pragma: no cover
            pass

        self.prompt = "pwman> "
Ejemplo n.º 9
0
 def test_db_change_pass(self):
     "f**k yeah, we change the password and the new dummy works"
     enc = CryptoEngine.get()
     enc._callback = DummyCallback3()
     self.tester.cli._db.changepassword()
     self.tester.cli.do_forget('')
     enc._callback = DummyCallback4()
     self.tester.cli.do_ls('')
Ejemplo n.º 10
0
    def read_old_db(self):
        "read the old db and get all nodes"

        self.db = SQLiteDatabaseReader()
        enc = CryptoEngine.get()
        enc.set_callback(CLICallback())
        self.db.open()
        self.oldnodes = self.db.listnodes()
        self.oldnodes = self.db.getnodes(self.oldnodes)
Ejemplo n.º 11
0
 def get_username(self):
     """
     Return the username.
     This solution with strip is horribly assuming that
     the username does not containg space as the last character.
     The same is also true for the password.
     """
     enc = CryptoEngine.get()
     return enc.decrypt(self._username).strip()
Ejemplo n.º 12
0
    def open(self):
        """Open the database."""
        self._open()

        enc = CryptoEngine.get()
        key = self.loadkey()
        if key != None:
            enc.set_cryptedkey(key)
        else:
            self.changepassword()
Ejemplo n.º 13
0
    def open(self):
        """Open the database."""
        self._open()

        enc = CryptoEngine.get()
        key = self.loadkey()
        if (key != None):
            enc.set_cryptedkey(key)
        else:
            self.changepassword()
Ejemplo n.º 14
0
    def __init__(self,username="",password="",url="",notes="",tags=[]):
        """Initialise everything to null."""
        self._id = 0;

        enc = CryptoEngine.get()
        self._username = enc.encrypt(username)
        self._password = enc.encrypt(password)
        self._url = enc.encrypt(url)
        self._notes = enc.encrypt(notes)
        self._tags = []
        self.set_tags(tags)
Ejemplo n.º 15
0
    def __init__(self, username="", password="", url="", notes="", tags=[]):
        """Initialise everything to null."""
        self._id = 0

        enc = CryptoEngine.get()
        self._username = enc.encrypt(username)
        self._password = enc.encrypt(password)
        self._url = enc.encrypt(url)
        self._notes = enc.encrypt(notes)
        self._tags = []
        self.set_tags(tags)
Ejemplo n.º 16
0
    def __str__(self):  # pragma: no cover
        enc = CryptoEngine.get()
        try:
            tags = ', '.join([enc.decrypt(tag).strip() for tag in filter(None,
                             self._tags)])
        except Exception:
            tags = ', '.join([tag.strip() for tag in filter(None, self._tags)])

        user = enc.decrypt(self._username).strip()
        url = enc.decrypt(self._url).strip()
        return '{0}@{1}\t{2}'.format(user, url,
                                     tags)
Ejemplo n.º 17
0
Archivo: cli.py Proyecto: k0lter/pwman3
 def do_tags(self, arg):
     tags = self._db.listtags()
     # request password
     enc = CryptoEngine.get()
     if not enc.alive():
         enc._getcipher()
     print "Tags: ",
     if len(tags) == 0:
         print "None",
     for t in tags:
         print "%s " % t,
     print
Ejemplo n.º 18
0
Archivo: cli.py Proyecto: ikegam/pwman3
 def complete_filter(self, text, line, begidx, endidx):
     strings = []
     enc = CryptoEngine.get()
     if not enc.alive():
         return strings
     
     tags = self._db.listtags()
     for t in tags:
         name = t.get_name()
         if name.startswith(text):
             strings.append(t.get_name())
     return strings
Ejemplo n.º 19
0
    def complete_filter(self, text, line, begidx, endidx):
        strings = []
        enc = CryptoEngine.get()
        if not enc.alive():
            return strings

        tags = self._db.listtags()
        for t in tags:
            name = t.get_name()
            if name.startswith(text):
                strings.append(t.get_name())
        return strings
Ejemplo n.º 20
0
    def __init__(self, db):
        cmd.Cmd.__init__(self)
        self.intro = "%s %s (c) %s <%s>" % (pwman.appname, pwman.version, pwman.author, pwman.authoremail)
        self._historyfile = config.get_value("Readline", "history")

        try:
            enc = CryptoEngine.get()
            enc.set_callback(CLICallback())
            self._db = db
            self._db.open()
        except Exception, e:
            self.error(e)
            sys.exit(1)
Ejemplo n.º 21
0
    def __init__(self, db):
        cmd.Cmd.__init__(self)
        self.intro = "%s %s (c) %s <%s>" % (pwman.appname, pwman.version,
                                            pwman.author, pwman.authoremail)
        self._historyfile = config.get_value("Readline", "history")

        try:
            enc = CryptoEngine.get()
            enc.set_callback(CLICallback())
            self._db = db
            self._db.open()
        except Exception, e:
            self.error(e)
            sys.exit(1)
    def run(self):
        # before add nodes to db1 we have to create an encryption key!
        # this is handeld by the open method
        self.db1._open()
        enc1 = CryptoEngine.get(dbver=0.4)
        enc1.callback = DummyCallback4()
        key = self.db1.loadkey()
        if key is not None:
            enc1.set_cryptedkey(key)
        else:
            newkey = enc1.changepassword()
            self.db1.savekey(newkey)

        enc1c = copy.copy(enc1)
        if key is not None:
            enc1.set_cryptedkey(key)

        self.add_nodes_to_db1()
        CryptoEngine._instance = None

        self.db2._open()
        enc2 = CryptoEngine.get(dbver=0.5)
        enc2.callback = DummyCallback4()
        key = self.db2.loadkey()
        if key is not None:
            enc2.set_cryptedkey(key)
        else:
            newkey = enc2.changepassword()
            self.db2.savekey(newkey)

        enc2c = copy.copy(enc2)
        if key is not None:
            enc2.set_cryptedkey(key)

        self.add_nodes_to_db2()
        assert enc1 is not enc2
        assert enc1c is not enc2c
Ejemplo n.º 23
0
 def open(self):
     """
     Open the database, by calling the _open method of the
     class inherited for the specific database.
     When done validation that the file is OK, check if it has
     encryption key, by calling   
     enc = CryptoEngine.get()
     key = self.loadkey()
     """
     self._open()
     enc = CryptoEngine.get()
     key = self.loadkey()
     if (key != None):
         enc.set_cryptedkey(key)
     else:
         self.changepassword()
Ejemplo n.º 24
0
 def dump_to_db(self):
     enc = CryptoEngine.get()
     dump = ""
     dump += "username:"******"##"
     dump += "password:"******"##"
     dump += "url:"+enc.encrypt(self._url)+"##"
     dump += "notes:"+enc.encrypt(self._notes)+"##"
     dump += "tags:"
     tagsloc = ""
     for tag in self._tags:
         if isinstance(tag, str):
             tagsloc += "tag:"+tag.strip()+"**endtag**"
         else:
             tagsloc += "tag:"+tag.get_name()+"**endtag**"
     dump += tagsloc
     dump = [dump]
     return dump
Ejemplo n.º 25
0
Archivo: cli.py Proyecto: k0lter/pwman3
 def __init__(self, db, hasxsel):
     """
     initialize CLI interface, set up the DB
     connecion, see if we have xsel ...
     """
     cmd.Cmd.__init__(self)
     self.intro = "%s %s (c) visit: %s" % (pwman.appname, pwman.version, pwman.website)
     self._historyfile = config.get_value("Readline", "history")
     self.hasxsel = hasxsel
     try:
         enc = CryptoEngine.get()
         enc.set_callback(CLICallback())
         self._db = db
         self._db.open()
     except Exception, e:
         self.error(e)
         sys.exit(1)
Ejemplo n.º 26
0
def is_authenticated():
    global AUTHENTICATED
    crypto = CryptoEngine.get(dbver=0.5)

    if request.method == 'POST':
        key = request.POST.get('pwd', '')
        while True:
            try:
                crypto.auth(key)
                break
            except Exception:
                redirect('/auth')

        AUTHENTICATED = True
        redirect('/')
    else:
        return template("login.tpl", template_lookup=templates_path)
Ejemplo n.º 27
0
Archivo: cli.py Proyecto: k0lter/pwman3
 def __init__(self, db, hasxsel):
     """
     initialize CLI interface, set up the DB
     connecion, see if we have xsel ...
     """
     _dbwarning = (
         "\n*** WARNNING: You are using the old db format which" + " uses cPickle, please upgrade your db !!! ***"
     )
     cmd.Cmd.__init__(self)
     self.intro = "%s %s (c) visit: %s %s" % (pwman.appname, pwman.version, pwman.website, _dbwarning)
     self._historyfile = config.get_value("Readline", "history")
     self.hasxsel = hasxsel
     try:
         enc = CryptoEngine.get()
         enc.set_callback(CLICallback())
         self._db = db
         self._db.open()
     except Exception, e:
         self.error(e)
         sys.exit(1)
Ejemplo n.º 28
0
    def _tagids(self, tags):
        ids = []
        sql = "SELECT ID FROM TAGS WHERE DATA LIKE ?"
        for tag in tags:
            try:
                if isinstance(tag, str):
                    enc = CryptoEngine.get()
                    tag = enc.encrypt(tag)
                    self._cur.execute(sql, [tag])
                else:
                    self._cur.execute(sql, [tag._name+'%'])

                values = self._cur.fetchall()
                if values:  # tags already exist in the database
                    ids.extend(list(itertools.chain(*values)))
                else:
                    self._create_tag(tag)
                    ids.append(self._cur.lastrowid)
            except sqlite.DatabaseError as e:  # pragma: no cover
                raise DatabaseException("SQLite: %s" % (e))
        return ids
Ejemplo n.º 29
0
 def get_notes(self):
     """Return the Notes."""
     enc = CryptoEngine.get()
     return enc.decrypt(self._notes)
Ejemplo n.º 30
0
 def set_url(self, url):
     """Set the URL."""
     enc = CryptoEngine.get()
     self._url = enc.encrypt(url)
Ejemplo n.º 31
0
 def get_url(self):
     """Return the URL."""
     enc = CryptoEngine.get()
     return enc.decrypt(self._url)
Ejemplo n.º 32
0
 def set_password(self, password):
     """Set the password."""
     enc = CryptoEngine.get()
     self._password = enc.encrypt(password)
Ejemplo n.º 33
0
 def changepassword(self):
     """Change the databases password."""
     enc = CryptoEngine.get()
     newkey = enc.changepassword()
     return self.savekey(newkey)
Ejemplo n.º 34
0
 def set_name(self, name):
     enc = CryptoEngine.get()
     self._name = enc.encrypt(name)
Ejemplo n.º 35
0
 def name(self, value):
     enc = CryptoEngine.get()  # pragma: no cover
     self._name = enc.encrypt(value)  # pragma: no cover
Ejemplo n.º 36
0
 def set_tags(self, tags):
     self._tags = []
     enc = CryptoEngine.get()
     for i in tags:
         self._tags.append(enc.encrypt(i))
Ejemplo n.º 37
0
 def get_tags(self):
     tags = []
     enc = CryptoEngine.get()
     for i in self._tags:
         tags.append(enc.decrypt(i))
     return tags
Ejemplo n.º 38
0
 def do_forget(self, args):
     try:
         enc = CryptoEngine.get()
         enc.forget()
     except Exception, e:
         self.error(e)
Ejemplo n.º 39
0
 def get_name(self):
     enc = CryptoEngine.get()
     return enc.decrypt(self._name)
Ejemplo n.º 40
0
 def do_forget(self, args):
     try:
         enc = CryptoEngine.get()
         enc.forget()
     except Exception as e:
         self.error(e)
Ejemplo n.º 41
0
 def set_name(self, name):
     enc = CryptoEngine.get()
     self._name = enc.encrypt(name)
Ejemplo n.º 42
0
 def set_notes(self, notes):
     """Set the Notes."""
     enc = CryptoEngine.get()
     self._notes = enc.encrypt(notes)
Ejemplo n.º 43
0
 def __init__(self, name):
     enc = CryptoEngine.get()
     self._name = enc.encrypt(name)
Ejemplo n.º 44
0
 def get_username(self):
     """Return the username."""
     enc = CryptoEngine.get()
     return enc.decrypt(self._username)
Ejemplo n.º 45
0
 def get_name(self):
     enc = CryptoEngine.get()
     return enc.decrypt(self._name)
Ejemplo n.º 46
0
 def set_username(self, username):
     """Set the username."""
     enc = CryptoEngine.get()
     self._username = enc.encrypt(username)
Ejemplo n.º 47
0
 def __str__(self):
     enc = CryptoEngine.get()
     return enc.decrypt(self._name)
Ejemplo n.º 48
0
 def get_password(self):
     """Return the password."""
     enc = CryptoEngine.get()
     return enc.decrypt(self._password)