use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class VerifySignatureStep method perform.
@Override
public VerifySignatureResponse perform(VerifySignature request, Map<String, Object> internalData) {
VerifySignatureResponse response = WSHelper.makeResponse(VerifySignatureResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(internalData, connectionHandle);
String didName = SALUtils.getDIDName(request);
DIDStructureType didStructure = SALUtils.getDIDStructure(request, didName, cardStateEntry, connectionHandle);
// required
byte[] signature = request.getSignature();
// optional
byte[] message = request.getMessage();
CryptoMarkerType cryptoMarker = new CryptoMarkerType(didStructure.getDIDMarker());
String dataSetNameCertificate = cryptoMarker.getCertificateRefs().get(0).getDataSetName();
String algorithmIdentifier = cryptoMarker.getAlgorithmInfo().getAlgorithmIdentifier().getAlgorithm();
DSIRead dsiRead = new DSIRead();
dsiRead.setConnectionHandle(connectionHandle);
dsiRead.setDSIName(dataSetNameCertificate);
DSIReadResponse dsiReadResponse = (DSIReadResponse) dispatcher.safeDeliver(dsiRead);
WSHelper.checkResult(dsiReadResponse);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
Certificate cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(dsiReadResponse.getDSIContent()));
Signature signatureAlgorithm;
if (algorithmIdentifier.equals(GenericCryptoUris.RSA_ENCRYPTION)) {
signatureAlgorithm = Signature.getInstance("RSA", new BouncyCastleProvider());
} else if (algorithmIdentifier.equals(GenericCryptoUris.RSASSA_PSS_SHA256)) {
signatureAlgorithm = Signature.getInstance("RAWRSASSA-PSS", new BouncyCastleProvider());
signatureAlgorithm.setParameter(new PSSParameterSpec("SHA-256", "MGF1", new MGF1ParameterSpec("SHA-256"), 32, 1));
} else if (algorithmIdentifier.equals(GenericCryptoUris.sigS_ISO9796_2)) {
return WSHelper.makeResponse(VerifySignatureResponse.class, WSHelper.makeResultUnknownError(algorithmIdentifier + " Not supported yet."));
} else if (algorithmIdentifier.equals(GenericCryptoUris.sigS_ISO9796_2rnd)) {
return WSHelper.makeResponse(VerifySignatureResponse.class, WSHelper.makeResultUnknownError(algorithmIdentifier + " Not supported yet."));
} else {
throw new IncorrectParameterException("Unknown signature algorithm.");
}
signatureAlgorithm.initVerify(cert);
if (message != null) {
signatureAlgorithm.update(message);
}
if (!signatureAlgorithm.verify(signature)) {
throw new InvalidSignatureException();
}
} catch (ECardException e) {
LOG.error(e.getMessage(), e);
response.setResult(e.getResult());
} catch (Exception 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 CardStateMap method addEntry.
public synchronized void addEntry(CardStateEntry entry) {
ConnectionHandleType handle = entry.handleCopy();
ChannelHandleType channel = handle.getChannelHandle();
if (channel != null) {
addMapEntry(channel.getSessionIdentifier(), sessionMap, entry);
}
addMapEntry(handle.getContextHandle(), contextMap, entry);
addMapEntry(handle.getSlotHandle(), slothandleMap, entry);
allEntries.add(entry);
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class CardStateMap method removeEntry.
/**
* Remove all references to this CardStateEntry.
* @param entry Entry to delete.
* @param removeSlotHandles When set remove all occurrences of this entry in the slotHandle index.
*/
private synchronized void removeEntry(CardStateEntry entry, boolean removeSlotHandles) {
ConnectionHandleType handle = entry.handleCopy();
ChannelHandleType channel = handle.getChannelHandle();
if (channel != null) {
removeMapEntry(channel.getSessionIdentifier(), sessionMap, entry);
}
removeMapEntry(handle.getContextHandle(), contextMap, entry);
// remove all or just the one a key is given for
if (removeSlotHandles) {
Iterator<byte[]> it = slothandleMap.keySet().iterator();
while (it.hasNext()) {
byte[] key = it.next();
removeMapEntry(key, slothandleMap, entry);
}
} else {
removeMapEntry(handle.getSlotHandle(), slothandleMap, entry);
}
allEntries.remove(entry);
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class HandlePrinter method printHandle.
public static void printHandle(Writer w, ConnectionHandleType handle) throws IOException {
ChannelHandleType channel = handle.getChannelHandle();
String session = null;
if (channel != null) {
session = channel.getSessionIdentifier();
}
byte[] ctx = handle.getContextHandle();
String ifdname = handle.getIFDName();
BigInteger slotIdx = handle.getSlotIndex();
byte[] slotHandle = handle.getSlotHandle();
ConnectionHandleType.RecognitionInfo rec = handle.getRecognitionInfo();
String cardType = null;
if (rec != null) {
cardType = rec.getCardType();
}
w.write("ConnectionHandle:");
if (session != null) {
w.write("\n Session: ");
w.write(session);
}
if (ctx != null) {
w.write("\n ContextHandle: ");
w.write(ByteUtils.toHexString(ctx));
}
if (ifdname != null) {
w.write("\n IFDName: ");
w.write(ifdname);
if (slotIdx != null) {
w.write(" SlotIndex: ");
w.write(slotIdx.toString());
}
}
if (slotHandle != null) {
w.write("\n SlotHandle: ");
w.write(ByteUtils.toHexString(slotHandle));
}
if (cardType != null) {
w.write("\n CardType: ");
w.write(cardType);
}
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class TestClient method setup.
private void setup() throws Exception {
// Set up client environment
ClientEnv env = new ClientEnv();
// Set up the IFD
IFD ifd = new IFD();
env.setIFD(ifd);
// Set up Management
TinyManagement management = new TinyManagement(env);
env.setManagement(management);
// Set up the Dispatcher
MessageDispatcher dispatcher = new MessageDispatcher(env);
env.setDispatcher(dispatcher);
// Perform an EstablishContext to get a ContextHandle
EstablishContext establishContext = new EstablishContext();
EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
byte[] contextHandle = ifd.establishContext(establishContext).getContextHandle();
final CardRecognitionImpl recognition = new CardRecognitionImpl(env);
env.setRecognition(recognition);
env.setCIFProvider(new CIFProvider() {
@Override
public CardInfoType getCardInfo(ConnectionHandleType type, String cardType) {
return recognition.getCardInfo(cardType);
}
@Override
public boolean needsRecognition(byte[] atr) {
return true;
}
@Override
public CardInfoType getCardInfo(String cardType) throws RuntimeException {
return recognition.getCardInfo(cardType);
}
@Override
public InputStream getCardImage(String cardType) {
return recognition.getCardImage(cardType);
}
});
// Set up EventManager
EventDispatcher ed = new EventDispatcherImpl();
env.setEventDispatcher(ed);
// Set up SALStateCallback
cardStates = new CardStateMap();
SALStateCallback salCallback = new SALStateCallback(env, cardStates);
ed.add(salCallback);
// Set up SAL
sal = new TinySAL(env, cardStates);
env.setSAL(sal);
// Set up GUI
SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
sal.setGUI(gui);
ifd.setGUI(gui);
// Initialize the EventManager
ed.start();
AddonManager manager = new AddonManager(env, gui, cardStates, null);
sal.setAddonManager(manager);
HttpBinding binding = new HttpBinding(24727);
binding.setAddonManager(manager);
binding.start();
}
Aggregations