1- from __future__ import division , absolute_import , print_function , unicode_literals
1+ import logging
22from .transmission import TransmissionProtocol
33from .protocol .structures import TLV
44from .protocol .data import Tag
1010 GetProcessingOptions ,
1111 VerifyCommand ,
1212)
13- from .exc import InvalidPINException , MissingAppException , EMVProtocolError
13+ from .exc import InvalidPINException , MissingAppException
1414from .util import decode_int
15- from .cap import get_arqc_req , get_cap_value
15+ from .cap import get_arqc_req , get_cap_value , VISA_STATIC_IPB
16+
17+ log = logging .getLogger (__name__ )
1618
1719
1820class Card (object ):
@@ -174,18 +176,6 @@ def generate_cap_value(self, pin, challenge=None, value=None):
174176 # of the data passed to the Get Application Cryptogram function.
175177 app_data = self .get_application_data (opts ["AFL" ])
176178
177- # In some cases the IPB may not be present. EMVCAP uses the IPB:
178- # 0000FFFFFF0000000000000000000020B938
179- # for VISA cards which don't provide their own, but relies on a hard-coded
180- # list of app names to work out which cards are VISA.
181- #
182- # It appears that Belgian cards use their own silliness.
183- # https://github.com/zoobab/EMVCAP/blob/master/EMV-CAP#L512
184- if Tag .IPB not in app_data :
185- raise EMVProtocolError (
186- "Issuer Proprietary Bitmap not found in application file"
187- )
188-
189179 self .verify_pin (pin )
190180
191181 resp = self .tp .exchange (
@@ -199,4 +189,17 @@ def generate_cap_value(self, pin, challenge=None, value=None):
199189 if Tag .IAF in app_data and app_data [Tag .IAF ][0 ] & 0x40 :
200190 psn = app_data [Tag .PAN_SN ]
201191
202- return get_cap_value (resp , app_data [Tag .IPB ], psn )
192+ # Fetch the Issuer Proprietary Bitmap. In most UK cards this is provided in the application data file.
193+ #
194+ # In some cases the IPB may not be present. This static IPB is from the EMVCAP code.
195+ #
196+ # It appears that Belgian cards use their own silliness.
197+ # https://github.com/zoobab/EMVCAP/blob/master/EMV-CAP#L512
198+ if Tag .IPB in app_data :
199+ ipb = app_data [Tag .IPB ]
200+ else :
201+ log .warn ("Issuer Proprietary Bitmap not found on card - using static VISA IPB. "
202+ "The resulting code may not work!" )
203+ ipb = VISA_STATIC_IPB
204+
205+ return get_cap_value (resp , ipb , psn )
0 commit comments