Exemplo n.º 1
0
 def remove_by_id(self, uid):
     """
         Remove an account by uid
         :param uid: (int) account uid
         :return:
     """
     secret_code = self.get_secret_code(uid)
     if secret_code:
         found = False
         (result, ids) = GK.list_item_ids_sync("TwoFactorAuth")
         for gid in ids:
             (result, item) = GK.item_get_info_sync("TwoFactorAuth", gid)
             if result == GK.Result.OK:
                 if item.get_display_name().strip("'") == secret_code:
                     found = True
                     break
         if found:
             GK.item_delete_sync("TwoFactorAuth", gid)
     query = "DELETE FROM accounts WHERE uid=?"
     try:
         self.conn.execute(query, (uid, ))
         self.conn.commit()
     except Exception as e:
         logging.error(
             "SQL: Couldn't remove account by uid : %s with error : %s" %
             (uid, str(e)))
Exemplo n.º 2
0
 def remove_by_id(self, uid):
     """
         Remove an account by uid
         :param uid: (int) account uid
         :return:
     """
     secret_code = self.get_secret_code(uid)
     if secret_code:
         found = False
         (result, ids) = GK.list_item_ids_sync("TwoFactorAuth")
         for gid in ids:
             (result, item) = GK.item_get_info_sync("TwoFactorAuth", gid)
             if result == GK.Result.OK:
                 if item.get_display_name().strip("'") == secret_code:
                     found = True
                     break
         if found:
             GK.item_delete_sync("TwoFactorAuth", gid)
     query = "DELETE FROM accounts WHERE uid=?"
     try:
         self.conn.execute(query, (uid,))
         self.conn.commit()
     except Exception as e:
         logging.error(
             "SQL: Couldn't remove account by uid : %s with error : %s" % (uid, str(e)))
Exemplo n.º 3
0
    def remove(self, key):
        attrs = self._get_attrs(key)
        result, items = GnomeKeyring.find_items_sync(
            GnomeKeyring.ItemType.GENERIC_SECRET, attrs)

        if result == GnomeKeyring.Result.OK:
            GnomeKeyring.item_delete_sync(self._defaultKeyring,
                                          items[0].item_id)
Exemplo n.º 4
0
 def delete_credentials(self, user):
     attrs = attributes({
                         "user": user,
                         "server": self._server,
                         "protocol": self._protocol
                         })
     result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
     for item in items:
         GnomeKeyring.item_delete_sync(self._keyring, item.item_id)
Exemplo n.º 5
0
	def _migrate_keyring(self):
		attrs = GnomeKeyring.Attribute.list_new()
		GnomeKeyring.Attribute.list_append_string(attrs, 'application', 'Mailnag')
		result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
		
		if result == GnomeKeyring.Result.OK:
			for i in items:
				result, info = GnomeKeyring.item_get_info_sync(self._defaultKeyring, i.item_id)
				self.set(info.get_display_name(), i.secret)
				GnomeKeyring.item_delete_sync(self._defaultKeyring, i.item_id)
 def remove_credentials(self, acc):
     self.lock.acquire()
     try:
         logger.debug("Removing credentias from gnome keyring for the account: %s" % (acc.get_name()))
         if hasattr(acc, "keyringid"):
             gk.item_delete_sync(self._KEYRING_NAME, int(acc.keyringid))
             logger.debug("Credentials removed")
         else:
             logger.debug("The account has not credentials asigned, continue")
     finally:
         self.lock.release()
Exemplo n.º 7
0
    def _migrate_keyring(self):
        attrs = GnomeKeyring.Attribute.list_new()
        GnomeKeyring.Attribute.list_append_string(attrs, 'application',
                                                  'Mailnag')
        result, items = GnomeKeyring.find_items_sync(
            GnomeKeyring.ItemType.GENERIC_SECRET, attrs)

        if result == GnomeKeyring.Result.OK:
            for i in items:
                result, info = GnomeKeyring.item_get_info_sync(
                    self._defaultKeyring, i.item_id)
                self.set(info.get_display_name(), i.secret)
                GnomeKeyring.item_delete_sync(self._defaultKeyring, i.item_id)
Exemplo n.º 8
0
 def remove_credentials(self, acc):
     self.lock.acquire()
     try:
         logger.debug(
             "Removing credentias from gnome keyring for the account: %s" %
             (acc.get_name()))
         if hasattr(acc, "keyringid"):
             gk.item_delete_sync(self._KEYRING_NAME, int(acc.keyringid))
             logger.debug("Credentials removed")
         else:
             logger.debug(
                 "The account has not credentials asigned, continue")
     finally:
         self.lock.release()
Exemplo n.º 9
0
	def remove(self, accounts):
		# create list of all valid accounts
		valid_accounts = []
		for acc in accounts:
			protocol = 'imap' if acc.imap else 'pop'
			valid_accounts.append(self.KEYRING_ITEM_NAME % \
			(protocol, acc.user, acc.server))

		# find and delete invalid entries
		(result, ids) = GnomeKeyring.list_item_ids_sync(self._defaultKeyring)
		if result == GnomeKeyring.Result.OK:
			displayNameDict = {}
			for identity in ids:
				(result, item) = GnomeKeyring.item_get_info_sync(self._defaultKeyring, identity)
				displayNameDict[item.get_display_name()] = identity
			for key in displayNameDict.keys():
				if key.startswith('Mailnag password for') \
				and key not in valid_accounts:
					GnomeKeyring.item_delete_sync(self._defaultKeyring, displayNameDict[key])
Exemplo n.º 10
0
	def remove_entry(self, entry):
		"""Remove entry from keyring"""
		if not self.keyring_exists():
			raise InvalidKeyringError('Keyring does not exist!')

		result = False

		# if keyring is locked, try to unlock it
		if self.is_locked() and not self.__unlock_keyring():
			return result

		# get entry id
		entry_id = self.__get_entry_id(entry)

		if entry_id is not None:
			keyring.item_delete_sync(self.KEYRING_NAME, entry_id)
			result = True

		return result
Exemplo n.º 11
0
def set_secrets(krname, to_write, overwrite_all):
    item_ids = verify(gk.list_item_ids_sync(krname),
                      'list pre-existing items in keyring=%s' % krname)

    if overwrite_all:
        # Remove existing items from the keyring, leaving the container intact.
        for i in item_ids:
            verify(gk.item_delete_sync(krname, i),
                   'delete pre-existing item from keyring=%s' % krname)
        item_ids = []

    existing_items = {}
    for i in item_ids:
        item = verify(get_item(krname, i),
                      'access pre-existing item in keyring=%s' % krname)
        existing_items[item.get_display_name()] = i

    try:
        typ = gk.ItemType.GENERIC_SECRET
    except AttributeError:
        typ = gk.ITEM_GENERIC_SECRET

    # Write out new items.
    for i in to_write:
        needle = encode_label(i[DICT_ATTRIBUTES])
        secret = i[DICT_SECRET]
        label = pretty_print_label(needle)
        if needle in existing_items:
            # Matched an existing item; update it in-place.
            info = gk.ItemInfo()
            info.set_type(typ)
            info.set_display_name(needle)
            info.set_secret(secret)
            verify(gk.item_set_info_sync(krname, existing_items[needle], info),
                   'edit item (%s) in keyring=%s' % (label, krname))
        else:
            #
            # No existing item was present. Create a new one.
            #
            # XXX: We must pass update_if_exists=False because if we did not,
            # every item would collide with every other. In other words, we
            # would only be able to store a single item in the keyring, as we
            # are forced to use the same identifying attributes for every item
            # we create. This is because the only GLib.Array we can create is
            # the empty Array(). Awful.
            #
            item_id = verify(
                gk.item_create_sync(krname,
                                    typ,
                                    display_name=needle,
                                    attributes=Array(),
                                    secret=secret,
                                    update_if_exists=False),
                'create new item (%s) in keyring=%s' % (label, krname))
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
0
 def delete_password(self, service, username):
     """Delete the password for the username of the service.
     """
     from gi.repository import GnomeKeyring
     attrs = GnomeKeyring.Attribute.list_new()
     GnomeKeyring.Attribute.list_append_string(attrs, 'username', username)
     GnomeKeyring.Attribute.list_append_string(attrs, 'domain', service)
     result, items = GnomeKeyring.find_items_sync(
         GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
     if result == GnomeKeyring.Result.NO_MATCH:
         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")
Exemplo n.º 15
0
def remove_secrets(krname, to_remove):
    item_ids = verify(gk.list_item_ids_sync(krname),
                      'list pre-existing items in keyring=%s' % krname)

    existing_items = {}
    for i in item_ids:
        item = verify(get_item(krname, i),
                      'access pre-existing item in keyring=%s' % krname)
        existing_items[item.get_display_name()] = i

    for i in to_remove:
        needle = encode_label(i[DICT_ATTRIBUTES])
        label = pretty_print_label(needle)
        if needle not in existing_items:
            err('Cannot find item (%s) in keyring=%s' % (label, krname))
        verify(gk.item_delete_sync(krname, existing_items[needle]),
               'remove item (%s) from keyring=%s' % (label, krname))
Exemplo n.º 16
0
 def do_delete(self, id):
     keyring = GnomeKeyring.get_default_keyring_sync()[1]
     GnomeKeyring.item_delete_sync(keyring, id)
Exemplo n.º 17
0
 def do_delete(self, id):
     keyring = GnomeKeyring.get_default_keyring_sync()[1]
     GnomeKeyring.item_delete_sync(keyring, id)
Exemplo n.º 18
0
	def remove(self, key):
		attrs = self._get_attrs(key)
		result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
		
		if result == GnomeKeyring.Result.OK:
			GnomeKeyring.item_delete_sync(self._defaultKeyring, items[0].item_id)
Exemplo n.º 19
0
def del_from_keyring(keyring_id):
  """Delete an entry from the keyring."""
  keyring = GnomeKeyring.get_default_keyring_sync()[1]
  GnomeKeyring.item_delete_sync(keyring, keyring_id)
	def removeEncriptedFolder(self,epath):
		id = self.find_folder(epath)
		if id != None:
			GnomeKeyring.item_delete_sync(self.keyring,id[0])
			return True
		return False