diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py b/virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py
index 5dd6d2c..e136185 100644
--- a/virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py
+++ b/virtualsmartcard/src/vpicc/virtualsmartcard/CardGenerator.py
@@ -17,7 +17,7 @@
# virtualsmartcard. If not, see .
#
-import sys, getpass, anydbm, readline
+import sys, getpass, anydbm, readline, logging
from pickle import loads, dumps
from virtualsmartcard.TLVutils import pack
from virtualsmartcard.utils import inttostring
@@ -45,9 +45,13 @@ class CardGenerator(object):
self.sam = sam
def __generate_iso_card(self):
- print "Using default SAM. Insecure!!!"
+ default_pin = "1234"
+ default_cardno = "1234567890"
+
+ logging.warning("Using default SAM parameters. PIN=%s, Card Nr=%s"
+ & (default_pin, default_cardno))
#TODO: Use user provided data
- self.sam = virtualsmartcard.SmartcardSAM.SAM("1234", "1234567890")
+ self.sam = virtualsmartcard.SmartcardSAM.SAM(default_pin, default_cardno)
self.mf = MF(filedescriptor=FDB["DF"])
self.sam.set_MF(self.mf)
@@ -74,7 +78,7 @@ class CardGenerator(object):
picture = fd.read()
fd.close()
except IOError:
- print "Failed to open file: " + picturepath
+ logging.warning("Failed to open file: " + picturepath)
pic_width = 0
pic_height = 0
picture = None
@@ -212,7 +216,7 @@ if __name__ == "__main__":
(options, args) = parser.parse_args()
if options.filename == None:
- print "You have to provide a filename using the -f option"
+ logging.error("You have to provide a filename using the -f option")
sys.exit()
generator = CardGenerator(options.type)
diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/CryptoUtils.py b/virtualsmartcard/src/vpicc/virtualsmartcard/CryptoUtils.py
index e03524e..4f4d8b4 100644
--- a/virtualsmartcard/src/vpicc/virtualsmartcard/CryptoUtils.py
+++ b/virtualsmartcard/src/vpicc/virtualsmartcard/CryptoUtils.py
@@ -16,14 +16,13 @@
# You should have received a copy of the GNU General Public License along with
# virtualsmartcard. If not, see .
#
-import sys, binascii, utils, random
-from Crypto.Cipher import DES3, DES, AES, ARC4 #,IDEA no longer present in python-crypto?
+import sys, binascii, utils, random, logging
+from Crypto.Cipher import DES3, DES, AES, ARC4 #,IDEA no longer present in python-crypto? @UnusedImport
from struct import pack
from binascii import b2a_hex, a2b_hex
from random import randint
-from virtualsmartcard.utils import inttostring, stringtoint, hexdump
-import string
-import re
+from virtualsmartcard.utils import inttostring, hexdump
+import string, re
try:
# Use PyCrypto (if available)
@@ -166,7 +165,7 @@ def hash(hashmethod, data):
from Crypto.Hash import SHA, MD5#, RIPEMD
hash_class = locals().get(hashmethod.upper(), None)
if hash_class == None:
- print "Unknown Hash method %s" % hashmethod
+ logging.error("Unknown Hash method %s" % hashmethod)
raise ValueError
hash = hash_class.new()
hash.update(data)
@@ -231,7 +230,7 @@ def read_protected_string(string, password, cipherspec=None):
#Verify HMAC
checksum = crypto_checksum("HMAC", key, crypted)
if checksum != hmac:
- print "Found HMAC %s expected %s" % (str(hmac), str(checksum))
+ logging.error("Found HMAC %s expected %s" % (str(hmac), str(checksum)))
raise ValueError, "Failed to authenticate data. Wrong password?"
#Decrypt data
diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/SmartcardFilesystem.py b/virtualsmartcard/src/vpicc/virtualsmartcard/SmartcardFilesystem.py
index 0270a7c..d9b0567 100644
--- a/virtualsmartcard/src/vpicc/virtualsmartcard/SmartcardFilesystem.py
+++ b/virtualsmartcard/src/vpicc/virtualsmartcard/SmartcardFilesystem.py
@@ -21,6 +21,7 @@
@todo zu lange daten abschneiden und trotzdem tlv laenge beibehalten
"""
from pickle import dumps, loads
+import logging
from virtualsmartcard.ConstantDefinitions import *
from virtualsmartcard.TLVutils import *
from virtualsmartcard.SWutils import *
@@ -481,9 +482,9 @@ class DF(File): # {{{
return file
# not found
if isinstance(value, int):
- print "file not found %s=%x" % (attribute, value)
+ logging.debug("file not found %s=%x" % (attribute, value))
elif isinstance(value, str):
- print "file not found %s=%r" % (attribute, value)
+ logging.debug("file not found %s=%r" % (attribute, value))
raise SwError(SW["ERR_FILENOTFOUND"])
def remove(self, file):
@@ -674,7 +675,7 @@ class MF(DF): # {{{
selected = self.select('dfname', data, p2 &
REF["REFERENCE_CONTROL"], index_current)
else:
- print "unknown selection method: p1 =", p1
+ logging.debug("unknown selection method: p1 =%s" % p1)
selected = None
if selected == None:
@@ -1219,7 +1220,7 @@ class MF(DF): # {{{
if shortfid != 0:
args["shortfid"] = shortfid
def unknown(tag, value):
- print "unknown tag 0x%x with %r" % tag, value
+ logging.debug("unknown tag 0x%x with %r" % (tag, value))
tag2cmd = {
# TODO support other tags
TAG["FILEDISCRIPTORBYTE"] : 'fdb2args(value, args)',
@@ -1250,7 +1251,7 @@ class MF(DF): # {{{
if (args["filedescriptor"] & FDB["DF"]) == FDB["DF"]:
# FIXME: data for DF
if "data" in args:
- print 'what to do with DF-data %r?' % args["data"]
+ logging.debug('what to do with DF-data %r?' % args["data"])
del args["data"]
file = DF(**args)
elif ((args["filedescriptor"] & 7) in
diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/SmartcardSAM.py b/virtualsmartcard/src/vpicc/virtualsmartcard/SmartcardSAM.py
index 1c29273..6600750 100644
--- a/virtualsmartcard/src/vpicc/virtualsmartcard/SmartcardSAM.py
+++ b/virtualsmartcard/src/vpicc/virtualsmartcard/SmartcardSAM.py
@@ -17,7 +17,7 @@
# virtualsmartcard. If not, see .
#
-import struct, hashlib
+import struct, hashlib, logging
from pickle import dumps, loads
from os import urandom
@@ -122,7 +122,7 @@ class SAM(object):
equals zero, block the card until reset with correct PUK
"""
- print "Received PIN: %s" % PIN.strip()
+ logging.debug("Received PIN: %s" % PIN.strip())
PIN = PIN.replace("\0","") #Strip NULL charakters
if p1 != 0x00:
@@ -145,7 +145,6 @@ class SAM(object):
data = data.replace("\0","") #Strip NULL charakters
self.PIN = data
- print "New PIN = %s" % self.PIN
return SW["NORMAL"], ""
def internal_authenticate(self, p1, p2, data):
@@ -171,7 +170,7 @@ class SAM(object):
def external_authenticate(self, p1, p2, data):
"""
- Authenticate the terminal to the card. Check wether Terminal correctly
+ Authenticate the terminal to the card. Check whether Terminal correctly
encrypted the given challenge or not
"""
if self.last_challenge is None:
@@ -190,10 +189,6 @@ class SAM(object):
self.last_challenge = None
return SW["NORMAL"], ""
else:
- plain = vsCrypto.decrypt(cipher, key, data)
- print plain
- print "Reference: " + hexdump(reference)
- print "Data: " + hexdump(data)
raise SwError(SW["WARN_NOINFO63"])
#TODO: Counter for external authenticate?
@@ -201,7 +196,7 @@ class SAM(object):
"""
Takes an encrypted challenge in the form
'Terminal Challenge | Card Challenge | Card number'
- and checks it for validity. If the challenge is succesful
+ and checks it for validity. If the challenge is successful
the card encrypts 'Card Challenge | Terminal challenge' and
returns this value
"""
@@ -242,7 +237,7 @@ class SAM(object):
length = 8 #Length of the challenge in Byte
self.last_challenge = urandom(length)
- print "Generated challenge: %s" % str(self.last_challenge)
+ logging.debug("Generated challenge: %s" % str(self.last_challenge))
self.last_challenge = inttostring(self.last_challenge, length)
return SW["NORMAL"], self.last_challenge
@@ -282,7 +277,7 @@ class SAM(object):
df = self.mf.currentDF()
fid = df.select("fid", stringtoint(qualifier))
key = fid.readbinary(keylength)
-
+
if key != None:
return key
else:
@@ -1056,8 +1051,8 @@ class CryptoflexSM(Secure_Messaging):
e_in = struct.unpack("