def getKeyring(): #Use this so we only get the keyring when needed. This avoids unnecessary keyring password prompts when the user enters the incorrect password. global keyring if keyring: return keyring try: import keyring except errors.AbortException: LOG('Keyring import - User aborted keyring unlock!!!') except: ERROR('Error importing keyring') keyring = __keyringFallback() LOG('Backend: %s' % getKeyringName(keyring)) return keyring try: keyringName = getKeyringName() if keyringName.startswith('file.') or keyringName.startswith('SecretService.') or keyringName.startswith('Gnome.'): #SecretService and Gnome are broken because of a DBus issue with XBMC - they only work on the first run addon that uses it #I remove them from _load_backends() in backend.py, but have this here in case I forget when updating the keyring core #We don't want any of the file ones because we want to ensure encryption and also handle the dialogs properly for the keyring password LOG('Not using: {0}'.format(keyringName)) keyring = __keyringFallback() #analysis:ignore else: keyring.set_password('PasswordStorage_TEST','TEST','test') if not keyring.get_password('PasswordStorage_TEST','TEST') == 'test': raise Exception() except errors.AbortException: LOG('At test - User aborted keyring unlock!!!') except errors.IncorrectKeyringKeyException: LOG('User entered bad keyring key') except: ERROR('Keyring failed test') keyring = __keyringFallback() LOG('Backend: %s' % getKeyringName(keyring)) return keyring
def store(username,password,only_if_unlocked=False): """ Save the provided password for the associated username Returns true if the password was successfully saved, otherwise false """ if only_if_unlocked: if getKeyringName().startswith('Internal.'): if not internalGetpass.getRememberedKey(): return keyring = getKeyring() try: if not password: try: keyring.delete_password(SERVICE_NAME,username) except: pass else: keyring.set_password(SERVICE_NAME,username,password or '') LOG('Password saved via keyring.') return True except: ERROR('Failed to save password to keyring') return False
def store(username, password, only_if_unlocked=False): """ Save the provided password for the associated username Returns true if the password was successfully saved, otherwise false """ if only_if_unlocked: if getKeyringName().startswith('Internal.'): if not internalGetpass.getRememberedKey(): return keyring = getKeyring() try: if not password: try: keyring.delete_password(SERVICE_NAME, username) except: pass else: keyring.set_password(SERVICE_NAME, username, password or '') LOG('Password saved via keyring.') return True except: ERROR('Failed to save password to keyring') return False
def getKeyring( ): #Use this so we only get the keyring when needed. This avoids unnecessary keyring password prompts when the user enters the incorrect password. global keyring if keyring: return keyring try: import keyring except errors.AbortException: LOG('Keyring import - User aborted keyring unlock!!!') except: ERROR('Error importing keyring') keyring = __keyringFallback() LOG('Backend: %s' % getKeyringName(keyring)) return keyring try: keyringName = getKeyringName() if keyringName.startswith('file.') or keyringName.startswith( 'SecretService.') or keyringName.startswith('Gnome.'): #SecretService and Gnome are broken because of a DBus issue with XBMC - they only work on the first run addon that uses it #I remove them from _load_backends() in backend.py, but have this here in case I forget when updating the keyring core #We don't want any of the file ones because we want to ensure encryption and also handle the dialogs properly for the keyring password LOG('Not using: {0}'.format(keyringName)) keyring = __keyringFallback() #analysis:ignore else: keyring.set_password('PasswordStorage_TEST', 'TEST', 'test') if not keyring.get_password('PasswordStorage_TEST', 'TEST') == 'test': raise Exception() except errors.AbortException: LOG('At test - User aborted keyring unlock!!!') except errors.IncorrectKeyringKeyException: LOG('User entered bad keyring key') except: ERROR('Keyring failed test') keyring = __keyringFallback() LOG('Backend: %s' % getKeyringName(keyring)) return keyring