Explorar o código

Add method to authenticate without cli

oz123 %!s(int64=11) %!d(string=hai) anos
pai
achega
3c1372e1e0
Modificáronse 2 ficheiros con 15 adicións e 0 borrados
  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