def test_pem_public(self): cipher = CitizenCard("a") pubKey = cipher.get_pubKey() pem = pem_utils.get_publicKey_To_Pem(pubKey) result = pem_utils.get_publicKey_From_Pem(pem) pem2 = pem_utils.get_publicKey_To_Pem(result) print("PRIVATE KEY {}".format(pubKey)) print("RESULT KEY 1{}\n\n\n".format(pem)) print("RESULT KEY 2{}".format(pem2)) self.assertEqual(pem, pem2, "Should be the same")
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")
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)")
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
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")
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")
def verifySignature(signature, data, publicKey, ccFlag=False): if (ccFlag): if (CitizenCard.valid_signature2(signature, data, publicKey)): logger.log('Server', 'Valid signature with CC on message: {}.'.format(data), 'blue') return else: if AsymCipher.valid_signature2(signature, data, publicKey): logger.log( 'Server', 'Valid signature with RSA cipher on message: {}.'.format(data), 'blue') return logger.log('Server', 'Invalid signature on message: {}.'.format(data), 'red') logger.log('Server', 'Pentesting, are we?', 'red') sys.exit(3)
parser.add_argument('-i', '--ip-address', type=str, help='Server IP address', required=True) parser.add_argument('-p', '--port', type=int, help='Server port', required=True) args = parser.parse_args() verbose = args.verbose # Create Citizen Card instance try: citizen_card = CitizenCard("PIN - NOT USED") name = citizen_card.get_name() logger.log( 'Client', 'Using Citizen Card with name {} and id {}'.format( name, citizen_card.get_number()), 'green') except Exception as e: logger.log('Client', e, 'red') logger.log( 'Client', 'Not using Citizen Card - no available cards. Using name on arguments', 'red') name = args.username exception_happened = True # Create RSA and AES ciphers asym_cipher = AsymCipher(name)