Merge pull request #18 from d0/master
Use the python unittest framework for vpicc
This commit is contained in:
@@ -9,7 +9,8 @@ env:
|
|||||||
-PREFIX=/tmp/install
|
-PREFIX=/tmp/install
|
||||||
script:
|
script:
|
||||||
#Build virtualsmartcard
|
#Build virtualsmartcard
|
||||||
- cd virtualsmartcard && autoreconf -vsi && ./configure && make && cd ..
|
- cd virtualsmartcard && autoreconf -vsi && ./configure && make
|
||||||
|
- cd src/vpicc/ && export PYTHONPATH=$PYTHONPATH:`pwd` && python -m unittest discover -s virtualsmartcard.tests -p *_test.py -v && cd $TRAVIS_BUILD_DIR
|
||||||
# Build pcsc-relay, which requires libnfc
|
# Build pcsc-relay, which requires libnfc
|
||||||
- cd /tmp && git clone https://code.google.com/p/libnfc && cd libnfc && autoreconf -i && ./configure --prefix=$PREFIX && make install && cd $TRAVIS_BUILD_DIR
|
- cd /tmp && git clone https://code.google.com/p/libnfc && cd libnfc && autoreconf -i && ./configure --prefix=$PREFIX && make install && cd $TRAVIS_BUILD_DIR
|
||||||
- cd pcsc-relay && autoreconf -vsi && ./configure && make && cd ..
|
- cd pcsc-relay && autoreconf -vsi && ./configure && make && cd ..
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2011 Dominik Oepen
|
# Copyright (C) 2014 Dominik Oepen
|
||||||
#
|
#
|
||||||
# This file is part of virtualsmartcard.
|
# This file is part of virtualsmartcard.
|
||||||
#
|
#
|
||||||
@@ -604,21 +604,3 @@ def test_pbkdf2():
|
|||||||
if result != expected:
|
if result != expected:
|
||||||
raise RuntimeError("self-test failed")
|
raise RuntimeError("self-test failed")
|
||||||
print "PBKDF2 self test successfull"
|
print "PBKDF2 self test successfull"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
too_short = binascii.a2b_hex("".join("89 45 19 BF".split()))
|
|
||||||
padded = append_padding(8, too_short)
|
|
||||||
print "Padded data: " + hexdump(padded)
|
|
||||||
unpadded = strip_padding(8, padded)
|
|
||||||
print "Without padding: " + hexdump(unpadded)
|
|
||||||
|
|
||||||
teststring = "DEADBEEFistatsyksdvhwohfwoehcowc8hw8rogfq8whv75tsgohsav8wress"
|
|
||||||
foo = append_padding(16, teststring)
|
|
||||||
assert(strip_padding(16, foo) == teststring)
|
|
||||||
|
|
||||||
testpass = "SomeRandomPassphrase"
|
|
||||||
protectedString = protect_string(teststring, testpass)
|
|
||||||
unprotectedString = read_protected_string(protectedString, testpass)
|
|
||||||
assert(teststring == unprotectedString)
|
|
||||||
|
|
||||||
#test_pbkdf2()
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2011 Dominik Oepen
|
# Copyright (C) 2014 Dominik Oepen
|
||||||
#
|
#
|
||||||
# This file is part of virtualsmartcard.
|
# This file is part of virtualsmartcard.
|
||||||
#
|
#
|
||||||
@@ -356,48 +356,3 @@ class SAM(object):
|
|||||||
def manage_security_environment(self, p1, p2, data):
|
def manage_security_environment(self, p1, p2, data):
|
||||||
return self.current_SE.manage_security_environment(p1, p2, data)
|
return self.current_SE.manage_security_environment(p1, p2, data)
|
||||||
|
|
||||||
#Unit Tests
|
|
||||||
if __name__ == "__main__":
|
|
||||||
|
|
||||||
password = "DUMMYKEYDUMMYKEY"
|
|
||||||
|
|
||||||
MyCard = SAM("1234", "1234567890")
|
|
||||||
try:
|
|
||||||
print(MyCard.verify(0x00, 0x00, "5678"))
|
|
||||||
except SwError as e:
|
|
||||||
print(e.message)
|
|
||||||
|
|
||||||
print("Counter = " + str(MyCard.counter))
|
|
||||||
print(MyCard.verify(0x00, 0x00, "1234"))
|
|
||||||
print("Counter = " + str(MyCard.counter))
|
|
||||||
sw, challenge = MyCard.get_challenge(0x00, 0x00, "")
|
|
||||||
print("Before encryption: " + challenge)
|
|
||||||
blocklen = vsCrypto.get_cipher_blocklen("DES3-ECB")
|
|
||||||
padded = vsCrypto.append_padding(blocklen, challenge)
|
|
||||||
sw, result_data = MyCard.internal_authenticate(0x00, 0x00, padded)
|
|
||||||
print("Internal Authenticate status code: %x" % sw)
|
|
||||||
|
|
||||||
try:
|
|
||||||
sw, res = MyCard.external_authenticate(0x00, 0x00, result_data)
|
|
||||||
except SwError as e:
|
|
||||||
print(e.message)
|
|
||||||
sw = e.sw
|
|
||||||
print("Decryption Status code: %x" % sw)
|
|
||||||
|
|
||||||
#SE = Security_Environment(None)
|
|
||||||
#testvektor = "foobar"
|
|
||||||
#print "Testvektor = %s" % testvektor
|
|
||||||
#sw, hash = SE.hash(0x90,0x80,testvektor)
|
|
||||||
#print "SW after hashing = %s" % sw
|
|
||||||
#print "Hash = %s" % hash
|
|
||||||
#sw, crypted = SE.encipher(0x00, 0x00, testvektor)
|
|
||||||
#print "SW after encryption = %s" % sw
|
|
||||||
#sw, plain = SE.decipher(0x00, 0x00, crypted)
|
|
||||||
#print "SW after encryption = %s" % sw
|
|
||||||
#print "Testvektor after en- and deciphering: %s" % plain
|
|
||||||
#sw, pk = SE.generate_public_key_pair(0x02, 0x00, "")
|
|
||||||
#print "SW after keygen = %s" % sw
|
|
||||||
#print "Public Key = %s" % pk
|
|
||||||
#CF = CryptoflexSE(None)
|
|
||||||
#print CF.generate_public_key_pair(0x00, 0x80, "\x01\x00\x01\x00")
|
|
||||||
#print MyCard._get_referenced_key(0x01)
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import unittest
|
||||||
|
from virtualsmartcard.CryptoUtils import *
|
||||||
|
|
||||||
|
class TestCryptoUtils(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.teststring = "DEADBEEFistatsyksdvhwohfwoehcowc8hw8rogfq8whv75tsgohsav8wress"
|
||||||
|
self.testpass = "SomeRandomPassphrase"
|
||||||
|
|
||||||
|
def test_padding(self):
|
||||||
|
padded = append_padding(16, self.teststring)
|
||||||
|
unpadded = strip_padding(16, padded)
|
||||||
|
self.assertEqual(unpadded, self.teststring)
|
||||||
|
|
||||||
|
def test_protect_string(self):
|
||||||
|
protectedString = protect_string(self.teststring, self.testpass)
|
||||||
|
unprotectedString = read_protected_string(protectedString, self.testpass)
|
||||||
|
self.assertEqual(self.teststring, unprotectedString)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
|
#test_pbkdf2()
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import unittest
|
||||||
|
from virtualsmartcard.SmartcardSAM import *
|
||||||
|
|
||||||
|
#Unit Tests
|
||||||
|
class TestSmartcardSAM(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.password = "DUMMYKEYDUMMYKEY"
|
||||||
|
self.myCard = SAM("1234", "1234567890")
|
||||||
|
|
||||||
|
def test_incorrect_pin(self):
|
||||||
|
with self.assertRaises(SwError):
|
||||||
|
self.myCard.verify(0x00, 0x00, "5678")
|
||||||
|
|
||||||
|
def test_counter_decrement(self):
|
||||||
|
ctr1 = self.myCard.counter
|
||||||
|
try:
|
||||||
|
self.myCard.verify(0x00, 0x00, "3456")
|
||||||
|
except SwError as e:
|
||||||
|
pass
|
||||||
|
self.assertEquals(self.myCard.counter, ctr1 - 1)
|
||||||
|
|
||||||
|
def test_internal_authenticate(self):
|
||||||
|
sw, challenge = self.myCard.get_challenge(0x00, 0x00, "")
|
||||||
|
print("Before encryption: " + challenge)
|
||||||
|
blocklen = vsCrypto.get_cipher_blocklen("DES3-ECB")
|
||||||
|
padded = vsCrypto.append_padding(blocklen, challenge)
|
||||||
|
sw, result_data = self.myCard.internal_authenticate(0x00, 0x00, padded)
|
||||||
|
print("Internal Authenticate status code: %x" % sw)
|
||||||
|
self.assertEquals(sw, SW["NORMAL"])
|
||||||
|
|
||||||
|
def test_external_authenticate(self):
|
||||||
|
sw, challenge = self.myCard.get_challenge(0x00, 0x00, "")
|
||||||
|
print("Before encryption: " + challenge)
|
||||||
|
blocklen = vsCrypto.get_cipher_blocklen("DES3-ECB")
|
||||||
|
padded = vsCrypto.append_padding(blocklen, challenge)
|
||||||
|
sw, result_data = self.myCard.internal_authenticate(0x00, 0x00, padded)
|
||||||
|
sw, result_data = self.myCard.external_authenticate(0x00, 0x00, result_data)
|
||||||
|
print ("After external authenticate: " + result_data)
|
||||||
|
self.assertEquals(sw, SW["NORMAL"])
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
|
#SE = Security_Environment(None)
|
||||||
|
#testvektor = "foobar"
|
||||||
|
#print "Testvektor = %s" % testvektor
|
||||||
|
#sw, hash = SE.hash(0x90,0x80,testvektor)
|
||||||
|
#print "SW after hashing = %s" % sw
|
||||||
|
#print "Hash = %s" % hash
|
||||||
|
#sw, crypted = SE.encipher(0x00, 0x00, testvektor)
|
||||||
|
#print "SW after encryption = %s" % sw
|
||||||
|
#sw, plain = SE.decipher(0x00, 0x00, crypted)
|
||||||
|
#print "SW after encryption = %s" % sw
|
||||||
|
#print "Testvektor after en- and deciphering: %s" % plain
|
||||||
|
#sw, pk = SE.generate_public_key_pair(0x02, 0x00, "")
|
||||||
|
#print "SW after keygen = %s" % sw
|
||||||
|
#print "Public Key = %s" % pk
|
||||||
|
#CF = CryptoflexSE(None)
|
||||||
|
#print CF.generate_public_key_pair(0x00, 0x80, "\x01\x00\x01\x00")
|
||||||
|
#print MyCard._get_referenced_key(0x01)
|
||||||
Reference in New Issue
Block a user