def test_key_ceremony(self):
        trustees_public_keys = [
            trustee.process_message('create_election',
                                    create_election_test_message())
            for trustee in self.trustees
        ]

        print('\n---- PUBLIC KEYS ----')
        print(repr(trustees_public_keys))
        print('---- END PUBLIC KEYS ----\n')

        trustees_partial_public_keys = list(
            filter(None, [
                trustee.process_message('trustee_election_keys', public_keys)
                for public_keys in trustees_public_keys
                for trustee in self.trustees
                if trustee.context.guardian_id != public_keys['owner_id']
            ]))

        print('\n---- PARTIAL PUBLIC KEYS ----')
        print(repr(trustees_partial_public_keys))
        print('---- END PARTIAL PUBLIC KEYS ----\n')

        trustees_verifications = list(
            filter(None, [
                trustee.process_message('trustee_partial_election_key',
                                        partial_public_keys)
                for partial_public_keys in trustees_partial_public_keys
                for trustee in self.trustees if trustee.context.guardian_id !=
                partial_public_keys['guardian_id']
            ]))

        print('\n---- VERIFICATIONS ----')
        print(repr(trustees_verifications))
        print('---- END VERIFICATIONS ----\n')

        # Process verifications results
        for verification in trustees_verifications:
            for trustee in self.trustees:
                if trustee.context.guardian_id != verification['guardian_id']:
                    trustee.process_message('trustee_verification',
                                            verification)

        # Simulate the message from the Bulletin Board
        joint_election_key = serialize({
            'joint_election_key':
            elgamal_combine_public_keys(
                deserialize_key(public_keys['election_public_key'])
                for public_keys in trustees_public_keys)
        })

        for trustee in self.trustees:
            print(
                repr(
                    trustee.process_message('joint_election_key',
                                            joint_election_key)))
Beispiel #2
0
def combine_election_keys(request: CombineElectionKeysRequest) -> ElectionJointKey:
    """
    Combine public election keys into a final one
    :return: Combine Election key
    """
    public_keys = []
    for key in request.election_public_keys:
        public_keys.append(int_to_p_unchecked(key))
    joint_key = elgamal_combine_public_keys(public_keys)
    return ElectionJointKey(joint_key=write_json_object(joint_key))
    def process_message(self, message_type: str, message: dict,
                        context: Context):
        self.verification_received.add(message['guardian_id'])
        # TO-DO: check verifications?

        if len(self.verification_received) == context.number_of_guardians:
            joint_key = elgamal_combine_public_keys(
                context.public_keys.values())
            context.election_builder.set_public_key(get_optional(joint_key))
            context.election_metadata, context.election_context = get_optional(
                context.election_builder.build())
            context.has_joint_key = True
            return {'joint_election_key': serialize(joint_key)}
Beispiel #4
0
    def test_elgamal_combine_public_keys(self):
        # Arrange
        random_keypair = elgamal_keypair_random()
        random_keypair_two = elgamal_keypair_random()
        public_keys = [
            random_keypair.public_key, random_keypair_two.public_key
        ]

        # Act
        joint_key = elgamal_combine_public_keys(public_keys)

        # Assert
        self.assertIsNotNone(joint_key)
        self.assertNotEqual(joint_key, random_keypair.public_key)
        self.assertNotEqual(joint_key, random_keypair_two.public_key)