def add_dummy_key_to_cryptfilekeyring(crypt_file_keyring: CryptFileKeyring): """ Add a fake key to the CryptFileKeyring """ crypt_file_keyring.keyring_key = "your keyring password" user: str = get_private_key_user(default_keychain_user(), 0) crypt_file_keyring.set_password(default_keychain_service(), user, "abc123")
def set_password(service, key, cryptfile_pw=None): kr = CryptFileKeyring() if cryptfile_pw is None: config = read_config() cryptfile_pw = config["cryptfile"]["password"] kr.keyring_key = base64_decode(cryptfile_pw) kr.set_password(service, key, getpass.getpass("Secret: "))
class Crypt(object): def __init__(self): self.path = "/root/.local/share/webtentacle_keyring" self.mother_service = '?' self.kr = CryptFileKeyring() self.kr.keyring_key = '?' parser = argparse.ArgumentParser( description="Decrypt the system file", usage='''crypt decrypt --username <username> crypt encrypt --username <username> --password <password> The most commonly used decrypt commands are: crypt decrypt --username admin, returns password ''') parser.add_argument('command', help='Subcommand to run') args = parser.parse_args(sys.argv[1:2]) if not hasattr(self, args.command): print('Unrecognized command') parser.print_help() exit(1) getattr(self, args.command)() def decrypt(self): try: parser = argparse.ArgumentParser( description="decrypt service usernames's password") parser.add_argument('--username', '-u') args = parser.parse_args(sys.argv[2:]) # invoke the keyring print(self.kr.get_password(self.mother_service, args.username), end='') except Exception as msg: print("Error in keyring decryption, {}".format(str(msg))) sys.exit(2) def encrypt(self): try: parser = argparse.ArgumentParser( description="encrypt service username's passowrd") parser.add_argument('--username', '-u') parser.add_argument('--password', '-p') args = parser.parse_args(sys.argv[2:]) self.kr.set_password(self.mother_service, args.username, args.password) return 0 except Exception as msg: print("Error in keyring encryption, {}".format(str(msg))) sys.exit(2)
class MinervaConfig(object): def __init__(self): self.settings_obj = {} self.descriptions = { 'default':'Determines whether the passwords are set to default', 'use_stored_credentials':'If value is "email" or "minerva", then use stored credentials regularly. Default: "false"' } self.defaults_obj = { 'default':'true', 'use_stored_credentials':'false' } self.kr = CryptFileKeyring() def __getitem__(self,key): return self.settings_obj[key] def __setitem__(self,key,value): self.settings_obj[key] = value def get_settings(self, keyring_pass='', inConsole=False): """Loads the settings from the computer's keyring""" if keyring_pass == '' and inConsole: self.kr.keyring_key = getpass.getpass() # only when in the console and no argument already given self.kr.keyring_key = keyring_pass # check if it's the first time for keys if self.kr.get_password('minervaclient_default','minerva') is None: self.default_settings() for key in self.descriptions.keys(): self[key] = self.kr.get_password('minervaclient_'+key,'minerva') def set_settings(self): """Takes the current settings and persists the changes to computer storage""" for key, item in self.settings_obj.items(): self.kr.set_password('minervaclient_'+key,'minerva',item) def default_settings(self, inConsole=False): """Resets the current settings to original""" for key, item in self.defaults_obj.items(): self.kr.set_password('minervaclient_'+key,'minerva',item) def list_settings(self): result = [ i for i in self.settings_obj.keys() ] result.sort() return result
def set_password(system, username, password, lib='keyrings.cryptfile', env='KEYRING_CRYPTFILE_PASSWORD', ask=True): """ Stores a password. By default, uses :epkg:`keyring` or :epkg:`keyrings.cryptfile`. :param system: system :param username: username :param password: password :param lib: which lib to use to store the password :param env: see below :param ask: ask for password if missing If `lib == 'keyrings.cryptfile'`, the function used the environment variable *env*, if present, no password is asked. """ if lib == 'keyring': from keyring import ( set_password as lib_set_password, get_password as lib_get_password) lib_set_password(system, username, password) pwd = lib_get_password(system, username) if pwd != password: raise RuntimeError( # pragma: no cover "Unable to store a password with keyring for '{}', '{}'.".format( system, username)) return if lib == 'keyrings.cryptfile': from keyrings.cryptfile.cryptfile import CryptFileKeyring # pylint: disable=E0401 kr = CryptFileKeyring() kr.keyring_key = getenv("KEYRING_CRYPTFILE_PASSWORD") if kr.keyring_key is None and ask: kr.keyring_key = getpass() kr.set_password(system, username, password) return raise RuntimeError( "Unknown library '{}'.".format(lib))
print("Using pasuspender to bypass pulseaudio.") aplay = pasuspender + aplay HASMQA = (which('mqadec') is not None) and (which('mqarender') is not None) session = tidalapi.Session() login_attempts = 0 allowed_attempts = 3 while login_attempts < allowed_attempts: kr = CryptFileKeyring() username = input('TIDAL username: '******'TIDAL password: '******'TIDAL username: '******'\N{EIGHTH NOTE} Successfully logged in! \N{EIGHTH NOTE}') except UnicodeEncodeError: print('Successfully logged in!') break else: print( 'Error establishing a session. Check your internet connection.' ) except HTTPError:
def run(self, argv): # parse args, setup logging and prepare keyrings args = self.parser.parse_args(argv) self.setup_logging(args.verbose) inkr = CryptFileKeyring() outkr = CryptFileKeyring() outkr.aesmode = args.aesmode # prepare infile infile = args.infile if not infile: infile = inkr.file_path else: inkr.file_path = infile inkr.filename = os.path.basename(infile) if not os.path.exists(infile): self.errexit('%s not found' % infile) if not inkr._check_file(): self.errexit('Failed to parse %s' % infile) log.info('infile %s: %s', infile, inkr.scheme) # prepare outfile outfile = args.outfile if not outfile: outfile = infile + '.%d' % os.getpid() if os.path.exists(outfile): if os.path.samefile(infile, outfile): self.errexit('infile and outfile must NOT be the same file') # outfile exists: rename os.rename(outfile, outfile + '~') log.info('%s renamed to %s~', outfile, outfile) outkr.file_path = outfile outkr.filename = os.path.basename(outfile) log.info('outfile %s: %s', outfile, outkr.scheme) # unlock the infile keyring try: inkr.keyring_key except ValueError as e: self.errexit('Unlock %s: %s' % (infile, e)) # keep old password or request password for new keyring if args.keep: outkr._get_new_password = lambda: inkr.keyring_key else: outkr.keyring_key # process infile config = configparser.RawConfigParser() config.read(infile) for section in config.sections(): log.debug('process section: [%s]', section) if section != escape('keyring-setting'): for username in config.options(section): username = unescape(username) section = unescape(section) log.info('process: [%s] %s', section, username) password = inkr.get_password(section, username) if password: outkr.set_password(section, username, password) log.debug('[%s] %s: %s', section, username, password) else: log.error('invalid entry: [%s]%s', section, username) return 0