Esempio n. 1
0
def retrieve(username, ask_on_fail=True, ask_msg=None):
    """
	Get the password associated with the provided username
	If no password is stored or the is an error and ask_on_fail is
	true (default) then shows a dialog asking for the password
	If no password is obtained, returns None
	"""
    keyring = getKeyring()
    password = None
    try:
        password = keyring.get_password(SERVICE_NAME, username)
    except errors.AbortException:
        LOG('retreive() 1 - User aborted keyring unlock!!!')
        xbmcutil.okDialog(
            'Failed', 'Keyring remains locked.', '',
            'Could not get the Facebook password from the keyring.')
    except errors.IncorrectKeyringKeyException:
        LOG('retreive() 1 - User entered incorrect keyring password!!!')
        xbmcutil.okDialog(
            'Failed', 'Incorrect keyring password.', '',
            'Could not get the Facebook password from the keyring.')
    except ValueError:
        try:
            internalGetpass.clearKeyMemory()
            password = keyring.get_password(SERVICE_NAME, username)
        except errors.AbortException:
            LOG('retreive() 2 - User aborted keyring unlock!!!')
            xbmcutil.okDialog(
                'Failed', 'Keyring remains locked.', '',
                'Could not get the Facebook password from the keyring.')
        except errors.IncorrectKeyringKeyException:
            LOG('retreive() 2 - User entered incorrect keyring password!!!')
            xbmcutil.okDialog(
                'Failed', 'Incorrect keyring password.', '',
                'Could not get the Facebook password from the keyring.')
        except:
            ERROR('Failed to get password from keyring')
    except:
        ERROR('Failed to get password from keyring')

    if password: return password

    if ask_on_fail:
        msg = ask_msg or xbmcutil.ADDON.getLocalizedString(32024).format(
            '[B]{0}[/B]'.format(
                xbmcaddon.Addon(ADDON_ID).getAddonInfo('name')))
        password = xbmcutil.passwordPrompt(msg)
        if password: return password

        xbmcutil.okDialog('Failed', 'Failed to retreive password.')

    return None
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 retrieve(username,ask_on_fail=True,ask_msg=None):
	"""
	Get the password associated with the provided username
	If no password is stored or the is an error and ask_on_fail is
	true (default) then shows a dialog asking for the password
	If no password is obtained, returns None
	"""
	keyring = getKeyring()
	password = None
	try:
		password = keyring.get_password(SERVICE_NAME,username)
	except errors.AbortException:
		LOG('retreive() 1 - User aborted keyring unlock!!!')
		xbmcutil.okDialog('Failed','Keyring remains locked.','','Could not get the Facebook password from the keyring.')
	except errors.IncorrectKeyringKeyException:
		LOG('retreive() 1 - User entered incorrect keyring password!!!')	
		xbmcutil.okDialog('Failed','Incorrect keyring password.','','Could not get the Facebook password from the keyring.')
	except ValueError:
		try:
			internalGetpass.clearKeyMemory()
			password = keyring.get_password(SERVICE_NAME,username)
		except errors.AbortException:
			LOG('retreive() 2 - User aborted keyring unlock!!!')	
			xbmcutil.okDialog('Failed','Keyring remains locked.','','Could not get the Facebook password from the keyring.')
		except errors.IncorrectKeyringKeyException:
			LOG('retreive() 2 - User entered incorrect keyring password!!!')	
			xbmcutil.okDialog('Failed','Incorrect keyring password.','','Could not get the Facebook password from the keyring.')
		except:
			ERROR('Failed to get password from keyring')
	except:
		ERROR('Failed to get password from keyring')
		
	if password: return password
		
	if ask_on_fail:
		msg = ask_msg or xbmcutil.ADDON.getLocalizedString(32024).format('[B]{0}[/B]'.format(xbmcaddon.Addon(ADDON_ID).getAddonInfo('name')))
		password = xbmcutil.passwordPrompt(msg)
		if password: return password

		xbmcutil.okDialog('Failed','Failed to retreive password.')

	return None
Esempio n. 4
0
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