diff options
Diffstat (limited to 'smccSTAL/src/main/java')
6 files changed, 108 insertions, 78 deletions
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<HashDataInput> 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<ReferenceType> 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<HashDataInput> 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); } |