-
Notifications
You must be signed in to change notification settings - Fork 24
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
krstom
wants to merge
2
commits into
grakic:master
Choose a base branch
from
krstom:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
jfreesteel/src/main/java/net/devbase/jfreesteel/EidCardSmartCafeExpert7.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
permanent_residence
?There was a problem hiding this comment.
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.