gpt4 book ai didi

Javacard 如何在 CardImpl.class 中的 checkState() 中移除并重新插入卡而不引发异常

转载 作者:太空宇宙 更新时间:2023-11-04 10:29:51 28 4
gpt4 key购买 nike

我在程序中找不到此问题的解决方案:我使用 JMRTD 库创建并个性化 JCOP 卡,但是在完成后,向服务发送关闭命令,然后再次插入卡,任何尝试执行任何操作都会返回卡已断开连接的信息。我是否缺少重置标志的方法?

关于我的代码的注释:ControlledDialog 顾名思义是一个以编程方式控制的对话框,因此我可以在代码的特定部分打开和关闭它。

感谢您的帮助!

我的 CardConnection 类:

package util;

import UI.MainPanel;
import UI.VerifyPanel;
import java.security.Security;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.smartcardio.CardException;
import javax.smartcardio.CardNotPresentException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.TerminalFactory;
import net.sf.scuba.smartcards.CardServiceException;
import net.sf.scuba.smartcards.TerminalCardService;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jmrtd.PassportService;

public class CardConnection {

static CardTerminal reader;
static PassportService service;

public static PassportService connectPassportService() throws CardException, CardServiceException {

//Encontra-se a factory
TerminalFactory terminal = TerminalFactory.getDefault();

//listam-se os terminais
List<CardTerminal> readers = terminal.terminals().list();

if (readers.isEmpty()) {
System.out.println("No Readers Found");
System.exit(-1);
}

//escolhe-se o primeiro
reader = readers.get(0);

if (GlobalFlags.DEBUG) {
System.err.println("Reader: " + reader);

System.err.println("Por favor insira um cartão");
}

for (int i = 0; i < 10 && !reader.isCardPresent(); i++) {
ControlledDialog.showMessageDialog("Por favor insira um cartão " + i, "Início");
reader.waitForCardPresent(1000);
System.err.println("Cartão " + (reader.isCardPresent() ? "" : "não ") + "conectado " + i);
}
try {
if (reader.isCardPresent()) {

service = new PassportService(new TerminalCardService(reader));
service.open();
service.sendSelectApplet(false);
BouncyCastleProvider provider = new BouncyCastleProvider();
Security.addProvider(provider);

} else {
throw new CardNotPresentException("Cartão não encontrado");
}
} finally {
ControlledDialog.closeMessageDialog();
}
return service;
}

public static void closeConnection() {

if (service == null) {
return;
}
service.close();

try {

if (reader.isCardPresent()) {
if (GlobalFlags.DEBUG) {
System.err.println("Por favor retire o cartão");
}
ControlledDialog.showMessageDialog("Por favor retire o cartão", "Fim");
}

while (reader.isCardPresent()) {
System.out.println("Remova o cartão atual");
reader.waitForCardAbsent(100000);
}

ControlledDialog.closeMessageDialog();

} catch (CardException ex) {
Logger.getLogger(VerifyPanel.class.getName()).log(Level.SEVERE, null, ex);
}

reader = null;
service = null;

}

}

最佳答案

我真的不知道如何删除问题,因为这里没有足够的信息来说明发生的情况。通过打印调用每个函数的对象的哈希码进行仔细调试后,我发现该问题的原因是我没有更新调用这些函数的对象的“服务”字段,因此,使用带有断开连接的卡的服务而不是新创建的服务。感谢您的理解!

关于Javacard 如何在 CardImpl.class 中的 checkState() 中移除并重新插入卡而不引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50138782/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com