use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class InsertCardStepAction method createHandleList.
/**
* Creates a list of {@link ConnectionHandleType} objects created from the card types.
*
* @return List {@link ConnectionHandleType} objects created from the card types.
*/
@Nonnull
private List<ConnectionHandleType> createHandleList() {
List<ConnectionHandleType> handles = new ArrayList<>();
for (String type : cardTypes) {
ConnectionHandleType conHandle = new ConnectionHandleType();
ConnectionHandleType.RecognitionInfo recInfo = new ConnectionHandleType.RecognitionInfo();
recInfo.setCardType(type);
conHandle.setRecognitionInfo(recInfo);
handles.add(conHandle);
}
return handles;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class SALUtils method getConnectionHandle.
public static ConnectionHandleType getConnectionHandle(Object object) throws IncorrectParameterException, Exception {
ConnectionHandleType value = (ConnectionHandleType) get(object, "getConnectionHandle");
Assert.assertIncorrectParameter(value, "The parameter ConnectionHandle is empty.");
return value;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class MiddlewareSAL method augmentCardInfo.
private CardInfoType augmentCardInfo(@Nonnull ConnectionHandleType handle, @Nonnull CardInfoType template, @Nonnull CardSpecType cardSpec) {
boolean needsConnect = handle.getSlotHandle() == null;
try {
// connect card, so that we have a session
MwSession session;
if (needsConnect) {
MwSlot slot = getMatchingSlot(handle.getIFDName(), handle.getSlotIndex());
if (slot != null) {
session = slot.openSession();
} else {
throw new TokenException("No card available in this slot.", CryptokiLibrary.CKR_TOKEN_NOT_PRESENT);
}
} else {
session = managedSessions.get(handle.getSlotHandle());
}
if (session != null) {
CIFCreator cc = new CIFCreator(session, template, cardSpec);
CardInfoType cif = cc.addTokenInfo();
LOG.info("Finished augmenting CardInfo file.");
return cif;
} else {
LOG.warn("Card not available for object info retrieval anymore.");
return null;
}
} catch (WSMarshallerException ex) {
throw new RuntimeException("Failed to marshal CIF file.", ex);
} catch (CryptokiException ex) {
throw new RuntimeException("Error in PKCS#11 module while requesting CIF data.", ex);
}
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class MiddlewareSAL method updatePin.
private Result updatePin(DIDUpdateDataType didUpdateData, CardStateEntry cardStateEntry, DIDStructureType didStruct) {
// make sure the pin is not entered already
setPinNotAuth(cardStateEntry);
ConnectionHandleType connectionHandle = cardStateEntry.handleCopy();
MwSession session = managedSessions.get(connectionHandle.getSlotHandle());
boolean protectedAuthPath = connectionHandle.getSlotInfo().isProtectedAuthPath();
try {
PinChangeDialog dialog = new PinChangeDialog(gui, protectedAuthPath, session);
dialog.show();
} catch (CryptokiException ex) {
return WSHelper.makeResultUnknownError(ex.getMessage());
}
return WSHelper.makeResultOK();
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class MiddlewareSAL method sign.
@Override
public SignResponse sign(Sign request) {
SignResponse response = WSHelper.makeResponse(SignResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
byte[] application = cardStateEntry.getImplicitlySelectedApplicationIdentifier();
byte[] slotHandle = connectionHandle.getSlotHandle();
String didName = SALUtils.getDIDName(request);
byte[] message = request.getMessage();
Assert.assertIncorrectParameter(message, "The parameter Message is empty.");
DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, application);
Assert.assertNamedEntityNotFound(didStructure, "The given DIDName cannot be found.");
CryptoMarkerType marker = new CryptoMarkerType(didStructure.getDIDMarker());
String keyLabel = marker.getLegacyKeyName();
MwSession session = managedSessions.get(slotHandle);
for (MwPrivateKey key : session.getPrivateKeys()) {
String nextLabel = "";
try {
nextLabel = key.getKeyLabel();
} catch (CryptokiException ex) {
LOG.warn("Error reading key label.", ex);
}
LOG.debug("Try to match keys '{}' == '{}'", keyLabel, nextLabel);
if (keyLabel.equals(nextLabel)) {
long sigAlg = getPKCS11Alg(marker.getAlgorithmInfo());
byte[] sig = key.sign(sigAlg, message);
response.setSignature(sig);
// set PIN to unauthenticated
setPinNotAuth(cardStateEntry);
return response;
}
}
// TODO: use other exception
String msg = String.format("The given DIDName %s references an unknown key.", didName);
throw new IncorrectParameterException(msg);
} catch (ECardException e) {
LOG.debug(e.getMessage(), e);
response.setResult(e.getResult());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throwThreadKillException(e);
response.setResult(WSHelper.makeResult(e));
}
return response;
}
Aggregations