def test_keys():
    privkey = PrivateKey()
    pubkey = privkey.public_key()

    message = "Hello World"

    sig = privkey.sign(message.encode("utf-8"))
    pubkey.verify(sig, message.encode("utf-8"))

    c = pubkey.encrypt(message.encode("utf-8"))

    m = privkey.decrypt(c).decode("utf-8")
    assert (m == message)

    privkey2 = PrivateKey()
    sig2 = privkey2.sign(message.encode("utf-8"))

    with pytest.raises(SignatureVerificationError):
        pubkey.verify(sig2, message.encode("utf-8"))

    bytes = privkey.bytes("testPass32")

    PrivateKey.read_bytes(bytes, "testPass32")

    privkey.write("test.pem", "testPass32")

    PrivateKey.read("test.pem", "testPass32")

    bytes = pubkey.bytes()
    pubkey2 = PublicKey.read_bytes(bytes)

    assert (bytes == pubkey2.bytes())

    long_message = str([random.getrandbits(8)
                        for _ in range(4096)]).encode("utf-8")

    c = pubkey.encrypt(long_message)

    m = privkey.decrypt(c)

    assert (m == long_message)

    os.unlink("test.pem")

    data = pubkey.to_data()

    pubkey2 = PublicKey.from_data(data)

    assert (pubkey.bytes() == pubkey2.bytes())

    data = privkey.to_data("testPass33")

    privkey2 = PrivateKey.from_data(data, "testPass33")

    assert (privkey == privkey2)
Beispiel #2
0
# The passphrase to unlock the key - VERY SECRET!!!
data["pass_phrase"] = sys.argv[2]

# Make sure that this is the correct password...
privkey = PrivateKey.read(sys.argv[1], sys.argv[2])

# The region for this tenancy
data["region"] = "eu-frankfurt-1"

secret_config["LOGIN"] = data

## Now create the bucket info so we know where the bucket is
## that will store all data related to logging into accounts

data = {}
data[
    "compartment"] = "ocid1.compartment.oc1..aaaaaaaat33j7w74mdyjenwoinyeawztxe7ri6qkfbm5oihqb5zteamvbpzq"
data["bucket"] = "acquire_compute"

secret_config["BUCKET"] = data

secret_config["PASSWORD"] = sys.argv[2]

config_data = bytes_to_string(
    config_key.encrypt(json.dumps(secret_config).encode("utf-8")))
secret_key = json.dumps(config_key.to_data(sys.argv[3]))

os.system("fn config app compute SECRET_CONFIG '%s'" % config_data)
os.system("fn config app compute SECRET_KEY '%s'" % secret_key)
Beispiel #3
0
    while True:
        password = getpass.getpass(
            prompt="Please enter the service primary password: "******"Please enter the password again: ")

        if password == password2:
            break

        print("Passwords not equal - please try again")

    service_salt = PrivateKey.random_passphrase()
    password = Hash.multi_md5(password, service_salt)

    old_config = None
    service_key = PrivateKey()
    service_key_data = service_key.to_data(passphrase=password)

with open(config_file, "r") as FILE:
    config = load(FILE, Loader=Loader)

if old_config is not None:
    if old_config["service"] != config["service"]:
        for key in config["service"].keys():
            if old_config["service"][key] != config["service"][key]:
                print(
                    "\nDisagree key = %s\n%s\n%s" %
                    (key, old_config["service"][key], config["service"][key]))

        raise PermissionError("Config disagreement: %s vs %s" %
                              (config["service"], old_config["service"]))