Project

General

Profile

Altersverifikation

Added by Christian Kirsch over 3 years ago

Sehr geehrte Damen und Herren,

vielen Dank für Ihre Arbeiten an der Open eCard API.

Wir möchten in einem Projekt einen Getränkefach mit alkoholischen Getränken an einem Wanderweg aufstellen. Dazu möchten wir eine Altersverifikation zum Öffnen des Faches über den Personalausweis realisieren.
Mein Gedanke ist dies mit einem Rasperry Pi Zero und einem Reinersect USB Lesegerät umzusetzen. Es ist keine Internetverbindung vorhanden.

Ich habe es nun geschafft die jars mit Maven zu compilieren, in mein Eclipse Projekt einzufügen und auf API Elemente zuzugreifen. Ich habe ein org.openecard.ifd.scio.IFD Objekt instanziert und konnte mein kleines Programm ohne Exception ausführen,

Nun versuche ich, eine Kartenerkennung mit Fragmenten des Testprogramms ExecuteRecognition von Thomas Wich zu kompilieren. Anbei der Code:

@package org.avs;

import java.math.BigInteger;

import org.openecard.common.ClientEnv;
import org.openecard.common.interfaces.Environment;
import org.openecard.ifd.scio.IFD;
import org.openecard.recognition.CardRecognitionImpl;

import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo;
import iso.std.iso_iec._24727.tech.schema.EstablishContext;
import iso.std.iso_iec._24727.tech.schema.EstablishContextResponse;
import iso.std.iso_iec._24727.tech.schema.GetStatus;
import iso.std.iso_iec._24727.tech.schema.GetStatusResponse;
import iso.std.iso_iec._24727.tech.schema.IFDStatusType;

public class Loop {

public static void main(String[] args) {
Loop loop = new Loop();
loop.recognize();
}
private void recognize () {
Environment env = new ClientEnv();
IFD ifd = new IFD();
env.setIFD(ifd);
byte[] ctx;
// establish context
EstablishContext eCtx = new EstablishContext();
EstablishContextResponse eCtxR = ifd.establishContext(eCtx);
ctx = eCtxR.getContextHandle();
// get status to see if we can execute the recognition
GetStatus status = new GetStatus();
status.setContextHandle(ctx);
GetStatusResponse statusR = ifd.getStatus(status);
if (statusR.getIFDStatus().size() > 0 && statusR.getIFDStatus().get(0).getSlotStatus().get(0).isCardAvailable()) {
CardRecognitionImpl recog = new CardRecognitionImpl(env);
IFDStatusType stat = statusR.getIFDStatus().get(0);
RecognitionInfo info = recog.recognizeCard(ctx, stat.getIFDName(), BigInteger.ZERO);
if (info == null) {
System.out.println("Card not recognized.");
} else {
System.out.println(info.getCardType());
}
}

}@

Er zeigt mir bei EstablishContextResponse eCtxR = ifd.establishContext(eCtx); folgenden Fehler
The method establishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) in the type IFD is not applicable for the arguments (iso.std.iso_iec._24727.tech.schema.EstablishContext)

Dies macht für mich keinen Sinn, da eCTX genau das Objekt EstablishContent ist, welches die Methode ifd.establishContext(..) haben möchte. Kann mir hier einer weiterhelfen?

Ich würde mich über eine Antwort freuen!

Christian

Nachtrag:

Es war eine Mehrdeutigkeit, da ich auch die Richclient.jar im Build-Path hatte. Als ich diese entfernt habe, hat es funktioniert.


Replies (1)

RE: Altersverifikation - Added by Christian Kirsch over 3 years ago

Mit Hilfe des Richclients habe ich nun eine Klasse entworfen, welche u.a. den CardType erkennen soll. Anbei der Code:

@
package org.avs;

import org.openecard.addon.AddonManager;
import org.openecard.common.AppVersion;
import org.openecard.common.ClientEnv;
import org.openecard.common.ECardConstants;
import org.openecard.common.WSHelper;
import org.openecard.common.event.EventDispatcherImpl;
import org.openecard.common.event.EventObject;
import org.openecard.common.event.EventType;
import org.openecard.common.interfaces.EventCallback;
import org.openecard.common.sal.state.CardStateMap;
import org.openecard.common.util.ByteUtils;
import org.openecard.ifd.protocol.pace.PACEProtocolFactory;
import org.openecard.ifd.scio.IFD;
import org.openecard.recognition.CardRecognitionImpl;
import org.openecard.sal.SelectorSAL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType;
import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo;
import iso.std.iso_iec._24727.tech.schema.EstablishContext;
import iso.std.iso_iec._24727.tech.schema.EstablishContextResponse;

public class Loop implements EventCallback {

private static final Logger LOG;
private ClientEnv env = new ClientEnv();
// Interface Device Layer (IFD)
private IFD ifd;
// Service Access Layer (SAL)
private SelectorSAL sal;
// EventDispatcherImpl
private EventDispatcherImpl eventDispatcher;
// Card recognition
private CardRecognitionImpl recognition;
// card states
private CardStateMap cardStates;
// ContextHandle determines a specific IFD layer context
private byte[] contextHandle;
static {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
LOG = LoggerFactory.getLogger(Loop.class.getName());
}
/**
 * Constructor to initialize.
 * @throws Exception
*/
public Loop() throws Exception {
// Set up client environment
env = new ClientEnv();
// Set up the Dispatcher
//MessageDispatcher dispatcher = new MessageDispatcher(env);
//env.setDispatcher(dispatcher);
// Set up EventDispatcherImpl
eventDispatcher = new EventDispatcherImpl();
// start event dispatcher
eventDispatcher.start();
env.setEventDispatcher(eventDispatcher);
// Set up Management
//TinyManagement management = new TinyManagement(env);
//env.setManagement(management);
// Set up CardRecognitionImpl
recognition = new CardRecognitionImpl(env);
//recognition.setGUI(gui);
env.setRecognition(recognition);
// Set up StateCallbacks
//cardStates = new CardStateMap();
//SALStateCallback salCallback = new SALStateCallback(env, cardStates);
//eventDispatcher.add(salCallback);
// Set up the IFD
ifd = new IFD();
ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
//ifd.setGUI(gui);
ifd.setEnvironment(env);
env.setIFD(ifd);
// Set up SAL
//TinySAL mainSal = new TinySAL(env, cardStates);
//mainSal.setGUI(gui);
//sal = new SelectorSAL(mainSal, env);
//env.setSAL(sal);
//env.setCIFProvider(sal);
// Initialize the EventManager
eventDispatcher.add(this,
EventType.TERMINAL_ADDED, EventType.TERMINAL_REMOVED,
EventType.CARD_INSERTED, EventType.CARD_RECOGNIZED, EventType.CARD_REMOVED);
// initialize SAL
//WSHelper.checkResult(sal.initialize(new Initialize()));
// Perform an EstablishContext to get a ContextHandle
try {
EstablishContext establishContext = new EstablishContext();
EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
WSHelper.checkResult(establishContextResponse);
contextHandle = establishContextResponse.getContextHandle();
} catch (WSHelper.WSException ex) {
LOG.debug("Failed to establish context :" + ex.getMessage());
//String message = LANG.translationForKey("client.startup.failed.nocontext");
//throw ex;
}
}
public static void main(String[] args) {    
LOG.info("Starting {} {} ...", AppVersion.getName(), AppVersion.getVersion());
LOG.debug("Running on {} {} {}.", System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"));
try {
Loop loop = new Loop();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void signalEvent(EventType eventType, EventObject eventData) {
LOG.debug("Event: {}", eventType);
ConnectionHandleType ch = eventData.getHandle();
if (ch == null) {
LOG.error("No handle provided in event {}.", eventType);
return;
}
String ifdName = ch.getIFDName();
byte[] ctx = ch.getContextHandle();
LOG.debug("ConnectionHandle: ifd={}, slot={}, ctx={}", ifdName, ByteUtils.toHexString(ch.getSlotHandle()),
ByteUtils.toHexString(ctx));
RecognitionInfo info = ch.getRecognitionInfo();
if (info != null) {
LOG.debug("RecognitionInfo: {}, {}", info.getCardType(), ByteUtils.toHexString(info.getCardIdentifier()));
} else {
LOG.debug("RecognitionInfo: null");
}
}

}@

Die Methode signalEvent wird Korrekt von EventHandler aufgerufen, wenn ich das USB Lesegerät einstecke und entferne. Sobald ich jedoch eine Smartcard einlege, zeigt der Logger folgende Meldung:
[SCIO Watcher 0] INFO org.openecard.ifd.scio.wrapper.SingleThreadChannel - Card connected with protocol T=1.

Danach zeigt das Programm keine Funktion mehr. Was mache ich falsch?

Anbei der Log zur Info:

[main] INFO org.avs.Loop - Starting Open eCard App 1.4.6-SNAPSHOT ...
[main] DEBUG org.avs.Loop - Running on Linux 5.8.0-41-generic amd64.
[main] WARN org.openecard.common.I18n - Failed to load resource ifd for lang C.
[main] WARN org.openecard.common.I18n - Failed to load resource ifd for lang de.
[main] WARN org.openecard.common.I18n - Failed to load resource ifd for lang de_DE.
[main] WARN org.openecard.common.I18n - Failed to load resource sal for lang C.
[main] WARN org.openecard.common.I18n - Failed to load resource sal for lang de.
[main] WARN org.openecard.common.I18n - Failed to load resource sal for lang de_DE.
[main] WARN org.openecard.common.I18n - Failed to load resource recognition for lang C.
[main] WARN org.openecard.common.I18n - Failed to load resource recognition for lang de.
[main] WARN org.openecard.common.I18n - Failed to load resource recognition for lang de_DE.
[Init-CardInfo-Repo] INFO org.openecard.recognition.CardRecognitionImpl - Initializing CIF Repo.
[Init-RecognitionTree-Repo] INFO org.openecard.recognition.CardRecognitionImpl - Initializing RecognitionTree Repo.
[main] INFO org.openecard.scio.PCSCFactory - Trying to initialize PCSC subsystem.
[main] INFO org.openecard.scio.PCSCFactory - Successfully initialized PCSC subsystem.
[main] DEBUG org.openecard.ifd.event.IfdEventRunner - Requesting terminal names.
[main] DEBUG org.openecard.ifd.event.IfdEventRunner - Requesting status for all terminals found.
[IFD Watcher 0] DEBUG org.openecard.ifd.event.IfdEventRunner - Found a terminal added event (REINER SCT cyberJack RFID basis 00 00).
[IFD Watcher 0] DEBUG org.openecard.common.event.EventDispatcherImpl - Sending event notification TERMINAL_ADDED to EventCallback org.avs.Loop@7c75222b.
[Dispatcher Event 0] DEBUG org.avs.Loop - Event: TERMINAL_ADDED
[Dispatcher Event 0] DEBUG org.avs.Loop - ConnectionHandle: ifd=REINER SCT cyberJack RFID basis 00 00, slot=null, ctx=9D5B5293E127248DF48EBB1312E8AAF9
[Dispatcher Event 0] DEBUG org.avs.Loop - RecognitionInfo: null
[IFD Watcher 0] DEBUG org.openecard.scio.PCSCTerminals - Detecting initial terminal status.
[IFD Watcher 0] DEBUG org.openecard.scio.PCSCTerminals - Terminal='REINER SCT cyberJack RFID basis 00 00' cardPresent=false
[SCIO Watcher 0] INFO org.openecard.ifd.scio.wrapper.SingleThreadChannel - Card connected with protocol T=1.

Vielen Dank für die Antworten

Christian

    (1-1/1)