def get_token_password(self, token=pki.nssdb.INTERNAL_TOKEN_NAME): # determine the password name for the token if not pki.nssdb.normalize_token(token): name = pki.nssdb.INTERNAL_TOKEN_NAME else: name = 'hardware-%s' % token # find password in password.conf if name in self.passwords: return self.passwords[name] # find password in keyring try: keyring = Keyring() key_name = self.name + '/' + name password = keyring.get_password(key_name=key_name) self.passwords[name] = password return password except subprocess.CalledProcessError: logger.info('Password unavailable in Keyring.') # prompt for password if not found password = getpass.getpass(prompt='Enter password for %s: ' % token) self.passwords[name] = password return password
def get_password(self, name): # find password (e.g. internaldb, replicationdb) in password.conf if name in self.passwords: return self.passwords[name] # find password in keyring try: keyring = Keyring() key_name = self.name + '/' + name password = keyring.get_password(key_name=key_name) self.passwords[name] = password return password except subprocess.CalledProcessError: logger.info('Password unavailable in Keyring.') # prompt for password if not found password = getpass.getpass(prompt='Enter password for %s: ' % name) self.passwords[name] = password return password
def setUpClass(cls): cls.keyring = Keyring() cls.password = '******' cls.key_name = 'test-key'