浏览代码

Add method to authenticate without cli

oz123 11 年之前
父节点
当前提交
3c1372e1e0
共有 2 个文件被更改,包括 15 次插入0 次删除
  1. 4 0
      pwman/ui/base.py
  2. 11 0
      pwman/util/crypto.py

+ 4 - 0
pwman/ui/base.py

@@ -468,6 +468,10 @@ class BaseCommands(BaseUI, HelpUI):
         return tags
 
     def do_list(self, args):
+
+        #crypto  = CryptoEngine.get()
+        #crypto.auth('YOURPASSWORD')
+
         if len(args.split()) > 0:
             self.do_clear('')
             self.do_filter(args)

+ 11 - 0
pwman/util/crypto.py

@@ -171,6 +171,17 @@ class CryptoEngine(object):
             self._timeout = -1
         self._cipher = None
 
+    def auth(self, key):
+        """
+        authenticate using a given key
+        """
+        tmpcipher = self._getcipher_real(key, self._algo)
+        plainkey = tmpcipher.decrypt(str(self._keycrypted).decode('base64'))
+        key = self._retrievedata(plainkey)
+        key = str(key).decode('base64')
+        self._cipher = self._getcipher_real(key, self._algo)
+
+
     def encrypt(self, obj):
         """
         encrypt(obj) -> ciphertext