Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for G&D SmartCafe Expert 7 based cards issued from 07/21 #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jfreesteel/src/main/java/net/devbase/jfreesteel/EidCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public static EidCard fromCard(final Card card)
if(EidCardGemalto.isKnownAtr(atrBytes))
return new EidCardGemalto(card);

if(EidCardSmartCafeExpert7.isKnownAtr(atrBytes))
return new EidCardSmartCafeExpert7(card);

throw new IllegalArgumentException(
String.format("EidCard: Card is not recognized as Serbian eID. Card ATR: %s",
Utils.bytes2HexString(atrBytes)));
Expand Down Expand Up @@ -247,6 +250,7 @@ public Image readEidPhoto() throws CardException {
put(1575, Tag.FLOOR);
put(1578, Tag.APPARTMENT_NUMBER);
put(1580, Tag.ADDRESS_DATE); // = default 01010001
put(1581, Tag.PERMANENT_RESIDENCE);
// AddressLabel ?
}};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package net.devbase.jfreesteel;

import java.io.ByteArrayOutputStream;
import java.util.Arrays;

import javax.smartcardio.Card;
import javax.smartcardio.CardException;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;

/**
* Smart card wrapper for Gemalto MultiApp ID smart card
*
* EidCardSmartCafeExpert7 implements EidCard abstract interface for reading
* data from the Serbian eID cards based on G&D CardSmartCafeExpert7 JavaCard that
* are issued after Jul 2021.
*
* You should not initialize this class directly. Use EidCard.fromCard()
* factory method for "direct" access, or initialize a Reader class and
* assign the listener for the card insertion/removal events. The listener
* will receive EidCard object when the card is inserted into the terminal.
*
* @author krstom (krstom@gmail.com)
* @author Goran Rakic (grakic@devbase.net)
*/
@SuppressWarnings("restriction") // Various javax.smartcardio.*
public class EidCardSmartCafeExpert7 extends EidCard {

/** The list of known card ATRs, used to identify this smartcard. */

public static final byte[] CARD_ATR = {
(byte) 0x3B, (byte) 0xF9, (byte) 0x96, (byte) 0x00, (byte) 0x00, (byte) 0x80, (byte) 0x31,
(byte) 0xFE, (byte) 0x45, (byte) 0x53, (byte) 0x43, (byte) 0x45, (byte) 0x37, (byte) 0x20,
(byte) 0x47, (byte) 0x43, (byte) 0x4E, (byte) 0x33, (byte) 0x5E
};

/** Factory "selection" method */
protected static boolean isKnownAtr(byte[] atrBytes) {
return Arrays.equals(atrBytes, CARD_ATR);
}

static final byte[] LICNA_KARTA_AID = {
(byte) 0xF3, (byte) 0x81, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x53, (byte) 0x45,
(byte) 0x52, (byte) 0x49, (byte) 0x44, (byte) 0x01
};

protected EidCardSmartCafeExpert7(Card card) throws CardException {
super(card);

// Select aid
ResponseAPDU response = channel.transmit(
new CommandAPDU(0x00, 0xA4, 0x04, 0x00, LICNA_KARTA_AID));
if (response.getSW() != 0x9000) {
throw new CardException(
String.format("Select AID failed: status=%s",
Utils.int2HexString(response.getSW())));
}
}

protected byte[] readElementaryFile(final byte[] name, boolean strip_tag) throws CardException {

ByteArrayOutputStream out = new ByteArrayOutputStream();

byte[] fileinfo = selectFile(name, 4);

// length hint from file info
int length = ((0xFF&fileinfo[2])<<8) + (0xFF&fileinfo[3]);
int offset = 0;
boolean known_real_length = false;

while (length > 0) {
byte[] data = readBinary(offset, length);

if (!known_real_length) {
// get length from outher tag, skip first 4 bytes (outher tag + length)
// if strip_tag is true, skip 4 more bytes (inner tag + length) and return content
length = ((0xFF&data[3])<<8) + (0xFF&data[2]);
int skip = strip_tag ? 8 : 4;
out.write(data, skip, data.length-skip);
known_real_length = true;
}
else out.write(data, 0, data.length);

offset += data.length;
length -= data.length;
}

return out.toByteArray();
}
}
8 changes: 6 additions & 2 deletions jfreesteel/src/main/java/net/devbase/jfreesteel/EidInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public enum Tag {
/** The appartment number of the person residence */
APPARTMENT_NUMBER(409, "appartment_number", "Appartment number"),
/** Address update date */
ADDRESS_DATE(410, "address_date", "Address date");
ADDRESS_DATE(410, "address_date", "Address date"),
PERMANENT_RESIDENCE(411, "prebivalište", "Permanent residence");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permanent_residence?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ovo ima i na mojoj LK. Namenjeno je onima koji žive u inostranstvu.


private final int code;
private final String key;
Expand Down Expand Up @@ -368,8 +369,11 @@ public String getAddressDate() {
if (value == null || value.equals("01010001"))
return null;
return formatDate(get(Tag.APPARTMENT_NUMBER));
}
public String getPeremanentResidence() {
return get(Tag.PERMANENT_RESIDENCE);
}

@Override
public String toString() {
StringBuilder out = new StringBuilder();
Expand Down