From 32d17447a258188b2d534bcb0bf65a659ba7b7d0 Mon Sep 17 00:00:00 2001 From: mcentner Date: Fri, 29 Aug 2008 12:11:34 +0000 Subject: Initial import. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../egiz/bku/smccstal/AbstractRequestHandler.java | 86 ++++++++++++ .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 116 ++++++++++++++++ .../at/gv/egiz/bku/smccstal/DomainIdConverter.java | 85 ++++++++++++ .../bku/smccstal/InfoBoxReadRequestHandler.java | 140 +++++++++++++++++++ .../egiz/bku/smccstal/SMCCSTALRequestHandler.java | 36 +++++ .../gv/egiz/bku/smccstal/STALMessageConsumer.java | 21 +++ .../gv/egiz/bku/smccstal/SignRequestHandler.java | 151 +++++++++++++++++++++ 7 files changed, 635 insertions(+) create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/DomainIdConverter.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/STALMessageConsumer.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java new file mode 100644 index 00000000..e5afa478 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java @@ -0,0 +1,86 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.smccstal; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +public abstract class AbstractRequestHandler implements SMCCSTALRequestHandler, + ActionListener { + private final static Log log = LogFactory + .getLog(AbstractRequestHandler.class); + + protected SignatureCard card; + protected BKUGUIFacade gui; + protected static STALMessageConsumer messageConsumer = null; + protected String actionCommand; + protected boolean actionPerformed = false; + + @Override + public abstract STALResponse handleRequest(STALRequest request); + + @Override + public void init(SignatureCard sc, BKUGUIFacade gui) { + if ((sc == null) || (gui == null)) { + throw new NullPointerException("Parameter must not be set to null"); + } + this.card = sc; + this.gui = gui; + } + + public static void setMessageConsumer(STALMessageConsumer messageConsumer) { + AbstractRequestHandler.messageConsumer = messageConsumer; + } + + protected static void newSTALMessage(String caption, String message) { + if (messageConsumer != null) { + messageConsumer.consumeNewSTALMessage(caption, message); + } + } + + protected synchronized void waitForAction() { + try { + while (!actionPerformed) { + wait(); + } + } catch (InterruptedException e) { + log.info(e); + } + actionPerformed = false; + } + + private synchronized void actionPerformed() { + actionPerformed = true; + notifyAll(); + } + + @Override + public void actionPerformed(ActionEvent e) { + actionCommand = e.getActionCommand(); + actionPerformed(); + } + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java new file mode 100644 index 00000000..7bd9e264 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -0,0 +1,116 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.smccstal; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.util.SMCCHelper; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.InfoboxReadRequest; +import at.gv.egiz.stal.STAL; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; + +public abstract class AbstractSMCCSTAL implements STAL { + private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); + + protected Locale locale = Locale.getDefault(); + protected SMCCHelper smccHelper = new SMCCHelper(); + protected SignatureCard signatureCard = null; + protected static Map handlerMap = new HashMap(); + + static { + addRequestHandler(InfoboxReadRequest.class, new InfoBoxReadRequestHandler()); + addRequestHandler(SignRequest.class, new SignRequestHandler()); + } + + public AbstractSMCCSTAL() { + } + + /** + * Implementations must assign the signature card within this method. + * + * @return if the user canceled + */ + protected abstract boolean waitForCard(); + + protected abstract BKUGUIFacade getGUI(); + + @Override + public List handleRequest( + List requestList) { + log.debug("Got request list containing " + requestList.size() + + " STAL requests"); + List responseList = new ArrayList(requestList + .size()); + for (STALRequest request : requestList) { + log.info("Processing: " + request); + SMCCSTALRequestHandler handler = null; + handler = handlerMap.get(request.getClass().getSimpleName()); + if (handler != null) { + if (handler.requireCard()) { + if (waitForCard()) { + responseList.add(new ErrorResponse(6001)); + break; + } + } + try { + handler = handler.newInstance(); + handler.init(signatureCard, getGUI()); + responseList.add(handler.handleRequest(request)); + } catch (Exception e) { + log.info("Error while handling STAL request:" + e); + responseList.add(new ErrorResponse(6000)); + } + } else { + log.error("Cannot find a handler for STAL request: " + request); + responseList.add(new ErrorResponse()); + } + } + return responseList; + } + + public static void addRequestHandler(Class id, + SMCCSTALRequestHandler handler) { + log.debug("Registering STAL request handler: " + id.getSimpleName()); + handlerMap.put(id.getSimpleName(), handler); + } + + public static SMCCSTALRequestHandler getRequestHandler( + Class request) { + return handlerMap.get(request.getSimpleName()); + } + + @Override + public void setLocale(Locale locale) { + if (locale == null) { + throw new NullPointerException("Locale must not be set to null"); + } + this.locale = locale; + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/DomainIdConverter.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/DomainIdConverter.java new file mode 100644 index 00000000..3a564b91 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/DomainIdConverter.java @@ -0,0 +1,85 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.smccstal; + +import iaik.me.asn1.ASN1; +import iaik.me.utils.Base64; + +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Vector; + +public class DomainIdConverter { + + private static String getBaseId(ASN1 identityLink) throws IOException { + + if (identityLink.getType() == ASN1.TYPE_SEQUENCE) { + ASN1 personData = identityLink.getElementAt(4); + if (personData.getType() == ASN1.TAG_CONTEXT_SPECIFIC) { + ASN1 physicalPersonData = personData.gvASN1(); + ASN1 baseId = physicalPersonData.getElementAt(0); + return baseId.gvString(); + } + throw new IOException("Invalid structure."); + + } + throw new IOException("Invalid structure."); + + } + + private static ASN1 replaceBaseId(ASN1 identityLink, String newBaseId) + throws IOException { + + ASN1 newIdentityLink = new ASN1(ASN1.TYPE_SEQUENCE, new Vector()); + for (int i = 0; i < identityLink.getSize(); i++) { + ASN1 asn1 = identityLink.getElementAt(i); + if (i == 4 && asn1.getType() == ASN1.TAG_CONTEXT_SPECIFIC) { + ASN1 physicalPersonData = asn1.gvASN1(); + ASN1 newPhysicalPersonData = new ASN1(ASN1.TYPE_SEQUENCE, + new Vector()); + newPhysicalPersonData.addElement(new ASN1(ASN1.TYPE_UTF8_STRING, + newBaseId)); + for (int j = 1; j < physicalPersonData.getSize(); j++) { + newPhysicalPersonData.addElement(physicalPersonData.getElementAt(j)); + } + asn1 = new ASN1(ASN1.TAG_CONTEXT_SPECIFIC, newPhysicalPersonData); + } + newIdentityLink.addElement(asn1); + } + return newIdentityLink; + + } + + public static byte[] convertDomainId(byte[] data, String domainId) + throws IOException, NoSuchAlgorithmException { + if (domainId == null) { + return data; + } + ASN1 identityLink = new ASN1(data); + MessageDigest sha = null; + sha = MessageDigest.getInstance("SHA"); + String base = getBaseId(identityLink); + sha.update((base + "+" + domainId).getBytes()); + String bpkStr = new String(Base64.encode(sha.digest())); + bpkStr = bpkStr.trim(); + identityLink = replaceBaseId(identityLink, bpkStr); + System.out.println(getBaseId(identityLink)); + return identityLink.getEncoded(); + } + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java new file mode 100644 index 00000000..7dc2e202 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -0,0 +1,140 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.smccstal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.InfoboxReadRequest; +import at.gv.egiz.stal.InfoboxReadResponse; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements + PINProvider { + + private static Log log = LogFactory.getLog(InfoBoxReadRequestHandler.class); + + private int retryCounter = 0; + + @Override + public STALResponse handleRequest(STALRequest request) { + if (request instanceof InfoboxReadRequest) { + InfoboxReadRequest infoBox = (InfoboxReadRequest) request; + try { + if (infoBox.getInfoboxIdentifier().equals("IdentityLink")) { + newSTALMessage("Message.RequestCaption", "Message.IdentityLink"); + log.debug("Handling identitylink infobox"); + byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, + infoBox.getDomainIdentifier()); + if (resp == null) { + log.info("Got null as result->user cancelled"); + return new ErrorResponse(6001); + } else { + try { + resp = DomainIdConverter.convertDomainId(resp, infoBox + .getDomainIdentifier()); + } catch (Exception e) { + log.error("Cannot convert domain specific id", e); + return new ErrorResponse(1000); + } + } + InfoboxReadResponse stalResp = new InfoboxReadResponse(); + stalResp.setInfoboxValue(resp); + return stalResp; + } else if (SignatureCard.KeyboxName.CERITIFIED_KEYPAIR.equals(infoBox + .getInfoboxIdentifier())) { + newSTALMessage("Message.RequestCaption", "Message.CertifiedKeypair"); + log.debug("Handling certified keypair infobox"); + byte[] resp = card + .getCertificate(SignatureCard.KeyboxName.CERITIFIED_KEYPAIR); + if (resp == null) { + return new ErrorResponse(6001); + } + InfoboxReadResponse stalResp = new InfoboxReadResponse(); + stalResp.setInfoboxValue(resp); + return stalResp; + } else if (SignatureCard.KeyboxName.SECURE_SIGNATURE_KEYPAIR + .equals(infoBox.getInfoboxIdentifier())) { + newSTALMessage("Message.RequestCaption", + "Message.SecureSignatureKeypair"); + log.debug("Handling secure signature keypair infobox"); + byte[] resp = card + .getCertificate(SignatureCard.KeyboxName.SECURE_SIGNATURE_KEYPAIR); + if (resp == null) { + return new ErrorResponse(6001); + } + InfoboxReadResponse stalResp = new InfoboxReadResponse(); + stalResp.setInfoboxValue(resp); + return stalResp; + } else { + newSTALMessage("Message.RequestCaption", "Message.InfoboxReadRequest"); + log.warn("Unknown infobox identifier: " + + infoBox.getInfoboxIdentifier() + " trying generic request"); + byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, + infoBox.getDomainIdentifier()); + if (resp == null) { + return new ErrorResponse(6001); + } + InfoboxReadResponse stalResp = new InfoboxReadResponse(); + stalResp.setInfoboxValue(resp); + return stalResp; + } + } catch (CancelledException cx) { + log.debug("User cancelled request", cx); + return new ErrorResponse(6001); + } catch (SignatureCardException e) { + log.info("Error while reading infobox: " + e); + return new ErrorResponse(4000); + } + } else { + log.fatal("Got unexpected STAL request: " + request); + return new ErrorResponse(1000); + } + } + + @Override + public boolean requireCard() { + return true; + } + + @Override + public String providePIN(PINSpec spec, int retries) { + if (retryCounter++ > 0) { + log.info("PIN wrong retrying ..."); + gui.showCardPINRetryDialog(spec, retries, this, "ok", this, "cancel"); + } else { + gui.showCardPINDialog(spec, this, "ok", this, "cancel"); + } + waitForAction(); + if (actionCommand.equals("cancel")) { + return null; + } + return new String(gui.getPin()); + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return new InfoBoxReadRequestHandler(); + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java new file mode 100644 index 00000000..7badb2a0 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java @@ -0,0 +1,36 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.smccstal; + + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +public interface SMCCSTALRequestHandler { + + public void init(SignatureCard sc, BKUGUIFacade gui); + + public STALResponse handleRequest(STALRequest request); + + public boolean requireCard(); + + public SMCCSTALRequestHandler newInstance(); + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/STALMessageConsumer.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/STALMessageConsumer.java new file mode 100644 index 00000000..7d7a6ec0 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/STALMessageConsumer.java @@ -0,0 +1,21 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.smccstal; + +public interface STALMessageConsumer { + public void consumeNewSTALMessage(String captionId, String messageId); +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java new file mode 100644 index 00000000..6ae4fa01 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -0,0 +1,151 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.smccstal; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; +import at.gv.egiz.stal.SignResponse; +import at.gv.egiz.stal.signedinfo.ObjectFactory; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import at.gv.egiz.stal.util.JCEAlgorithmNames; + +public class SignRequestHandler extends AbstractRequestHandler implements + PINProvider { + private static Log log = LogFactory.getLog(SignRequestHandler.class); + + private static JAXBContext jaxbContext; + + static { + try { + jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage() + .getName()); + } catch (JAXBException e) { + log.fatal("Cannot init jaxbContext", e); + } + } + + private int retryCounter = 0; + + public SignRequestHandler() { + } + + @SuppressWarnings("unchecked") + @Override + public STALResponse handleRequest(STALRequest request) { + if (request instanceof SignRequest) { + SignRequest signReq = (SignRequest) request; + newSTALMessage("Message.RequestCaption", "Message.SignRequest"); + try { + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + InputStream is = new ByteArrayInputStream(signReq.getSignedInfo()); + JAXBElement signedInfo = (JAXBElement) unmarshaller + .unmarshal(is); + String signatureMethod = signedInfo.getValue().getSignatureMethod() + .getAlgorithm(); + log.debug("Found signature method: " + signatureMethod); + String jceName = JCEAlgorithmNames.getJCEHashName(signatureMethod); + if (jceName == null) { + log.error("Hash algorithm not supported:"); + return new ErrorResponse(1000); + } + MessageDigest md = MessageDigest.getInstance(jceName); + md.update(signReq.getSignedInfo()); + KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq + .getKeyIdentifier()); + byte[] resp = card.createSignature(md.digest(), kb, this); + if (resp == null) { + return new ErrorResponse(6001); + } + SignResponse stalResp = new SignResponse(); + stalResp.setSignatureValue(resp); + return stalResp; + } catch (CancelledException cx) { + log.debug("User cancelled request"); + return new ErrorResponse(6001); + } catch (SignatureCardException e) { + log.error("Error while creating signature: " + e); + return new ErrorResponse(4000); + } catch (JAXBException e) { + log.error("Cannot unmarshall signed info", e); + return new ErrorResponse(1000); + } catch (NoSuchAlgorithmException e) { + log.error(e); + return new ErrorResponse(1000); + } + } else { + log.fatal("Got unexpected STAL request: " + request); + return new ErrorResponse(1000); + } + } + + @Override + public boolean requireCard() { + return true; + } + + @Override + public String providePIN(PINSpec spec, int retries) { + if (retryCounter++ > 0) { + log.info("PIN wrong retrying ..."); + gui.showSignaturePINRetryDialog(spec, retries, this, "sign", this, + "cancel", this, "hashData"); + } else { + gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, + "hashData"); + } + do { + waitForAction(); + if (actionCommand.equals("cancel")) { + return null; + } else if (actionCommand.equals("hashData")) { + // FIXME provide hashdata input + gui.showHashDataInputDialog(null, this, "ok"); + } else if (actionCommand.equals("sign")) { + return new String(gui.getPin()); + } else if (actionCommand.equals("ok")) { + gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, + "hashData"); + } + } while (true); + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return new SignRequestHandler(); + } +} -- cgit v1.2.3 From 35b64892bad13c846f19260311c7625d88cef7a1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 5 Sep 2008 13:39:53 +0000 Subject: HashDataInput git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@23 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../egiz/bku/smccstal/AbstractRequestHandler.java | 139 +++++---- .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 196 ++++++------ .../egiz/bku/smccstal/SMCCSTALRequestHandler.java | 39 ++- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 337 ++++++++++++--------- 4 files changed, 371 insertions(+), 340 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java index e5afa478..995e2b77 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java @@ -14,73 +14,72 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.smccstal; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; - -public abstract class AbstractRequestHandler implements SMCCSTALRequestHandler, - ActionListener { - private final static Log log = LogFactory - .getLog(AbstractRequestHandler.class); - - protected SignatureCard card; - protected BKUGUIFacade gui; - protected static STALMessageConsumer messageConsumer = null; - protected String actionCommand; - protected boolean actionPerformed = false; - - @Override - public abstract STALResponse handleRequest(STALRequest request); - - @Override - public void init(SignatureCard sc, BKUGUIFacade gui) { - if ((sc == null) || (gui == null)) { - throw new NullPointerException("Parameter must not be set to null"); - } - this.card = sc; - this.gui = gui; - } - - public static void setMessageConsumer(STALMessageConsumer messageConsumer) { - AbstractRequestHandler.messageConsumer = messageConsumer; - } - - protected static void newSTALMessage(String caption, String message) { - if (messageConsumer != null) { - messageConsumer.consumeNewSTALMessage(caption, message); - } - } - - protected synchronized void waitForAction() { - try { - while (!actionPerformed) { - wait(); - } - } catch (InterruptedException e) { - log.info(e); - } - actionPerformed = false; - } - - private synchronized void actionPerformed() { - actionPerformed = true; - notifyAll(); - } - - @Override - public void actionPerformed(ActionEvent e) { - actionCommand = e.getActionCommand(); - actionPerformed(); - } - -} +package at.gv.egiz.bku.smccstal; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +public abstract class AbstractRequestHandler implements SMCCSTALRequestHandler, + ActionListener { + private final static Log log = LogFactory + .getLog(AbstractRequestHandler.class); + + protected SignatureCard card; + protected BKUGUIFacade gui; + protected static STALMessageConsumer messageConsumer = null; + protected String actionCommand; + protected boolean actionPerformed = false; + + @Override + public abstract STALResponse handleRequest(STALRequest request); + + @Override + public void init(SignatureCard sc, BKUGUIFacade gui) { + if ((sc == null) || (gui == null)) { + throw new NullPointerException("Parameter must not be set to null"); + } + this.card = sc; + this.gui = gui; + } + + public static void setMessageConsumer(STALMessageConsumer messageConsumer) { + AbstractRequestHandler.messageConsumer = messageConsumer; + } + + protected static void newSTALMessage(String caption, String message) { + if (messageConsumer != null) { + messageConsumer.consumeNewSTALMessage(caption, message); + } + } + + protected synchronized void waitForAction() { + try { + while (!actionPerformed) { + wait(); + } + } catch (InterruptedException e) { + log.info(e); + } + actionPerformed = false; + } + + private synchronized void actionPerformed() { + actionPerformed = true; + notifyAll(); + } + + @Override + public void actionPerformed(ActionEvent e) { + actionCommand = e.getActionCommand(); + actionPerformed(); + } + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 7bd9e264..56c8340b 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -14,103 +14,99 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.smccstal; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.smcc.util.SMCCHelper; -import at.gv.egiz.stal.ErrorResponse; -import at.gv.egiz.stal.InfoboxReadRequest; -import at.gv.egiz.stal.STAL; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.SignRequest; - -public abstract class AbstractSMCCSTAL implements STAL { - private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); - - protected Locale locale = Locale.getDefault(); - protected SMCCHelper smccHelper = new SMCCHelper(); - protected SignatureCard signatureCard = null; - protected static Map handlerMap = new HashMap(); - - static { - addRequestHandler(InfoboxReadRequest.class, new InfoBoxReadRequestHandler()); - addRequestHandler(SignRequest.class, new SignRequestHandler()); - } - - public AbstractSMCCSTAL() { - } - - /** - * Implementations must assign the signature card within this method. - * - * @return if the user canceled - */ - protected abstract boolean waitForCard(); - - protected abstract BKUGUIFacade getGUI(); - - @Override - public List handleRequest( - List requestList) { - log.debug("Got request list containing " + requestList.size() - + " STAL requests"); - List responseList = new ArrayList(requestList - .size()); - for (STALRequest request : requestList) { - log.info("Processing: " + request); - SMCCSTALRequestHandler handler = null; - handler = handlerMap.get(request.getClass().getSimpleName()); - if (handler != null) { - if (handler.requireCard()) { - if (waitForCard()) { - responseList.add(new ErrorResponse(6001)); - break; - } - } - try { - handler = handler.newInstance(); - handler.init(signatureCard, getGUI()); - responseList.add(handler.handleRequest(request)); - } catch (Exception e) { - log.info("Error while handling STAL request:" + e); - responseList.add(new ErrorResponse(6000)); - } - } else { - log.error("Cannot find a handler for STAL request: " + request); - responseList.add(new ErrorResponse()); - } - } - return responseList; - } - - public static void addRequestHandler(Class id, - SMCCSTALRequestHandler handler) { - log.debug("Registering STAL request handler: " + id.getSimpleName()); - handlerMap.put(id.getSimpleName(), handler); - } - - public static SMCCSTALRequestHandler getRequestHandler( - Class request) { - return handlerMap.get(request.getSimpleName()); - } - - @Override - public void setLocale(Locale locale) { - if (locale == null) { - throw new NullPointerException("Locale must not be set to null"); - } - this.locale = locale; - } -} +package at.gv.egiz.bku.smccstal; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.util.SMCCHelper; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.InfoboxReadRequest; +import at.gv.egiz.stal.STAL; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; + +public abstract class AbstractSMCCSTAL implements STAL { + private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); + + protected Locale locale = Locale.getDefault(); + protected SMCCHelper smccHelper = new SMCCHelper(); + protected SignatureCard signatureCard = null; + protected static Map handlerMap = new HashMap(); + + static { + addRequestHandler(InfoboxReadRequest.class, new InfoBoxReadRequestHandler()); + addRequestHandler(SignRequest.class, new SignRequestHandler()); + } + + /** + * Implementations must assign the signature card within this method. + * + * @return if the user canceled + */ + protected abstract boolean waitForCard(); + + protected abstract BKUGUIFacade getGUI(); + + @Override + public List handleRequest( + List requestList) { + log.debug("Got request list containing " + requestList.size() + + " STAL requests"); + List responseList = new ArrayList(requestList + .size()); + for (STALRequest request : requestList) { + log.info("Processing: " + request); + SMCCSTALRequestHandler handler = null; + handler = handlerMap.get(request.getClass().getSimpleName()); + if (handler != null) { + if (handler.requireCard()) { + if (waitForCard()) { + responseList.add(new ErrorResponse(6001)); + break; + } + } + try { + handler = handler.newInstance(); + handler.init(signatureCard, getGUI()); + responseList.add(handler.handleRequest(request)); + } catch (Exception e) { + log.info("Error while handling STAL request:" + e); + responseList.add(new ErrorResponse(6000)); + } + } else { + log.error("Cannot find a handler for STAL request: " + request); + responseList.add(new ErrorResponse()); + } + } + return responseList; + } + + public static void addRequestHandler(Class id, + SMCCSTALRequestHandler handler) { + log.debug("Registering STAL request handler: " + id.getSimpleName()); + handlerMap.put(id.getSimpleName(), handler); + } + + public static SMCCSTALRequestHandler getRequestHandler( + Class request) { + return handlerMap.get(request.getSimpleName()); + } + + @Override + public void setLocale(Locale locale) { + if (locale == null) { + throw new NullPointerException("Locale must not be set to null"); + } + this.locale = locale; + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java index 7badb2a0..6f303f76 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java @@ -14,23 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.smccstal; - - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; - -public interface SMCCSTALRequestHandler { - - public void init(SignatureCard sc, BKUGUIFacade gui); - - public STALResponse handleRequest(STALRequest request); - - public boolean requireCard(); - - public SMCCSTALRequestHandler newInstance(); - -} +package at.gv.egiz.bku.smccstal; + + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +public interface SMCCSTALRequestHandler { + + public void init(SignatureCard sc, BKUGUIFacade gui); + + public STALResponse handleRequest(STALRequest request); + + public boolean requireCard(); + + public SMCCSTALRequestHandler newInstance(); + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 6ae4fa01..2fe77c5d 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -1,151 +1,188 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package at.gv.egiz.bku.smccstal; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.PINSpec; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.smcc.SignatureCardException; -import at.gv.egiz.smcc.SignatureCard.KeyboxName; -import at.gv.egiz.stal.ErrorResponse; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.SignRequest; -import at.gv.egiz.stal.SignResponse; -import at.gv.egiz.stal.signedinfo.ObjectFactory; -import at.gv.egiz.stal.signedinfo.SignedInfoType; -import at.gv.egiz.stal.util.JCEAlgorithmNames; - -public class SignRequestHandler extends AbstractRequestHandler implements - PINProvider { - private static Log log = LogFactory.getLog(SignRequestHandler.class); - - private static JAXBContext jaxbContext; - - static { - try { - jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage() - .getName()); - } catch (JAXBException e) { - log.fatal("Cannot init jaxbContext", e); - } - } - - private int retryCounter = 0; - - public SignRequestHandler() { - } - - @SuppressWarnings("unchecked") - @Override - public STALResponse handleRequest(STALRequest request) { - if (request instanceof SignRequest) { - SignRequest signReq = (SignRequest) request; - newSTALMessage("Message.RequestCaption", "Message.SignRequest"); - try { - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - InputStream is = new ByteArrayInputStream(signReq.getSignedInfo()); - JAXBElement signedInfo = (JAXBElement) unmarshaller - .unmarshal(is); - String signatureMethod = signedInfo.getValue().getSignatureMethod() - .getAlgorithm(); - log.debug("Found signature method: " + signatureMethod); - String jceName = JCEAlgorithmNames.getJCEHashName(signatureMethod); - if (jceName == null) { - log.error("Hash algorithm not supported:"); - return new ErrorResponse(1000); - } - MessageDigest md = MessageDigest.getInstance(jceName); - md.update(signReq.getSignedInfo()); - KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq - .getKeyIdentifier()); - byte[] resp = card.createSignature(md.digest(), kb, this); - if (resp == null) { - return new ErrorResponse(6001); - } - SignResponse stalResp = new SignResponse(); - stalResp.setSignatureValue(resp); - return stalResp; - } catch (CancelledException cx) { - log.debug("User cancelled request"); - return new ErrorResponse(6001); - } catch (SignatureCardException e) { - log.error("Error while creating signature: " + e); - return new ErrorResponse(4000); - } catch (JAXBException e) { - log.error("Cannot unmarshall signed info", e); - return new ErrorResponse(1000); - } catch (NoSuchAlgorithmException e) { - log.error(e); - return new ErrorResponse(1000); - } - } else { - log.fatal("Got unexpected STAL request: " + request); - return new ErrorResponse(1000); - } - } - - @Override - public boolean requireCard() { - return true; - } - - @Override - public String providePIN(PINSpec spec, int retries) { - if (retryCounter++ > 0) { - log.info("PIN wrong retrying ..."); - gui.showSignaturePINRetryDialog(spec, retries, this, "sign", this, - "cancel", this, "hashData"); - } else { - gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, - "hashData"); - } - do { - waitForAction(); - if (actionCommand.equals("cancel")) { - return null; - } else if (actionCommand.equals("hashData")) { - // FIXME provide hashdata input - gui.showHashDataInputDialog(null, this, "ok"); - } else if (actionCommand.equals("sign")) { - return new String(gui.getPin()); - } else if (actionCommand.equals("ok")) { - gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, - "hashData"); - } - } while (true); - } - - @Override - public SMCCSTALRequestHandler newInstance() { - return new SignRequestHandler(); - } -} + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.smccstal; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; +import at.gv.egiz.stal.SignResponse; +import at.gv.egiz.stal.signedinfo.ObjectFactory; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import at.gv.egiz.stal.util.JCEAlgorithmNames; +import java.util.ArrayList; +import java.util.List; + +/** + * This class is NOT thread-safe. + * handleRequest() sets the SignedInfo which is used in providePIN. + */ +public class SignRequestHandler extends AbstractRequestHandler implements + PINProvider { + + private static Log log = LogFactory.getLog(SignRequestHandler.class); + private static JAXBContext jaxbContext; + + + static { + try { + jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName()); + } catch (JAXBException e) { + log.fatal("Cannot init jaxbContext", e); + } + } + /** the SignedInfo of the current SignRequest */ + protected SignedInfoType signedInfo; + protected List hashDataInputs; + + private int retryCounter = 0; + + @SuppressWarnings("unchecked") + @Override + public STALResponse handleRequest(STALRequest request) { + if (request instanceof SignRequest) { + SignRequest signReq = (SignRequest) request; + newSTALMessage("Message.RequestCaption", "Message.SignRequest"); + try { + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + InputStream is = new ByteArrayInputStream(signReq.getSignedInfo()); + JAXBElement si = (JAXBElement) unmarshaller.unmarshal(is); + signedInfo = si.getValue(); + String signatureMethod = signedInfo.getSignatureMethod().getAlgorithm(); + log.debug("Found signature method: " + signatureMethod); + String jceName = JCEAlgorithmNames.getJCEHashName(signatureMethod); + if (jceName == null) { + log.error("Hash algorithm not supported:"); + return new ErrorResponse(1000); + } + MessageDigest md = MessageDigest.getInstance(jceName); + md.update(signReq.getSignedInfo()); + KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq.getKeyIdentifier()); + byte[] resp = card.createSignature(md.digest(), kb, this); + if (resp == null) { + return new ErrorResponse(6001); + } + SignResponse stalResp = new SignResponse(); + stalResp.setSignatureValue(resp); + return stalResp; + } catch (CancelledException cx) { + log.debug("User cancelled request"); + return new ErrorResponse(6001); + } catch (SignatureCardException e) { + log.error("Error while creating signature: " + e); + return new ErrorResponse(4000); + } catch (JAXBException e) { + log.error("Cannot unmarshall signed info", e); + return new ErrorResponse(1000); + } catch (NoSuchAlgorithmException e) { + log.error(e); + return new ErrorResponse(1000); + } finally { + signedInfo = null; + } + } else { + log.fatal("Got unexpected STAL request: " + request); + return new ErrorResponse(1000); + } + } + + @Override + public boolean requireCard() { + return true; + } + + @Override + public String providePIN(PINSpec spec, int retries) { + if (retryCounter++ > 0) { + log.info("PIN wrong retrying ..."); + gui.showSignaturePINRetryDialog(spec, retries, this, "sign", this, + "cancel", this, "hashData"); + } else { + gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, + "hashData"); + } + do { + waitForAction(); + if (actionCommand.equals("cancel")) { + return null; + } else if (actionCommand.equals("hashData")) { + if (signedInfo != null) { + try { + gui.showWaitDialog(null); + if (hashDataInputs == null) { + hashDataInputs = getHashDataInputs(signedInfo.getReference()); + } + gui.showHashDataInputDialog(hashDataInputs, this, "ok"); + waitForAction(); + gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, + "hashData"); + } catch (Exception ex) { + //FIXME localize messages + log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); + gui.showErrorDialog("Failed to obtain HashDataInputs: " + ex.getMessage(), this, "ok"); + } + } else { + //FIXME get all hashdatainputs + gui.showErrorDialog("Failed to obtain HashDataInputs: No dsig:SignedInfo provided.", this, "ok"); + } + } else if (actionCommand.equals("sign")) { + return new String(gui.getPin()); + } else if (actionCommand.equals("ok")) { + gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, + "hashData"); + } + } while (true); + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return new SignRequestHandler(); + } + + /** + * override by subclass + * @return + */ + protected List getHashDataInputs(List signedReferences) throws Exception { + //TODO + log.warn("Return empty HashDataInput"); + return new ArrayList(); + } +} -- cgit v1.2.3 From d3698ed2a4f129e5af970f072bc79bb8226d7765 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 5 Sep 2008 15:41:19 +0000 Subject: Text HashDataInput git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@24 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 2fe77c5d..1f84300a 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -146,7 +146,7 @@ public class SignRequestHandler extends AbstractRequestHandler implements if (signedInfo != null) { try { gui.showWaitDialog(null); - if (hashDataInputs == null) { + if (hashDataInputs == null || hashDataInputs.size() == 0) { hashDataInputs = getHashDataInputs(signedInfo.getReference()); } gui.showHashDataInputDialog(hashDataInputs, this, "ok"); -- cgit v1.2.3 From 3794536434fdbb06067eddcfd248898ce85f85a1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 12 Sep 2008 13:06:34 +0000 Subject: gui 0.2 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@34 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 1f84300a..d37d0551 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -47,6 +47,8 @@ import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.ReferenceType; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -150,9 +152,6 @@ public class SignRequestHandler extends AbstractRequestHandler implements hashDataInputs = getHashDataInputs(signedInfo.getReference()); } gui.showHashDataInputDialog(hashDataInputs, this, "ok"); - waitForAction(); - gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, - "hashData"); } catch (Exception ex) { //FIXME localize messages log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); @@ -178,6 +177,7 @@ public class SignRequestHandler extends AbstractRequestHandler implements /** * override by subclass + * @post-condition returned list != null * @return */ protected List getHashDataInputs(List signedReferences) throws Exception { -- cgit v1.2.3 From cf82096145bbdd548e388c1bc25f0e703b9b4624 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 17 Sep 2008 17:17:10 +0000 Subject: hashdatainput digest verification git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@44 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 2 +- .../bku/smccstal/CashedHashDataInputResolver.java | 27 ++ .../gv/egiz/bku/smccstal/SignRequestHandler.java | 273 ++++++++++++++++----- 3 files changed, 240 insertions(+), 62 deletions(-) create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/CashedHashDataInputResolver.java (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 56c8340b..ac2b725c 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -45,7 +45,7 @@ public abstract class AbstractSMCCSTAL implements STAL { static { addRequestHandler(InfoboxReadRequest.class, new InfoBoxReadRequestHandler()); - addRequestHandler(SignRequest.class, new SignRequestHandler()); +// addRequestHandler(SignRequest.class, new SignRequestHandler()); } /** diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/CashedHashDataInputResolver.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/CashedHashDataInputResolver.java new file mode 100644 index 00000000..05af85d9 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/CashedHashDataInputResolver.java @@ -0,0 +1,27 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.smccstal; + +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.DigestException; +import java.util.List; +import java.util.Set; + +/** + * + * @author clemens + */ +public interface CashedHashDataInputResolver { + + /** + * implementations may verify the hashvalue + * @post-condition returned list != null + * @return + */ + List getCashedHashDataInputs(List signedReferences) throws DigestException, Exception; +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index d37d0551..59eed55f 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -21,8 +21,6 @@ import java.io.InputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; @@ -43,21 +41,26 @@ import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; import at.gv.egiz.stal.SignResponse; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.ReferenceType; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.security.DigestException; +import java.security.DigestInputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Set; /** * This class is NOT thread-safe. * handleRequest() sets the SignedInfo which is used in providePIN. */ -public class SignRequestHandler extends AbstractRequestHandler implements - PINProvider { +public abstract class SignRequestHandler extends AbstractRequestHandler implements + CashedHashDataInputResolver { private static Log log = LogFactory.getLog(SignRequestHandler.class); private static JAXBContext jaxbContext; @@ -71,10 +74,10 @@ public class SignRequestHandler extends AbstractRequestHandler implements } } /** the SignedInfo of the current SignRequest */ - protected SignedInfoType signedInfo; - protected List hashDataInputs; +// protected SignedInfoType signedInfo; +// protected List hashDataInputs; - private int retryCounter = 0; +// private int retryCounter = 0; @SuppressWarnings("unchecked") @Override @@ -86,8 +89,7 @@ public class SignRequestHandler extends AbstractRequestHandler implements Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); InputStream is = new ByteArrayInputStream(signReq.getSignedInfo()); JAXBElement si = (JAXBElement) unmarshaller.unmarshal(is); - signedInfo = si.getValue(); - String signatureMethod = signedInfo.getSignatureMethod().getAlgorithm(); + String signatureMethod = si.getValue().getSignatureMethod().getAlgorithm(); log.debug("Found signature method: " + signatureMethod); String jceName = JCEAlgorithmNames.getJCEHashName(signatureMethod); if (jceName == null) { @@ -97,7 +99,7 @@ public class SignRequestHandler extends AbstractRequestHandler implements MessageDigest md = MessageDigest.getInstance(jceName); md.update(signReq.getSignedInfo()); KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq.getKeyIdentifier()); - byte[] resp = card.createSignature(md.digest(), kb, this); + byte[] resp = card.createSignature(md.digest(), kb, new STALPinProvider(si.getValue())); if (resp == null) { return new ErrorResponse(6001); } @@ -116,9 +118,7 @@ public class SignRequestHandler extends AbstractRequestHandler implements } catch (NoSuchAlgorithmException e) { log.error(e); return new ErrorResponse(1000); - } finally { - signedInfo = null; - } + } } else { log.fatal("Got unexpected STAL request: " + request); return new ErrorResponse(1000); @@ -130,59 +130,210 @@ public class SignRequestHandler extends AbstractRequestHandler implements return true; } - @Override - public String providePIN(PINSpec spec, int retries) { - if (retryCounter++ > 0) { - log.info("PIN wrong retrying ..."); - gui.showSignaturePINRetryDialog(spec, retries, this, "sign", this, - "cancel", this, "hashData"); - } else { - gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, - "hashData"); - } - do { - waitForAction(); - if (actionCommand.equals("cancel")) { - return null; - } else if (actionCommand.equals("hashData")) { - if (signedInfo != null) { - try { - gui.showWaitDialog(null); - if (hashDataInputs == null || hashDataInputs.size() == 0) { - hashDataInputs = getHashDataInputs(signedInfo.getReference()); - } - gui.showHashDataInputDialog(hashDataInputs, this, "ok"); - } catch (Exception ex) { - //FIXME localize messages - log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); - gui.showErrorDialog("Failed to obtain HashDataInputs: " + ex.getMessage(), this, "ok"); - } - } else { - //FIXME get all hashdatainputs - gui.showErrorDialog("Failed to obtain HashDataInputs: No dsig:SignedInfo provided.", this, "ok"); - } - } else if (actionCommand.equals("sign")) { - return new String(gui.getPin()); - } else if (actionCommand.equals("ok")) { - gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, - "hashData"); - } - } while (true); - } +// @Override +// public String providePIN(PINSpec spec, int retries) { +// if (retryCounter++ > 0) { +// log.info("PIN wrong retrying ..."); +// gui.showSignaturePINRetryDialog(spec, retries, this, "sign", this, +// "cancel", this, "hashData"); +// } else { +// gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, +// "hashData"); +// } +// do { +// waitForAction(); +// if (actionCommand.equals("cancel")) { +// return null; +// } else if (actionCommand.equals("hashData")) { +// if (signedInfo != null) { +// try { +// gui.showWaitDialog(null); +// if (hashDataInputs == null || hashDataInputs.size() == 0) { +// HashMap signedReferences = new HashMap(); +// for (ReferenceType reference : signedInfo.getReference()) { +// //don't get Manifest, QualifyingProperties, ... +// if (reference.getType() == null) { +// signedReferences.put(reference.getId(), reference); +// } +// } +// hashDataInputs = getHashDataInputs(signedReferences.keySet()); +// for (HashDataInput hashDataInput : hashDataInputs) { +// ReferenceType reference = signedReferences.get(hashDataInput.getReferenceId()); +// String algorithm = reference.getDigestMethod().getAlgorithm(); +// MessageDigest md = MessageDigest.getInstance(algorithm); +// DigestInputStream dis = new DigestInputStream(hashDataInput.getHashDataInput(), md); +// while(dis.read() != -1) ; +// byte[] digestValue = md.digest(); +// boolean valid = reference.getDigestValue().equals(digestValue); +// } +// } +// gui.showHashDataInputDialog(hashDataInputs, this, "ok"); +// } catch (Exception ex) { +// //FIXME localize messages +// log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); +// gui.showErrorDialog("Failed to obtain HashDataInputs: " + ex.getMessage(), this, "ok"); +// } +// } else { +// //FIXME get all hashdatainputs +// gui.showErrorDialog("Failed to obtain HashDataInputs: No dsig:SignedInfo provided.", this, "ok"); +// } +// } else if (actionCommand.equals("sign")) { +// return new String(gui.getPin()); +// } else if (actionCommand.equals("ok")) { +// gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, +// "hashData"); +// } +// } while (true); +// } - @Override - public SMCCSTALRequestHandler newInstance() { - return new SignRequestHandler(); - } +// @Override +// public SMCCSTALRequestHandler newInstance() { +// return new SignRequestHandler(); +// } /** - * override by subclass + * implementations may verify the hashvalue * @post-condition returned list != null * @return */ - protected List getHashDataInputs(List signedReferences) throws Exception { - //TODO - log.warn("Return empty HashDataInput"); - return new ArrayList(); + @Override + public abstract List getCashedHashDataInputs(List signedReferences) throws Exception; +// { +// //TODO +// log.warn("Return empty HashDataInput"); +// return new ArrayList(); +// } + + + +// protected void validateHashDataInputs(List signedReferences, List hashDataInputs) { +// if (hashDataInputs != null) { +// +// Map hashDataIdMap = new HashMap(); +// for (HashDataInput hdi : hashDataInputs) { +// if (log.isTraceEnabled()) { +// log.trace("Provided HashDataInput for reference " + hdi.getReferenceId()); +// } +// hashDataIdMap.put(hdi.getReferenceId(), hdi); +// } +// +// List reqRefs = request.getReference(); +// for (GetHashDataInputType.Reference reqRef : reqRefs) { +// String reqRefId = reqRef.getID(); +// HashDataInput reqHdi = hashDataIdMap.get(reqRefId); +// if (reqHdi == null) { +// String msg = "Failed to resolve HashDataInput for reference " + reqRefId; +// log.error(msg); +// GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); +// faultInfo.setErrorCode(1); +// faultInfo.setErrorMessage(msg); +// throw new GetHashDataInputFault(msg, faultInfo); +// } +// +// InputStream hashDataIS = reqHdi.getHashDataInput(); +// if (hashDataIS == null) { +// //HashDataInput not cached? +// String msg = "Failed to obtain HashDataInput for reference " + reqRefId + ", reference not cached"; +// log.error(msg); +// GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); +// faultInfo.setErrorCode(1); +// faultInfo.setErrorMessage(msg); +// throw new GetHashDataInputFault(msg, faultInfo); +// } +// ByteArrayOutputStream baos = null; +// try { +// if (log.isDebugEnabled()) { +// log.debug("Resolved HashDataInput " + reqRefId + " (" + reqHdi.getMimeType() + ";charset=" + reqHdi.getEncoding() + ")"); +// } +// baos = new ByteArrayOutputStream(hashDataIS.available()); +// int c; +// while ((c = hashDataIS.read()) != -1) { +// baos.write(c); +// } +// GetHashDataInputResponseType.Reference ref = new GetHashDataInputResponseType.Reference(); +// ref.setID(reqRefId); +// ref.setMimeType(reqHdi.getMimeType()); +// ref.setEncoding(reqHdi.getEncoding()); +// ref.setValue(baos.toByteArray()); +// response.getReference().add(ref); +// } catch (IOException ex) { +// String msg = "Failed to get HashDataInput for reference " + reqRefId; +// log.error(msg, ex); +// GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); +// faultInfo.setErrorCode(1); +// faultInfo.setErrorMessage(msg); +// throw new GetHashDataInputFault(msg, faultInfo, ex); +// } finally { +// try { +// baos.close(); +// } catch (IOException ex) { +// } +// } +// } +// return response; +// } +// for (ReferenceType reference : signedReferences) { +// String algorithm = reference.getDigestMethod().getAlgorithm(); +// +// } +// } + + + /** + * cashes the HashDataInputs provided by SignRequestHandler.this.getHashDataInputs() + * (don't know whether outer class is LocalSignRequestHandler or WSSignRequestHandler, providing DataObjectHDI or ByteArrayHDI, resp) + */ + class STALPinProvider implements PINProvider { + + protected SignedInfoType signedInfo; + protected List hashDataInputs; + private int retryCounter = 0; + + public STALPinProvider(SignedInfoType signedInfo) { + this.signedInfo = signedInfo; + } + + @Override + public String providePIN(PINSpec spec, int retries) { + if (retryCounter++ > 0) { + log.info("PIN wrong retrying ..."); + gui.showSignaturePINRetryDialog(spec, retries, SignRequestHandler.this, "sign", SignRequestHandler.this, + "cancel", SignRequestHandler.this, "hashData"); + } else { + gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, + "hashData"); } + do { + waitForAction(); + if (actionCommand.equals("cancel")) { + return null; + } else if (actionCommand.equals("hashData")) { + if (signedInfo != null) { + try { + gui.showWaitDialog(null); + if (hashDataInputs == null || hashDataInputs.size() == 0) { + hashDataInputs = getCashedHashDataInputs(signedInfo.getReference()); + } + gui.showHashDataInputDialog(hashDataInputs, SignRequestHandler.this, "ok"); + } catch (DigestException ex) { + log.error("Bad digest value: " + ex.getMessage()); + gui.showErrorDialog(ex.getMessage()); + } catch (Exception ex) { + //FIXME localize messages + log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); + gui.showErrorDialog("Failed to obtain HashDataInputs: " + ex.getMessage(), SignRequestHandler.this, "ok"); + } + } else { + //FIXME get all hashdatainputs + gui.showErrorDialog("Failed to obtain HashDataInputs: No dsig:SignedInfo provided.", SignRequestHandler.this, "ok"); + } + } else if (actionCommand.equals("sign")) { + return new String(gui.getPin()); + } else if (actionCommand.equals("ok")) { + gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, + "hashData"); + } + } while (true); + } + } } -- cgit v1.2.3 From 1c4df47223a6d655b9fb7f46f807171ceda07ba7 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 23 Sep 2008 12:09:10 +0000 Subject: bitte warten... git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@56 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../bku/smccstal/InfoBoxReadRequestHandler.java | 249 +++++++++++---------- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 1 + 2 files changed, 126 insertions(+), 124 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index 7dc2e202..25085b16 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -14,127 +14,128 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.smccstal; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.PINSpec; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.smcc.SignatureCardException; -import at.gv.egiz.stal.ErrorResponse; -import at.gv.egiz.stal.InfoboxReadRequest; -import at.gv.egiz.stal.InfoboxReadResponse; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; - -public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements - PINProvider { - - private static Log log = LogFactory.getLog(InfoBoxReadRequestHandler.class); - - private int retryCounter = 0; - - @Override - public STALResponse handleRequest(STALRequest request) { - if (request instanceof InfoboxReadRequest) { - InfoboxReadRequest infoBox = (InfoboxReadRequest) request; - try { - if (infoBox.getInfoboxIdentifier().equals("IdentityLink")) { - newSTALMessage("Message.RequestCaption", "Message.IdentityLink"); - log.debug("Handling identitylink infobox"); - byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, - infoBox.getDomainIdentifier()); - if (resp == null) { - log.info("Got null as result->user cancelled"); - return new ErrorResponse(6001); - } else { - try { - resp = DomainIdConverter.convertDomainId(resp, infoBox - .getDomainIdentifier()); - } catch (Exception e) { - log.error("Cannot convert domain specific id", e); - return new ErrorResponse(1000); - } - } - InfoboxReadResponse stalResp = new InfoboxReadResponse(); - stalResp.setInfoboxValue(resp); - return stalResp; - } else if (SignatureCard.KeyboxName.CERITIFIED_KEYPAIR.equals(infoBox - .getInfoboxIdentifier())) { - newSTALMessage("Message.RequestCaption", "Message.CertifiedKeypair"); - log.debug("Handling certified keypair infobox"); - byte[] resp = card - .getCertificate(SignatureCard.KeyboxName.CERITIFIED_KEYPAIR); - if (resp == null) { - return new ErrorResponse(6001); - } - InfoboxReadResponse stalResp = new InfoboxReadResponse(); - stalResp.setInfoboxValue(resp); - return stalResp; - } else if (SignatureCard.KeyboxName.SECURE_SIGNATURE_KEYPAIR - .equals(infoBox.getInfoboxIdentifier())) { - newSTALMessage("Message.RequestCaption", - "Message.SecureSignatureKeypair"); - log.debug("Handling secure signature keypair infobox"); - byte[] resp = card - .getCertificate(SignatureCard.KeyboxName.SECURE_SIGNATURE_KEYPAIR); - if (resp == null) { - return new ErrorResponse(6001); - } - InfoboxReadResponse stalResp = new InfoboxReadResponse(); - stalResp.setInfoboxValue(resp); - return stalResp; - } else { - newSTALMessage("Message.RequestCaption", "Message.InfoboxReadRequest"); - log.warn("Unknown infobox identifier: " - + infoBox.getInfoboxIdentifier() + " trying generic request"); - byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, - infoBox.getDomainIdentifier()); - if (resp == null) { - return new ErrorResponse(6001); - } - InfoboxReadResponse stalResp = new InfoboxReadResponse(); - stalResp.setInfoboxValue(resp); - return stalResp; - } - } catch (CancelledException cx) { - log.debug("User cancelled request", cx); - return new ErrorResponse(6001); - } catch (SignatureCardException e) { - log.info("Error while reading infobox: " + e); - return new ErrorResponse(4000); - } - } else { - log.fatal("Got unexpected STAL request: " + request); - return new ErrorResponse(1000); - } - } - - @Override - public boolean requireCard() { - return true; - } - - @Override - public String providePIN(PINSpec spec, int retries) { - if (retryCounter++ > 0) { - log.info("PIN wrong retrying ..."); - gui.showCardPINRetryDialog(spec, retries, this, "ok", this, "cancel"); - } else { - gui.showCardPINDialog(spec, this, "ok", this, "cancel"); - } - waitForAction(); - if (actionCommand.equals("cancel")) { - return null; - } - return new String(gui.getPin()); - } - - @Override - public SMCCSTALRequestHandler newInstance() { - return new InfoBoxReadRequestHandler(); - } -} +package at.gv.egiz.bku.smccstal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.InfoboxReadRequest; +import at.gv.egiz.stal.InfoboxReadResponse; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements + PINProvider { + + private static Log log = LogFactory.getLog(InfoBoxReadRequestHandler.class); + + private int retryCounter = 0; + + @Override + public STALResponse handleRequest(STALRequest request) { + if (request instanceof InfoboxReadRequest) { + InfoboxReadRequest infoBox = (InfoboxReadRequest) request; + try { + if (infoBox.getInfoboxIdentifier().equals("IdentityLink")) { + newSTALMessage("Message.RequestCaption", "Message.IdentityLink"); + log.debug("Handling identitylink infobox"); + byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, + infoBox.getDomainIdentifier()); + if (resp == null) { + log.info("Got null as result->user cancelled"); + return new ErrorResponse(6001); + } else { + try { + resp = DomainIdConverter.convertDomainId(resp, infoBox + .getDomainIdentifier()); + } catch (Exception e) { + log.error("Cannot convert domain specific id", e); + return new ErrorResponse(1000); + } + } + InfoboxReadResponse stalResp = new InfoboxReadResponse(); + stalResp.setInfoboxValue(resp); + return stalResp; + } else if (SignatureCard.KeyboxName.CERITIFIED_KEYPAIR.equals(infoBox + .getInfoboxIdentifier())) { + newSTALMessage("Message.RequestCaption", "Message.CertifiedKeypair"); + log.debug("Handling certified keypair infobox"); + byte[] resp = card + .getCertificate(SignatureCard.KeyboxName.CERITIFIED_KEYPAIR); + if (resp == null) { + return new ErrorResponse(6001); + } + InfoboxReadResponse stalResp = new InfoboxReadResponse(); + stalResp.setInfoboxValue(resp); + return stalResp; + } else if (SignatureCard.KeyboxName.SECURE_SIGNATURE_KEYPAIR + .equals(infoBox.getInfoboxIdentifier())) { + newSTALMessage("Message.RequestCaption", + "Message.SecureSignatureKeypair"); + log.debug("Handling secure signature keypair infobox"); + byte[] resp = card + .getCertificate(SignatureCard.KeyboxName.SECURE_SIGNATURE_KEYPAIR); + if (resp == null) { + return new ErrorResponse(6001); + } + InfoboxReadResponse stalResp = new InfoboxReadResponse(); + stalResp.setInfoboxValue(resp); + return stalResp; + } else { + newSTALMessage("Message.RequestCaption", "Message.InfoboxReadRequest"); + log.warn("Unknown infobox identifier: " + + infoBox.getInfoboxIdentifier() + " trying generic request"); + byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, + infoBox.getDomainIdentifier()); + if (resp == null) { + return new ErrorResponse(6001); + } + InfoboxReadResponse stalResp = new InfoboxReadResponse(); + stalResp.setInfoboxValue(resp); + return stalResp; + } + } catch (CancelledException cx) { + log.debug("User cancelled request", cx); + return new ErrorResponse(6001); + } catch (SignatureCardException e) { + log.info("Error while reading infobox: " + e); + return new ErrorResponse(4000); + } + } else { + log.fatal("Got unexpected STAL request: " + request); + return new ErrorResponse(1000); + } + } + + @Override + public boolean requireCard() { + return true; + } + + @Override + public String providePIN(PINSpec spec, int retries) { + if (retryCounter++ > 0) { + log.info("PIN wrong retrying ..."); + gui.showCardPINRetryDialog(spec, retries, this, "ok", this, "cancel"); + } else { + gui.showCardPINDialog(spec, this, "ok", this, "cancel"); + } + waitForAction(); + gui.showWaitDialog(null); + if (actionCommand.equals("cancel")) { + return null; + } + return new String(gui.getPin()); + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return new InfoBoxReadRequestHandler(); + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 59eed55f..8f380eec 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -305,6 +305,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen } do { waitForAction(); + gui.showWaitDialog(null); if (actionCommand.equals("cancel")) { return null; } else if (actionCommand.equals("hashData")) { -- cgit v1.2.3 From 03f5ae9e9068168b294c042d68a58637e71a54ee Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 23 Sep 2008 14:09:02 +0000 Subject: bitte warten... git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@59 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 8f380eec..0b297283 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -311,7 +311,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen } else if (actionCommand.equals("hashData")) { if (signedInfo != null) { try { - gui.showWaitDialog(null); +// gui.showWaitDialog(null); if (hashDataInputs == null || hashDataInputs.size() == 0) { hashDataInputs = getCashedHashDataInputs(signedInfo.getReference()); } -- cgit v1.2.3 From 013d98da75991857ea6e243e7360745d8d7d9048 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 24 Sep 2008 13:09:47 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@63 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index ac2b725c..f3b94078 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -39,7 +39,7 @@ public abstract class AbstractSMCCSTAL implements STAL { private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); protected Locale locale = Locale.getDefault(); - protected SMCCHelper smccHelper = new SMCCHelper(); +// protected SMCCHelper smccHelper = new SMCCHelper(); protected SignatureCard signatureCard = null; protected static Map handlerMap = new HashMap(); -- cgit v1.2.3 From d0879e9058943c6afa1912ccbeae936db2811f26 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 30 Sep 2008 13:54:54 +0000 Subject: backport to JAXWS2.0 STALService initial connect() git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@76 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index f3b94078..8ee70f1a 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -65,7 +65,7 @@ public abstract class AbstractSMCCSTAL implements STAL { List responseList = new ArrayList(requestList .size()); for (STALRequest request : requestList) { - log.info("Processing: " + request); + log.info("Processing: " + request.getClass()); SMCCSTALRequestHandler handler = null; handler = handlerMap.get(request.getClass().getSimpleName()); if (handler != null) { @@ -78,7 +78,10 @@ public abstract class AbstractSMCCSTAL implements STAL { try { handler = handler.newInstance(); handler.init(signatureCard, getGUI()); - responseList.add(handler.handleRequest(request)); + STALResponse response = handler.handleRequest(request); + if (response != null) { + responseList.add(response); + } } catch (Exception e) { log.info("Error while handling STAL request:" + e); responseList.add(new ErrorResponse(6000)); -- cgit v1.2.3 From 8ccd9ab69dc74762567930f4c576a359502f1071 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 30 Sep 2008 16:37:59 +0000 Subject: showErrorDialog l10n git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@77 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 0b297283..7d994392 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.smccstal; +import at.gv.egiz.bku.gui.BKUGUIFacade; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security.MessageDigest; @@ -318,15 +319,15 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen gui.showHashDataInputDialog(hashDataInputs, SignRequestHandler.this, "ok"); } catch (DigestException ex) { log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}); } catch (Exception ex) { //FIXME localize messages log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); - gui.showErrorDialog("Failed to obtain HashDataInputs: " + ex.getMessage(), SignRequestHandler.this, "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "ok"); } } else { //FIXME get all hashdatainputs - gui.showErrorDialog("Failed to obtain HashDataInputs: No dsig:SignedInfo provided.", SignRequestHandler.this, "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {"No dsig:SignedInfo provided"}, SignRequestHandler.this, "ok"); } } else if (actionCommand.equals("sign")) { return new String(gui.getPin()); -- cgit v1.2.3 From 144c0133dcb107b30799a310ba51460d6479358d Mon Sep 17 00:00:00 2001 From: wbauer Date: Thu, 9 Oct 2008 13:14:45 +0000 Subject: Added an smcc retry function to make smartcard access more robust. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@89 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 111 +++++++++++++-------- 1 file changed, 72 insertions(+), 39 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 8ee70f1a..c453e06e 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -1,19 +1,19 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package at.gv.egiz.bku.smccstal; import java.util.ArrayList; @@ -37,15 +37,19 @@ import at.gv.egiz.stal.SignRequest; public abstract class AbstractSMCCSTAL implements STAL { private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); + + public final static int DEFAULT_MAX_RETRIES = 3; protected Locale locale = Locale.getDefault(); -// protected SMCCHelper smccHelper = new SMCCHelper(); + // protected SMCCHelper smccHelper = new SMCCHelper(); protected SignatureCard signatureCard = null; protected static Map handlerMap = new HashMap(); + + protected int maxRetries = DEFAULT_MAX_RETRIES; static { addRequestHandler(InfoboxReadRequest.class, new InfoBoxReadRequestHandler()); -// addRequestHandler(SignRequest.class, new SignRequestHandler()); + // addRequestHandler(SignRequest.class, new SignRequestHandler()); } /** @@ -58,37 +62,61 @@ public abstract class AbstractSMCCSTAL implements STAL { protected abstract BKUGUIFacade getGUI(); @Override - public List handleRequest( - List requestList) { + public List handleRequest(List requestList) { log.debug("Got request list containing " + requestList.size() + " STAL requests"); List responseList = new ArrayList(requestList .size()); + for (STALRequest request : requestList) { log.info("Processing: " + request.getClass()); - SMCCSTALRequestHandler handler = null; - handler = handlerMap.get(request.getClass().getSimpleName()); - if (handler != null) { - if (handler.requireCard()) { - if (waitForCard()) { - responseList.add(new ErrorResponse(6001)); - break; + int retryCounter = 0; + while (retryCounter < maxRetries) { + log.info("Number of retries: "+retryCounter); + SMCCSTALRequestHandler handler = null; + handler = handlerMap.get(request.getClass().getSimpleName()); + if (handler != null) { + if (handler.requireCard()) { + if (waitForCard()) { + responseList.add(new ErrorResponse(6001)); + break; + } } - } - try { - handler = handler.newInstance(); - handler.init(signatureCard, getGUI()); - STALResponse response = handler.handleRequest(request); - if (response != null) { - responseList.add(response); + try { + handler = handler.newInstance(); + handler.init(signatureCard, getGUI()); + STALResponse response = handler.handleRequest(request); + if (response != null) { + if (response instanceof ErrorResponse) { + log.info("Got an error response"); + if (++retryCounter < maxRetries) { + log.info("Retrying"); + signatureCard = null; + } else { + responseList.add(response); + } + } else { + responseList.add(response); + retryCounter = Integer.MAX_VALUE; + break; + } + } else { + log.info("Got null response from handler, assuming quit"); + retryCounter = Integer.MAX_VALUE; + } + } catch (Exception e) { + log.info("Error while handling STAL request:" + e); + if (++retryCounter < maxRetries) { + log.info("Retrying"); + signatureCard = null; + } else { + responseList.add(new ErrorResponse(6000)); + } } - } catch (Exception e) { - log.info("Error while handling STAL request:" + e); - responseList.add(new ErrorResponse(6000)); + } else { + log.error("Cannot find a handler for STAL request: " + request); + responseList.add(new ErrorResponse()); } - } else { - log.error("Cannot find a handler for STAL request: " + request); - responseList.add(new ErrorResponse()); } } return responseList; @@ -112,4 +140,9 @@ public abstract class AbstractSMCCSTAL implements STAL { } this.locale = locale; } + + public void setMaxRetries(int maxRetries) { + this.maxRetries = maxRetries; + } + } -- cgit v1.2.3 From 378f735d14a1f21571a3c3d5d4ae7eab02c5cf3c Mon Sep 17 00:00:00 2001 From: wbauer Date: Fri, 10 Oct 2008 09:12:46 +0000 Subject: added a reset command git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@97 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index c453e06e..9e47aeb8 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -91,6 +91,7 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Got an error response"); if (++retryCounter < maxRetries) { log.info("Retrying"); + signatureCard.reset(); signatureCard = null; } else { responseList.add(response); @@ -108,6 +109,7 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Error while handling STAL request:" + e); if (++retryCounter < maxRetries) { log.info("Retrying"); + signatureCard.reset(); signatureCard = null; } else { responseList.add(new ErrorResponse(6000)); -- cgit v1.2.3 From 8852be703a5cacaf271575ccee04bbe27612d16b Mon Sep 17 00:00:00 2001 From: wbauer Date: Fri, 10 Oct 2008 12:35:07 +0000 Subject: Improved Quit Handling for multiple applet instances git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@101 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 9e47aeb8..b7697db1 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -91,7 +91,7 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Got an error response"); if (++retryCounter < maxRetries) { log.info("Retrying"); - signatureCard.reset(); + signatureCard.disconnect(true); signatureCard = null; } else { responseList.add(response); @@ -109,7 +109,7 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Error while handling STAL request:" + e); if (++retryCounter < maxRetries) { log.info("Retrying"); - signatureCard.reset(); + signatureCard.disconnect(true); signatureCard = null; } else { responseList.add(new ErrorResponse(6000)); -- cgit v1.2.3 From 255269ab17404fa1249c257e88815cbbee6e0d0f Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 12:53:57 +0000 Subject: ExternalDisplaySignRequestHandler git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@105 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../bku/smccstal/CashedHashDataInputResolver.java | 27 --- .../gv/egiz/bku/smccstal/HashDataInputDisplay.java | 30 ++++ .../gv/egiz/bku/smccstal/SignRequestHandler.java | 186 ++++++--------------- 3 files changed, 82 insertions(+), 161 deletions(-) delete mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/CashedHashDataInputResolver.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/CashedHashDataInputResolver.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/CashedHashDataInputResolver.java deleted file mode 100644 index 05af85d9..00000000 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/CashedHashDataInputResolver.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package at.gv.egiz.bku.smccstal; - -import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; -import at.gv.egiz.stal.signedinfo.ReferenceType; -import java.security.DigestException; -import java.util.List; -import java.util.Set; - -/** - * - * @author clemens - */ -public interface CashedHashDataInputResolver { - - /** - * implementations may verify the hashvalue - * @post-condition returned list != null - * @return - */ - List getCashedHashDataInputs(List signedReferences) throws DigestException, Exception; -} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java new file mode 100644 index 00000000..f79a2027 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java @@ -0,0 +1,30 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.smccstal; + +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.DigestException; +import java.util.List; + +/** + * + * @author clemens + */ +public interface HashDataInputDisplay { + + /** + * Displays the hashdata inputs for all provided dsig:SignedReferences. + * Implementations may verify the digest value if necessary. + * (LocalSignRequestHandler operates on DataObjectHashDataInput, + * other SignRequestHandlers should cache the HashDataInputs obtained by webservice calls, + * or simply forward to a HashDataInputServlet.) + * @param signedReferences The caller may select a subset of the references in SignedInfo to be displayed. + * @throws java.security.DigestException if digest values are verified and do not correspond + * (or any other digest computation error occurs) + * @throws java.lang.Exception + */ + void displayHashDataInputs(List signedReferences) throws DigestException, Exception; + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 7d994392..dcd12b02 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -17,6 +17,7 @@ package at.gv.egiz.bku.smccstal; import at.gv.egiz.bku.gui.BKUGUIFacade; +import java.awt.event.ActionEvent; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security.MessageDigest; @@ -42,31 +43,18 @@ import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; import at.gv.egiz.stal.SignResponse; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import at.gv.egiz.stal.signedinfo.ObjectFactory; -import at.gv.egiz.stal.signedinfo.ReferenceType; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import java.awt.event.ActionListener; import java.security.DigestException; -import java.security.DigestInputStream; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Set; -/** - * This class is NOT thread-safe. - * handleRequest() sets the SignedInfo which is used in providePIN. - */ -public abstract class SignRequestHandler extends AbstractRequestHandler implements - CashedHashDataInputResolver { +public abstract class SignRequestHandler extends AbstractRequestHandler implements HashDataInputDisplay { private static Log log = LogFactory.getLog(SignRequestHandler.class); private static JAXBContext jaxbContext; - static { try { jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName()); @@ -74,11 +62,6 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen log.fatal("Cannot init jaxbContext", e); } } - /** the SignedInfo of the current SignRequest */ -// protected SignedInfoType signedInfo; -// protected List hashDataInputs; - -// private int retryCounter = 0; @SuppressWarnings("unchecked") @Override @@ -192,99 +175,10 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen // return new SignRequestHandler(); // } - /** - * implementations may verify the hashvalue - * @post-condition returned list != null - * @return - */ - @Override - public abstract List getCashedHashDataInputs(List signedReferences) throws Exception; -// { -// //TODO -// log.warn("Return empty HashDataInput"); -// return new ArrayList(); -// } - + -// protected void validateHashDataInputs(List signedReferences, List hashDataInputs) { -// if (hashDataInputs != null) { -// -// Map hashDataIdMap = new HashMap(); -// for (HashDataInput hdi : hashDataInputs) { -// if (log.isTraceEnabled()) { -// log.trace("Provided HashDataInput for reference " + hdi.getReferenceId()); -// } -// hashDataIdMap.put(hdi.getReferenceId(), hdi); -// } -// -// List reqRefs = request.getReference(); -// for (GetHashDataInputType.Reference reqRef : reqRefs) { -// String reqRefId = reqRef.getID(); -// HashDataInput reqHdi = hashDataIdMap.get(reqRefId); -// if (reqHdi == null) { -// String msg = "Failed to resolve HashDataInput for reference " + reqRefId; -// log.error(msg); -// GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); -// faultInfo.setErrorCode(1); -// faultInfo.setErrorMessage(msg); -// throw new GetHashDataInputFault(msg, faultInfo); -// } -// -// InputStream hashDataIS = reqHdi.getHashDataInput(); -// if (hashDataIS == null) { -// //HashDataInput not cached? -// String msg = "Failed to obtain HashDataInput for reference " + reqRefId + ", reference not cached"; -// log.error(msg); -// GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); -// faultInfo.setErrorCode(1); -// faultInfo.setErrorMessage(msg); -// throw new GetHashDataInputFault(msg, faultInfo); -// } -// ByteArrayOutputStream baos = null; -// try { -// if (log.isDebugEnabled()) { -// log.debug("Resolved HashDataInput " + reqRefId + " (" + reqHdi.getMimeType() + ";charset=" + reqHdi.getEncoding() + ")"); -// } -// baos = new ByteArrayOutputStream(hashDataIS.available()); -// int c; -// while ((c = hashDataIS.read()) != -1) { -// baos.write(c); -// } -// GetHashDataInputResponseType.Reference ref = new GetHashDataInputResponseType.Reference(); -// ref.setID(reqRefId); -// ref.setMimeType(reqHdi.getMimeType()); -// ref.setEncoding(reqHdi.getEncoding()); -// ref.setValue(baos.toByteArray()); -// response.getReference().add(ref); -// } catch (IOException ex) { -// String msg = "Failed to get HashDataInput for reference " + reqRefId; -// log.error(msg, ex); -// GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); -// faultInfo.setErrorCode(1); -// faultInfo.setErrorMessage(msg); -// throw new GetHashDataInputFault(msg, faultInfo, ex); -// } finally { -// try { -// baos.close(); -// } catch (IOException ex) { -// } -// } -// } -// return response; -// } -// for (ReferenceType reference : signedReferences) { -// String algorithm = reference.getDigestMethod().getAlgorithm(); -// -// } -// } - - - /** - * cashes the HashDataInputs provided by SignRequestHandler.this.getHashDataInputs() - * (don't know whether outer class is LocalSignRequestHandler or WSSignRequestHandler, providing DataObjectHDI or ByteArrayHDI, resp) - */ - class STALPinProvider implements PINProvider { + class STALPinProvider implements PINProvider, ActionListener { protected SignedInfoType signedInfo; protected List hashDataInputs; @@ -293,49 +187,73 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen public STALPinProvider(SignedInfoType signedInfo) { this.signedInfo = signedInfo; } + + private void showSignaturePINDialog(PINSpec spec, int retries) { + if (retryCounter > 0) { + gui.showSignaturePINRetryDialog(spec, retries, SignRequestHandler.this, "sign", SignRequestHandler.this, + "cancel", SignRequestHandler.this, "hashData"); + } else { + gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, + "hashData"); + } + } @Override public String providePIN(PINSpec spec, int retries) { - if (retryCounter++ > 0) { - log.info("PIN wrong retrying ..."); - gui.showSignaturePINRetryDialog(spec, retries, SignRequestHandler.this, "sign", SignRequestHandler.this, - "cancel", SignRequestHandler.this, "hashData"); - } else { - gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, - "hashData"); - } + + showSignaturePINDialog(spec, retries); + do { waitForAction(); gui.showWaitDialog(null); if (actionCommand.equals("cancel")) { return null; } else if (actionCommand.equals("hashData")) { - if (signedInfo != null) { + + showSignaturePINDialog(spec, retries); + try { -// gui.showWaitDialog(null); - if (hashDataInputs == null || hashDataInputs.size() == 0) { - hashDataInputs = getCashedHashDataInputs(signedInfo.getReference()); - } - gui.showHashDataInputDialog(hashDataInputs, SignRequestHandler.this, "ok"); + displayHashDataInputs(signedInfo.getReference()); } catch (DigestException ex) { log.error("Bad digest value: " + ex.getMessage()); gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}); } catch (Exception ex) { - //FIXME localize messages - log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "ok"); + log.error("Could not display hashdata inputs: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "ok"); } - } else { - //FIXME get all hashdatainputs - gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {"No dsig:SignedInfo provided"}, SignRequestHandler.this, "ok"); - } + + // OLD HASHDATA DISPLAY (in applet), + // register SignRequestHandler.this as hashdataListener to use +// if (signedInfo != null) { +// try { +// if (hashDataInputs == null || hashDataInputs.size() == 0) { +// hashDataInputs = getCashedHashDataInputs(signedInfo.getReference()); +// } +// gui.showHashDataInputDialog(hashDataInputs, SignRequestHandler.this, "ok"); +// } catch (DigestException ex) { +// log.error("Bad digest value: " + ex.getMessage()); +// gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}); +// } catch (Exception ex) { +// //FIXME localize messages +// log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); +// gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "ok"); +// } +// } else { +// //FIXME get all hashdatainputs +// gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {"No dsig:SignedInfo provided"}, SignRequestHandler.this, "ok"); +// } } else if (actionCommand.equals("sign")) { + retryCounter++; return new String(gui.getPin()); } else if (actionCommand.equals("ok")) { - gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, - "hashData"); + showSignaturePINDialog(spec, retries); } } while (true); } + + @Override + public void actionPerformed(ActionEvent e) { + throw new UnsupportedOperationException("Not supported yet."); + } } } -- cgit v1.2.3 From 70b917ae4b8aece8652dc076e0e1b127a89f5086 Mon Sep 17 00:00:00 2001 From: wbauer Date: Mon, 13 Oct 2008 14:51:56 +0000 Subject: not retrying smcc commands when canceled by user via gui git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@108 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index b7697db1..b48388db 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -89,6 +89,10 @@ public abstract class AbstractSMCCSTAL implements STAL { if (response != null) { if (response instanceof ErrorResponse) { log.info("Got an error response"); + ErrorResponse err = (ErrorResponse) response; + if (err.getErrorCode() == 6001) { + retryCounter = Integer.MAX_VALUE-1; + } if (++retryCounter < maxRetries) { log.info("Retrying"); signatureCard.disconnect(true); -- cgit v1.2.3 From ef8dc449ddc60008bce9264c73b4162cc487c174 Mon Sep 17 00:00:00 2001 From: wbauer Date: Thu, 16 Oct 2008 07:51:13 +0000 Subject: Changed STAL Handler from static registration to one Object per STAL instance git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@121 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 21 +++++++++------------ .../bku/smccstal/InfoBoxReadRequestHandler.java | 5 ----- .../egiz/bku/smccstal/SMCCSTALRequestHandler.java | 2 -- 3 files changed, 9 insertions(+), 19 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index b48388db..cf524737 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -37,19 +37,17 @@ import at.gv.egiz.stal.SignRequest; public abstract class AbstractSMCCSTAL implements STAL { private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); - + public final static int DEFAULT_MAX_RETRIES = 3; protected Locale locale = Locale.getDefault(); - // protected SMCCHelper smccHelper = new SMCCHelper(); protected SignatureCard signatureCard = null; - protected static Map handlerMap = new HashMap(); - + protected Map handlerMap = new HashMap(); + protected int maxRetries = DEFAULT_MAX_RETRIES; - static { + protected AbstractSMCCSTAL() { addRequestHandler(InfoboxReadRequest.class, new InfoBoxReadRequestHandler()); - // addRequestHandler(SignRequest.class, new SignRequestHandler()); } /** @@ -72,7 +70,7 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Processing: " + request.getClass()); int retryCounter = 0; while (retryCounter < maxRetries) { - log.info("Number of retries: "+retryCounter); + log.info("Number of retries: " + retryCounter); SMCCSTALRequestHandler handler = null; handler = handlerMap.get(request.getClass().getSimpleName()); if (handler != null) { @@ -83,7 +81,6 @@ public abstract class AbstractSMCCSTAL implements STAL { } } try { - handler = handler.newInstance(); handler.init(signatureCard, getGUI()); STALResponse response = handler.handleRequest(request); if (response != null) { @@ -91,7 +88,7 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Got an error response"); ErrorResponse err = (ErrorResponse) response; if (err.getErrorCode() == 6001) { - retryCounter = Integer.MAX_VALUE-1; + retryCounter = Integer.MAX_VALUE - 1; } if (++retryCounter < maxRetries) { log.info("Retrying"); @@ -128,13 +125,13 @@ public abstract class AbstractSMCCSTAL implements STAL { return responseList; } - public static void addRequestHandler(Class id, + public void addRequestHandler(Class id, SMCCSTALRequestHandler handler) { log.debug("Registering STAL request handler: " + id.getSimpleName()); handlerMap.put(id.getSimpleName(), handler); } - public static SMCCSTALRequestHandler getRequestHandler( + public SMCCSTALRequestHandler getRequestHandler( Class request) { return handlerMap.get(request.getSimpleName()); } @@ -150,5 +147,5 @@ public abstract class AbstractSMCCSTAL implements STAL { public void setMaxRetries(int maxRetries) { this.maxRetries = maxRetries; } - + } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index 25085b16..b48d6d50 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -133,9 +133,4 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements } return new String(gui.getPin()); } - - @Override - public SMCCSTALRequestHandler newInstance() { - return new InfoBoxReadRequestHandler(); - } } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java index 6f303f76..94ab7a5b 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java @@ -30,6 +30,4 @@ public interface SMCCSTALRequestHandler { public boolean requireCard(); - public SMCCSTALRequestHandler newInstance(); - } -- cgit v1.2.3 From c2ae3db1bc6dcb8ba3eb3461c05e293917c004ca Mon Sep 17 00:00:00 2001 From: mcentner Date: Thu, 30 Oct 2008 10:33:29 +0000 Subject: Updated SMCC to use exclusive access and to throw exceptions upon locked or not activated cards. Improved locale support in the security layer request and response processing. Fixed issue in STAL which prevented the use of RSA-SHA1 signatures. Added additional parameters to the applet test pages. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@128 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java | 8 ++++++++ .../main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index b48d6d50..cfac8cf5 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -20,6 +20,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.LockedException; +import at.gv.egiz.smcc.NotActivatedException; import at.gv.egiz.smcc.PINProvider; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.smcc.SignatureCard; @@ -100,6 +102,12 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements stalResp.setInfoboxValue(resp); return stalResp; } + } catch (NotActivatedException e) { + log.info("Citizen card not activated.", e); + return new ErrorResponse(6001); + } catch (LockedException e) { + log.info("Citizen card locked.", e); + return new ErrorResponse(6001); } catch (CancelledException cx) { log.debug("User cancelled request", cx); return new ErrorResponse(6001); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index dcd12b02..466ec2a9 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -32,6 +32,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.LockedException; +import at.gv.egiz.smcc.NotActivatedException; import at.gv.egiz.smcc.PINProvider; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.smcc.SignatureCard; @@ -78,7 +80,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen String jceName = JCEAlgorithmNames.getJCEHashName(signatureMethod); if (jceName == null) { log.error("Hash algorithm not supported:"); - return new ErrorResponse(1000); + return new ErrorResponse(4006); } MessageDigest md = MessageDigest.getInstance(jceName); md.update(signReq.getSignedInfo()); @@ -90,6 +92,12 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen SignResponse stalResp = new SignResponse(); stalResp.setSignatureValue(resp); return stalResp; + } catch (NotActivatedException e) { + log.info("Citizen card not activated.", e); + return new ErrorResponse(6001); + } catch (LockedException e) { + log.info("Citizen card locked.", e); + return new ErrorResponse(6001); } catch (CancelledException cx) { log.debug("User cancelled request"); return new ErrorResponse(6001); -- cgit v1.2.3 From 4032e46810c24dc3f013de296a2133f4651696b9 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 31 Oct 2008 15:30:34 +0000 Subject: local HelpListener card locked/not activated git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@137 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java | 7 +++++++ .../src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java | 6 ++++++ 2 files changed, 13 insertions(+) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index cfac8cf5..cfc5c4bd 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.smccstal; +import at.gv.egiz.bku.gui.BKUGUIFacade; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -104,9 +105,15 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements } } catch (NotActivatedException e) { log.info("Citizen card not activated.", e); + gui.showErrorDialog(BKUGUIFacade.ERR_CARD_NOTACTIVATED, null, this, null); + waitForAction(); + gui.showWaitDialog(null); return new ErrorResponse(6001); } catch (LockedException e) { log.info("Citizen card locked.", e); + gui.showErrorDialog(BKUGUIFacade.ERR_CARD_LOCKED, null, this, null); + waitForAction(); + gui.showWaitDialog(null); return new ErrorResponse(6001); } catch (CancelledException cx) { log.debug("User cancelled request", cx); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 466ec2a9..dbc70bff 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -94,9 +94,15 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen return stalResp; } catch (NotActivatedException e) { log.info("Citizen card not activated.", e); + gui.showErrorDialog(BKUGUIFacade.ERR_CARD_NOTACTIVATED, null, this, null); + waitForAction(); + gui.showWaitDialog(null); return new ErrorResponse(6001); } catch (LockedException e) { log.info("Citizen card locked.", e); + gui.showErrorDialog(BKUGUIFacade.ERR_CARD_LOCKED, null, this, null); + waitForAction(); + gui.showWaitDialog(null); return new ErrorResponse(6001); } catch (CancelledException cx) { log.debug("User cancelled request"); -- cgit v1.2.3 From 16b188bae57cfc10c94a0e251a815ab35345e113 Mon Sep 17 00:00:00 2001 From: wbauer Date: Mon, 3 Nov 2008 11:11:30 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@139 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 127 ++++++++++++--------- 1 file changed, 73 insertions(+), 54 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index cf524737..f310dd42 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -18,22 +18,22 @@ package at.gv.egiz.bku.smccstal; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.smcc.util.SMCCHelper; import at.gv.egiz.stal.ErrorResponse; import at.gv.egiz.stal.InfoboxReadRequest; import at.gv.egiz.stal.STAL; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.SignRequest; public abstract class AbstractSMCCSTAL implements STAL { private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); @@ -45,9 +45,11 @@ public abstract class AbstractSMCCSTAL implements STAL { protected Map handlerMap = new HashMap(); protected int maxRetries = DEFAULT_MAX_RETRIES; + protected Set unrecoverableErrors = new HashSet(); protected AbstractSMCCSTAL() { addRequestHandler(InfoboxReadRequest.class, new InfoBoxReadRequestHandler()); + unrecoverableErrors.add(6001); } /** @@ -59,66 +61,76 @@ public abstract class AbstractSMCCSTAL implements STAL { protected abstract BKUGUIFacade getGUI(); + private STALResponse getRespone(STALRequest request) { + log.info("Processing: " + request.getClass()); + int retryCounter = 0; + while (retryCounter < maxRetries) { + log.info("Retry #" + retryCounter + " of " + maxRetries); + SMCCSTALRequestHandler handler = null; + handler = handlerMap.get(request.getClass().getSimpleName()); + if (handler != null) { + if (handler.requireCard()) { + if (waitForCard()) { + return new ErrorResponse(6001); + } + } + try { + handler.init(signatureCard, getGUI()); + STALResponse response = handler.handleRequest(request); + if (response != null) { + if (response instanceof ErrorResponse) { + log.info("Got an error response"); + ErrorResponse err = (ErrorResponse) response; + if (unrecoverableErrors.contains(err.getErrorCode())) { + return response; + } + if ((++retryCounter < maxRetries) && (handler.requireCard())) { + signatureCard.disconnect(true); + signatureCard = null; + } else { + log.info("Exceeded max retries, returning error " + + err.getErrorMessage()); + return response; + } + } else { + return response; + } + } else { + log.info("Got null response from handler, assuming quit"); + return null; + } + } catch (Exception e) { + log.info("Error while handling STAL request:" + e); + if (++retryCounter < maxRetries) { + signatureCard.disconnect(true); + signatureCard = null; + } else { + log.info("Exceeded max retries, returning error."); + return new ErrorResponse(6000); + } + } + } else { + log.error("Cannot find a handler for STAL request: " + request); + return new ErrorResponse(); + } + } + return new ErrorResponse(6000); + } + @Override public List handleRequest(List requestList) { log.debug("Got request list containing " + requestList.size() + " STAL requests"); List responseList = new ArrayList(requestList .size()); - for (STALRequest request : requestList) { log.info("Processing: " + request.getClass()); - int retryCounter = 0; - while (retryCounter < maxRetries) { - log.info("Number of retries: " + retryCounter); - SMCCSTALRequestHandler handler = null; - handler = handlerMap.get(request.getClass().getSimpleName()); - if (handler != null) { - if (handler.requireCard()) { - if (waitForCard()) { - responseList.add(new ErrorResponse(6001)); - break; - } - } - try { - handler.init(signatureCard, getGUI()); - STALResponse response = handler.handleRequest(request); - if (response != null) { - if (response instanceof ErrorResponse) { - log.info("Got an error response"); - ErrorResponse err = (ErrorResponse) response; - if (err.getErrorCode() == 6001) { - retryCounter = Integer.MAX_VALUE - 1; - } - if (++retryCounter < maxRetries) { - log.info("Retrying"); - signatureCard.disconnect(true); - signatureCard = null; - } else { - responseList.add(response); - } - } else { - responseList.add(response); - retryCounter = Integer.MAX_VALUE; - break; - } - } else { - log.info("Got null response from handler, assuming quit"); - retryCounter = Integer.MAX_VALUE; - } - } catch (Exception e) { - log.info("Error while handling STAL request:" + e); - if (++retryCounter < maxRetries) { - log.info("Retrying"); - signatureCard.disconnect(true); - signatureCard = null; - } else { - responseList.add(new ErrorResponse(6000)); - } - } - } else { - log.error("Cannot find a handler for STAL request: " + request); - responseList.add(new ErrorResponse()); + STALResponse response = getRespone(request); + if (response != null) { + responseList.add(response); + if (response instanceof ErrorResponse) { + log.info("Got an error response, don't process remaining requests"); + break; } } } @@ -148,4 +160,11 @@ public abstract class AbstractSMCCSTAL implements STAL { this.maxRetries = maxRetries; } + public Set getUnrecoverableErrors() { + return unrecoverableErrors; + } + + public void setUnrecoverableErrors(Set unrecoverableErrors) { + this.unrecoverableErrors = unrecoverableErrors; + } } -- cgit v1.2.3 From c7c00fbb89717c2a3a51f64908ad78a61ae70da0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 5 Nov 2008 10:05:54 +0000 Subject: BKUWorker refactoring jssessionId git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@148 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/AbstractBKUWorker.java | 199 +++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java new file mode 100644 index 00000000..e10ba8f9 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java @@ -0,0 +1,199 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.smccstal; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.util.SMCCHelper; +import at.gv.egiz.stal.QuitRequest; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +/** + * Abstract base class for AppletBKUWorker and LocalBKUWorker, + * providing card specific functionality not implemented by AbstractSMCCSTAL + * as well as common GUI functionality (action event handling). + *
+ * This class implements SMCCSTALRequestHandler and registers itself as QUIT handler. + * + * @author Clemens Orthacker + */ +public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements ActionListener, SMCCSTALRequestHandler { + + protected static Log log = LogFactory.getLog(AbstractBKUWorker.class); + protected BKUGUIFacade gui; + protected List actionCommandList = new ArrayList(); + protected Boolean actionPerformed = false; + protected boolean finished = false; + + public AbstractBKUWorker(BKUGUIFacade gui) { + if (gui == null) { + throw new NullPointerException("No BKU GUI provided"); + } + this.gui = gui; + this.locale = gui.getLocale(); + addRequestHandler(QuitRequest.class, this); + } + + /////////////////////////////////////////////////////////////////// + // Common action event handling // + /////////////////////////////////////////////////////////////////// + + /** + * notifies all registered handlers that an event occured + * @param e + */ + @Override + public void actionPerformed(ActionEvent e) { + log.info("Action: " + e); + if (actionCommandList != null) { + if (actionCommandList.contains(e.getActionCommand())) { + actionOccured(); + } + } else { + actionOccured(); + } + } + + /** + * register for notification on action event + * @throws java.lang.InterruptedException + */ + protected synchronized void waitForAction() throws InterruptedException { + log.info("Waiting for Action"); + while (!actionPerformed) { + wait(); + } + actionPerformed = false; + } + + protected synchronized void actionOccured() { + log.info("Received Action"); + actionPerformed = true; + notifyAll(); + } + + /////////////////////////////////////////////////////////////////// + // card specific implementations of AbstractSMCCSTAL // + /////////////////////////////////////////////////////////////////// + + @Override + protected boolean waitForCard() { + SMCCHelper smccHelper = new SMCCHelper(); + actionCommandList.clear(); + actionCommandList.add("cancel"); + // while no sigcard found or cancel button pressed + int oldValue = SMCCHelper.PC_SC_NOT_SUPPORTED; // this is a save default + while ((signatureCard == null) && (!actionPerformed)) { + switch (smccHelper.getResultCode()) { + case SMCCHelper.PC_SC_NOT_SUPPORTED: + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, this, "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.TERMINAL_NOT_PRESENT: + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_CARDTERMINAL, null, this, "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.CARD_NOT_SUPPORTED: + if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { + actionCommandList.clear(); + actionCommandList.add("cancel"); + gui.showCardNotSupportedDialog(this, "cancel"); + oldValue = SMCCHelper.CARD_NOT_SUPPORTED; + } + break; + case SMCCHelper.NO_CARD: + if (oldValue != SMCCHelper.NO_CARD) { + actionCommandList.clear(); + actionCommandList.add("cancel"); + gui.showInsertCardDialog(this, "cancel"); + oldValue = SMCCHelper.NO_CARD; + } + break; + case SMCCHelper.CARD_FOUND: + signatureCard = smccHelper.getSignatureCard(locale); + return false; + } + smccHelper.update(3000); + } + return signatureCard == null; + } + + @Override + protected BKUGUIFacade getGUI() { + return gui; + } + + /////////////////////////////////////////////////////////////////// + // SMCCSTALRequestHandler for QUIT requests // + /////////////////////////////////////////////////////////////////// + + /** + * Handle QUIT requests: set finished true. + * @param request a QUIT request + * @return null (no response on QUIT) + */ + @Override + public STALResponse handleRequest(STALRequest request) { + if (request instanceof QuitRequest) { + log.info("Setting state to: finished for BKUWorker " + this); + finished = true; + } else { + log.error("Unexpected request to handle: " + request); + } + return null; + } + + /** + * No initialization required for QUIT request handlers. + * @param sc + * @param gui + */ + @Override + public void init(SignatureCard sc, BKUGUIFacade gui) { + } + + /** + * QUIT request handlers do not require a card. + * @return false + */ + @Override + public boolean requireCard() { + return false; + } +} -- cgit v1.2.3 From e4a47aa9393d74647f4f0c66b54dc4519fed492f Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 11 Nov 2008 12:16:00 +0000 Subject: Interrupt in waitForAction (applet closed) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@162 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../egiz/bku/smccstal/AbstractRequestHandler.java | 9 +++---- .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 28 ++++++++++++++++------ .../bku/smccstal/InfoBoxReadRequestHandler.java | 4 ++-- .../egiz/bku/smccstal/SMCCSTALRequestHandler.java | 2 +- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 4 ++-- 5 files changed, 31 insertions(+), 16 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java index 995e2b77..98b21f79 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractRequestHandler.java @@ -39,8 +39,8 @@ public abstract class AbstractRequestHandler implements SMCCSTALRequestHandler, protected boolean actionPerformed = false; @Override - public abstract STALResponse handleRequest(STALRequest request); - + public abstract STALResponse handleRequest(STALRequest request) throws InterruptedException; + @Override public void init(SignatureCard sc, BKUGUIFacade gui) { if ((sc == null) || (gui == null)) { @@ -60,13 +60,14 @@ public abstract class AbstractRequestHandler implements SMCCSTALRequestHandler, } } - protected synchronized void waitForAction() { + protected synchronized void waitForAction() throws InterruptedException { try { while (!actionPerformed) { wait(); } } catch (InterruptedException e) { - log.info(e); + log.error("interrupt in waitForAction"); + throw e; } actionPerformed = false; } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index f310dd42..04d8d0dd 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -24,6 +24,8 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -34,6 +36,7 @@ import at.gv.egiz.stal.InfoboxReadRequest; import at.gv.egiz.stal.STAL; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; +import java.util.Collections; public abstract class AbstractSMCCSTAL implements STAL { private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); @@ -61,7 +64,7 @@ public abstract class AbstractSMCCSTAL implements STAL { protected abstract BKUGUIFacade getGUI(); - private STALResponse getRespone(STALRequest request) { + private STALResponse getRespone(STALRequest request) throws InterruptedException { log.info("Processing: " + request.getClass()); int retryCounter = 0; while (retryCounter < maxRetries) { @@ -99,6 +102,9 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Got null response from handler, assuming quit"); return null; } + } catch (InterruptedException e) { + log.info("Interrupt in handleRequest, do not retry"); + throw e; } catch (Exception e) { log.info("Error while handling STAL request:" + e); if (++retryCounter < maxRetries) { @@ -125,14 +131,22 @@ public abstract class AbstractSMCCSTAL implements STAL { .size()); for (STALRequest request : requestList) { log.info("Processing: " + request.getClass()); - STALResponse response = getRespone(request); - if (response != null) { - responseList.add(response); - if (response instanceof ErrorResponse) { - log.info("Got an error response, don't process remaining requests"); - break; + STALResponse response; + try { + response = getRespone(request); + if (response != null) { + responseList.add(response); + if (response instanceof ErrorResponse) { + log.info("Got an error response, don't process remaining requests"); + break; + } } + } catch (InterruptedException ex) { + log.error("got interrupted, return ErrorResponse 6001"); + responseList = Collections.singletonList((STALResponse) new ErrorResponse(6001)); + break; } + } return responseList; } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index cfc5c4bd..04f179e7 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -41,7 +41,7 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements private int retryCounter = 0; @Override - public STALResponse handleRequest(STALRequest request) { + public STALResponse handleRequest(STALRequest request) throws InterruptedException { if (request instanceof InfoboxReadRequest) { InfoboxReadRequest infoBox = (InfoboxReadRequest) request; try { @@ -134,7 +134,7 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements } @Override - public String providePIN(PINSpec spec, int retries) { + public String providePIN(PINSpec spec, int retries) throws InterruptedException { if (retryCounter++ > 0) { log.info("PIN wrong retrying ..."); gui.showCardPINRetryDialog(spec, retries, this, "ok", this, "cancel"); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java index 94ab7a5b..f19b3ef3 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SMCCSTALRequestHandler.java @@ -26,7 +26,7 @@ public interface SMCCSTALRequestHandler { public void init(SignatureCard sc, BKUGUIFacade gui); - public STALResponse handleRequest(STALRequest request); + public STALResponse handleRequest(STALRequest request) throws InterruptedException; public boolean requireCard(); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index dbc70bff..6c30a68a 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -67,7 +67,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen @SuppressWarnings("unchecked") @Override - public STALResponse handleRequest(STALRequest request) { + public STALResponse handleRequest(STALRequest request) throws InterruptedException { if (request instanceof SignRequest) { SignRequest signReq = (SignRequest) request; newSTALMessage("Message.RequestCaption", "Message.SignRequest"); @@ -213,7 +213,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen } @Override - public String providePIN(PINSpec spec, int retries) { + public String providePIN(PINSpec spec, int retries) throws InterruptedException { showSignaturePINDialog(spec, retries); -- cgit v1.2.3 From 9662ac90b6aa84bc54543d3c8670ba6c8e42bbac Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 13 Nov 2008 18:24:57 +0000 Subject: FRAME HashDataDisplay FRAME Help git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@165 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/smccstal/HashDataInputDisplay.java | 20 ++++++++++++++++++-- .../at/gv/egiz/bku/smccstal/SignRequestHandler.java | 16 +++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java index f79a2027..59700d4a 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package at.gv.egiz.bku.smccstal; @@ -14,7 +26,11 @@ import java.util.List; */ public interface HashDataInputDisplay { + /** + * TODO: (see AbstractHelpListener) + * + * * Displays the hashdata inputs for all provided dsig:SignedReferences. * Implementations may verify the digest value if necessary. * (LocalSignRequestHandler operates on DataObjectHashDataInput, diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 6c30a68a..77ee45b6 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -192,7 +192,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen - class STALPinProvider implements PINProvider, ActionListener { + class STALPinProvider implements PINProvider { protected SignedInfoType signedInfo; protected List hashDataInputs; @@ -230,10 +230,10 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen displayHashDataInputs(signedInfo.getReference()); } catch (DigestException ex) { log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}, SignRequestHandler.this, "error"); } catch (Exception ex) { log.error("Could not display hashdata inputs: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "error"); } // OLD HASHDATA DISPLAY (in applet), @@ -261,13 +261,15 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen return new String(gui.getPin()); } else if (actionCommand.equals("ok")) { showSignaturePINDialog(spec, retries); + } else if (actionCommand.equals("error")) { + return null; } } while (true); } - @Override - public void actionPerformed(ActionEvent e) { - throw new UnsupportedOperationException("Not supported yet."); - } +// @Override +// public void actionPerformed(ActionEvent e) { +// throw new UnsupportedOperationException("Not supported yet."); +// } } } -- cgit v1.2.3 From 28e81afd92a6568ff78736b72c5257a86c0b9b91 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 18 Nov 2008 08:03:35 +0000 Subject: GUI refactoring 1 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@177 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 81 ---------------------- 1 file changed, 81 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 77ee45b6..26905f50 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -130,67 +130,6 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen // @Override // public String providePIN(PINSpec spec, int retries) { -// if (retryCounter++ > 0) { -// log.info("PIN wrong retrying ..."); -// gui.showSignaturePINRetryDialog(spec, retries, this, "sign", this, -// "cancel", this, "hashData"); -// } else { -// gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, -// "hashData"); -// } -// do { -// waitForAction(); -// if (actionCommand.equals("cancel")) { -// return null; -// } else if (actionCommand.equals("hashData")) { -// if (signedInfo != null) { -// try { -// gui.showWaitDialog(null); -// if (hashDataInputs == null || hashDataInputs.size() == 0) { -// HashMap signedReferences = new HashMap(); -// for (ReferenceType reference : signedInfo.getReference()) { -// //don't get Manifest, QualifyingProperties, ... -// if (reference.getType() == null) { -// signedReferences.put(reference.getId(), reference); -// } -// } -// hashDataInputs = getHashDataInputs(signedReferences.keySet()); -// for (HashDataInput hashDataInput : hashDataInputs) { -// ReferenceType reference = signedReferences.get(hashDataInput.getReferenceId()); -// String algorithm = reference.getDigestMethod().getAlgorithm(); -// MessageDigest md = MessageDigest.getInstance(algorithm); -// DigestInputStream dis = new DigestInputStream(hashDataInput.getHashDataInput(), md); -// while(dis.read() != -1) ; -// byte[] digestValue = md.digest(); -// boolean valid = reference.getDigestValue().equals(digestValue); -// } -// } -// gui.showHashDataInputDialog(hashDataInputs, this, "ok"); -// } catch (Exception ex) { -// //FIXME localize messages -// log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); -// gui.showErrorDialog("Failed to obtain HashDataInputs: " + ex.getMessage(), this, "ok"); -// } -// } else { -// //FIXME get all hashdatainputs -// gui.showErrorDialog("Failed to obtain HashDataInputs: No dsig:SignedInfo provided.", this, "ok"); -// } -// } else if (actionCommand.equals("sign")) { -// return new String(gui.getPin()); -// } else if (actionCommand.equals("ok")) { -// gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, -// "hashData"); -// } -// } while (true); -// } - -// @Override -// public SMCCSTALRequestHandler newInstance() { -// return new SignRequestHandler(); -// } - - - class STALPinProvider implements PINProvider { @@ -236,26 +175,6 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "error"); } - // OLD HASHDATA DISPLAY (in applet), - // register SignRequestHandler.this as hashdataListener to use -// if (signedInfo != null) { -// try { -// if (hashDataInputs == null || hashDataInputs.size() == 0) { -// hashDataInputs = getCashedHashDataInputs(signedInfo.getReference()); -// } -// gui.showHashDataInputDialog(hashDataInputs, SignRequestHandler.this, "ok"); -// } catch (DigestException ex) { -// log.error("Bad digest value: " + ex.getMessage()); -// gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}); -// } catch (Exception ex) { -// //FIXME localize messages -// log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); -// gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "ok"); -// } -// } else { -// //FIXME get all hashdatainputs -// gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {"No dsig:SignedInfo provided"}, SignRequestHandler.this, "ok"); -// } } else if (actionCommand.equals("sign")) { retryCounter++; return new String(gui.getPin()); -- cgit v1.2.3 From bc81c317e254fa617fc24c8129b743ac74aad470 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 19 Nov 2008 11:49:55 +0000 Subject: GUI feature complete git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@180 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 26905f50..d041a8cb 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -48,7 +48,6 @@ import at.gv.egiz.stal.SignResponse; import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; -import java.awt.event.ActionListener; import java.security.DigestException; import java.util.List; @@ -128,9 +127,6 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen return true; } -// @Override -// public String providePIN(PINSpec spec, int retries) { - class STALPinProvider implements PINProvider { protected SignedInfoType signedInfo; @@ -178,7 +174,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen } else if (actionCommand.equals("sign")) { retryCounter++; return new String(gui.getPin()); - } else if (actionCommand.equals("ok")) { + } else if (actionCommand.equals("hashDataDone")) { showSignaturePINDialog(spec, retries); } else if (actionCommand.equals("error")) { return null; -- cgit v1.2.3 From 05fdd03fdc275a3b728b6b6b5892c9fae5e401ee Mon Sep 17 00:00:00 2001 From: wbauer Date: Fri, 28 Nov 2008 12:07:40 +0000 Subject: Changed session handling strategy when reconnecting (eg. reload pressed) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@224 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 04d8d0dd..55f51b22 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -24,8 +24,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,7 +34,6 @@ import at.gv.egiz.stal.InfoboxReadRequest; import at.gv.egiz.stal.STAL; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; -import java.util.Collections; public abstract class AbstractSMCCSTAL implements STAL { private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); @@ -106,7 +103,7 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Interrupt in handleRequest, do not retry"); throw e; } catch (Exception e) { - log.info("Error while handling STAL request:" + e); + log.info("Error while handling STAL request:", e); if (++retryCounter < maxRetries) { signatureCard.disconnect(true); signatureCard = null; @@ -143,8 +140,7 @@ public abstract class AbstractSMCCSTAL implements STAL { } } catch (InterruptedException ex) { log.error("got interrupted, return ErrorResponse 6001"); - responseList = Collections.singletonList((STALResponse) new ErrorResponse(6001)); - break; + throw new RuntimeException(ex); } } -- cgit v1.2.3 From 2df9621154ad057f6cace73efe49c9ef42515fde Mon Sep 17 00:00:00 2001 From: mcentner Date: Tue, 9 Dec 2008 08:14:43 +0000 Subject: Refactored STAL interface. Additional infobox functionality. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@236 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 55f51b22..6f08a135 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -121,7 +121,7 @@ public abstract class AbstractSMCCSTAL implements STAL { } @Override - public List handleRequest(List requestList) { + public List handleRequest(List requestList) { log.debug("Got request list containing " + requestList.size() + " STAL requests"); List responseList = new ArrayList(requestList -- cgit v1.2.3 From 887f6727479f3ae3d89a08ba619f9382b450e4c1 Mon Sep 17 00:00:00 2001 From: mcentner Date: Fri, 12 Dec 2008 11:48:47 +0000 Subject: Updated SMCC to support non-blocking PIN entry. Added SV-Personendaten infobox implementation. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@248 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index 04f179e7..5a54e97f 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -103,6 +103,9 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements stalResp.setInfoboxValue(resp); return stalResp; } + } catch (IllegalArgumentException e) { + log.info("Infobox " + infoBox.getInfoboxIdentifier() + " not supported."); + return new ErrorResponse(4002); } catch (NotActivatedException e) { log.info("Citizen card not activated.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_NOTACTIVATED, null, this, null); -- cgit v1.2.3 From 54aa4703e3d66c5b1a63b8d925fd4c9c1766687c Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 28 Jan 2009 19:40:11 +0000 Subject: activation git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@291 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 6f08a135..92491139 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -61,8 +61,7 @@ public abstract class AbstractSMCCSTAL implements STAL { protected abstract BKUGUIFacade getGUI(); - private STALResponse getRespone(STALRequest request) throws InterruptedException { - log.info("Processing: " + request.getClass()); + private STALResponse getResponse(STALRequest request) throws InterruptedException { int retryCounter = 0; while (retryCounter < maxRetries) { log.info("Retry #" + retryCounter + " of " + maxRetries); @@ -130,7 +129,7 @@ public abstract class AbstractSMCCSTAL implements STAL { log.info("Processing: " + request.getClass()); STALResponse response; try { - response = getRespone(request); + response = getResponse(request); if (response != null) { responseList.add(response); if (response instanceof ErrorResponse) { -- cgit v1.2.3 From f8daac3a191bcb0fe280ed0204f28f8edcfb3008 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 11 Feb 2009 20:11:05 +0000 Subject: GetStatusRequest git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@302 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 4 +- .../gv/egiz/bku/smccstal/StatusRequestHandler.java | 72 ++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/StatusRequestHandler.java (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 92491139..0074860f 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -34,11 +34,12 @@ import at.gv.egiz.stal.InfoboxReadRequest; import at.gv.egiz.stal.STAL; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.StatusRequest; public abstract class AbstractSMCCSTAL implements STAL { private static Log log = LogFactory.getLog(AbstractSMCCSTAL.class); - public final static int DEFAULT_MAX_RETRIES = 3; + public final static int DEFAULT_MAX_RETRIES = 1; protected Locale locale = Locale.getDefault(); protected SignatureCard signatureCard = null; @@ -49,6 +50,7 @@ public abstract class AbstractSMCCSTAL implements STAL { protected AbstractSMCCSTAL() { addRequestHandler(InfoboxReadRequest.class, new InfoBoxReadRequestHandler()); + addRequestHandler(StatusRequest.class, new StatusRequestHandler()); unrecoverableErrors.add(6001); } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/StatusRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/StatusRequestHandler.java new file mode 100644 index 00000000..56b24920 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/StatusRequestHandler.java @@ -0,0 +1,72 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.smccstal; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.util.SMCCHelper; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.StatusRequest; +import at.gv.egiz.stal.StatusResponse; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class StatusRequestHandler extends AbstractRequestHandler { + + protected static final Log log = LogFactory.getLog(StatusRequestHandler.class); + + @Override + public void init(SignatureCard sc, BKUGUIFacade gui) { + //nothing, avoid NullPointerEx since requireCard==false => sc==null + } + + + @Override + public STALResponse handleRequest(STALRequest request) throws InterruptedException { + + if (request instanceof StatusRequest) { + log.info("handling STATUS request"); + SMCCHelper smccHelper = new SMCCHelper(); + StatusResponse response = new StatusResponse(); + if (log.isTraceEnabled()) { + log.trace("SMCC result code: " + smccHelper.getResultCode() + + ", cardReady: " + + (smccHelper.getResultCode() == SMCCHelper.CARD_FOUND)); + } + if (smccHelper.getResultCode() == SMCCHelper.CARD_FOUND) { + response.setCardReady(Boolean.TRUE); + } else { + response.setCardReady(Boolean.FALSE); + } + return response; + } else { + log.error("Got unexpected STAL request: " + request); + return new ErrorResponse(1000); + } + } + + @Override + public boolean requireCard() { + return false; + } +} -- cgit v1.2.3 From 6576428966f1e3d688269a407b072fb01f9f7647 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 26 Feb 2009 19:39:00 +0000 Subject: 1.1 candidate (activation) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@309 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java index e10ba8f9..b6c5a8ca 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java @@ -102,6 +102,9 @@ public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements Acti @Override protected boolean waitForCard() { + if (signatureCard != null) { + return false; + } SMCCHelper smccHelper = new SMCCHelper(); actionCommandList.clear(); actionCommandList.add("cancel"); -- cgit v1.2.3 From 4387153c6f65b55d576e1890c5b582237227369e Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 27 Feb 2009 18:10:57 +0000 Subject: 1.1-rc2 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@310 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/AbstractBKUWorker.java | 4 ++-- .../java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java index b6c5a8ca..23b71690 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java @@ -54,7 +54,7 @@ public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements Acti throw new NullPointerException("No BKU GUI provided"); } this.gui = gui; - this.locale = gui.getLocale(); +// this.locale = gui.getLocale(); addRequestHandler(QuitRequest.class, this); } @@ -149,7 +149,7 @@ public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements Acti } break; case SMCCHelper.CARD_FOUND: - signatureCard = smccHelper.getSignatureCard(locale); + signatureCard = smccHelper.getSignatureCard(gui.getLocale()); return false; } smccHelper.update(3000); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 0074860f..3691156e 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Locale; +//import java.util.Locale; import java.util.Map; import java.util.Set; @@ -41,7 +41,7 @@ public abstract class AbstractSMCCSTAL implements STAL { public final static int DEFAULT_MAX_RETRIES = 1; - protected Locale locale = Locale.getDefault(); +// protected Locale locale = Locale.getDefault(); protected SignatureCard signatureCard = null; protected Map handlerMap = new HashMap(); @@ -159,13 +159,13 @@ public abstract class AbstractSMCCSTAL implements STAL { return handlerMap.get(request.getSimpleName()); } - @Override - public void setLocale(Locale locale) { - if (locale == null) { - throw new NullPointerException("Locale must not be set to null"); - } - this.locale = locale; - } +// @Override +// public void setLocale(Locale locale) { +// if (locale == null) { +// throw new NullPointerException("Locale must not be set to null"); +// } +// this.locale = locale; +// } public void setMaxRetries(int maxRetries) { this.maxRetries = maxRetries; -- cgit v1.2.3 From 18932bb8a7ebf805026701416389e08bdb0d6dae Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 10 Mar 2009 13:36:20 +0000 Subject: do not return errorResponse on interrupt git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@318 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 3691156e..1cf81e05 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -101,7 +101,7 @@ public abstract class AbstractSMCCSTAL implements STAL { return null; } } catch (InterruptedException e) { - log.info("Interrupt in handleRequest, do not retry"); + log.info("Interrupt during request handling, do not retry"); throw e; } catch (Exception e) { log.info("Error while handling STAL request:", e); @@ -140,8 +140,8 @@ public abstract class AbstractSMCCSTAL implements STAL { } } } catch (InterruptedException ex) { - log.error("got interrupted, return ErrorResponse 6001"); - throw new RuntimeException(ex); + log.error("interrupted during request handling"); + throw new RuntimeException("interrupted during request handling", ex); } } -- cgit v1.2.3 From 2a1df5e58e44f8d77f34eb80df74e8c0d27caceb Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 18 Mar 2009 22:27:28 +0000 Subject: 1.1-rc5 (pinProviderFactories, gui refactoring, signatureCard, secureViewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@322 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/AbstractBKUWorker.java | 8 +- .../gv/egiz/bku/smccstal/AbstractPINProvider.java | 67 +++++++++ .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 6 + .../bku/smccstal/InfoBoxReadRequestHandler.java | 40 ++---- .../gv/egiz/bku/smccstal/PINProviderFactory.java | 47 +++++++ .../bku/smccstal/PinpadPINProviderFactory.java | 155 +++++++++++++++++++++ .../java/at/gv/egiz/bku/smccstal/SecureViewer.java | 44 ++++++ .../gv/egiz/bku/smccstal/SignRequestHandler.java | 149 +++++++++++--------- .../bku/smccstal/SoftwarePINProviderFactory.java | 140 +++++++++++++++++++ 9 files changed, 562 insertions(+), 94 deletions(-) create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java index 23b71690..14b36e28 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java @@ -136,7 +136,9 @@ public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements Acti if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { actionCommandList.clear(); actionCommandList.add("cancel"); - gui.showCardNotSupportedDialog(this, "cancel"); + gui.showMessageDialog(BKUGUIFacade.TITLE_CARD_NOT_SUPPORTED, + BKUGUIFacade.MESSAGE_CARD_NOT_SUPPORTED, null, + BKUGUIFacade.BUTTON_CANCEL, this, "cancel"); oldValue = SMCCHelper.CARD_NOT_SUPPORTED; } break; @@ -144,7 +146,9 @@ public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements Acti if (oldValue != SMCCHelper.NO_CARD) { actionCommandList.clear(); actionCommandList.add("cancel"); - gui.showInsertCardDialog(this, "cancel"); + gui.showMessageDialog(BKUGUIFacade.TITLE_INSERTCARD, + BKUGUIFacade.MESSAGE_INSERTCARD, null, + BKUGUIFacade.BUTTON_CANCEL, this, "cancel"); oldValue = SMCCHelper.NO_CARD; } break; diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java new file mode 100644 index 00000000..e32f08d4 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java @@ -0,0 +1,67 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.smccstal; + +import at.gv.egiz.smcc.PINProvider; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public abstract class AbstractPINProvider implements PINProvider, ActionListener { + + protected static final Log log = LogFactory.getLog(AbstractPINProvider.class); + + protected boolean retry = false; + + protected String action; + + private boolean actionPerformed; + +// protected void waitForAction() throws InterruptedException { +// super.wait(); +// } + + protected synchronized void waitForAction() throws InterruptedException { + try { + while (!actionPerformed) { + this.wait(); + } + } catch (InterruptedException e) { + log.error("interrupt in waitForAction"); + throw e; + } + actionPerformed = false; + } + + private synchronized void actionPerformed() { + actionPerformed = true; + notify();//All(); + } + + @Override + public void actionPerformed(ActionEvent e) { + log.debug("command " + e.getActionCommand()); + action = e.getActionCommand(); + actionPerformed(); + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 1cf81e05..71f35181 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -121,6 +121,12 @@ public abstract class AbstractSMCCSTAL implements STAL { return new ErrorResponse(6000); } + /** + * + * @param requestList + * @return + * @throws RuntimeException with cause InterruptedException if interrupted + */ @Override public List handleRequest(List requestList) { log.debug("Got request list containing " + requestList.size() diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index 5a54e97f..94444922 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -33,23 +33,26 @@ import at.gv.egiz.stal.InfoboxReadResponse; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; -public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements - PINProvider { +public class InfoBoxReadRequestHandler extends AbstractRequestHandler { private static Log log = LogFactory.getLog(InfoBoxReadRequestHandler.class); - private int retryCounter = 0; + protected PINProviderFactory pinProviderFactory; @Override public STALResponse handleRequest(STALRequest request) throws InterruptedException { if (request instanceof InfoboxReadRequest) { InfoboxReadRequest infoBox = (InfoboxReadRequest) request; + if (pinProviderFactory == null) { + pinProviderFactory = PINProviderFactory.getInstance(card, gui); + } try { if (infoBox.getInfoboxIdentifier().equals("IdentityLink")) { newSTALMessage("Message.RequestCaption", "Message.IdentityLink"); log.debug("Handling identitylink infobox"); - byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, - infoBox.getDomainIdentifier()); + byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), + pinProviderFactory.getCardPINProvider(), + infoBox.getDomainIdentifier()); if (resp == null) { log.info("Got null as result->user cancelled"); return new ErrorResponse(6001); @@ -94,8 +97,9 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements newSTALMessage("Message.RequestCaption", "Message.InfoboxReadRequest"); log.warn("Unknown infobox identifier: " + infoBox.getInfoboxIdentifier() + " trying generic request"); - byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, - infoBox.getDomainIdentifier()); + byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), + pinProviderFactory.getCardPINProvider(), + infoBox.getDomainIdentifier()); if (resp == null) { return new ErrorResponse(6001); } @@ -110,13 +114,15 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements log.info("Citizen card not activated.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_NOTACTIVATED, null, this, null); waitForAction(); - gui.showWaitDialog(null); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); return new ErrorResponse(6001); } catch (LockedException e) { log.info("Citizen card locked.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_LOCKED, null, this, null); waitForAction(); - gui.showWaitDialog(null); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); return new ErrorResponse(6001); } catch (CancelledException cx) { log.debug("User cancelled request", cx); @@ -135,20 +141,4 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements public boolean requireCard() { return true; } - - @Override - public String providePIN(PINSpec spec, int retries) throws InterruptedException { - if (retryCounter++ > 0) { - log.info("PIN wrong retrying ..."); - gui.showCardPINRetryDialog(spec, retries, this, "ok", this, "cancel"); - } else { - gui.showCardPINDialog(spec, this, "ok", this, "cancel"); - } - waitForAction(); - gui.showWaitDialog(null); - if (actionCommand.equals("cancel")) { - return null; - } - return new String(gui.getPin()); - } } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java new file mode 100644 index 00000000..670b71dc --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java @@ -0,0 +1,47 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.smccstal; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.stal.signedinfo.SignedInfoType; + +/** + * + * @author Clemens Orthacker + */ +public abstract class PINProviderFactory { + + BKUGUIFacade gui; + + public static PINProviderFactory getInstance(SignatureCard forCard, + BKUGUIFacade gui) { + if (forCard.ifdSupportsFeature(SignatureCard.FEATURE_VERIFY_PIN_DIRECT)) { + return new PinpadPINProviderFactory(gui); + } else { + return new SoftwarePINProviderFactory(gui); + } + } + + public abstract PINProvider getSignaturePINProvider(SecureViewer viewer, + SignedInfoType signedInfo); + + public abstract PINProvider getCardPINProvider(); + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java new file mode 100644 index 00000000..55321b72 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java @@ -0,0 +1,155 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.smccstal; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.util.List; + +/** + * + * @author Clemens Orthacker + */ +public class PinpadPINProviderFactory extends PINProviderFactory { + + protected PinpadPINProviderFactory(BKUGUIFacade gui) { + this.gui = gui; + } + + @Override + public PINProvider getSignaturePINProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + + return new SignaturePinProvider(viewer, signedInfo); + } + + @Override + public PINProvider getCardPINProvider() { + return new CardPinProvider(); + } + + class SignaturePinProvider extends AbstractPINProvider { + +// protected BKUGUIFacade gui; + protected SecureViewer viewer; + protected SignedInfoType signedInfo; + protected List hashDataInputs; + + private SignaturePinProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + this.viewer = viewer; + this.signedInfo = signedInfo; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + showPinpadPINDialog(retries, spec); + retry = true; + return null; + +// do { +// waitForAction(); +// gui.showWaitDialog(null); +// +// if ("hashData".equals(action)) { +// // show pin dialog in background +// gui.showSignaturePINDialog(spec, (retry) ? retries : -1, +// this, "sign", +// this, "cancel", +// this, "hashData"); +// +// viewer.displayDataToBeSigned(signedInfo.getReference()); +// +// } else if ("sign".equals(action)) { +// retry = true; +// return gui.getPin(); +// } else if ("hashDataDone".equals(action)) { +// gui.showSignaturePINDialog(spec, (retry) ? retries : -1, +// this, "sign", +// this, "cancel", +// this, "hashData"); +// } else if ("cancel".equals(action) || +// "error".equals(action)) { +// throw new CancelledException(spec.getLocalizedName() + +// " entry cancelled"); +// } +// } while (true); + } + + private void showPinpadPINDialog(int retries, PINSpec pinSpec) { + String title, message; + Object[] params; + if (retry) { + title = BKUGUIFacade.TITLE_RETRY; + message = BKUGUIFacade.MESSAGE_RETRIES; + params = new Object[]{String.valueOf(retries)}; + } else { + title = BKUGUIFacade.TITLE_SIGN; + message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } + gui.showMessageDialog(title, message, params); + } + } + + class CardPinProvider extends AbstractPINProvider { + + private CardPinProvider() { + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + showPinpadPINDialog(retries, spec); + retry = true; + return null; + + } + + private void showPinpadPINDialog(int retries, PINSpec pinSpec) { + String title, message; + Object[] params; + if (retry) { + title = BKUGUIFacade.TITLE_RETRY; + message = BKUGUIFacade.MESSAGE_RETRIES; + params = new Object[]{String.valueOf(retries)}; + } else { + title = BKUGUIFacade.TITLE_CARDPIN; + message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } + gui.showMessageDialog(title, message, params); + } + } +} + diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java new file mode 100644 index 00000000..c395679a --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java @@ -0,0 +1,44 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.smccstal; + +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.DigestException; +import java.util.List; + +/** + * + * @author Clemens Orthacker + */ +public interface SecureViewer { + + /** + * Displays the hashdata inputs for all provided dsig:SignedReferences. + * Implementations may verify the digest value if necessary. + * (LocalSignRequestHandler operates on DataObjectHashDataInput, + * other SignRequestHandlers should cache the HashDataInputs obtained by webservice calls, + * or simply forward to a HashDataInputServlet.) + * @param signedReferences The caller may select a subset of the references in SignedInfo to be displayed. + * @throws java.security.DigestException if digest values are verified and do not correspond + * (or any other digest computation error occurs) + * @throws java.lang.Exception + */ + void displayDataToBeSigned(List signedReferences) + throws DigestException, Exception; + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index d041a8cb..ac510f38 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -17,7 +17,6 @@ package at.gv.egiz.bku.smccstal; import at.gv.egiz.bku.gui.BKUGUIFacade; -import java.awt.event.ActionEvent; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security.MessageDigest; @@ -35,12 +34,11 @@ import at.gv.egiz.smcc.CancelledException; import at.gv.egiz.smcc.LockedException; import at.gv.egiz.smcc.NotActivatedException; import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.TimeoutException; import at.gv.egiz.stal.ErrorResponse; -import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; @@ -48,13 +46,12 @@ import at.gv.egiz.stal.SignResponse; import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; -import java.security.DigestException; -import java.util.List; -public abstract class SignRequestHandler extends AbstractRequestHandler implements HashDataInputDisplay { +public abstract class SignRequestHandler extends AbstractRequestHandler implements SecureViewer { private static Log log = LogFactory.getLog(SignRequestHandler.class); private static JAXBContext jaxbContext; + private PINProviderFactory pinProviderFactory; static { try { @@ -84,7 +81,14 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen MessageDigest md = MessageDigest.getInstance(jceName); md.update(signReq.getSignedInfo()); KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq.getKeyIdentifier()); - byte[] resp = card.createSignature(md.digest(), kb, new STALPinProvider(si.getValue())); + + if (pinProviderFactory == null) { + pinProviderFactory = PINProviderFactory.getInstance(card, gui); + } + PINProvider pinProvider = pinProviderFactory. + getSignaturePINProvider(this, si.getValue()); + + byte[] resp = card.createSignature(md.digest(), kb, pinProvider); if (resp == null) { return new ErrorResponse(6001); } @@ -95,17 +99,28 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen log.info("Citizen card not activated.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_NOTACTIVATED, null, this, null); waitForAction(); - gui.showWaitDialog(null); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); return new ErrorResponse(6001); } catch (LockedException e) { log.info("Citizen card locked.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_LOCKED, null, this, null); waitForAction(); - gui.showWaitDialog(null); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); return new ErrorResponse(6001); } catch (CancelledException cx) { log.debug("User cancelled request"); return new ErrorResponse(6001); + } catch (TimeoutException ex) { + log.error("Timeout during pin entry"); + gui.showMessageDialog(BKUGUIFacade.TITLE_ENTRY_TIMEOUT, + BKUGUIFacade.ERR_PIN_TIMEOUT, null, + BKUGUIFacade.BUTTON_CANCEL, this, null); + waitForAction(); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + return new ErrorResponse(6001); } catch (SignatureCardException e) { log.error("Error while creating signature: " + e); return new ErrorResponse(4000); @@ -127,64 +142,64 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen return true; } - class STALPinProvider implements PINProvider { - - protected SignedInfoType signedInfo; - protected List hashDataInputs; - private int retryCounter = 0; - - public STALPinProvider(SignedInfoType signedInfo) { - this.signedInfo = signedInfo; - } - - private void showSignaturePINDialog(PINSpec spec, int retries) { - if (retryCounter > 0) { - gui.showSignaturePINRetryDialog(spec, retries, SignRequestHandler.this, "sign", SignRequestHandler.this, - "cancel", SignRequestHandler.this, "hashData"); - } else { - gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, - "hashData"); - } - } - - @Override - public String providePIN(PINSpec spec, int retries) throws InterruptedException { - - showSignaturePINDialog(spec, retries); - - do { - waitForAction(); - gui.showWaitDialog(null); - if (actionCommand.equals("cancel")) { - return null; - } else if (actionCommand.equals("hashData")) { - - showSignaturePINDialog(spec, retries); - - try { - displayHashDataInputs(signedInfo.getReference()); - } catch (DigestException ex) { - log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}, SignRequestHandler.this, "error"); - } catch (Exception ex) { - log.error("Could not display hashdata inputs: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "error"); - } - - } else if (actionCommand.equals("sign")) { - retryCounter++; - return new String(gui.getPin()); - } else if (actionCommand.equals("hashDataDone")) { - showSignaturePINDialog(spec, retries); - } else if (actionCommand.equals("error")) { - return null; - } - } while (true); - } - +// class SoftwarePinProvider implements PINProvider { +// +// protected SignedInfoType signedInfo; +// protected List hashDataInputs; +// private boolean retry = false; +// +// public SoftwarePinProvider(SignedInfoType signedInfo) { +// this.signedInfo = signedInfo; +// } +// +// private void showSignaturePINDialog(PINSpec spec, int retries) { +// if (retry) { +// gui.showSignaturePINRetryDialog(spec, retries, SignRequestHandler.this, "sign", SignRequestHandler.this, +// "cancel", SignRequestHandler.this, "hashData"); +// } else { +// gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, +// "hashData"); +// } +// } +// // @Override -// public void actionPerformed(ActionEvent e) { -// throw new UnsupportedOperationException("Not supported yet."); +// public char[] providePIN(PINSpec spec, int retries) +// throws CancelledException, InterruptedException { +// showSignaturePINDialog(spec, retries); +// +// do { +// waitForAction(); +// gui.showWaitDialog(null); +// if (actionCommand.equals("hashData")) { +// +// showSignaturePINDialog(spec, retries); +// +// try { +// displayHashDataInputs(signedInfo.getReference()); +// +// } catch (DigestException ex) { +// log.error("Bad digest value: " + ex.getMessage()); +// gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, +// new Object[] {ex.getMessage()}, +// SignRequestHandler.this, "error"); +// } catch (Exception ex) { +// log.error("Could not display hashdata inputs: " + +// ex.getMessage()); +// gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, +// new Object[] {ex.getMessage()}, +// SignRequestHandler.this, "error"); +// } +// } else if (actionCommand.equals("sign")) { +// retry = true; +// return gui.getPin(); +// } else if (actionCommand.equals("hashDataDone")) { +// showSignaturePINDialog(spec, retries); +// } else if (actionCommand.equals("cancel") || +// actionCommand.equals("error")) { +// throw new CancelledException(spec.getLocalizedName() + +// " entry cancelled"); +// } +// } while (true); // } - } +// } } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java new file mode 100644 index 00000000..54a34280 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java @@ -0,0 +1,140 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.smccstal; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.*; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.security.DigestException; +import java.util.List; + +/** + * + * @author Clemens Orthacker + */ +public class SoftwarePINProviderFactory extends PINProviderFactory { + + protected SoftwarePINProviderFactory(BKUGUIFacade gui) { + this.gui = gui; + } + + @Override + public PINProvider getSignaturePINProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + return new SignaturePinProvider(viewer, signedInfo); + } + + @Override + public PINProvider getCardPINProvider() { + return new CardPinProvider(); + } + + class SignaturePinProvider extends AbstractPINProvider { + +// protected BKUGUIFacade gui; + protected SecureViewer viewer; + protected SignedInfoType signedInfo; + protected List hashDataInputs; + + private SignaturePinProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + this.viewer = viewer; + this.signedInfo = signedInfo; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "hashData"); + + do { + waitForAction(); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + + if ("hashData".equals(action)) { + // show pin dialog in background + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "hashData"); + + try { + viewer.displayDataToBeSigned(signedInfo.getReference()); + } catch (DigestException ex) { + log.error("Bad digest value: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, + new Object[]{ex.getMessage()}, + this, "error"); + } catch (Exception ex) { + log.error("Could not display hashdata inputs: " + + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, + new Object[]{ex.getMessage()}, + this, "error"); + } + } else if ("sign".equals(action)) { + retry = true; + return gui.getPin(); + } else if ("hashDataDone".equals(action)) { + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "hashData"); + } else if ("cancel".equals(action) || + "error".equals(action)) { + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } + } while (true); + } + } + + class CardPinProvider extends AbstractPINProvider { + +// protected BKUGUIFacade gui; + + private CardPinProvider() { + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showCardPINDialog(spec, (retry) ? retries : -1, + this, "ok", + this, "cancel"); + + waitForAction(); + + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + + if ("cancel".equals(action)) { + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } + retry = true; + return gui.getPin(); + } + } +} -- cgit v1.2.3 From 616e06910051528674165319a1d6d161dff5859c Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 27 Mar 2009 17:33:11 +0000 Subject: 1.1-RC6 (pinpad, pinmgmt, secureviewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@323 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/smccstal/AbstractPINProvider.java | 2 +- .../gv/egiz/bku/smccstal/PINProviderFactory.java | 3 +- .../bku/smccstal/PinpadPINProviderFactory.java | 131 +++++++++++++-------- .../java/at/gv/egiz/bku/smccstal/SecureViewer.java | 11 +- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 14 ++- .../bku/smccstal/SoftwarePINProviderFactory.java | 25 ++-- 6 files changed, 108 insertions(+), 78 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java index e32f08d4..e2499023 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java @@ -35,7 +35,7 @@ public abstract class AbstractPINProvider implements PINProvider, ActionListener protected String action; - private boolean actionPerformed; + protected boolean actionPerformed; // protected void waitForAction() throws InterruptedException { // super.wait(); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java index 670b71dc..ce1b2d00 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java @@ -18,6 +18,7 @@ package at.gv.egiz.bku.smccstal; import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.ccid.CCID; import at.gv.egiz.smcc.PINProvider; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.stal.signedinfo.SignedInfoType; @@ -32,7 +33,7 @@ public abstract class PINProviderFactory { public static PINProviderFactory getInstance(SignatureCard forCard, BKUGUIFacade gui) { - if (forCard.ifdSupportsFeature(SignatureCard.FEATURE_VERIFY_PIN_DIRECT)) { + if (forCard.getReader().hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { return new PinpadPINProviderFactory(gui); } else { return new SoftwarePINProviderFactory(gui); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java index 55321b72..c109ceba 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java @@ -21,9 +21,8 @@ import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.smcc.CancelledException; import at.gv.egiz.smcc.PINProvider; import at.gv.egiz.smcc.PINSpec; -import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.signedinfo.SignedInfoType; -import java.util.List; +import java.security.DigestException; /** * @@ -51,8 +50,9 @@ public class PinpadPINProviderFactory extends PINProviderFactory { // protected BKUGUIFacade gui; protected SecureViewer viewer; + protected ViewerThread viewerThread; protected SignedInfoType signedInfo; - protected List hashDataInputs; + private SignaturePinProvider(SecureViewer viewer, SignedInfoType signedInfo) { @@ -60,61 +60,92 @@ public class PinpadPINProviderFactory extends PINProviderFactory { this.signedInfo = signedInfo; } + protected class ViewerThread extends Thread { + + PINSpec pinSpec; + int retries; + + public ViewerThread(PINSpec pinSpec, int retries) { + this.pinSpec = pinSpec; + this.retries = retries; + } + + @Override + public void run() { + + try { + + gui.showPinpadSignaturePINDialog(pinSpec, retries, + SignaturePinProvider.this, "secureViewer"); + + while (true) { + waitForAction(); + + if ("secureViewer".equals(action)) { + viewer.displayDataToBeSigned(signedInfo, + SignaturePinProvider.this, "pinEntry"); + } else if ("pinEntry".equals(action)) { + gui.showPinpadSignaturePINDialog(pinSpec, retries, + SignaturePinProvider.this, "secureViewer"); + } else { + log.error("unsupported action command: " + action); + } + } + + } catch (DigestException ex) { + log.error("Bad digest value: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, + new Object[]{ex.getMessage()}); + } catch (InterruptedException ex) { + log.info("pinpad secure viewer thread interrupted"); + } catch (Exception ex) { + log.error("Could not display hashdata inputs: " + + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, + new Object[]{ex.getMessage()}); + } + } + } + @Override public char[] providePIN(PINSpec spec, int retries) throws CancelledException, InterruptedException { - showPinpadPINDialog(retries, spec); + if (viewerThread != null) { + updateViewerThread(retries); + } else { + viewerThread = new ViewerThread(spec, -1); + viewerThread.start(); + } +// if (viewerThread != null) { +// log.trace("interrupt old secure viewer thread"); +// viewerThread.interrupt(); +// } +// viewerThread = new ViewerThread(spec, (retry) ? retries : -1); +// log.trace("start new secure viewer thread"); +// viewerThread.start(); + retry = true; return null; - -// do { -// waitForAction(); -// gui.showWaitDialog(null); -// -// if ("hashData".equals(action)) { -// // show pin dialog in background -// gui.showSignaturePINDialog(spec, (retry) ? retries : -1, -// this, "sign", -// this, "cancel", -// this, "hashData"); -// -// viewer.displayDataToBeSigned(signedInfo.getReference()); -// -// } else if ("sign".equals(action)) { -// retry = true; -// return gui.getPin(); -// } else if ("hashDataDone".equals(action)) { -// gui.showSignaturePINDialog(spec, (retry) ? retries : -1, -// this, "sign", -// this, "cancel", -// this, "hashData"); -// } else if ("cancel".equals(action) || -// "error".equals(action)) { -// throw new CancelledException(spec.getLocalizedName() + -// " entry cancelled"); -// } -// } while (true); } - private void showPinpadPINDialog(int retries, PINSpec pinSpec) { - String title, message; - Object[] params; - if (retry) { - title = BKUGUIFacade.TITLE_RETRY; - message = BKUGUIFacade.MESSAGE_RETRIES; - params = new Object[]{String.valueOf(retries)}; - } else { - title = BKUGUIFacade.TITLE_SIGN; - message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - params = new Object[]{pinSpec.getLocalizedName(), pinSize}; - } - gui.showMessageDialog(title, message, params); + private synchronized void updateViewerThread(int retries) { + log.trace("update viewer thread"); + viewerThread.retries = retries; + action = "pinEntry"; + actionPerformed = true; + notify(); } + + +// @Override +// protected void finalize() throws Throwable { +// if (viewerThread != null) { +// viewerThread.interrupt(); +// } +// log.info("finalizing Pinpad SignaturePinProvider"); +// super.finalize(); +// } } class CardPinProvider extends AbstractPINProvider { @@ -151,5 +182,5 @@ public class PinpadPINProviderFactory extends PINProviderFactory { gui.showMessageDialog(title, message, params); } } -} + } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java index c395679a..2ee37dc1 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java @@ -14,12 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package at.gv.egiz.bku.smccstal; -import at.gv.egiz.stal.signedinfo.ReferenceType; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.awt.event.ActionListener; import java.security.DigestException; -import java.util.List; /** * @@ -38,7 +37,7 @@ public interface SecureViewer { * (or any other digest computation error occurs) * @throws java.lang.Exception */ - void displayDataToBeSigned(List signedReferences) - throws DigestException, Exception; - + void displayDataToBeSigned(SignedInfoType signedInfo, + ActionListener okListener, String okCommand) + throws DigestException, Exception; } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index ac510f38..7a4f6572 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -33,7 +33,6 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.smcc.CancelledException; import at.gv.egiz.smcc.LockedException; import at.gv.egiz.smcc.NotActivatedException; -import at.gv.egiz.smcc.PINProvider; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCard.KeyboxName; @@ -47,11 +46,12 @@ import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; -public abstract class SignRequestHandler extends AbstractRequestHandler implements SecureViewer { +public class SignRequestHandler extends AbstractRequestHandler { private static Log log = LogFactory.getLog(SignRequestHandler.class); private static JAXBContext jaxbContext; private PINProviderFactory pinProviderFactory; + private SecureViewer secureViewer; static { try { @@ -61,6 +61,10 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen } } + public SignRequestHandler(SecureViewer secureViewer) { + this.secureViewer = secureViewer; + } + @SuppressWarnings("unchecked") @Override public STALResponse handleRequest(STALRequest request) throws InterruptedException { @@ -85,10 +89,8 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen if (pinProviderFactory == null) { pinProviderFactory = PINProviderFactory.getInstance(card, gui); } - PINProvider pinProvider = pinProviderFactory. - getSignaturePINProvider(this, si.getValue()); - - byte[] resp = card.createSignature(md.digest(), kb, pinProvider); + byte[] resp = card.createSignature(md.digest(), kb, + pinProviderFactory.getSignaturePINProvider(secureViewer, si.getValue())); if (resp == null) { return new ErrorResponse(6001); } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java index 54a34280..7d36c2c3 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java @@ -49,7 +49,6 @@ public class SoftwarePINProviderFactory extends PINProviderFactory { // protected BKUGUIFacade gui; protected SecureViewer viewer; protected SignedInfoType signedInfo; - protected List hashDataInputs; private SignaturePinProvider(SecureViewer viewer, SignedInfoType signedInfo) { @@ -64,22 +63,14 @@ public class SoftwarePINProviderFactory extends PINProviderFactory { gui.showSignaturePINDialog(spec, (retry) ? retries : -1, this, "sign", this, "cancel", - this, "hashData"); + this, "secureViewer"); do { waitForAction(); - gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, - BKUGUIFacade.MESSAGE_WAIT); - - if ("hashData".equals(action)) { - // show pin dialog in background - gui.showSignaturePINDialog(spec, (retry) ? retries : -1, - this, "sign", - this, "cancel", - this, "hashData"); + if ("secureViewer".equals(action)) { try { - viewer.displayDataToBeSigned(signedInfo.getReference()); + viewer.displayDataToBeSigned(signedInfo, this, "pinEntry"); } catch (DigestException ex) { log.error("Bad digest value: " + ex.getMessage()); gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, @@ -93,17 +84,23 @@ public class SoftwarePINProviderFactory extends PINProviderFactory { this, "error"); } } else if ("sign".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); retry = true; return gui.getPin(); - } else if ("hashDataDone".equals(action)) { + } else if ("pinEntry".equals(action)) { gui.showSignaturePINDialog(spec, (retry) ? retries : -1, this, "sign", this, "cancel", - this, "hashData"); + this, "secureViewer"); } else if ("cancel".equals(action) || "error".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); throw new CancelledException(spec.getLocalizedName() + " entry cancelled"); + } else { + log.error("unknown action command " + action); } } while (true); } -- cgit v1.2.3 From 2dbf2347bc78fd835c857ad438514fb6251f6f7a Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 2 Apr 2009 19:13:48 +0000 Subject: 1.1-RC7 (pinpad revisited) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@325 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../bku/smccstal/InfoBoxReadRequestHandler.java | 12 +- .../gv/egiz/bku/smccstal/PINProviderFactory.java | 298 ++++++++++++++++++++- .../bku/smccstal/PinpadPINProviderFactory.java | 186 ------------- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 10 +- .../bku/smccstal/SoftwarePINProviderFactory.java | 137 ---------- 5 files changed, 296 insertions(+), 347 deletions(-) delete mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java delete mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index 94444922..eeb97290 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -37,21 +37,20 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler { private static Log log = LogFactory.getLog(InfoBoxReadRequestHandler.class); - protected PINProviderFactory pinProviderFactory; +// protected PINProviderFactory pinProviderFactory; @Override public STALResponse handleRequest(STALRequest request) throws InterruptedException { if (request instanceof InfoboxReadRequest) { InfoboxReadRequest infoBox = (InfoboxReadRequest) request; - if (pinProviderFactory == null) { - pinProviderFactory = PINProviderFactory.getInstance(card, gui); - } + try { if (infoBox.getInfoboxIdentifier().equals("IdentityLink")) { newSTALMessage("Message.RequestCaption", "Message.IdentityLink"); log.debug("Handling identitylink infobox"); byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), - pinProviderFactory.getCardPINProvider(), + new PINProviderFactory(card.getReader(), gui) + .getCardPINProvider(), infoBox.getDomainIdentifier()); if (resp == null) { log.info("Got null as result->user cancelled"); @@ -98,7 +97,8 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler { log.warn("Unknown infobox identifier: " + infoBox.getInfoboxIdentifier() + " trying generic request"); byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), - pinProviderFactory.getCardPINProvider(), + new PINProviderFactory(card.getReader(), gui) + .getCardPINProvider(), infoBox.getDomainIdentifier()); if (resp == null) { return new ErrorResponse(6001); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java index ce1b2d00..78ae6c2b 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java @@ -18,31 +18,305 @@ package at.gv.egiz.bku.smccstal; import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.CancelledException; import at.gv.egiz.smcc.ccid.CCID; import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.security.DigestException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * * @author Clemens Orthacker */ -public abstract class PINProviderFactory { +public class PINProviderFactory { + + protected static final Log log = LogFactory.getLog(PINProviderFactory.class); + + protected CCID reader; + protected BKUGUIFacade gui; + + /** + * don't reuse the instance if the card reader might have changed! + * @param reader + * @param gui + */ + public PINProviderFactory(CCID reader, BKUGUIFacade gui) { + log.trace("PINProviderFactory for " + reader.getName()); + this.reader = reader; + this.gui = gui; + } + - BKUGUIFacade gui; - public static PINProviderFactory getInstance(SignatureCard forCard, - BKUGUIFacade gui) { - if (forCard.getReader().hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { - return new PinpadPINProviderFactory(gui); +// public static PINProviderFactory getInstance(SignatureCard forCard, +// BKUGUIFacade gui) { +// if (forCard.getReader().hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT) || +// forCard.getReader().hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { +// return new PinpadPINProviderFactory(gui); +// } else { +// return new SoftwarePINProviderFactory(gui); +// } +// } + + /** + * don't reuse the instance if the card reader might have changed! + * @param reader + * @param gui + * @return + */ +// public static PINProviderFactory getInstance(CCID reader, BKUGUIFacade gui) { +// log.trace("PINProviderFactory for " + reader.getName()); +// return new PINProviderFactory(reader, gui); +// } + + public PINProvider getSignaturePINProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + if (reader.hasFeature(CCID.FEATURE_VERIFY_PIN_START) || + reader.hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { + log.debug("pinpad signature-pin provider"); + return new PinpadSignaturePinProvider(viewer, signedInfo); } else { - return new SoftwarePINProviderFactory(gui); + log.debug("software signature-pin provider"); + return new SoftwareSignaturePinProvider(viewer, signedInfo); } } - public abstract PINProvider getSignaturePINProvider(SecureViewer viewer, - SignedInfoType signedInfo); - - public abstract PINProvider getCardPINProvider(); + public PINProvider getCardPINProvider() { + if (reader.hasFeature(CCID.FEATURE_VERIFY_PIN_START) || + reader.hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { + log.debug("pinpad card-pin provider"); + return new PinpadCardPinProvider(); + } else { + log.debug("software card-pin provider"); + return new SoftwareCardPinProvider(); + } + } + + class SoftwareSignaturePinProvider extends AbstractPINProvider { + + protected SecureViewer viewer; + protected SignedInfoType signedInfo; + + private SoftwareSignaturePinProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + this.viewer = viewer; + this.signedInfo = signedInfo; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "secureViewer"); + + do { + waitForAction(); + + if ("secureViewer".equals(action)) { + try { + viewer.displayDataToBeSigned(signedInfo, this, "pinEntry"); + } catch (DigestException ex) { + log.error("Bad digest value: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, + new Object[]{ex.getMessage()}, + this, "error"); + } catch (Exception ex) { + log.error("Could not display hashdata inputs: " + + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, + new Object[]{ex.getMessage()}, + this, "error"); + } + } else if ("sign".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + retry = true; + return gui.getPin(); + } else if ("pinEntry".equals(action)) { + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "secureViewer"); + } else if ("cancel".equals(action) || + "error".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } else { + log.error("unknown action command " + action); + } + } while (true); + } + } + + class SoftwareCardPinProvider extends AbstractPINProvider { + + private SoftwareCardPinProvider() { + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showCardPINDialog(spec, (retry) ? retries : -1, + this, "ok", + this, "cancel"); + + waitForAction(); + + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + + if ("cancel".equals(action)) { + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } + retry = true; + return gui.getPin(); + } + } + + class PinpadSignaturePinProvider extends AbstractPINProvider { +// protected BKUGUIFacade gui; + protected SecureViewer viewer; + protected ViewerThread viewerThread; + protected SignedInfoType signedInfo; + + + private PinpadSignaturePinProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + this.viewer = viewer; + this.signedInfo = signedInfo; + } + + protected class ViewerThread extends Thread { + + PINSpec pinSpec; + int retries; + + public ViewerThread(PINSpec pinSpec, int retries) { + this.pinSpec = pinSpec; + this.retries = retries; + } + + @Override + public void run() { + + try { + + gui.showPinpadSignaturePINDialog(pinSpec, retries, + PinpadSignaturePinProvider.this, "secureViewer"); + + while (true) { + waitForAction(); + + if ("secureViewer".equals(action)) { + viewer.displayDataToBeSigned(signedInfo, + PinpadSignaturePinProvider.this, "pinEntry"); + } else if ("pinEntry".equals(action)) { + gui.showPinpadSignaturePINDialog(pinSpec, retries, + PinpadSignaturePinProvider.this, "secureViewer"); + } else { + log.error("unsupported action command: " + action); + } + } + + } catch (DigestException ex) { + log.error("Bad digest value: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, + new Object[]{ex.getMessage()}); + } catch (InterruptedException ex) { + log.info("pinpad secure viewer thread interrupted"); + } catch (Exception ex) { + log.error("Could not display hashdata inputs: " + + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, + new Object[]{ex.getMessage()}); + } + } + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + if (viewerThread != null) { + updateViewerThread(retries); + } else { + viewerThread = new ViewerThread(spec, -1); + viewerThread.start(); + } +// if (viewerThread != null) { +// log.trace("interrupt old secure viewer thread"); +// viewerThread.interrupt(); +// } +// viewerThread = new ViewerThread(spec, (retry) ? retries : -1); +// log.trace("start new secure viewer thread"); +// viewerThread.start(); + + retry = true; + return null; + } + + private synchronized void updateViewerThread(int retries) { + log.trace("update viewer thread"); + viewerThread.retries = retries; + action = "pinEntry"; + actionPerformed = true; + notify(); + } + + +// @Override +// protected void finalize() throws Throwable { +// if (viewerThread != null) { +// viewerThread.interrupt(); +// } +// log.info("finalizing Pinpad SignaturePinProvider"); +// super.finalize(); +// } + } + + class PinpadCardPinProvider extends AbstractPINProvider { + + private PinpadCardPinProvider() { + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + showPinpadPINDialog(retries, spec); + retry = true; + return null; + + } + + private void showPinpadPINDialog(int retries, PINSpec pinSpec) { + String title, message; + Object[] params; + if (retry) { + title = BKUGUIFacade.TITLE_RETRY; + message = BKUGUIFacade.MESSAGE_RETRIES; + params = new Object[]{String.valueOf(retries)}; + } else { + title = BKUGUIFacade.TITLE_CARDPIN; + message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } + gui.showMessageDialog(title, message, params); + } + } } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java deleted file mode 100644 index c109ceba..00000000 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.smccstal; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.PINSpec; -import at.gv.egiz.stal.signedinfo.SignedInfoType; -import java.security.DigestException; - -/** - * - * @author Clemens Orthacker - */ -public class PinpadPINProviderFactory extends PINProviderFactory { - - protected PinpadPINProviderFactory(BKUGUIFacade gui) { - this.gui = gui; - } - - @Override - public PINProvider getSignaturePINProvider(SecureViewer viewer, - SignedInfoType signedInfo) { - - return new SignaturePinProvider(viewer, signedInfo); - } - - @Override - public PINProvider getCardPINProvider() { - return new CardPinProvider(); - } - - class SignaturePinProvider extends AbstractPINProvider { - -// protected BKUGUIFacade gui; - protected SecureViewer viewer; - protected ViewerThread viewerThread; - protected SignedInfoType signedInfo; - - - private SignaturePinProvider(SecureViewer viewer, - SignedInfoType signedInfo) { - this.viewer = viewer; - this.signedInfo = signedInfo; - } - - protected class ViewerThread extends Thread { - - PINSpec pinSpec; - int retries; - - public ViewerThread(PINSpec pinSpec, int retries) { - this.pinSpec = pinSpec; - this.retries = retries; - } - - @Override - public void run() { - - try { - - gui.showPinpadSignaturePINDialog(pinSpec, retries, - SignaturePinProvider.this, "secureViewer"); - - while (true) { - waitForAction(); - - if ("secureViewer".equals(action)) { - viewer.displayDataToBeSigned(signedInfo, - SignaturePinProvider.this, "pinEntry"); - } else if ("pinEntry".equals(action)) { - gui.showPinpadSignaturePINDialog(pinSpec, retries, - SignaturePinProvider.this, "secureViewer"); - } else { - log.error("unsupported action command: " + action); - } - } - - } catch (DigestException ex) { - log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, - new Object[]{ex.getMessage()}); - } catch (InterruptedException ex) { - log.info("pinpad secure viewer thread interrupted"); - } catch (Exception ex) { - log.error("Could not display hashdata inputs: " + - ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, - new Object[]{ex.getMessage()}); - } - } - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - - if (viewerThread != null) { - updateViewerThread(retries); - } else { - viewerThread = new ViewerThread(spec, -1); - viewerThread.start(); - } -// if (viewerThread != null) { -// log.trace("interrupt old secure viewer thread"); -// viewerThread.interrupt(); -// } -// viewerThread = new ViewerThread(spec, (retry) ? retries : -1); -// log.trace("start new secure viewer thread"); -// viewerThread.start(); - - retry = true; - return null; - } - - private synchronized void updateViewerThread(int retries) { - log.trace("update viewer thread"); - viewerThread.retries = retries; - action = "pinEntry"; - actionPerformed = true; - notify(); - } - - -// @Override -// protected void finalize() throws Throwable { -// if (viewerThread != null) { -// viewerThread.interrupt(); -// } -// log.info("finalizing Pinpad SignaturePinProvider"); -// super.finalize(); -// } - } - - class CardPinProvider extends AbstractPINProvider { - - private CardPinProvider() { - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - - showPinpadPINDialog(retries, spec); - retry = true; - return null; - - } - - private void showPinpadPINDialog(int retries, PINSpec pinSpec) { - String title, message; - Object[] params; - if (retry) { - title = BKUGUIFacade.TITLE_RETRY; - message = BKUGUIFacade.MESSAGE_RETRIES; - params = new Object[]{String.valueOf(retries)}; - } else { - title = BKUGUIFacade.TITLE_CARDPIN; - message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - params = new Object[]{pinSpec.getLocalizedName(), pinSize}; - } - gui.showMessageDialog(title, message, params); - } - } - } - diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 7a4f6572..56fc8804 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -50,7 +50,7 @@ public class SignRequestHandler extends AbstractRequestHandler { private static Log log = LogFactory.getLog(SignRequestHandler.class); private static JAXBContext jaxbContext; - private PINProviderFactory pinProviderFactory; +// private PINProviderFactory pinProviderFactory; private SecureViewer secureViewer; static { @@ -86,11 +86,9 @@ public class SignRequestHandler extends AbstractRequestHandler { md.update(signReq.getSignedInfo()); KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq.getKeyIdentifier()); - if (pinProviderFactory == null) { - pinProviderFactory = PINProviderFactory.getInstance(card, gui); - } - byte[] resp = card.createSignature(md.digest(), kb, - pinProviderFactory.getSignaturePINProvider(secureViewer, si.getValue())); + byte[] resp = card.createSignature(md.digest(), kb, + new PINProviderFactory(card.getReader(), gui) + .getSignaturePINProvider(secureViewer, si.getValue())); if (resp == null) { return new ErrorResponse(6001); } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java deleted file mode 100644 index 7d36c2c3..00000000 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package at.gv.egiz.bku.smccstal; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.smcc.*; -import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.signedinfo.SignedInfoType; -import java.security.DigestException; -import java.util.List; - -/** - * - * @author Clemens Orthacker - */ -public class SoftwarePINProviderFactory extends PINProviderFactory { - - protected SoftwarePINProviderFactory(BKUGUIFacade gui) { - this.gui = gui; - } - - @Override - public PINProvider getSignaturePINProvider(SecureViewer viewer, - SignedInfoType signedInfo) { - return new SignaturePinProvider(viewer, signedInfo); - } - - @Override - public PINProvider getCardPINProvider() { - return new CardPinProvider(); - } - - class SignaturePinProvider extends AbstractPINProvider { - -// protected BKUGUIFacade gui; - protected SecureViewer viewer; - protected SignedInfoType signedInfo; - - private SignaturePinProvider(SecureViewer viewer, - SignedInfoType signedInfo) { - this.viewer = viewer; - this.signedInfo = signedInfo; - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - - gui.showSignaturePINDialog(spec, (retry) ? retries : -1, - this, "sign", - this, "cancel", - this, "secureViewer"); - - do { - waitForAction(); - - if ("secureViewer".equals(action)) { - try { - viewer.displayDataToBeSigned(signedInfo, this, "pinEntry"); - } catch (DigestException ex) { - log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, - new Object[]{ex.getMessage()}, - this, "error"); - } catch (Exception ex) { - log.error("Could not display hashdata inputs: " + - ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, - new Object[]{ex.getMessage()}, - this, "error"); - } - } else if ("sign".equals(action)) { - gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, - BKUGUIFacade.MESSAGE_WAIT); - retry = true; - return gui.getPin(); - } else if ("pinEntry".equals(action)) { - gui.showSignaturePINDialog(spec, (retry) ? retries : -1, - this, "sign", - this, "cancel", - this, "secureViewer"); - } else if ("cancel".equals(action) || - "error".equals(action)) { - gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, - BKUGUIFacade.MESSAGE_WAIT); - throw new CancelledException(spec.getLocalizedName() + - " entry cancelled"); - } else { - log.error("unknown action command " + action); - } - } while (true); - } - } - - class CardPinProvider extends AbstractPINProvider { - -// protected BKUGUIFacade gui; - - private CardPinProvider() { - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - - gui.showCardPINDialog(spec, (retry) ? retries : -1, - this, "ok", - this, "cancel"); - - waitForAction(); - - gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, - BKUGUIFacade.MESSAGE_WAIT); - - if ("cancel".equals(action)) { - throw new CancelledException(spec.getLocalizedName() + - " entry cancelled"); - } - retry = true; - return gui.getPin(); - } - } -} -- cgit v1.2.3 From ac3d1788dfa8db5dd8de5a99764b439dd5ec54db Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 7 Apr 2009 08:37:53 +0000 Subject: MOCCA-1.1 final git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@327 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java index 78ae6c2b..543fbb3a 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java @@ -28,7 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * + * don't reuse the instance if the card reader might have changed! * @author Clemens Orthacker */ public class PINProviderFactory { -- cgit v1.2.3 From f5de24a8c3a20311fc0b0849a427e780d2fc2325 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 17 Apr 2009 07:25:16 +0000 Subject: local secureviewer git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@333 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 66 +--------------------- 1 file changed, 3 insertions(+), 63 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 56fc8804..560f1373 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -50,9 +50,7 @@ public class SignRequestHandler extends AbstractRequestHandler { private static Log log = LogFactory.getLog(SignRequestHandler.class); private static JAXBContext jaxbContext; -// private PINProviderFactory pinProviderFactory; - private SecureViewer secureViewer; - + static { try { jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName()); @@ -61,6 +59,8 @@ public class SignRequestHandler extends AbstractRequestHandler { } } + protected SecureViewer secureViewer; + public SignRequestHandler(SecureViewer secureViewer) { this.secureViewer = secureViewer; } @@ -142,64 +142,4 @@ public class SignRequestHandler extends AbstractRequestHandler { return true; } -// class SoftwarePinProvider implements PINProvider { -// -// protected SignedInfoType signedInfo; -// protected List hashDataInputs; -// private boolean retry = false; -// -// public SoftwarePinProvider(SignedInfoType signedInfo) { -// this.signedInfo = signedInfo; -// } -// -// private void showSignaturePINDialog(PINSpec spec, int retries) { -// if (retry) { -// gui.showSignaturePINRetryDialog(spec, retries, SignRequestHandler.this, "sign", SignRequestHandler.this, -// "cancel", SignRequestHandler.this, "hashData"); -// } else { -// gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, -// "hashData"); -// } -// } -// -// @Override -// public char[] providePIN(PINSpec spec, int retries) -// throws CancelledException, InterruptedException { -// showSignaturePINDialog(spec, retries); -// -// do { -// waitForAction(); -// gui.showWaitDialog(null); -// if (actionCommand.equals("hashData")) { -// -// showSignaturePINDialog(spec, retries); -// -// try { -// displayHashDataInputs(signedInfo.getReference()); -// -// } catch (DigestException ex) { -// log.error("Bad digest value: " + ex.getMessage()); -// gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, -// new Object[] {ex.getMessage()}, -// SignRequestHandler.this, "error"); -// } catch (Exception ex) { -// log.error("Could not display hashdata inputs: " + -// ex.getMessage()); -// gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, -// new Object[] {ex.getMessage()}, -// SignRequestHandler.this, "error"); -// } -// } else if (actionCommand.equals("sign")) { -// retry = true; -// return gui.getPin(); -// } else if (actionCommand.equals("hashDataDone")) { -// showSignaturePINDialog(spec, retries); -// } else if (actionCommand.equals("cancel") || -// actionCommand.equals("error")) { -// throw new CancelledException(spec.getLocalizedName() + -// " entry cancelled"); -// } -// } while (true); -// } -// } } -- cgit v1.2.3 From 6cb4a071eab9a3b8cf78b8ec7e407aa148f2d038 Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 1 Jul 2009 13:03:41 +0000 Subject: Major refactoring of SMCC git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@381 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index eeb97290..32e990c5 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -53,8 +53,8 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler { .getCardPINProvider(), infoBox.getDomainIdentifier()); if (resp == null) { - log.info("Got null as result->user cancelled"); - return new ErrorResponse(6001); + log.info("Infobox doesn't contain any data. Assume card is not activated."); + throw new NotActivatedException(); } else { try { resp = DomainIdConverter.convertDomainId(resp, infoBox -- cgit v1.2.3 From 22001c93bca360d1b15c252cb22d2a4147ff350d Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 20 Aug 2009 16:24:55 +0000 Subject: [#430] Activation/PIN-management in MOCCA Web Start - new Modules: smccSTALExt, BKUGuiExt in order not to depend on BKUAppletExt in BKULocal - provide stal-request handler de-registration in abstractSMCCSTAL git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@448 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 71f35181..d0762da9 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -160,6 +160,11 @@ public abstract class AbstractSMCCSTAL implements STAL { handlerMap.put(id.getSimpleName(), handler); } + public void removeRequestHandler(Class id) { + log.debug("De-registering STAL request handler: " + id.getSimpleName()); + handlerMap.remove(id.getSimpleName()); + } + public SMCCSTALRequestHandler getRequestHandler( Class request) { return handlerMap.get(request.getSimpleName()); -- cgit v1.2.3 From caca721368d8c24559b1cd5ea2018884b4874f6b Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 10 Nov 2009 15:30:16 +0000 Subject: Removed switchFocusListener due to problem with viewer/help dialogs on Firefox/Mac git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@539 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java | 4 ++-- .../src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java index e2499023..bc52c955 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java @@ -47,7 +47,7 @@ public abstract class AbstractPINProvider implements PINProvider, ActionListener this.wait(); } } catch (InterruptedException e) { - log.error("interrupt in waitForAction"); + log.error("[" + Thread.currentThread().getName() + "] interrupt in waitForAction"); throw e; } actionPerformed = false; @@ -60,7 +60,7 @@ public abstract class AbstractPINProvider implements PINProvider, ActionListener @Override public void actionPerformed(ActionEvent e) { - log.debug("command " + e.getActionCommand()); + log.debug("[" + Thread.currentThread().getName() + "] action performed - " + e.getActionCommand()); action = e.getActionCommand(); actionPerformed(); } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java index 543fbb3a..e5afe0ae 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java @@ -116,7 +116,9 @@ public class PINProviderFactory { this, "secureViewer"); do { + log.debug("[" + Thread.currentThread().getName() + "] wait for action"); waitForAction(); + log.debug("[" + Thread.currentThread().getName() + "] received action"); if ("secureViewer".equals(action)) { try { @@ -169,6 +171,7 @@ public class PINProviderFactory { this, "ok", this, "cancel"); + log.debug("[" + Thread.currentThread().getName() + "] wait for action"); waitForAction(); gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, @@ -216,7 +219,9 @@ public class PINProviderFactory { PinpadSignaturePinProvider.this, "secureViewer"); while (true) { + log.debug("[" + Thread.currentThread().getName() + "] wait for action"); waitForAction(); + log.debug("[" + Thread.currentThread().getName() + "] received action"); if ("secureViewer".equals(action)) { viewer.displayDataToBeSigned(signedInfo, -- cgit v1.2.3 From 68941b57df2caeead67a5bede2ef5a635d07db32 Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 11 Nov 2009 15:51:08 +0000 Subject: Added support for SHA-256 and partial support for e-card G3, BELPIC and Italian cards. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@540 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/smccstal/SignRequestHandler.java | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 560f1373..58d7b305 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -18,9 +18,8 @@ package at.gv.egiz.bku.smccstal; import at.gv.egiz.bku.gui.BKUGUIFacade; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; @@ -44,7 +43,6 @@ import at.gv.egiz.stal.SignRequest; import at.gv.egiz.stal.SignResponse; import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.SignedInfoType; -import at.gv.egiz.stal.util.JCEAlgorithmNames; public class SignRequestHandler extends AbstractRequestHandler { @@ -77,18 +75,11 @@ public class SignRequestHandler extends AbstractRequestHandler { JAXBElement si = (JAXBElement) unmarshaller.unmarshal(is); String signatureMethod = si.getValue().getSignatureMethod().getAlgorithm(); log.debug("Found signature method: " + signatureMethod); - String jceName = JCEAlgorithmNames.getJCEHashName(signatureMethod); - if (jceName == null) { - log.error("Hash algorithm not supported:"); - return new ErrorResponse(4006); - } - MessageDigest md = MessageDigest.getInstance(jceName); - md.update(signReq.getSignedInfo()); KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq.getKeyIdentifier()); - byte[] resp = card.createSignature(md.digest(), kb, + byte[] resp = card.createSignature(new ByteArrayInputStream(signReq.getSignedInfo()), kb, new PINProviderFactory(card.getReader(), gui) - .getSignaturePINProvider(secureViewer, si.getValue())); + .getSignaturePINProvider(secureViewer, si.getValue()), signatureMethod); if (resp == null) { return new ErrorResponse(6001); } @@ -127,9 +118,9 @@ public class SignRequestHandler extends AbstractRequestHandler { } catch (JAXBException e) { log.error("Cannot unmarshall signed info", e); return new ErrorResponse(1000); - } catch (NoSuchAlgorithmException e) { - log.error(e); - return new ErrorResponse(1000); + } catch (IOException e) { + log.error("Error while creating signature: " + e); + return new ErrorResponse(4000); } } else { log.fatal("Got unexpected STAL request: " + request); -- cgit v1.2.3 From 3da4655d011dfc2f04f9e4ac28b38aee42d01bc0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 5 Jan 2010 10:06:47 +0000 Subject: Features [#437] Handle pinpad [64:03] response apdu correctly [#445] pin entry feedback for VERIFY_PIN_START/FINISH [#471] Provide SecureViewer Link before Pinpad PinEntry timeout starts Bugs [#479] PIN Managment Applet allows unmatching new pin and pin confirmation [#480] PIN Management displays blocked PINs as ACTIVE [#486] Not possible to select 3 times in series the same item from signedReferencesList for display in secureViewer [#506] change pin dialog (gui) issues [#508] e-card G3 PIN activation (with TransportPIN) not supported [#509] closing secure viewer window (WINDOW_CLOSING) leaves "signature data is displayed in viewer" dialog in applet git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@565 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/pin/gui/AbstractPINProvider.java | 60 ++++ .../java/at/gv/egiz/bku/pin/gui/SignPINGUI.java | 136 +++++++++ .../at/gv/egiz/bku/pin/gui/SignPINProvider.java | 105 +++++++ .../java/at/gv/egiz/bku/pin/gui/VerifyPINGUI.java | 76 +++++ .../at/gv/egiz/bku/pin/gui/VerifyPINProvider.java | 72 +++++ .../gv/egiz/bku/smccstal/AbstractPINProvider.java | 67 ----- .../bku/smccstal/InfoBoxReadRequestHandler.java | 9 +- .../gv/egiz/bku/smccstal/PINProviderFactory.java | 327 --------------------- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 4 +- 9 files changed, 454 insertions(+), 402 deletions(-) create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/AbstractPINProvider.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/SignPINGUI.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/SignPINProvider.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/VerifyPINGUI.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/VerifyPINProvider.java delete mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java delete mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java (limited to 'smccSTAL/src/main/java/at/gv/egiz/bku') diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/AbstractPINProvider.java b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/AbstractPINProvider.java new file mode 100644 index 00000000..00738188 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/AbstractPINProvider.java @@ -0,0 +1,60 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.pin.gui; + +import at.gv.egiz.smcc.pin.gui.PINProvider; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * common super class providing action listener for all PIN GUIs + * @author Clemens Orthacker + */ +public abstract class AbstractPINProvider implements ActionListener { + + protected static final Log log = LogFactory.getLog(AbstractPINProvider.class); + + protected String action; + protected boolean actionPerformed; + + protected synchronized void waitForAction() throws InterruptedException { + try { + while (!actionPerformed) { + this.wait(); + } + } catch (InterruptedException e) { + log.error("[" + Thread.currentThread().getName() + "] interrupt in waitForAction"); + throw e; + } + actionPerformed = false; + } + + private synchronized void actionPerformed() { + actionPerformed = true; + notify();//All(); + } + + @Override + public void actionPerformed(ActionEvent e) { + log.debug("[" + Thread.currentThread().getName() + "] action performed - " + e.getActionCommand()); + action = e.getActionCommand(); + actionPerformed(); + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/SignPINGUI.java b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/SignPINGUI.java new file mode 100644 index 00000000..81db0e90 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/SignPINGUI.java @@ -0,0 +1,136 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.pin.gui; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.smccstal.SecureViewer; +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.pin.gui.PINGUI; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.security.DigestException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The number of retries is not fixed and there is no way (?) to obtain this value. + * A PINProvider should therefore maintain an internal retry counter or flag + * to decide whether or not to warn the user (num retries passed in providePIN). + * + * Therefore PINProvider objects should not be reused. + * + * (ACOS: reload counter: between 0 and 15, where 15 meens deactivated) + * + * @author Clemens Orthacker + */ +public class SignPINGUI extends SignPINProvider implements PINGUI { + + protected static final Log log = LogFactory.getLog(SignPINGUI.class); + + private boolean retry = false; + + public SignPINGUI(BKUGUIFacade gui, SecureViewer viewer, SignedInfoType signedInfo) { + super(gui, viewer, signedInfo); + } + + @Override + public void enterPINDirect(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + if (retry) { + gui.showEnterPINDirect(spec, retries); + } else { + showSignatureData(spec); + gui.showEnterPINDirect(spec, -1); + retry = true; + } + } + + @Override + public void enterPIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + if (retry) { + gui.showEnterPIN(spec, retries); + } else { + showSignatureData(spec); + gui.showEnterPIN(spec, -1); + retry = true; + } + } + + private void showSignatureData(PINSpec spec) + throws CancelledException, InterruptedException { + + gui.showSignatureDataDialog(spec, + this, "enterPIN", + this, "cancel", + this, "secureViewer"); + + do { + log.trace("[" + Thread.currentThread().getName() + "] wait for action"); + waitForAction(); + log.trace("[" + Thread.currentThread().getName() + "] received action " + action); + + if ("secureViewer".equals(action)) { + try { + viewer.displayDataToBeSigned(signedInfo, this, "signatureData"); + } catch (DigestException ex) { + log.error("Bad digest value: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, + new Object[]{ex.getMessage()}, + this, "error"); + } catch (Exception ex) { + log.error("Could not display hashdata inputs: " + + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, + new Object[]{ex.getMessage()}, + this, "error"); + } + } else if ("signatureData".equals(action)) { + gui.showSignatureDataDialog(spec, + this, "enterPIN", + this, "cancel", + this, "secureViewer"); + } else if ("enterPIN".equals(action)) { + return; + } else if ("cancel".equals(action) || + "error".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } else { + log.error("unknown action command " + action); + } + } while (true); + } + + @Override + public void validKeyPressed() { + gui.validKeyPressed(); + } + + @Override + public void correctionButtonPressed() { + gui.correctionButtonPressed(); + } + + @Override + public void allKeysCleared() { + gui.allKeysCleared(); + } + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/SignPINProvider.java b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/SignPINProvider.java new file mode 100644 index 00000000..fc1d39af --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/SignPINProvider.java @@ -0,0 +1,105 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.pin.gui; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.smccstal.SecureViewer; +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.pin.gui.PINProvider; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.security.DigestException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The number of retries is not fixed and there is no way (?) to obtain this value. + * A PINProvider should therefore maintain an internal retry counter or flag + * to decide whether or not to warn the user (num retries passed in providePIN). + * + * Therefore PINProvider objects should not be reused. + * + * (ACOS: reload counter: between 0 and 15, where 15 meens deactivated) + * + * @author Clemens Orthacker + */ +public class SignPINProvider extends AbstractPINProvider implements PINProvider { + + protected static final Log log = LogFactory.getLog(SignPINProvider.class); + + protected BKUGUIFacade gui; + protected SecureViewer viewer; + protected SignedInfoType signedInfo; + private boolean retry = false; + + public SignPINProvider(BKUGUIFacade gui, SecureViewer viewer, SignedInfoType signedInfo) { + this.gui = gui; + this.viewer = viewer; + this.signedInfo = signedInfo; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "secureViewer"); + + do { + log.trace("[" + Thread.currentThread().getName() + "] wait for action"); + waitForAction(); + log.trace("[" + Thread.currentThread().getName() + "] received action " + action); + + if ("secureViewer".equals(action)) { + try { + viewer.displayDataToBeSigned(signedInfo, this, "pinEntry"); + } catch (DigestException ex) { + log.error("Bad digest value: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, + new Object[]{ex.getMessage()}, + this, "error"); + } catch (Exception ex) { + log.error("Could not display hashdata inputs: " + + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, + new Object[]{ex.getMessage()}, + this, "error"); + } + } else if ("sign".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + retry = true; + return gui.getPin(); + } else if ("pinEntry".equals(action)) { + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "secureViewer"); + } else if ("cancel".equals(action) || + "error".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } else { + log.error("unknown action command " + action); + } + } while (true); + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/VerifyPINGUI.java b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/VerifyPINGUI.java new file mode 100644 index 00000000..dc21492e --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/VerifyPINGUI.java @@ -0,0 +1,76 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.pin.gui; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.pin.gui.PINGUI; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The number of retries is not fixed and there is no way (?) to obtain this value. + * A PINProvider should therefore maintain an internal retry counter or flag + * to decide whether or not to warn the user (num retries passed in providePIN). + * + * Therefore PINProvider objects should not be reused. + * + * (ACOS: reload counter: between 0 and 15, where 15 meens deactivated) + * + * @author Clemens Orthacker + */ +public class VerifyPINGUI extends VerifyPINProvider implements PINGUI { + + protected static final Log log = LogFactory.getLog(VerifyPINGUI.class); + + private boolean retry = false; + + public VerifyPINGUI(BKUGUIFacade gui) { + super(gui); + } + + @Override + public void enterPINDirect(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + gui.showEnterPINDirect(spec, (retry) ? retries : -1); + retry = true; + } + + @Override + public void enterPIN(PINSpec spec, int retries) { + gui.showEnterPIN(spec, (retry) ? retries : -1); + retry = true; + } + + + @Override + public void validKeyPressed() { + gui.validKeyPressed(); + } + + @Override + public void correctionButtonPressed() { + gui.correctionButtonPressed(); + } + + @Override + public void allKeysCleared() { + gui.allKeysCleared(); + } + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/VerifyPINProvider.java b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/VerifyPINProvider.java new file mode 100644 index 00000000..fda1e402 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/pin/gui/VerifyPINProvider.java @@ -0,0 +1,72 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.pin.gui; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.pin.gui.PINProvider; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The number of retries is not fixed and there is no way (?) to obtain this value. + * A PINProvider should therefore maintain an internal retry counter or flag + * to decide whether or not to warn the user (num retries passed in providePIN). + * + * Therefore PINProvider objects should not be reused. + * + * (ACOS: reload counter: between 0 and 15, where 15 meens deactivated) + * + * @author Clemens Orthacker + */ +public class VerifyPINProvider extends AbstractPINProvider implements PINProvider { + + protected static final Log log = LogFactory.getLog(VerifyPINProvider.class); + + protected BKUGUIFacade gui; + private boolean retry = false; + + public VerifyPINProvider(BKUGUIFacade gui) { + this.gui = gui; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showVerifyPINDialog(spec, (retry) ? retries : -1, + this, "verify", + this, "cancel"); + + log.trace("[" + Thread.currentThread().getName() + "] wait for action"); + waitForAction(); + log.trace("[" + Thread.currentThread().getName() + "] received action " + action); + + if ("cancel".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } + + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + retry = true; + return gui.getPin(); + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java deleted file mode 100644 index bc52c955..00000000 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.smccstal; - -import at.gv.egiz.smcc.PINProvider; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker - */ -public abstract class AbstractPINProvider implements PINProvider, ActionListener { - - protected static final Log log = LogFactory.getLog(AbstractPINProvider.class); - - protected boolean retry = false; - - protected String action; - - protected boolean actionPerformed; - -// protected void waitForAction() throws InterruptedException { -// super.wait(); -// } - - protected synchronized void waitForAction() throws InterruptedException { - try { - while (!actionPerformed) { - this.wait(); - } - } catch (InterruptedException e) { - log.error("[" + Thread.currentThread().getName() + "] interrupt in waitForAction"); - throw e; - } - actionPerformed = false; - } - - private synchronized void actionPerformed() { - actionPerformed = true; - notify();//All(); - } - - @Override - public void actionPerformed(ActionEvent e) { - log.debug("[" + Thread.currentThread().getName() + "] action performed - " + e.getActionCommand()); - action = e.getActionCommand(); - actionPerformed(); - } -} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index 32e990c5..b34ab862 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -17,14 +17,13 @@ package at.gv.egiz.bku.smccstal; import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.pin.gui.VerifyPINGUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.smcc.CancelledException; import at.gv.egiz.smcc.LockedException; import at.gv.egiz.smcc.NotActivatedException; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.stal.ErrorResponse; @@ -49,8 +48,7 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler { newSTALMessage("Message.RequestCaption", "Message.IdentityLink"); log.debug("Handling identitylink infobox"); byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), - new PINProviderFactory(card.getReader(), gui) - .getCardPINProvider(), + new VerifyPINGUI(gui), infoBox.getDomainIdentifier()); if (resp == null) { log.info("Infobox doesn't contain any data. Assume card is not activated."); @@ -97,8 +95,7 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler { log.warn("Unknown infobox identifier: " + infoBox.getInfoboxIdentifier() + " trying generic request"); byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), - new PINProviderFactory(card.getReader(), gui) - .getCardPINProvider(), + new VerifyPINGUI(gui), infoBox.getDomainIdentifier()); if (resp == null) { return new ErrorResponse(6001); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java deleted file mode 100644 index e5afe0ae..00000000 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.smccstal; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.ccid.CCID; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.PINSpec; -import at.gv.egiz.stal.signedinfo.SignedInfoType; -import java.security.DigestException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * don't reuse the instance if the card reader might have changed! - * @author Clemens Orthacker - */ -public class PINProviderFactory { - - protected static final Log log = LogFactory.getLog(PINProviderFactory.class); - - protected CCID reader; - protected BKUGUIFacade gui; - - /** - * don't reuse the instance if the card reader might have changed! - * @param reader - * @param gui - */ - public PINProviderFactory(CCID reader, BKUGUIFacade gui) { - log.trace("PINProviderFactory for " + reader.getName()); - this.reader = reader; - this.gui = gui; - } - - - -// public static PINProviderFactory getInstance(SignatureCard forCard, -// BKUGUIFacade gui) { -// if (forCard.getReader().hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT) || -// forCard.getReader().hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { -// return new PinpadPINProviderFactory(gui); -// } else { -// return new SoftwarePINProviderFactory(gui); -// } -// } - - /** - * don't reuse the instance if the card reader might have changed! - * @param reader - * @param gui - * @return - */ -// public static PINProviderFactory getInstance(CCID reader, BKUGUIFacade gui) { -// log.trace("PINProviderFactory for " + reader.getName()); -// return new PINProviderFactory(reader, gui); -// } - - public PINProvider getSignaturePINProvider(SecureViewer viewer, - SignedInfoType signedInfo) { - if (reader.hasFeature(CCID.FEATURE_VERIFY_PIN_START) || - reader.hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { - log.debug("pinpad signature-pin provider"); - return new PinpadSignaturePinProvider(viewer, signedInfo); - } else { - log.debug("software signature-pin provider"); - return new SoftwareSignaturePinProvider(viewer, signedInfo); - } - } - - public PINProvider getCardPINProvider() { - if (reader.hasFeature(CCID.FEATURE_VERIFY_PIN_START) || - reader.hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { - log.debug("pinpad card-pin provider"); - return new PinpadCardPinProvider(); - } else { - log.debug("software card-pin provider"); - return new SoftwareCardPinProvider(); - } - } - - class SoftwareSignaturePinProvider extends AbstractPINProvider { - - protected SecureViewer viewer; - protected SignedInfoType signedInfo; - - private SoftwareSignaturePinProvider(SecureViewer viewer, - SignedInfoType signedInfo) { - this.viewer = viewer; - this.signedInfo = signedInfo; - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - - gui.showSignaturePINDialog(spec, (retry) ? retries : -1, - this, "sign", - this, "cancel", - this, "secureViewer"); - - do { - log.debug("[" + Thread.currentThread().getName() + "] wait for action"); - waitForAction(); - log.debug("[" + Thread.currentThread().getName() + "] received action"); - - if ("secureViewer".equals(action)) { - try { - viewer.displayDataToBeSigned(signedInfo, this, "pinEntry"); - } catch (DigestException ex) { - log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, - new Object[]{ex.getMessage()}, - this, "error"); - } catch (Exception ex) { - log.error("Could not display hashdata inputs: " + - ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, - new Object[]{ex.getMessage()}, - this, "error"); - } - } else if ("sign".equals(action)) { - gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, - BKUGUIFacade.MESSAGE_WAIT); - retry = true; - return gui.getPin(); - } else if ("pinEntry".equals(action)) { - gui.showSignaturePINDialog(spec, (retry) ? retries : -1, - this, "sign", - this, "cancel", - this, "secureViewer"); - } else if ("cancel".equals(action) || - "error".equals(action)) { - gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, - BKUGUIFacade.MESSAGE_WAIT); - throw new CancelledException(spec.getLocalizedName() + - " entry cancelled"); - } else { - log.error("unknown action command " + action); - } - } while (true); - } - } - - class SoftwareCardPinProvider extends AbstractPINProvider { - - private SoftwareCardPinProvider() { - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - - gui.showCardPINDialog(spec, (retry) ? retries : -1, - this, "ok", - this, "cancel"); - - log.debug("[" + Thread.currentThread().getName() + "] wait for action"); - waitForAction(); - - gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, - BKUGUIFacade.MESSAGE_WAIT); - - if ("cancel".equals(action)) { - throw new CancelledException(spec.getLocalizedName() + - " entry cancelled"); - } - retry = true; - return gui.getPin(); - } - } - - class PinpadSignaturePinProvider extends AbstractPINProvider { - -// protected BKUGUIFacade gui; - protected SecureViewer viewer; - protected ViewerThread viewerThread; - protected SignedInfoType signedInfo; - - - private PinpadSignaturePinProvider(SecureViewer viewer, - SignedInfoType signedInfo) { - this.viewer = viewer; - this.signedInfo = signedInfo; - } - - protected class ViewerThread extends Thread { - - PINSpec pinSpec; - int retries; - - public ViewerThread(PINSpec pinSpec, int retries) { - this.pinSpec = pinSpec; - this.retries = retries; - } - - @Override - public void run() { - - try { - - gui.showPinpadSignaturePINDialog(pinSpec, retries, - PinpadSignaturePinProvider.this, "secureViewer"); - - while (true) { - log.debug("[" + Thread.currentThread().getName() + "] wait for action"); - waitForAction(); - log.debug("[" + Thread.currentThread().getName() + "] received action"); - - if ("secureViewer".equals(action)) { - viewer.displayDataToBeSigned(signedInfo, - PinpadSignaturePinProvider.this, "pinEntry"); - } else if ("pinEntry".equals(action)) { - gui.showPinpadSignaturePINDialog(pinSpec, retries, - PinpadSignaturePinProvider.this, "secureViewer"); - } else { - log.error("unsupported action command: " + action); - } - } - - } catch (DigestException ex) { - log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, - new Object[]{ex.getMessage()}); - } catch (InterruptedException ex) { - log.info("pinpad secure viewer thread interrupted"); - } catch (Exception ex) { - log.error("Could not display hashdata inputs: " + - ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, - new Object[]{ex.getMessage()}); - } - } - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - - if (viewerThread != null) { - updateViewerThread(retries); - } else { - viewerThread = new ViewerThread(spec, -1); - viewerThread.start(); - } -// if (viewerThread != null) { -// log.trace("interrupt old secure viewer thread"); -// viewerThread.interrupt(); -// } -// viewerThread = new ViewerThread(spec, (retry) ? retries : -1); -// log.trace("start new secure viewer thread"); -// viewerThread.start(); - - retry = true; - return null; - } - - private synchronized void updateViewerThread(int retries) { - log.trace("update viewer thread"); - viewerThread.retries = retries; - action = "pinEntry"; - actionPerformed = true; - notify(); - } - - -// @Override -// protected void finalize() throws Throwable { -// if (viewerThread != null) { -// viewerThread.interrupt(); -// } -// log.info("finalizing Pinpad SignaturePinProvider"); -// super.finalize(); -// } - } - - class PinpadCardPinProvider extends AbstractPINProvider { - - private PinpadCardPinProvider() { - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - - showPinpadPINDialog(retries, spec); - retry = true; - return null; - - } - - private void showPinpadPINDialog(int retries, PINSpec pinSpec) { - String title, message; - Object[] params; - if (retry) { - title = BKUGUIFacade.TITLE_RETRY; - message = BKUGUIFacade.MESSAGE_RETRIES; - params = new Object[]{String.valueOf(retries)}; - } else { - title = BKUGUIFacade.TITLE_CARDPIN; - message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - params = new Object[]{pinSpec.getLocalizedName(), pinSize}; - } - gui.showMessageDialog(title, message, params); - } - } -} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 58d7b305..5b436d16 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -17,6 +17,7 @@ package at.gv.egiz.bku.smccstal; import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.pin.gui.SignPINGUI; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -78,8 +79,7 @@ public class SignRequestHandler extends AbstractRequestHandler { KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq.getKeyIdentifier()); byte[] resp = card.createSignature(new ByteArrayInputStream(signReq.getSignedInfo()), kb, - new PINProviderFactory(card.getReader(), gui) - .getSignaturePINProvider(secureViewer, si.getValue()), signatureMethod); + new SignPINGUI(gui, secureViewer, si.getValue()), signatureMethod); if (resp == null) { return new ErrorResponse(6001); } -- cgit v1.2.3