示例#1
0
    def test_all_election_partial_key_backups_verified(self):
        # Arrange
        # Round 1
        guardian = Guardian(
            SENDER_GUARDIAN_ID, SENDER_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        other_guardian = Guardian(
            RECIPIENT_GUARDIAN_ID, RECIPIENT_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        guardian.save_guardian_public_keys(other_guardian.share_public_keys())
        other_guardian.save_guardian_public_keys(guardian.share_public_keys())

        # Round 2
        guardian.generate_election_partial_key_backups(identity_auxiliary_encrypt)
        key_backup = guardian.share_election_partial_key_backup(RECIPIENT_GUARDIAN_ID)
        other_guardian.save_election_partial_key_backup(key_backup)
        verification = other_guardian.verify_election_partial_key_backup(
            SENDER_GUARDIAN_ID, identity_auxiliary_decrypt
        )
        guardian.save_election_partial_key_verification(verification)

        # Act
        all_saved = guardian.all_election_partial_key_backups_verified()

        # Assert
        self.assertTrue(all_saved)
示例#2
0
    def test_verify_election_partial_key_backup(self):
        # Arrange
        # Round 1
        guardian = Guardian(
            SENDER_GUARDIAN_ID, SENDER_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        other_guardian = Guardian(
            RECIPIENT_GUARDIAN_ID, RECIPIENT_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        guardian.save_guardian_public_keys(other_guardian.share_public_keys())
        other_guardian.save_guardian_public_keys(guardian.share_public_keys())

        # Round 2
        guardian.generate_election_partial_key_backups(identity_auxiliary_encrypt)
        key_backup = guardian.share_election_partial_key_backup(RECIPIENT_GUARDIAN_ID)
        other_guardian.save_election_partial_key_backup(key_backup)

        # Act
        verification = other_guardian.verify_election_partial_key_backup(
            SENDER_GUARDIAN_ID, identity_auxiliary_decrypt
        )

        # Assert
        self.assertIsNotNone(verification)
        self.assertEqual(verification.owner_id, SENDER_GUARDIAN_ID)
        self.assertEqual(verification.designated_id, RECIPIENT_GUARDIAN_ID)
        self.assertEqual(verification.verifier_id, RECIPIENT_GUARDIAN_ID)
        self.assertTrue(verification.verified)
示例#3
0
    def test_all_election_partial_key_backups_received(self):
        # Arrange
        # Round 1
        guardian = Guardian(
            SENDER_GUARDIAN_ID, SENDER_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        other_guardian = Guardian(
            RECIPIENT_GUARDIAN_ID, RECIPIENT_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        guardian.save_guardian_public_keys(other_guardian.share_public_keys())
        other_guardian.save_guardian_public_keys(guardian.share_public_keys())

        # Round 2
        guardian.generate_election_partial_key_backups(identity_auxiliary_encrypt)
        key_backup = guardian.share_election_partial_key_backup(RECIPIENT_GUARDIAN_ID)

        # Assert
        self.assertFalse(other_guardian.all_election_partial_key_backups_received())
        other_guardian.save_election_partial_key_backup(key_backup)
        self.assertTrue(other_guardian.all_election_partial_key_backups_received())
示例#4
0
    def test_publish_joint_key(self):
        # Arrange
        # Round 1
        guardian = Guardian(
            SENDER_GUARDIAN_ID, SENDER_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        other_guardian = Guardian(
            RECIPIENT_GUARDIAN_ID, RECIPIENT_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        guardian.save_guardian_public_keys(other_guardian.share_public_keys())
        other_guardian.save_guardian_public_keys(guardian.share_public_keys())

        # Round 2
        guardian.generate_election_partial_key_backups(identity_auxiliary_encrypt)
        key_backup = guardian.share_election_partial_key_backup(RECIPIENT_GUARDIAN_ID)
        other_guardian.save_election_partial_key_backup(key_backup)
        verification = other_guardian.verify_election_partial_key_backup(
            SENDER_GUARDIAN_ID, identity_auxiliary_decrypt
        )

        # Act
        joint_key = guardian.publish_joint_key()

        # Assert
        self.assertIsNone(joint_key)

        # Act
        guardian.save_election_public_key(other_guardian.share_election_public_key())
        joint_key = guardian.publish_joint_key()

        # Assert
        self.assertIsNone(joint_key)

        # Act
        guardian.save_election_partial_key_verification(verification)
        joint_key = guardian.publish_joint_key()

        # Assert
        self.assertIsNotNone(joint_key)
        self.assertNotEqual(joint_key, guardian.share_election_public_key().key)
示例#5
0
    def test_all_public_keys_received(self):
        # Arrange
        guardian = Guardian(SENDER_GUARDIAN_ID, SENDER_SEQUENCE_ORDER,
                            NUMBER_OF_GUARDIANS, QUORUM)
        other_guardian = Guardian(RECIPIENT_GUARDIAN_ID,
                                  RECIPIENT_SEQUENCE_ORDER,
                                  NUMBER_OF_GUARDIANS, QUORUM)
        public_keys = other_guardian.share_public_keys()

        # Act
        self.assertFalse(guardian.all_public_keys_received())
        guardian.save_guardian_public_keys(public_keys)

        # Assert
        self.assertTrue(guardian.all_public_keys_received())
示例#6
0
    def test_share_public_keys(self):
        # Arrange
        guardian = Guardian(SENDER_GUARDIAN_ID, SENDER_SEQUENCE_ORDER,
                            NUMBER_OF_GUARDIANS, QUORUM)

        # Act
        public_keys = guardian.share_public_keys()

        # Assert
        self.assertIsNotNone(public_keys)
        self.assertIsNotNone(public_keys.auxiliary_public_key)
        self.assertIsNotNone(public_keys.election_public_key)
        self.assertEqual(public_keys.owner_id, SENDER_GUARDIAN_ID)
        self.assertEqual(public_keys.sequence_order, SENDER_SEQUENCE_ORDER)
        self.assertTrue(public_keys.election_public_key_proof.is_valid())
示例#7
0
)
from electionguard.key_ceremony_mediator import KeyCeremonyMediator

identity_auxiliary_decrypt = lambda message, public_key: message
identity_auxiliary_encrypt = lambda message, private_key: message

NUMBER_OF_GUARDIANS = 2
QUORUM = 2
CEREMONY_DETAILS = CeremonyDetails(NUMBER_OF_GUARDIANS, QUORUM)
GUARDIAN_1_ID = "Guardian 1"
GUARDIAN_2_ID = "Guardian 2"
VERIFIER_ID = "Guardian 3"
GUARDIAN_1 = Guardian(GUARDIAN_1_ID, 1, NUMBER_OF_GUARDIANS, QUORUM)
GUARDIAN_2 = Guardian(GUARDIAN_2_ID, 2, NUMBER_OF_GUARDIANS, QUORUM)
VERIFIER = Guardian(VERIFIER_ID, 3, NUMBER_OF_GUARDIANS, QUORUM)
GUARDIAN_1.save_guardian_public_keys(GUARDIAN_2.share_public_keys())
GUARDIAN_2.save_guardian_public_keys(GUARDIAN_1.share_public_keys())
VERIFIER.save_guardian_public_keys(GUARDIAN_2.share_public_keys())
GUARDIAN_1.generate_election_partial_key_backups(identity_auxiliary_encrypt)
GUARDIAN_2.generate_election_partial_key_backups(identity_auxiliary_encrypt)


class TestKeyCeremonyMediator(TestCase):
    def test_reset(self):
        # Arrange
        mediator = KeyCeremonyMediator(CEREMONY_DETAILS)
        new_ceremony_details = CeremonyDetails(3, 3)

        mediator.reset(new_ceremony_details)
        self.assertEqual(mediator.ceremony_details, new_ceremony_details)