Beispiel #1
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service.
     """
     key = username + '@' + service
     wallet = open_kwallet()
     if wallet is None:
         # the user pressed "cancel" when prompted to unlock their keyring.
         raise PasswordDeleteError("Cancelled by user")
     if wallet.keyDoesNotExist(wallet.walletName(), 'Python', key):
         raise PasswordDeleteError("Password not found")
     wallet.removeEntry(key)
Beispiel #2
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service."""
     items = self._find_passwords(service, username, deleting=True)
     if not items:
         raise PasswordDeleteError("Password not found")
     for current in items:
         result = GnomeKeyring.item_delete_sync(current.keyring,
                                                current.item_id)
         if result == GnomeKeyring.Result.CANCELLED:
             raise PasswordDeleteError("Cancelled by user")
         elif result != GnomeKeyring.Result.OK:
             raise PasswordDeleteError(result.value_name)
Beispiel #3
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service."""
     service = escape_for_ini(service)
     username = escape_for_ini(username)
     config = configparser.RawConfigParser()
     if os.path.exists(self.file_path):
         config.read(self.file_path)
     try:
         if not config.remove_option(service, username):
             raise PasswordDeleteError("Password not found")
     except configparser.NoSectionError:
         raise PasswordDeleteError("Password not found")
     # update the file
     with open(self.file_path, 'w') as config_file:
         config.write(config_file)
Beispiel #4
0
    def delete_password(self, service, username):
        """Delete the password for the username of the service.
        """
        service = _escape_for_s3(service)
        username = _escape_for_s3(username)
        prefix = self._get_s3_key(service, username)
        try:
            objects = list(self.bucket.objects.filter(Prefix=prefix))
            if len(objects) == 0:
                msg = ("Password for {service}/{username} not found").format(
                    service=service, username=username)
                raise PasswordDeleteError(msg)
            elif len(objects) > 1:
                msg = ("Multiple objects in bucket {bucket} match the prefix "
                       "{prefix}.").format(bucket=self.bucket.name,
                                           prefix=prefix)
            else:
                objects[0].delete()
        except EndpointConnectionError:
            if self.use_local_keyring:
                # Can't connect to S3: fallback to OS keyring
                print("WARNING: can't connect to S3, deleting from OS keyring",
                      file=sys.stderr)
            else:
                raise

        # Delete also in the local keyring
        try:
            keyring.delete_password(service, username)
        except PasswordDeleteError:
            # It's OK: the password was not available in the local keyring
            print("WARNING: {}/{} not found in OS keyring".format(
                service, username))
Beispiel #5
0
 def delete_password(self, service, username):
     try:
         subprocess.run(['pass', 'rm', f'{service}/{username}'],
                        capture_output=True,
                        check=True)
     except subprocess.CalledProcessError as e:
         raise PasswordDeleteError(e.output)
Beispiel #6
0
 def delete_password(self, service, key):
     """
     Delete the secret for the key of the service.
     """
     raise PasswordDeleteError(
         "Delete secret from cyberark backend is disabled"
     )
 def delete_password(self, service, username):
     key = self._find_key(service, username)
     if key is None:
         msg = "no such password: service={}, username={}".format(
             service, username)
         raise PasswordDeleteError(msg)
     key.invalidate()
    def delete_password(self, service: str, username: str) -> None:
        """
        Deletes the keyring / enclave key with kSecAttrLabel = service and kSecAttrApplicationTag = username.
        Beware: If more than one key matches the query, this will delete all matched keys.

        :param service: If set, will lookup the key with kSecAttrLabel = service
        :param username: If set, will lookup the key with kSecAttrApplicationTag = username
        """
        query = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, None, None)
        CFDictionarySetValue(query, kSecClass, kSecClassKey)

        if service:
            CFDictionarySetValue(query, kSecAttrLabel, service)

        if username:
            CFDictionarySetValue(
                query, kSecAttrApplicationTag, username.encode('utf-8')
            )

        if self.access_group:
            CFDictionarySetValue(query, kSecAttrAccessGroup, self.access_group)

        error = SecItemDelete(query)
        if error:
            raise PasswordDeleteError(f'Error calling SecItemDelete: {error}')
Beispiel #9
0
 def delete_password(self, service, username):
     """Delete the stored password (only the first one)
     """
     collection = self.get_default_collection()
     items = collection.search_items(
         {"username": username, "service": service})
     for item in items:
         return item.delete()
     raise PasswordDeleteError("No such password!")
Beispiel #10
0
 def delete_password(self, service, username):
     compound = self._compound_name(username, service)
     deleted = False
     for target in service, compound:
         existing_pw = self._get_password(target)
         if existing_pw and existing_pw['UserName'] == username:
             deleted = True
             self._delete_password(target)
     if not deleted:
         raise PasswordDeleteError(service)
Beispiel #11
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service.
     """
     try:
         key_name = r'Software\%s\Keyring' % service
         hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_name, 0,
                               winreg.KEY_ALL_ACCESS)
         winreg.DeleteValue(hkey, username)
     except WindowsError:
         e = sys.exc_info()[1]
         raise PasswordDeleteError(e)
 def delete_password(self, servicename, username):
     """Delete the password for the username of the service."""
     ws = self.sheet
     rows = self._find_rows(servicename, username)
     if not rows:
         raise PasswordDeleteError("Password not found")
     # There can be multiple matching rows if the sheet has been
     # manually edited or there's been a race.
     for r in sorted(rows)[::-1]:
         ws.delete_row(r)
     self._cache.pop((servicename, username), None)
Beispiel #13
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service."""
     try:
         key_name = self._key_for_service(service)
         hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_name, 0,
                               winreg.KEY_ALL_ACCESS)
         winreg.DeleteValue(hkey, username)
         winreg.CloseKey(hkey)
     except WindowsError:
         e = sys.exc_info()[1]
         raise PasswordDeleteError(e)
     self._delete_key_if_empty(service)
Beispiel #14
0
    def _find_passwords(self, service, username, deleting=False):
        """Get password of the username for the service"""
        passwords = []

        service = self._safe_string(service)
        username = self._safe_string(username)
        for attrs_tuple in (('username', 'service'), ('user', 'domain')):
            attrs = GnomeKeyring.Attribute.list_new()
            GnomeKeyring.Attribute.list_append_string(attrs, attrs_tuple[0],
                                                      username)
            GnomeKeyring.Attribute.list_append_string(attrs, attrs_tuple[1],
                                                      service)
            result, items = GnomeKeyring.find_items_sync(
                GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
            if result == GnomeKeyring.Result.OK:
                passwords += items
            elif deleting:
                if result == GnomeKeyring.Result.CANCELLED:
                    raise PasswordDeleteError("Cancelled by user")
                elif result != GnomeKeyring.Result.NO_MATCH:
                    raise PasswordDeleteError(result.value_name)
        return passwords
Beispiel #15
0
 def delete_password(self, service, username):
     del_error = PasswordDeleteError("Can't delete password in keychain")
     if username is None:
         username = ''
     try:
         cmd = [
             'security',
             SecurityCommand('delete', self.store),
             '-a',
             username,
             '-s',
             service,
         ]
         # set up the call for security.
         call = subprocess.Popen(cmd,
                                 stderr=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
         stdoutdata, stderrdata = call.communicate()
         code = call.returncode
         # check return code.
         if code is not 0:
             raise del_error
     except:
         raise del_error