Beispiel #1
0
def get_password(system, username, lib='keyrings.cryptfile',
                 env='KEYRING_CRYPTFILE_PASSWORD', ask=True):
    """
    Restores a password.
    By default, uses :epkg:`keyring`.

    :param system: system
    :param username: username
    :param lib: which lib to use to store the password
    :param env: see below
    :param ask: ask for password if missing
    :return: password

    If `lib == 'keyrings.cryptfile'`, the function used the environment
    variable *env*, if present, no password is asked.
    """
    if lib == 'keyring':
        from keyring import get_password as lib_get_password
        pwd = lib_get_password(system, username)
        if pwd in (None, '', b''):
            raise RuntimeError(  # pragma: no cover
                "Unable to restore a password with keyring for '{}', '{}'.".format(
                    system, username))
        return pwd
    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()
        return kr.get_password(system, username)
    raise RuntimeError(
        "Unknown library '{}'.".format(lib))
Beispiel #2
0
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")
Beispiel #3
0
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: "))
Beispiel #4
0
    def getKr(self):
        if os.name != 'nt':
            #logging.getLogger().exception("getlogger "+self.configfile)
            config = configparser.ConfigParser()
            config.read(self.configfile)
            sd = config.get("other", "startdate")
            pc = config.get("other", "postcode")

            kr = CryptFileKeyring()
            kr.keyring_key = pc + platform.node() + os.name + sd + "!djl!"
            keyring.set_keyring(kr)
    def _configure_legacy_backend(self) -> CryptFileKeyring:
        # If keyring.yaml isn't found or is empty, check if we're using CryptFileKeyring
        filekeyring = self.keyring if type(self.keyring) == FileKeyring else None
        if filekeyring and not filekeyring.has_content():
            old_keyring = CryptFileKeyring()
            if Path(old_keyring.file_path).is_file():
                # After migrating content from legacy_keyring, we'll prompt to clear those keys
                old_keyring.keyring_key = "your keyring password"  # type: ignore
                return old_keyring

        return None
Beispiel #6
0
def get_password(key: str, service: str):
    config = read_config()
    try:
        cryptfile_pw = config.get("cryptfile", "password")
    except configparser.NoSectionError:
        cryptfile_pw = None

    if cryptfile_pw is not None:
        # See https://github.com/frispete/keyrings.cryptfile#example-session
        # on how to set pws.
        kr = CryptFileKeyring()
        kr.keyring_key = base64_decode(cryptfile_pw)
        pw = kr.get_password(service, key)
        if not pw:
            code = f"import net_worth_tracker as nwt; nwt.utils.set_password('{service}', '{key}')"
            raise Exception(f'Use:\npython -c "{code}"')
    else:
        pw = keyring.get_password(service, key)
        if not pw:
            raise Exception(f"python -m keyring set {service} {key}")

    return pw
Beispiel #7
0
from os import getenv
from keyrings.cryptfile.cryptfile import CryptFileKeyring
kr = CryptFileKeyring()
kr.keyring_key = getenv("KEYRING_CRYPTFILE_PASSWORD")
print(kr.get_password("web", "pyquickhelper,user"))
Beispiel #8
0
from keyrings.cryptfile.cryptfile import CryptFileKeyring
from src.util.hash import std_hash

MAX_KEYS = 100

if platform == "win32" or platform == "cygwin":
    import keyring.backends.Windows

    keyring.set_keyring(keyring.backends.Windows.WinVaultKeyring())
elif platform == "darwin":
    import keyring.backends.OS_X

    keyring.set_keyring(keyring.backends.OS_X.Keyring())
elif platform == "linux":
    keyring = CryptFileKeyring()
    keyring.keyring_key = "your keyring password"
else:
    keyring = keyring_main


def bip39_word_list() -> str:
    return pkg_resources.resource_string(__name__, "english.txt").decode()


def generate_mnemonic() -> str:
    mnemonic_bytes = token_bytes(32)
    mnemonic = bytes_to_mnemonic(mnemonic_bytes)
    return mnemonic


def bytes_to_mnemonic(mnemonic_bytes: bytes):
from pathlib import Path

from keyrings.cryptfile.cryptfile import CryptFileKeyring
from PyQt5 import QtWidgets

from audio_app import VkAudioApp


def ui():
    app = QtWidgets.QApplication(sys.argv)
    window = VkAudioApp(info, cookie, keyring)
    window.show()
    app.exec_()


if __name__ == "__main__":
    keyring = CryptFileKeyring()
    keyring.keyring_key = os.getlogin()
    home = Path.home() / ".vk_downloader"
    try:
        home.mkdir(exist_ok=True)
    except (PermissionError, FileNotFoundError):
        home = tempfile.TemporaryDirectory()
    cookie = home / "vk_cookies.json"
    data = keyring.get_password("vk_music_downloader", os.getlogin())
    if isinstance(data, str):
        info = data.split("|")
    else:
        info = None
    ui()
Beispiel #10
0
from chia.util.hash import std_hash

MAX_KEYS = 100

if platform == "win32" or platform == "cygwin":
    import keyring.backends.Windows

    keyring.set_keyring(keyring.backends.Windows.WinVaultKeyring())
elif platform == "darwin":
    import keyring.backends.macOS

    keyring.set_keyring(keyring.backends.macOS.Keyring())
elif platform == "linux":
    keyring = CryptFileKeyring()
    keyring.keyring_key = "your keyring password"  # type: ignore
else:
    keyring = keyring_main


def bip39_word_list() -> str:
    return pkg_resources.resource_string(__name__, "english.txt").decode()


def generate_mnemonic() -> str:
    mnemonic_bytes = token_bytes(32)
    mnemonic = bytes_to_mnemonic(mnemonic_bytes)
    return mnemonic


def bytes_to_mnemonic(mnemonic_bytes: bytes):
Beispiel #11
0
def set_keyring():
    kr = CryptFileKeyring()
    kr.keyring_key = os.environ["KEYRING_CRYPTFILE_PSSWRD"]
    keyring.set_keyring(kr)