def deleteKey(self, value, nameOrAttr='name', keyOrValue='key'): attrs = self.__find(value, nameOrAttr, keyOrValue) if attrs == False: print 'No such key exists.' else: gk.item_delete_sync(self.keyring, attrs['id']) if keyOrValue == value else False print "Successful key deletion."
def store_password(self, datasource): """Update password. If the gnomekeyring bindings are available, the password is stored in the keyring. Otherwise it's stored in datasources.cfg. It's assumed, that the data source has an ID. So, this method *must* be called after the data source has been saved once. :param datasource: A data source. """ if not USE_KEYRING: return item_type = gnomekeyring.ITEM_GENERIC_SECRET attrs = {"crunchyfrog": datasource.id} try: entry = gnomekeyring.find_items_sync(item_type, attrs) entry = entry[0] except gnomekeyring.NoMatchError: entry = None if datasource.url.password is not None: gnomekeyring.item_create_sync(None, item_type, 'crunchyfrog/%s' % datasource.id, attrs, datasource.url.password, True) elif entry is not None: gnomekeyring.item_delete_sync(None, entry.item_id)
def _GetNameAndPassword(self): """Display a modal dialog asking for a name and password. This info is used for login when deploying the applications; it is saved in GNOME keyring. Returns: wx.ID_OK or wx.ID_CANCEL """ self._ConfigureDialog() rtn = self.dialog.ShowModal() if rtn == wx.ID_OK: self._authname = str(self.dialog.name_text_ctrl.GetValue()) self._password = self.dialog.password_text_ctrl.GetValue() # Store information in keyring try: items = gk.find_items_sync(gk.ITEM_NETWORK_PASSWORD, self._gkAttr) for item in items: if item.attributes["user"] != self._authname: gk.item_delete_sync('login', item.item_id) except gk.NoMatchError: pass self._gkAttr["user"] = self._authname gk.item_create_sync('login', gk.ITEM_NETWORK_PASSWORD, 'Google App Engine Credentials', self._gkAttr, self._password, True) return rtn
def remove_logins(self, kind, username, url): _logger.debug("removing login (%s, %s, %s)" % (kind, username, url)) new_fallbacks = set() for ki in self.__fallback_items: if ki.get_kind() == kind and \ ki.get_username() == username and \ ki.get_url() == url: pass else: new_fallbacks.add(ki) self.__fallback_items = new_fallbacks if self.is_available(): try: found = bignative.keyring_find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, dict(appname='BigBoard', kind=kind, username=username, url=url)) except TypeError: found = set() for f in found: gnomekeyring.item_delete_sync('session', f.item_id)
def clear_cc_details(): print "clearing CC details" try: ids = gnomekeyring.find_items_sync (gnomekeyring.ITEM_GENERIC_SECRET, keyring_attributes) gnomekeyring.item_delete_sync (keyring, id[0]) except Exception, e: print e
def delete(self, auth_token): """ Deletes C{auth_token} from the keyring as its faulty """ try: gnomekeyring.item_delete_sync(self.keyring, auth_token) except Exception, e: raise
def clear_password(self, scheme, host, username): """Remove the password from the cache.""" try: if (scheme, host, username) in self.item_ids: ring_id, item_id = self.item_ids[(scheme, host, username)] gnomekeyring.item_delete_sync(ring_id, item_id) except gnomekeyring.NoKeyringDaemonError: pass
def delete(self): if keyring == 'gk': if self.key != None: gk.item_delete_sync('pycle', self.key) elif keyring == 'kk': pass elif keyring == 'xk': pass
def delete_credentials(self, user, pw=None): attrs = { "user":user, "server":self._server, "protocol":self._protocol, } items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs) for item in items: gkey.item_delete_sync(None, item.item_id)
def forget_password(self, menu_item = None): if not gnomekeyring.is_available(): return None if self.__uri is None or self.__bind_dn is None: return None display_name = "@".join([self.__bind_dn, self.__uri]) for pw_id in gnomekeyring.list_item_ids_sync("login"): if gnomekeyring.item_get_info_sync("login", pw_id).get_display_name() == display_name: gnomekeyring.item_delete_sync('login', pw_id)
def remove_key(self,keyring,query): """ Removes a key from an specified keyring that matches specified query """ key=self.search_key(query) if key: # TODO: Get keyring and key id from result gk.item_delete_sync(keyring,id) else: raise
def delete_details(self): """ Delete account details """ try: item = self.__get_item() if item is not None: gk.item_delete_sync(self.NAME, item) return True return False except self.GK_EXCEPT as e: raise AccountError(repr(e))
def delete(self): ''' Delete a keyring item. Return True if item created successfully, False otherwise. ''' try: gk.item_delete_sync(self.keyring, self.id) except gk.Error, e: print >>sys.stderr, 'Error deleting keyring item!\nDetails:\n%s'%e return False
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()
def on_account_delete(self, widget): if "id" in self.account: try: private_fields = [f.split(":")[-1] for f in self.services[self.account["service"]]["config"] if ":" in f] for f in private_fields: if self.account[f].startswith(":KEYRING:"): keyring_id = int(self.account[f].split(":")[-1]) gnomekeyring.item_delete_sync(gnomekeyring.get_default_keyring_sync(), keyring_id) except: pass self.gwibber.accounts.Delete(self.account["id"]) self.populate_account_tree() self.select_first()
def _set_credentials(self, username, password): " Stores the username and password in the Gnome keyring. " self._fetch_credentials() self._username, self._password = username, password if self._item_id: gnomekeyring.item_delete_sync(self._keyring, self._item_id) self._keyring = 'login' self._item_id = gnomekeyring.item_create_sync(self._keyring, gnomekeyring.ITEM_GENERIC_SECRET, 'rt-helper', {'application': APPLICATION_NAME, 'username': username}, password, False)
def delpass(self, username, server): ret = True # Does it already exist? protocol = self.get_protocol() try: results = gk.find_network_password_sync(user=username, server=server, protocol=protocol) except gk.NoMatchError: print "No password set for user '%s' in server '%s'" % (username, server) ret = False if ret: gk.item_delete_sync(self.keyring, results[0]['item_id']) print "Password successfully removed" return ret
def trigger_unlock(): gk.item_create_sync(KEYRING, gk.ITEM_GENERIC_SECRET, "dummy",{"dummy":"dummy"}, "dummy", True) item_keys = gk.list_item_ids_sync(KEYRING) for key in item_keys: item_info = gk.item_get_info_sync(KEYRING, key) if item_info.get_display_name() == "dummy": item_info = gk.item_delete_sync(KEYRING, key)
def store_password(self, scheme, host, username, password): """Return the password of username@root.""" try: if (scheme, host, username) in self.item_ids: ring_id, item_id = self.item_ids[(scheme, host, username)] gnomekeyring.item_delete_sync(ring_id, item_id) item_id = gnomekeyring.item_create_sync( None, gnomekeyring.ITEM_NETWORK_PASSWORD, host, {"user": username, "protocol": scheme, "server": host}, password, True) except (gnomekeyring.CancelledError, gnomekeyring.NoKeyringDaemonError): pass self.item_ids[(scheme, host, username)] = (None, item_id)
def new_auth(): # Clear all old entries try: for item in gk.find_items_sync(gk.ITEM_GENERIC_SECRET, {'application': KEY_NAME}): gk.item_delete_sync(KEYRING_NAME, item.item_id) except gk.NoMatchError: pass # Read in username and password user = raw_input('User: '******'user': user, 'application': KEY_NAME} gk.item_create_sync(KEYRING_NAME, gk.ITEM_GENERIC_SECRET, KEY_NAME, attrs, passwd, True) return user,passwd
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
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
def remove(self, accounts): # delete obsolete entries from Keyring defaultKeyring = gnomekeyring.get_default_keyring_sync() if defaultKeyring == None: defaultKeyring = 'login' valid_accounts = [] for acc in accounts: # create list of all valid accounts protocol = 'imap' if acc.imap else 'pop' valid_accounts.append('Mailnag password for %s://%s@%s' % \ (protocol, acc.user, acc.server)) if gnomekeyring.list_item_ids_sync(defaultKeyring): # find and delete invalid entries displayNameDict = {} for identity in gnomekeyring.list_item_ids_sync(defaultKeyring): item = gnomekeyring.item_get_info_sync(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(defaultKeyring, displayNameDict[key])
def gnomekeyring_delete_secrets(items): tried_to_unlock = False ret = 0 for container, itemid in items: itemid = int(itemid) try: gnomekeyring.item_delete_sync(container, itemid) except gnomekeyring.IOError as e: logging.info('%s', e) if not tried_to_unlock: tried_to_unlock = True if gnomekeyring_unlock(): # Try again. try: gnomekeyring.item_delete_sync(container, itemid) continue except gnomekeyring.IOError as e: logging.info('%s', e) print >> sys.stderr, 'Failed to delete %s #%d' % (container, itemid) ret = 1 return ret
def save(self,username,password,interval,multi=True,separator=False): try: self.gconf.set_int(self.interval_key,interval) self.gconf.set_bool(self.multi_key,multi) self.gconf.set_bool(self.sep_key,separator) self.multiline = multi self.separator = separator if not keyring: self.gconf.set_string(self.username_key,username) self.gconf.set_string(self.password_key,password) else: keys = gk.list_item_ids_sync(self.appname) if len(keys)>0: for key in keys: gk.item_delete_sync(self.appname,key) gk.item_create_sync(self.appname,gk.ITEM_GENERIC_SECRET,username,{"username":username},password,True) except Exception as exc: return False return True
def save_password(self, password, **attrs): """Save the new password, save the old password with the date prepended """ pos_of_match = self._match_exists(attrs['searchable']) if pos_of_match: old_password = self.get_password(pos_of_match).get_secret() gkr.item_delete_sync(self.keyring, pos_of_match) desc = str(int(time.time())) + "_" + attrs['searchable'] gkr.item_create_sync(self.keyring ,gkr.ITEM_GENERIC_SECRET ,desc ,{} ,old_password ,True) desc = attrs['searchable'] pos = gkr.item_create_sync(self.keyring ,gkr.ITEM_GENERIC_SECRET ,desc ,attrs ,password ,True) return pos
def gnomekeyring_delete_secrets(items): tried_to_unlock = False ret = 0 for container, itemid in items: itemid = int(itemid) try: gnomekeyring.item_delete_sync(container, itemid) except gnomekeyring.IOError as e: logging.info('%s', e) if not tried_to_unlock: tried_to_unlock = True if gnomekeyring_unlock(): # Try again. try: gnomekeyring.item_delete_sync(container, itemid) continue except gnomekeyring.IOError as e: logging.info('%s', e) print >> sys.stderr, 'Failed to delete %s #%d' % (container, itemid) ret = 1 return ret
def save(self, username, password, interval, multi=True, separator=False): try: self.gconf.set_int(self.interval_key, interval) self.gconf.set_bool(self.multi_key, multi) self.gconf.set_bool(self.sep_key, separator) self.multiline = multi self.separator = separator if not keyring: self.gconf.set_string(self.username_key, username) self.gconf.set_string(self.password_key, password) else: keys = gk.list_item_ids_sync(self.appname) if len(keys) > 0: for key in keys: gk.item_delete_sync(self.appname, key) gk.item_create_sync(self.appname, gk.ITEM_GENERIC_SECRET, username, {"username": username}, password, True) except Exception as exc: return False return True
def set_credentials(self, user, pw): """ Store or update username and password for account """ # Note: attrs is used to look up the account for old user credentials attrs = { "server": self._host, "protocol": self._protocol, } LOGGER.debug ("Updating credentials for %s" % self._host) keyring = gnomekeyring.get_default_keyring_sync() # Look up all accounts registered for this service and realm and delete # them. We get weird errors if more than one account is present try: items = gnomekeyring.find_items_sync (gnomekeyring.ITEM_NETWORK_PASSWORD, attrs) except gnomekeyring.NoMatchError: LOGGER.debug ("No existing accounts for %s" % self._host) items = [] for item in items: LOGGER.debug ("Purging account %s@%s" % (item.attributes["user"], item.attributes["server"])) gnomekeyring.item_delete_sync (keyring, item.item_id) # Add the 'user' attribute to attrs and commit it to the keyring LOGGER.debug ("Creating new account %s@%s" % (user, self._host)) attrs["user"] = user gnomekeyring.item_create_sync(keyring, gnomekeyring.ITEM_NETWORK_PASSWORD, self._realm, attrs, pw, True) LOGGER.debug ("Credential update success")
def tearDown(self): if self.auth_token: gnomekeyring.item_delete_sync(self.defkeyring, self.auth_token)
def delete(): item_keys = gk.list_item_ids_sync(KEYRING) for key in item_keys: item_info = gk.item_get_info_sync(KEYRING, key) if item_info.get_display_name().endswith(DISPLAY_NAME): item_info = gk.item_delete_sync(KEYRING, key)
def delete_password(self, keyring, login): _, item_id = self._get_item(keyring, login) if item_id is not None: gnomekeyring.item_delete_sync("Login", item_id)
def remove_keyring(self, password): id = password.split(":")[1] gkey.item_delete_sync(self._keyring, int(id))
def remove_keyring(self, password): id = password.split(":")[1] gkey.item_delete_sync(self._keyring, int(id))
def del_item(user, server, protocol): results = gkey.find_network_password_sync(user = username, server = server, protocol = protocol) gkey.item_delete_sync(keyring, results[0]['item_id'])
def delete_password(self, url, user): gk_data = self._keyring_data(url, user) if gk_data is None: return gnomekeyring.item_delete_sync(gk_data['keyring'], gk_data['item_id'])
def delete_key(self, keyid): gk.item_delete_sync(self.keyring_name, keyid)
def clear_secret(self, _id): try: gnomekeyring.item_delete_sync(self.keyring, _id) return True except: return False