예제 #1
0
 def set_password(self, service, username, password):
     existing_pw = self._get_password(service)
     if existing_pw:
         # resave the existing password using a compound target
         existing_username = existing_pw['UserName']
         target = self._compound_name(existing_username, service)
         self._set_password(target, existing_username,
             existing_pw['CredentialBlob'].decode('utf-16'))
     self._set_password(service, username, unicode_str(password))
예제 #2
0
    def get_password(self, service, username):
        """Get password of the username for the service
        """
        key = username + '@' + service
        network = KWallet.Wallet.NetworkWallet()
        wallet = open_kwallet()
        if wallet is None:
            # the user pressed "cancel" when prompted to unlock their keyring.
            return None
        if wallet.keyDoesNotExist(network, 'Python', key):
            return None

        result = wallet.readPassword(key)[1]
        # The string will be a PyQt4.QtCore.QString, so turn it into a unicode
        # object.
        return unicode_str(result)
예제 #3
0
    def get_password(self, service, username):
        """Get password of the username for the service
        """
        key = username + '@' + service
        network = KWallet.Wallet.NetworkWallet()
        wallet = open_kwallet()
        if wallet is None:
            # the user pressed "cancel" when prompted to unlock their keyring.
            return None
        if wallet.keyDoesNotExist(network, 'Python', key):
            return None

        result = wallet.readPassword(key)[1]
        # The string will be a PyQt4.QtCore.QString, so turn it into a unicode
        # object.
        return unicode_str(result)
예제 #4
0
 def get_password(self, service, username):
     if username is None:
         username = ''
     try:
         # set up the call to security.
         cmd = [
             'security',
             SecurityCommand('find', self.store),
             '-g',
             '-a',
             username,
             '-s',
             service,
         ]
         call = subprocess.Popen(cmd,
                                 stderr=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
         stdoutdata, stderrdata = call.communicate()
         code = call.returncode
         if code is not 0:
             raise OSError("Can't fetch password from system")
         output = stderrdata.decode()
         # check for empty password.
         if output == 'password: \n':
             return ''
         # search for special password pattern.
         matches = Keyring.password_regex.search(output)
         if matches:
             group_dict = matches.groupdict()
             hex = group_dict.get('hex')
             pw = group_dict.get('pw')
             if hex:
                 # it's a weird hex password, decode it.
                 return unicode_str(binascii.unhexlify(hex), 'utf-8')
             else:
                 # it's a normal password, send it back.
                 return pw
         # nothing was found, it doesn't exist.
     except:
         pass
예제 #5
0
 def get_password(self, service, username):
     if username is None:
         username = ''
     try:
         # set up the call to security.
         cmd = [
             'security',
             SecurityCommand('find', self.store),
             '-g',
             '-a', username,
             '-s', service,
         ]
         call = subprocess.Popen(cmd, stderr=subprocess.PIPE,
             stdout=subprocess.PIPE)
         stdoutdata, stderrdata = call.communicate()
         code = call.returncode
         if code is not 0:
             raise OSError("Can't fetch password from system")
         output = stderrdata.decode()
         # check for empty password.
         if output == 'password: \n':
             return ''
         # search for special password pattern.
         matches = Keyring.password_regex.search(output)
         if matches:
             group_dict = matches.groupdict()
             hex = group_dict.get('hex')
             pw = group_dict.get('pw')
             if hex:
                 # it's a weird hex password, decode it.
                 return unicode_str(binascii.unhexlify(hex), 'utf-8')
             else:
                 # it's a normal password, send it back.
                 return pw
         # nothing was found, it doesn't exist.
     except:
         pass