Skip to content

Commit

Permalink
Raise a nicer error if the IPB isn't present
Browse files Browse the repository at this point in the history
  • Loading branch information
russss committed Nov 19, 2021
1 parent 1a046d0 commit 5f74a1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 11 additions & 1 deletion emv/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions emv/exc.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5f74a1b

Please sign in to comment.