Пример #1
0
def test_id_nonce_signing(private_key, id_nonce):
    signature = V4IdentityScheme.create_id_nonce_signature(
        id_nonce=id_nonce,
        private_key=private_key,
    )
    signature_object = NonRecoverableSignature(signature)
    assert signature_object.verify_msg(id_nonce, PrivateKey(private_key).public_key)
Пример #2
0
def test_invalid_id_nonce_signature_validation():
    id_nonce = b"\xff" * 10
    private_key = b"\x11" * 32
    signature = V4IdentityScheme.create_id_nonce_signature(
        id_nonce=id_nonce,
        private_key=private_key,
    )

    public_key = PrivateKey(private_key).public_key.to_compressed_bytes()
    different_public_key = PrivateKey(b"\x22" *
                                      32).public_key.to_compressed_bytes()
    different_id_nonce = b"\x00" * 10
    assert different_public_key != public_key
    assert different_id_nonce != id_nonce

    with pytest.raises(ValidationError):
        V4IdentityScheme.validate_id_nonce_signature(
            id_nonce=id_nonce,
            signature=signature,
            public_key=different_public_key,
        )

    with pytest.raises(ValidationError):
        V4IdentityScheme.validate_id_nonce_signature(
            id_nonce=different_id_nonce,
            signature=signature,
            public_key=public_key,
        )
Пример #3
0
def test_official_auth_header_packet_preparation(
        tag, auth_tag, id_nonce, encoded_message, local_private_key,
        auth_response_key, encryption_key, ephemeral_public_key,
        auth_message_rlp):
    message_type_id = encoded_message[0]
    message_type = default_message_type_registry[message_type_id]
    message = rlp.decode(encoded_message[1:], message_type)
    assert message.to_bytes() == encoded_message

    id_nonce_signature = V4IdentityScheme.create_id_nonce_signature(
        id_nonce=id_nonce,
        ephemeral_public_key=ephemeral_public_key,
        private_key=local_private_key,
    )

    packet = AuthHeaderPacket.prepare(
        tag=tag,
        auth_tag=auth_tag,
        id_nonce=id_nonce,
        message=message,
        initiator_key=encryption_key,
        id_nonce_signature=id_nonce_signature,
        auth_response_key=auth_response_key,
        enr=None,
        ephemeral_public_key=ephemeral_public_key,
    )
    packet_wire_bytes = packet.to_wire_bytes()
    assert packet_wire_bytes == auth_message_rlp
Пример #4
0
def test_official_id_nonce_signature(id_nonce,
                                     ephemeral_public_key,
                                     local_secret_key,
                                     id_nonce_signature):
    created_signature = V4IdentityScheme.create_id_nonce_signature(
        id_nonce=id_nonce,
        ephemeral_public_key=ephemeral_public_key,
        private_key=local_secret_key,
    )
    assert created_signature == id_nonce_signature
Пример #5
0
def test_id_nonce_signing(private_key, id_nonce, ephemeral_key):
    ephemeral_public_key = PrivateKey(ephemeral_key).public_key.to_bytes()
    signature = V4IdentityScheme.create_id_nonce_signature(
        id_nonce=id_nonce,
        private_key=private_key,
        ephemeral_public_key=ephemeral_public_key,
    )
    signature_object = NonRecoverableSignature(signature)
    message_hash = sha256(ID_NONCE_SIGNATURE_PREFIX + id_nonce + ephemeral_public_key).digest()
    assert signature_object.verify_msg_hash(message_hash, PrivateKey(private_key).public_key)
Пример #6
0
def test_valid_id_nonce_signature_validation(private_key, id_nonce):
    signature = V4IdentityScheme.create_id_nonce_signature(
        id_nonce=id_nonce,
        private_key=private_key,
    )
    public_key = PrivateKey(private_key).public_key.to_compressed_bytes()
    V4IdentityScheme.validate_id_nonce_signature(
        id_nonce=id_nonce,
        signature=signature,
        public_key=public_key,
    )
Пример #7
0
def test_official_auth_response_encryption(secret_key, id_nonce, enr,
                                           auth_response_key,
                                           ephemeral_public_key,
                                           auth_cipher_text):
    id_nonce_signature = V4IdentityScheme.create_id_nonce_signature(
        id_nonce=id_nonce,
        private_key=secret_key,
        ephemeral_public_key=ephemeral_public_key,
    )
    assert compute_encrypted_auth_response(
        auth_response_key=auth_response_key,
        id_nonce_signature=id_nonce_signature,
        enr=enr,
    ) == auth_cipher_text