use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class DIDAuthenticateStep method perform.
@Override
public DIDAuthenticateResponse perform(DIDAuthenticate request, Map<String, Object> internalData) {
DIDAuthenticateResponse response = WSHelper.makeResponse(DIDAuthenticateResponse.class, WSHelper.makeResultOK());
char[] rawPIN = null;
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
String didName = SALUtils.getDIDName(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(internalData, connectionHandle);
PINCompareDIDAuthenticateInputType pinCompareInput = new PINCompareDIDAuthenticateInputType(request.getAuthenticationProtocolData());
PINCompareDIDAuthenticateOutputType pinCompareOutput = pinCompareInput.getOutputType();
byte[] cardApplication;
if (request.getDIDScope() != null && request.getDIDScope().equals(DIDScopeType.GLOBAL)) {
cardApplication = cardStateEntry.getInfo().getApplicationIdByDidName(request.getDIDName(), request.getDIDScope());
} else {
cardApplication = connectionHandle.getCardApplication();
}
Assert.securityConditionDID(cardStateEntry, cardApplication, didName, DifferentialIdentityServiceActionName.DID_AUTHENTICATE);
DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, cardApplication);
PINCompareMarkerType pinCompareMarker = new PINCompareMarkerType(didStructure.getDIDMarker());
byte keyRef = pinCompareMarker.getPINRef().getKeyRef()[0];
byte[] slotHandle = connectionHandle.getSlotHandle();
PasswordAttributesType attributes = pinCompareMarker.getPasswordAttributes();
rawPIN = pinCompareInput.getPIN();
// delete pin from memory of the structure
pinCompareInput.setPIN(null);
byte[] template = new byte[] { 0x00, 0x20, 0x00, keyRef };
byte[] responseCode;
// with [ISO7816-4] (Section 7.5.6).
if (rawPIN == null || rawPIN.length == 0) {
VerifyUser verify = new VerifyUser();
verify.setSlotHandle(slotHandle);
InputUnitType inputUnit = new InputUnitType();
verify.setInputUnit(inputUnit);
PinInputType pinInput = new PinInputType();
inputUnit.setPinInput(pinInput);
pinInput.setIndex(BigInteger.ZERO);
pinInput.setPasswordAttributes(attributes);
verify.setTemplate(template);
VerifyUserResponse verifyR = (VerifyUserResponse) dispatcher.safeDeliver(verify);
WSHelper.checkResult(verifyR);
responseCode = verifyR.getResponse();
} else {
Transmit verifyTransmit = PINUtils.buildVerifyTransmit(rawPIN, attributes, template, slotHandle);
try {
TransmitResponse transResp = (TransmitResponse) dispatcher.safeDeliver(verifyTransmit);
WSHelper.checkResult(transResp);
responseCode = transResp.getOutputAPDU().get(0);
} finally {
// blank PIN APDU
for (InputAPDUInfoType apdu : verifyTransmit.getInputAPDUInfo()) {
byte[] rawApdu = apdu.getInputAPDU();
if (rawApdu != null) {
java.util.Arrays.fill(rawApdu, (byte) 0);
}
}
}
}
CardResponseAPDU verifyResponseAPDU = new CardResponseAPDU(responseCode);
if (verifyResponseAPDU.isWarningProcessed()) {
pinCompareOutput.setRetryCounter(new BigInteger(Integer.toString((verifyResponseAPDU.getSW2() & 0x0F))));
}
cardStateEntry.addAuthenticated(didName, cardApplication);
response.setAuthenticationProtocolData(pinCompareOutput.getAuthDataType());
} catch (ECardException e) {
LOG.error(e.getMessage(), e);
response.setResult(e.getResult());
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
LOG.error(e.getMessage(), e);
response.setResult(WSHelper.makeResult(e));
} finally {
if (rawPIN != null) {
Arrays.fill(rawPIN, ' ');
}
}
return response;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class PINCompareProtocolTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
env = new ClientEnv();
Dispatcher d = new MessageDispatcher(env);
env.setDispatcher(d);
IFD ifd = new IFD();
ifd.setGUI(uc);
env.setIFD(ifd);
states = new CardStateMap();
EstablishContextResponse ecr = env.getIFD().establishContext(new EstablishContext());
final CardRecognitionImpl cr = new CardRecognitionImpl(env);
ListIFDs listIFDs = new ListIFDs();
CIFProvider cp = new CIFProvider() {
@Override
public CardInfoType getCardInfo(ConnectionHandleType type, String cardType) {
return cr.getCardInfo(cardType);
}
@Override
public boolean needsRecognition(byte[] atr) {
return true;
}
@Override
public CardInfoType getCardInfo(String cardType) throws RuntimeException {
return cr.getCardInfo(cardType);
}
@Override
public InputStream getCardImage(String cardType) {
return cr.getCardImage(cardType);
}
};
env.setCIFProvider(cp);
listIFDs.setContextHandle(ecr.getContextHandle());
ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
RecognitionInfo recognitionInfo = cr.recognizeCard(ecr.getContextHandle(), listIFDsResponse.getIFDName().get(0), BigInteger.ZERO);
SALStateCallback salCallback = new SALStateCallback(env, states);
Connect c = new Connect();
c.setContextHandle(ecr.getContextHandle());
c.setIFDName(listIFDsResponse.getIFDName().get(0));
c.setSlot(BigInteger.ZERO);
ConnectResponse connectResponse = env.getIFD().connect(c);
ConnectionHandleType connectionHandleType = new ConnectionHandleType();
connectionHandleType.setContextHandle(ecr.getContextHandle());
connectionHandleType.setRecognitionInfo(recognitionInfo);
connectionHandleType.setIFDName(listIFDsResponse.getIFDName().get(0));
connectionHandleType.setSlotIndex(BigInteger.ZERO);
connectionHandleType.setSlotHandle(connectResponse.getSlotHandle());
salCallback.signalEvent(EventType.CARD_RECOGNIZED, new IfdEventObject(connectionHandleType));
instance = new TinySAL(env, states);
// init AddonManager
AddonManager manager = new AddonManager(env, uc, states, null);
instance.setAddonManager(manager);
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class CardSelectionStep method update.
/**
* Update the step with a new list of connection handles.
*
* @param availableCards List of available cards represented by connection handles.
*/
public void update(List<ConnectionHandleType> availableCards) {
this.avCardWithName.clear();
for (ConnectionHandleType handle : availableCards) {
avCardWithName.put(rec.getTranslatedCardName(handle.getRecognitionInfo().getCardType()), handle);
}
CardMonitorTask task = (CardMonitorTask) getBackgroundTask();
if (task != null) {
ConnectionHandleType handle = task.getResult();
if (handle.getRecognitionInfo() != null && handle.getRecognitionInfo().getCardType() != null) {
avCardWithName.put(rec.getTranslatedCardName(handle.getRecognitionInfo().getCardType()), handle);
}
}
getInputInfoUnits().clear();
addElements();
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class CardRemovedFilter method matches.
@Override
public boolean matches(EventType t, Object o) {
LOG.debug("Received event.");
if (t.equals(EventType.CARD_REMOVED)) {
LOG.debug("Received CARD_REMOVED event.");
ConnectionHandleType conHandle = null;
if (o instanceof IfdEventObject) {
conHandle = ((IfdEventObject) o).getHandle();
} else if (o instanceof ConnectionHandleType) {
conHandle = (ConnectionHandleType) o;
}
if (conHandle != null && ifdName.equals(conHandle.getIFDName()) && slotIdx.equals(conHandle.getSlotIndex())) {
LOG.info("Card removed during processing of EAC GUI.");
return true;
} else {
LOG.debug("An unrelated card has been removed.");
return false;
}
}
return false;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class HandlerBuilder method buildRecognitionInfo.
/**
* Creates a {@code RecognitionInfo} if the relevant values are set in the instance.
*
* @return A {@code ConnectionHandleType} instance, or {@code null} if no values are available.
*/
@Nullable
public RecognitionInfo buildRecognitionInfo() {
if (cardType != null) {
RecognitionInfo rInfo = new RecognitionInfo();
rInfo.setCardType(cardType);
rInfo.setCardIdentifier(cardIdentifier);
return rInfo;
} else {
return null;
}
}
Aggregations