我需要通过智能卡登录。 该卡是意大利医疗卡(TS)国家服务卡(CNS)。 我试图将通用名称与身份验证证书进行比较,但我不知道该怎么做。根据提供的说明,我发现:
证书格式为标准ISO / 9594-8(X.509);共同的 证书中的名称必须遵循结构 - > codicefiscale / idcarta.hash(ef_dati_personali)codicefiscale是 税码,idcarta是序列号(16个ASCII字符的 card)和ef_dati_personali是个人数据。对于 hash(ef_dati_personali)只能使用有用的字符(' 00' hex 最后必须排除在外。)
我可以使用底层代码单独获取所有这些数据,但我无法获得证书。
try {
// Display the list of terminals
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
// Use the first terminal
CardTerminal terminal = terminals.get(0);
// Connect wit hthe card
Card card = terminal.connect("*");
System.out.println("card: " + card);
CardChannel channel = card.getBasicChannel();
//GET ATR
ATR atr = card.getATR();
byte[] ATR = atr.getBytes();
System.out.println("ATR della carta: " + bytesToHex(ATR));
//GET SELECT_FILE_APDU
byte[] dati_personali = {(byte) 0x00, (byte) 0xA4, (byte) 0x08, (byte) 0x00, (byte) 0x04, (byte) 0x11, (byte) 0x00, (byte) 0x11, (byte) 0x02, (byte) 0x00};
byte[] c_carta = {(byte) 0x00, (byte) 0xA4, (byte) 0x08, (byte) 0x00, (byte) 0x04, (byte) 0x11, (byte) 0x00, (byte) 0x11, (byte) 0x01, (byte) 0x00};
byte[] id_carta = {(byte) 0x00, (byte) 0xA4, (byte) 0x08, (byte) 0x00, (byte) 0x04, (byte) 0x10, (byte) 0x00, (byte) 0x10, (byte) 0x03, (byte) 0x00};
byte[] inst_file = {(byte) 0x00, (byte) 0xA4, (byte) 0x08, (byte) 0x00, (byte) 0x04, (byte) 0x12, (byte) 0x00, (byte) 0x41, (byte) 0x42, (byte) 0x00};
byte[] servizi_installati = {(byte) 0x00, (byte) 0xA4, (byte) 0x08, (byte) 0x00, (byte) 0x04, (byte) 0x12, (byte) 0x00, (byte) 0x12, (byte) 0x03, (byte) 0x00};
byte[] gdo = {(byte) 0x00, (byte) 0xA4, (byte) 0x08, (byte) 0x00, (byte) 0x04, (byte) 0x3F, (byte) 0x00, (byte) 0x2F, (byte) 0x02, (byte) 0x00};
byte[] key_pub = {(byte) 0x00, (byte) 0xA4, (byte) 0x08, (byte) 0x00, (byte) 0x04, (byte) 0x3F, (byte) 0x00, (byte) 0x3F, (byte) 0x01, (byte) 0x00};
richiedi(channel, READ_BINARY_APDU, dati_personali, "<b>Dati personali:</b><br>");
richiedi(channel, READ_BINARY_APDU, c_carta, "<b>Carta:</b><br>");
richiedi(channel, READ_BINARY_APDU, id_carta, "<b>ID Carta:</b><br>");
richiedi(channel, READ_BINARY_APDU, inst_file, "<b>Inst File:</b><br>");
richiedi(channel, READ_BINARY_APDU, servizi_installati, "<b>Servizi installati:</b><br>");
richiedi(channel, READ_BINARY_APDU, gdo, "<b>GDO:</b><br>");
richiedi(channel, READ_BINARY_APDU, key_pub, "<b>KEY PUB:</b><br>");
// Disconnect the card
card.disconnect(false);
System.out.println("DISCONEESSO ");
} catch (Exception e) {
System.out.println("Ouch: " + e.toString());
}
//
public static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
sb.append(String.format("%02x", bytes[i]));
}
return sb.toString();
}
//
public void richiedi(CardChannel channel, byte[] read, byte[] select, String titolo) throws CardException {
out.println(titolo);
// Send Select Applet command
ResponseAPDU answer = channel.transmit(new CommandAPDU(select));
// Send test command
answer = channel.transmit(new CommandAPDU(read));
byte r[] = answer.getData();
String test = "";
for (int i = 0; i < r.length; i++) {
test += (char) r[i];
}
System.out.print(test);
out.println(test);
out.println("<br><br>");
}