Exemplo n.º 1
0
def test_keying_material_serialization():
    umbral_keying_material = UmbralKeyingMaterial()

    encoded_key = umbral_keying_material.to_bytes()

    decoded_key = UmbralKeyingMaterial.from_bytes(encoded_key)
    assert umbral_keying_material.keying_material == decoded_key.keying_material
Exemplo n.º 2
0
 def __init__(self,
              keying_material: Optional[bytes] = None,
              password: Optional[bytes] = None) -> None:
     if keying_material is None:
         self.__umbral_keying_material = UmbralKeyingMaterial()
     else:
         self.__umbral_keying_material = UmbralKeyingMaterial.from_bytes(key_bytes=keying_material,
                                                                         password=password)
Exemplo n.º 3
0
def test_keying_material_serialization():
    umbral_keying_material = UmbralKeyingMaterial()

    encoded_keying_material = umbral_keying_material.to_bytes()

    decoded_keying_material = UmbralKeyingMaterial.from_bytes(encoded_keying_material)

    label = os.urandom(32)
    privkey_bytes = umbral_keying_material.derive_privkey_by_label(label).to_bytes()
    assert privkey_bytes == decoded_keying_material.derive_privkey_by_label(label).to_bytes()
Exemplo n.º 4
0
    def create_policy(self, label: bytes, alice_privkey: UmbralPrivateKey,
                      bob_pubkey: UmbralPublicKey, policy_expiration, m: int,
                      n: int):
        """
        Create a Policy with Alice granting Bob access to `label` DataSource

        :param label: A label to represent the policies data
        :param alice_privkey: Alice's private key
        :param bob_pubkey: Bob's public key
        :param policy_expiration: Datetime of policy expiration duration
        :param m: Minimum number of KFrags needed to rebuild ciphertext
        :param n: Total number of rekey shares to generate

        :return: The policy granted to Bob
        """
        # This is not how this should be implemented, but I am still figuring out
        # the keying material and why it is randomly generated when a character is
        # initialized, instead of being derived from the keys like the other powers
        # or explained how it should be stored.
        d = DelegatingPower()
        d.umbral_keying_material = UmbralKeyingMaterial.from_bytes(
            alice_privkey.to_bytes() + alice_privkey.get_pubkey().to_bytes())

        # Initialize Alice
        ALICE = Alice(
            crypto_power_ups=[
                SigningPower(keypair=SigningKeypair(alice_privkey)),
                EncryptingPower(keypair=EncryptingKeypair(alice_privkey)),
                # DelegatingPower
                d
            ],
            network_middleware=RestMiddleware(),
            known_nodes=(self.ursula, ),
            federated_only=True,
            always_be_learning=True)

        # Initialize Bob
        BOB = Bob(crypto_power_ups=[
            SigningPower(pubkey=bob_pubkey),
            EncryptingPower(pubkey=bob_pubkey)
        ],
                  known_nodes=(self.ursula, ),
                  federated_only=True,
                  always_be_learning=True)

        # Alice grants a policy for Bob
        policy = ALICE.grant(BOB,
                             label,
                             m=m,
                             n=n,
                             expiration=policy_expiration)

        return policy
Exemplo n.º 5
0
def test_keying_material_serialization_with_encryption():
    umbral_keying_material = UmbralKeyingMaterial()

    insecure_cost = 15  # This is deliberately insecure, just to make the tests faster
    encoded_key = umbral_keying_material.to_bytes(password=b'test',
                                                  _scrypt_cost=insecure_cost)

    decoded_key = UmbralKeyingMaterial.from_bytes(encoded_key,
                                                  password=b'test',
                                                  _scrypt_cost=insecure_cost)

    assert umbral_keying_material.keying_material == decoded_key.keying_material
Exemplo n.º 6
0
def test_keying_material_serialization_with_encryption():
    umbral_keying_material = UmbralKeyingMaterial()

    insecure_cost = 15  # This is deliberately insecure, just to make the tests faster
    encoded_keying_material = umbral_keying_material.to_bytes(password=b'test',
                                                              _scrypt_cost=insecure_cost)

    decoded_keying_material = UmbralKeyingMaterial.from_bytes(encoded_keying_material,
                                                              password=b'test',
                                                              _scrypt_cost=insecure_cost)

    label = os.urandom(32)
    privkey_bytes = umbral_keying_material.derive_privkey_by_label(label).to_bytes()
    assert privkey_bytes == decoded_keying_material.derive_privkey_by_label(label).to_bytes()