use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class ChangePinInSALAction method execute.
@Override
public void execute() {
List<ConnectionHandleType> connectedCards = null;
try {
connectedCards = connectCards();
if (connectedCards.isEmpty()) {
// TODO: show no card inserted dialog
}
for (ConnectionHandleType nextCard : connectedCards) {
// pick first card, find pin DID and call didupdate
String didName = null;
try {
didName = getPinDid(nextCard);
} catch (WSException ex) {
LOG.info("Skipping card, because it has no PIN DID.");
continue;
}
DIDUpdate updateReq = new DIDUpdate();
updateReq.setConnectionHandle(nextCard);
updateReq.setDIDName(didName);
DIDUpdateDataType updateData = new PinCompareDIDUpdateDataType();
updateData.setProtocol("urn:oid:1.3.162.15480.3.0.9");
updateReq.setDIDUpdateData(updateData);
dispatcher.safeDeliver(updateReq);
}
} catch (WSException ex) {
} finally {
if (connectedCards != null) {
for (ConnectionHandleType nextHandle : connectedCards) {
CardApplicationDisconnect dr = new CardApplicationDisconnect();
dr.setConnectionHandle(nextHandle);
dr.setAction(ActionType.RESET);
dispatcher.safeDeliver(dr);
}
}
}
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class ChangePinInSALAction method connectCards.
private List<ConnectionHandleType> connectCards() throws WSHelper.WSException {
// get all cards in the system
CardApplicationPath pathReq = new CardApplicationPath();
CardApplicationPathType pathType = new CardApplicationPathType();
pathReq.setCardAppPathRequest(pathType);
CardApplicationPathResponse pathRes = (CardApplicationPathResponse) dispatcher.safeDeliver(pathReq);
WSHelper.checkResult(pathRes);
// connect every card in the set
ArrayList<ConnectionHandleType> connectedCards = new ArrayList<>();
for (CardApplicationPathType path : pathRes.getCardAppPathResultSet().getCardApplicationPathResult()) {
try {
CardApplicationConnect conReq = new CardApplicationConnect();
conReq.setCardApplicationPath(path);
conReq.setExclusiveUse(false);
CardApplicationConnectResponse conRes = (CardApplicationConnectResponse) dispatcher.safeDeliver(conReq);
WSHelper.checkResult(conRes);
connectedCards.add(conRes.getConnectionHandle());
} catch (WSHelper.WSException ex) {
LOG.error("Failed to connect card, skipping this entry.", ex);
}
}
return connectedCards;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class GetCardsAndPINStatusAction method execute.
@Override
public void execute() {
// check if a german identity card is inserted, if not wait for it
ConnectionHandleType cHandle = waitForCardType(GERMAN_IDENTITY_CARD);
if (cHandle == null) {
LOG.debug("User cancelled card insertion.");
return;
}
cHandle = connectToRootApplication(cHandle);
RecognizedState pinState = recognizeState(cHandle);
boolean nativePace;
try {
nativePace = genericPACESupport(cHandle);
} catch (WSException e) {
LOG.error("Could not get capabilities from reader.");
return;
}
PINDialog uc = new PINDialog(gui, dispatcher, cHandle, pinState, !nativePace);
uc.show();
Disconnect d = new Disconnect();
d.setSlotHandle(cHandle.getSlotHandle());
dispatcher.safeDeliver(d);
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class SignStep method perform.
@Override
public SignResponse perform(Sign sign, Map<String, Object> internalData) {
SignResponse response = WSHelper.makeResponse(SignResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(sign);
String didName = SALUtils.getDIDName(sign);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(internalData, connectionHandle);
DIDStructureType didStructure = SALUtils.getDIDStructure(sign, didName, cardStateEntry, connectionHandle);
CryptoMarkerType cryptoMarker = new CryptoMarkerType(didStructure.getDIDMarker());
byte[] slotHandle = connectionHandle.getSlotHandle();
byte[] applicationID = connectionHandle.getCardApplication();
Assert.securityConditionDID(cardStateEntry, applicationID, didName, CryptographicServiceActionName.SIGN);
byte[] message = sign.getMessage();
byte[] keyReference = cryptoMarker.getCryptoKeyInfo().getKeyRef().getKeyRef();
byte[] algorithmIdentifier = cryptoMarker.getAlgorithmInfo().getCardAlgRef();
byte[] hashRef = cryptoMarker.getAlgorithmInfo().getHashAlgRef();
HashGenerationInfoType hashInfo = cryptoMarker.getHashGenerationInfo();
if (didStructure.getDIDScope() == DIDScopeType.LOCAL) {
keyReference[0] = (byte) (0x80 | keyReference[0]);
}
if (cryptoMarker.getSignatureGenerationInfo() != null) {
response = performSignature(cryptoMarker, keyReference, algorithmIdentifier, message, slotHandle, hashRef, hashInfo);
} else {
// assuming that legacySignatureInformation exists
BaseTemplateContext templateContext = new BaseTemplateContext();
templateContext.put(HASH_TO_SIGN, message);
templateContext.put(KEY_REFERENCE, keyReference);
templateContext.put(ALGORITHM_IDENTIFIER, algorithmIdentifier);
templateContext.put(HASHALGORITHM_REFERENCE, hashRef);
response = performLegacySignature(cryptoMarker, connectionHandle, templateContext);
}
} catch (ECardException e) {
response.setResult(e.getResult());
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
response.setResult(WSHelper.makeResult(e));
}
return response;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class SignStep method performLegacySignature.
/**
* The method performs the SignatureCreation if no standard commands are possible.
* This method creates a signature with APDUs which are not covered by the methods defined in TR-03112 part 7.
*
* @param cryptoMarker A {@link CryptoMarkerType} object containing the information about the creation of a signature
* in a legacy way.
* @param slotHandle A slotHandle identifying the current card.
* @param templateCTX A Map containing the context data for the evaluation of the template variables. This object
* contains per default the message to sign and the {@link TLVFunction}.
* @return A {@link SignResponse} object containing the signature of the <b>message</b>.
* @throws APDUTemplateException Thrown if the evaluation of the {@link CardCommandTemplate} failed.
* @throws APDUException Thrown if one of the commands to execute failed.
* @throws WSHelper.WSException Thrown if the checkResult method of WSHelper failed.
*/
private SignResponse performLegacySignature(CryptoMarkerType cryptoMarker, ConnectionHandleType connectionHandle, BaseTemplateContext templateCTX) throws APDUTemplateException, APDUException, WSHelper.WSException {
SignResponse response = WSHelper.makeResponse(SignResponse.class, WSHelper.makeResultOK());
List<Object> legacyCommands = cryptoMarker.getLegacySignatureGenerationInfo();
CardCommandAPDU cmdAPDU;
CardResponseAPDU responseAPDU = null;
byte[] slotHandle = connectionHandle.getSlotHandle();
byte[] signedMessage;
for (Object next : legacyCommands) {
if (next instanceof CardCallTemplateType) {
CardCallTemplateType cctt = (CardCallTemplateType) next;
CardCommandTemplate template = new CardCommandTemplate(cctt);
cmdAPDU = template.evaluate(templateCTX);
responseAPDU = cmdAPDU.transmit(dispatcher, slotHandle, Collections.<byte[]>emptyList());
} else if (next instanceof APICommand) {
sendAPICommand(connectionHandle, (APICommand) next);
}
}
signedMessage = responseAPDU.getData();
// check if further response data is available
while (responseAPDU.getTrailer()[0] == (byte) 0x61) {
CardCommandAPDU getResponseData = new CardCommandAPDU((byte) 0x00, (byte) 0xC0, (byte) 0x00, (byte) 0x00, responseAPDU.getTrailer()[1]);
responseAPDU = getResponseData.transmit(dispatcher, slotHandle, Collections.<byte[]>emptyList());
signedMessage = Arrays.concatenate(signedMessage, responseAPDU.getData());
}
if (!Arrays.areEqual(responseAPDU.getTrailer(), new byte[] { (byte) 0x90, (byte) 0x00 })) {
String minor = SALErrorUtils.getMinor(responseAPDU.getTrailer());
response.setResult(WSHelper.makeResultError(minor, responseAPDU.getStatusMessage()));
return response;
}
// fix output format
String outForm = cryptoMarker.getLegacyOutputFormat();
if (outForm != null) {
switch(outForm) {
case "rawRS":
signedMessage = encodeRawRS(signedMessage);
break;
default:
LOG.warn("Unsupport outputFormat={} specified in LegacySignatureGenerationInfo.", outForm);
}
}
response.setSignature(signedMessage);
return response;
}
Aggregations