python-emv icon indicating copy to clipboard operation
python-emv copied to clipboard

Unable to generate CAP codes for Barclays debit card

Open unlobito opened this issue 7 years ago • 4 comments

Hi there,

If I use the incorrect PIN, python-emv recognises this and bails.

$ emvtool -p 0000 cap
Invalid PIN

…but when I use the correct PIN, python-emv is unable to generate the CAP code.

$ emvtool -p 1111 cap
Traceback (most recent call last):
  File "/Users/htw/.pyenv/versions/3.6.4/bin/emvtool", line 11, in <module>
    sys.exit(run())
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/emv/command/client.py", line 46, in run
    cli(obj={})
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/emv/command/client.py", line 151, in cap
    click.echo(card.generate_cap_value(ctx.obj['pin'], challenge=challenge, value=amount))
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/emv/card.py", line 118, in generate_cap_value
    self.verify_pin(pin)
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/emv/card.py", line 89, in verify_pin
    res = self.tp.exchange(VerifyCommand(pin))
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/emv/transmission.py", line 51, in exchange
    res = RAPDU.unmarshal(data + [sw1, sw2])
  File "/Users/htw/.pyenv/versions/3.6.4/lib/python3.6/site-packages/emv/protocol/response.py", line 32, in unmarshal
    raise obj
emv.protocol.response.ErrorResponse: <ErrorResponse: "Command not allowed; conditions of use not satisfied">

EMV-CAP is able to successfully generate a code, so it seems the card is okay. I've created this as a separate issue since #6 appears to be related to different error messages.

unlobito avatar Jun 30 '18 13:06 unlobito

Can you show me the result of emvtool listapps please?

russss avatar Jul 11 '18 08:07 russss

Apologies for the delay, the requested output is as follows.

┌Applications──────────┬────────────────────────┐
│ Index │ Label        │ ADF                    │
├───────┼──────────────┼────────────────────────┤
│ 0     │ "Visa Debit" │ [A0 00 00 00 03 10 10] │
│ 1     │ "LINK ATM"   │ [A0 00 00 00 29 10 10] │
│ 2     │ "BARCLAYS"   │ [A0 00 00 00 03 80 02] │
└───────┴──────────────┴────────────────────────┘

unlobito avatar Jul 23 '18 21:07 unlobito

That's curious. My suspicion was that it was selecting the wrong app - at the moment it is hardcoded to select the last app on the card, but as far as I know "BARCLAYS" is the correct app.

python-emv is a bit of a mess, so it's very hard to work out what it's doing differently.

I'm not sure I'm going to be able to work this out without access to a problematic card, but can you let me know the date of issue of the card, and whether it's an unusual card in any way?

russss avatar Jul 23 '18 21:07 russss

Not an unusual card as far as I know (just a reissue due to name change). Issued early October 2017. I've also reproduced this issue with a card issued early September 2015 (although, compared to this one, it lacks contactless and only has the A0 00 00 00 03 10 10 application)

unlobito avatar Jul 23 '18 21:07 unlobito