Menu

Problem reading java card with Arduino

2014-06-12
2018-06-15
  • José Rodrigues

    José Rodrigues - 2014-06-12

    I'm trying to read a java card with Arduino Mega 2560. This card support the protocol T=0 or T=1.
    Is the Portuguese Citizen Card, I have some documents but are all in Portuguese,
    This: http://cc.di.ubi.pt/paginas/ECIW10-CC.pdf

    is a document of the card sniffing tests is in English, Which can help.

    • Java Card chip, multi-application;
    • Supports the latest version of the Java Card platform and the use of logical channels;
    • Has a capacity of EEPROM (or equivalent) Minimum of 64 KB memory;
    • Has management capabilities of dynamic memory, supporting garbage collection the JVM and memory protection;
    • Has management capabilities of storage space, including defragmentation and reuse of freed space;
    • Has capabilities true random number generation;
    • Supports multiple PIN. PINs are in accordance with ISO / IEC 7816 -4;
    • Supports locking mechanisms on error in entering PIN after N attempts and their release through introduction of the citizen and PUK administrative key card access, unlocking;
    • Supports new generation mechanisms PIN citizen, if forgotten this by introducing the PUK citizen, and PUK applicational generation PIN;
    • Has an internal cryptographic engine that supports:
    -Signature verification and RSA 1024 bits;
    -Qualified electronic signature according to CEN CWA 14169 (Secure Signature-creation devices "EAL 4 +");
    -DES and TDES (Triple Data Encription Standard);
    -MD5, SHA-1 and SHA-256, at least;
    -MAC (message authentication code);
    -PKCS # 1 (RSA Cryptography Standard) and PKCS # 15 (Cryptographic Token Information Standard Format);

    It's compatible with card reader EMV-CAP, for operation multichannel authentication based on one-time password;
    • Has a key protection of the initial customization;
    • Are prepared to resist known attacks such as "hardware attack", "Timing attack", "simple power analysis" and "differential power analysis" among others.

    My pin assignment is:

    '#define SC_C2_RST 8
    '#define SC_C1_VCC 9
    '#define SC_C7_IO 10
    '#define SC_C2_CLK 11
    '#define SC_SWITCH_CARD_PRESENT 7
    '#define SC_SWITCH_CARD_PRESENT_INVERT true

    I´m using 'Cryptware Smart Card Console' with a normal card reader, is a software that gives to send commands to the card, and reciving the respective answers. Goes a screenshot attached.

     

    Last edit: José Rodrigues 2014-06-12
    • angus71

      angus71 - 2014-06-29

      Hi José,

      The only thing, which might be a typo here is the

      define SC_C2_CLK 11

      as this define should be

      define SC_C3_CLK 11

      Hope this helps

      Angus71

       
  • José Rodrigues

    José Rodrigues - 2014-06-27

    I have exactly the same problem when I start the second time the ATR. How is attached!

     
  • angus71

    angus71 - 2014-06-29

    Hi José,

    As I understand your screenshots (Prev. attachment) you are using an "internal" reset command of your "SmartCard Contact Software" ("r" command) or are you removing and inserting the card?

    If you are using a "reset" command, it might be possible, that the SmartCard cycles through it' communication protocols ("Soft Reset"). This is defined in the standards to enable T0 or T1 protocol or any other supported communication protocol ..

    This might explain, why a command is working the first time and not after the second reset. You might try to create T1 command ans issue that, after the second reset ...

    Please let me know if this is the case, so that we can dig deeper into your problem ;-.)

    With kind regards

    Angus71

     
  • José Rodrigues

    José Rodrigues - 2014-06-30

    HI angus71,

    Yes, this problem only happens when using the reset command!
    If you remove the card and re-incerir this works well!
    I put this question because I do not know exactly what the library does. For example, the library will reboot twice to start reading?
    Because I saw the signal on the oscilloscope and the ATR is sent twice, once just as I insert the card, and another when the request is sent by the arduino!
    To do these readings, put the arduino asking the ATR with a 2-second pause.

    José Rodrigues

     
    • angus71

      angus71 - 2014-06-30

      Hi José,

      I tried to reproduce the described problem, but I was not able to see your problem ..

      I used the following code (Reduced from overhead)

        while (!sc.cardInserted())
        ;
      
        bytes_received = sc.activate(data, MAX_ATR_BYTES, CLK_1MHZ);
      
        delay(2000);
      
        uint16_t result = sc.sendAPDU(&command);
      
        sc.deactivate();
      
        while (sc.cardInserted())
        ;
      

      Is this what your code more or less looks like?

      With kind regards

      Angus71

       
  • José Rodrigues

    José Rodrigues - 2014-07-01

    HI angus71, my code is attached, and one image of osciloscope signal.

    I've been watching, and the problem of receiving the ATR twice, it's because I never was doing "sc.deactivate ();". I solved this problem, but am still unable to read the card. :(
    I get the same errors.

     

    Last edit: José Rodrigues 2014-07-01
    • angus71

      angus71 - 2014-07-01

      Hi José,

      So to sum it up ...

      You don't have the problem regading the "second" ATR anymore, but the commands given in "NO ERROR.png" are still not getting you the same result, as when you use the "SmartCard Contact Software"?

      Does this sum up your current situation?

      Is the apdu_t0_M5_ino.ino the current software you use (As it still contains a deactivated sc.deactivate() )?

      Can you share the serial output of the Arduino if you insert the Card?

      With kind regards

      Angus71

       
  • José Rodrigues

    José Rodrigues - 2014-07-02

    HI angus71, tanks for your help,

    Yes this is my problem.
    I'm currently using sc.deactivate(), just like the example "apdu_t0_communication".
    Attached is the output of the arduino and also other image of the oscilloscope.
    Made the measurement signal from the card reader, and the arduino. I concluded that the arduino is not sending the two bytes "DATE", only the header, as can be seen in "Arduino_t0_2".

    José Rodrigues

     
  • angus71

    angus71 - 2014-07-02

    Hi José,

    Based on the data provided it looks like the card itself is not reacting to the Arduino as does to the Smart Card Reader ...
    In Card_Reader_Signal you can see the Header(Reader) and the following "single" Byte send by the Card (Normally this is the INS value from the APDU command) as an indication that the card will now wait the "data".
    After all data is received by the card (Lc bytes), the card "calculates" result and indicates this to the card reader (First data strobe of the "?????"). The next data strobe looks like a "Get Response" command issued by the Card Reader and the following data ..

    The point I don't understand currently is, that if the "same" command is send by the Arduino, the card should react in the same way (Giving the one byte response, to aknowledge the received command etc), but instead the card send a SW1/SW2 combination right away ..

    Where you able to compare the Arduino_t0.jprg with the command send by the smart card reader in Card_Reader_Signal (Timing / Values)?

    Also I have some questions regarding your usage of the SCLib.

    What version are you using?

    Can you tried the same with the current "trunk" version?

    Thanks for providing the data ... We should be able to track this down with the available informations ... ;-.)

    With kind regards

    Angus71

     
  • José Rodrigues

    José Rodrigues - 2014-07-03

    HI angus71,
    I'm using the "arduinosclib-code-27-trunk" commit r27.

    I measurement of both signals at the same time like the image "Signals_Header".

    Did also with the signal and the clock with the arduino and the card reader.

    To do this I changed the clock to 4Mhz.

    Found that the sign on the same clock is different between Ardino and the card reader. This might be the problem.

    The Arduino uses 430 cycles to send the same date as the card reader, which uses only 32 cycles. I think the arduino is sending the data too slow.

    José Rodrigues

     
    • angus71

      angus71 - 2014-07-03

      Hi José,

      I will check the provided data and see if I can get closer to the Smart Card Reader behaviour ..

      With kind regards

      Angus71

       
  • José Rodrigues

    José Rodrigues - 2014-07-04

    Hi angus71,

    OK, thanks.

    José Rodrigues

     
  • angus71

    angus71 - 2014-09-15

    Hi José,

    Sorry it took me a little bit longer to look into your problem ... If you still are interested in getting your setup running, you might want to check the branch "ATRParameter" and add the following code to your source, right after you received the ATR from the card.

    // Change to ATR Parameter
    uint16_t b = 0;
    b = sc.setATRParameter(data, bytes_received);
    Serial.print("Changed ETU ... ");
    Serial.println(b);
    

    See also provided setATRParameter example.

    It looks like, that the problem you are facing with your card is based on the fact, that your card requests some communication parameters with the ATR (Mostly in the TA1 byte of the ATR) and enforces them right after the ATR is received by the Arduino.

    If you want to test, please use the 1MHz clock, otherwise some of the timings might be to small to be created by the SCLib.

    Please let me know if this helps, or if at least the timings created by the SCLib match the ones created by the Smart Card Reader you use.

    With kind regards

    Angus

     
  • Fatih GÜNGÖR

    Fatih GÜNGÖR - 2018-06-15

    hiii
    did you fix jose that

    i need helpppppp
    pleaaseeeeeeeeeeeeee

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.