From 5f74a1b41ba3fc589d4b161c1d4b8e9b761d5016 Mon Sep 17 00:00:00 2001 From: Russ Garrett Date: Fri, 19 Nov 2021 10:47:44 +0000 Subject: [PATCH] Raise a nicer error if the IPB isn't present --- emv/card.py | 12 +++++++++++- emv/exc.py | 8 ++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/emv/card.py b/emv/card.py index 7b9992b..7fcc9f1 100644 --- a/emv/card.py +++ b/emv/card.py @@ -10,7 +10,7 @@ GetProcessingOptions, VerifyCommand, ) -from .exc import InvalidPINException, MissingAppException +from .exc import InvalidPINException, MissingAppException, EMVProtocolError from .util import decode_int from .cap import get_arqc_req, get_cap_value @@ -174,6 +174,16 @@ def generate_cap_value(self, pin, challenge=None, value=None): # of the data passed to the Get Application Cryptogram function. app_data = self.get_application_data(opts["AFL"]) + # In some cases the IPB may not be present. EMVCAP uses the IPB: + # 0000FFFFFF0000000000000000000020B938 + # for VISA cards which don't provide their own, but relies on a hard-coded + # list of app names to work out which cards are VISA. + # + # It appears that Belgian cards use their own silliness. + # https://github.com/zoobab/EMVCAP/blob/master/EMV-CAP#L512 + if Tag.IPB not in app_data: + raise EMVProtocolError("Issuer Proprietary Bitmap not found in application file") + self.verify_pin(pin) resp = self.tp.exchange( diff --git a/emv/exc.py b/emv/exc.py index d8e8ad8..ad9d15e 100644 --- a/emv/exc.py +++ b/emv/exc.py @@ -1,10 +1,14 @@ +class EMVProtocolError(Exception): + pass + + class InvalidPINException(Exception): pass -class MissingAppException(Exception): +class MissingAppException(EMVProtocolError): pass -class CAPError(Exception): +class CAPError(EMVProtocolError): pass