Beispiel #1
0
def write_private(inp):
    priv = inp[0]
    salt = inp[1]
    global global_password
    
    priv_encoded = json.dumps(priv)
    key = crypto.kdf(global_password,salt)
    ciphertext = crypto.encrypt(priv_encoded,key)
    towrite = {'salt':salt,'priv':ciphertext}
    
    with os.fdopen(os.open('private.json',os.O_WRONLY | os.O_CREAT,0600), 'w') as f:
        json.dump(towrite,f)
Beispiel #2
0
def read_private():
    global global_password
    if global_password is None:
        setpassword(getpass.getpass("Please enter the password to decrypt your keystore: "))

    if os.path.exists('private.json'):
        with open('private.json','r') as f:
            toread = json.load(f)
        key = crypto.kdf(global_password,toread['salt'])
        try:
            plain = crypto.decrypt(toread['priv'],key)
        except ValueError:
            raise Exception("Invalid password for keystore")
            
        return json.loads(plain),toread['salt']
    else:
        #file doesn't exist, just invent a salt
        return {'revoked_keys':[]},base64.b64encode(crypto.generate_random_key())