Ejemplo n.º 1
0
    def test_validate_cert(self):
        citizen_card = CitizenCard(self.pin)

        cert = citizen_card.get_cert()
        is_valid = citizen_card.verify_certificate_chain(cert)
        citizen_card.signOut()
        self.assertTrue(is_valid, msg="Cert chain should be valid")
Ejemplo n.º 2
0
    def test_name_id(self):
        citizen_card = CitizenCard(self.pin)

        name = citizen_card.get_name()
        num = citizen_card.get_number()

        print("Name {:s}, Number {:s}".format(name, str(num)))
        citizen_card.signOut()
        self.assertTrue(True, msg="")  # dummy test
Ejemplo n.º 3
0
    def test_signature_equal(self):
        # Sign the data
        citizen_card = CitizenCard(self.pin)

        data = "Hello World"
        signature = citizen_card.sign(data)

        is_valid = citizen_card.valid_signature(signature, data)
        citizen_card.signOut()
        self.assertTrue(is_valid, msg="Signature should be valid")
Ejemplo n.º 4
0
    def test_signature_not_equal(self):
        # Sign the data
        citizen_card = CitizenCard(self.pin)

        data1 = "Hello World"
        signature = citizen_card.sign(data1)

        data2 = "Hello world, again"
        is_valid = citizen_card.valid_signature(signature, data2)
        citizen_card.signOut()
        self.assertFalse(is_valid, msg="Signature should be not valid")
Ejemplo n.º 5
0
    def test_several_users(self):
        citizen_card = CitizenCard(self.pin)
        citizen_card.signOut()
        exception_happened = False

        try:
            citizen_card_2 = CitizenCard(self.pin)
            citizen_card_2.signOut()

        except Exception as e:
            print(e)
            exception_happened = True

        self.assertTrue(
            exception_happened,
            "Should have raised an exception (if only 1 card is connected)")
Ejemplo n.º 6
0
            showHand()
        playFirst = decodedMessage[decodedMessage.index('[') +
                                   1:decodedMessage.index(']')] == 'Taken'
        playedCards = json.loads(decodedMessage[decodedMessage.index(']') +
                                                1:])
        printTable(playedCards)

    # 13 Rounds Over
    # Cheating Protest Phase
    if (input('Do you want to protest (cheating)? (yes/NO)\n> ').lower()
            in ['y', 'yes']):
        symCipherAndSend('[Protest]'.encode(), (serverIP, serverPort))
    else:
        symCipherAndSend('[NoProtest]'.encode(), (serverIP, serverPort))

    # Print Scores
    data, address = sock.recvfrom(1048576)
    data = symDecipher(data, address)
    decodedMessage = json.loads(data.decode())

    # TODO verify server signature?
    # TODO Check if server score equals client accounting
    printScore(decodedMessage)

    # Accouting
    accounting(decodedMessage, tableID)

    # Exit
    if citizen_card is not None:
        citizen_card.signOut()