diff options
author | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-11-11 12:16:00 +0000 |
---|---|---|
committer | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-11-11 12:16:00 +0000 |
commit | e4a47aa9393d74647f4f0c66b54dc4519fed492f (patch) | |
tree | dcacbccfc7b4e777854ee6b9b1c74f84f7fc7915 | |
parent | 82c59c9d862d3ee9ad43fdc1509d0b5a61cc107c (diff) | |
download | mocca-e4a47aa9393d74647f4f0c66b54dc4519fed492f.tar.gz mocca-e4a47aa9393d74647f4f0c66b54dc4519fed492f.tar.bz2 mocca-e4a47aa9393d74647f4f0c66b54dc4519fed492f.zip |
Interrupt in waitForAction (applet closed)
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@162 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
13 files changed, 113 insertions, 80 deletions
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java b/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java index 9e56701f..2baff834 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java @@ -106,8 +106,9 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { /* (non-Javadoc) * @see at.gv.egiz.smcc.SignatureCard#getCertificate(at.gv.egiz.smcc.SignatureCard.KeyboxName) */ + @Override public byte[] getCertificate(KeyboxName keyboxName) - throws SignatureCardException { + throws SignatureCardException, InterruptedException { byte[] aid; byte[] efc; @@ -150,8 +151,9 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { /* (non-Javadoc) * @see at.gv.egiz.smcc.SignatureCard#getInfobox(java.lang.String, at.gv.egiz.smcc.PINProvider, java.lang.String) */ + @Override public byte[] getInfobox(String infobox, PINProvider provider, String domainId) - throws SignatureCardException { + throws SignatureCardException, InterruptedException { if ("IdentityLink".equals(infobox)) { @@ -181,8 +183,9 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { } + @Override public byte[] createSignature(byte[] hash, KeyboxName keyboxName, - PINProvider provider) throws SignatureCardException { + PINProvider provider) throws SignatureCardException, InterruptedException { if (hash.length != 20) { throw new IllegalArgumentException("Hash value must be of length 20."); @@ -299,8 +302,9 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { * @throws javax.smartcardio.CardException * @throws at.gv.egiz.smcc.SignatureCardException */ + @Override protected void verifyPIN(PINProvider pinProvider, PINSpec spec, byte kid) - throws CardException, CancelledException, SignatureCardException { + throws CardException, CancelledException, SignatureCardException, InterruptedException { int retries = -1; do { diff --git a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java index cebc63fc..b828e8cd 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java @@ -110,7 +110,7 @@ public abstract class AbstractSignatureCard implements SignatureCard { * if VERIFY PIN fails */ protected abstract void verifyPIN(PINProvider pinProvider, PINSpec spec, - byte kid) throws CardException, SignatureCardException; + byte kid) throws CardException, SignatureCardException, InterruptedException; protected byte[] readBinary(CardChannel channel, int offset, int len) throws CardException, SignatureCardException { @@ -194,7 +194,7 @@ public abstract class AbstractSignatureCard implements SignatureCard { * @throws SignatureCardException */ protected byte[] readTLVFile(byte[] aid, byte[] ef, int maxLength) - throws SignatureCardException { + throws SignatureCardException, InterruptedException { return readTLVFilePIN(aid, ef, (byte) 0, null, null, maxLength); } @@ -215,7 +215,7 @@ public abstract class AbstractSignatureCard implements SignatureCard { */ protected byte[] readTLVFilePIN(byte[] aid, byte[] ef, byte kid, PINProvider provider, PINSpec spec, int maxLength) - throws SignatureCardException { + throws SignatureCardException, InterruptedException { try { diff --git a/smcc/src/main/java/at/gv/egiz/smcc/PINProvider.java b/smcc/src/main/java/at/gv/egiz/smcc/PINProvider.java index 844115a4..e0104618 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/PINProvider.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/PINProvider.java @@ -30,6 +30,6 @@ package at.gv.egiz.smcc; public interface PINProvider { - public String providePIN(PINSpec spec, int retries); + public String providePIN(PINSpec spec, int retries) throws InterruptedException; } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java b/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java index 99acbc0f..d6d02475 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java @@ -129,8 +129,9 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard /* (non-Javadoc) * @see at.gv.egiz.smcc.SignatureCard#getCertificate(at.gv.egiz.smcc.SignatureCard.KeyboxName) */ + @Override public byte[] getCertificate(KeyboxName keyboxName) - throws SignatureCardException { + throws SignatureCardException, InterruptedException { byte[] aid; byte[] efc; @@ -169,8 +170,9 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard /* (non-Javadoc) * @see at.gv.egiz.smcc.SignatureCard#getInfobox(java.lang.String, at.gv.egiz.smcc.PINProvider, java.lang.String) */ + @Override public byte[] getInfobox(String infobox, PINProvider provider, String domainId) - throws SignatureCardException { + throws SignatureCardException, InterruptedException { if ("IdentityLink".equals(infobox)) { @@ -204,7 +206,7 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard * @see at.gv.egiz.smcc.SignatureCard#createSignature(byte[], at.gv.egiz.smcc.SignatureCard.KeyboxName, at.gv.egiz.smcc.PINProvider) */ public byte[] createSignature(byte[] hash, KeyboxName keyboxName, - PINProvider provider) throws SignatureCardException { + PINProvider provider) throws SignatureCardException, InterruptedException { if (hash.length != 20) { throw new IllegalArgumentException("Hash value must be of length 20."); @@ -399,7 +401,7 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard * @see at.gv.egiz.smcc.AbstractSignatureCard#verifyPIN(at.gv.egiz.smcc.PINProvider, at.gv.egiz.smcc.PINSpec, byte, int) */ protected void verifyPIN(PINProvider pinProvider, PINSpec spec, byte kid) - throws CardException, SignatureCardException { + throws CardException, SignatureCardException, InterruptedException { int retries = verifyPIN(null, kid); do { diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java index 42a4be1b..42943541 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java @@ -297,7 +297,8 @@ public class SWCard implements SignatureCard { } - public byte[] createSignature(byte[] hash, KeyboxName keyboxName, PINProvider provider) throws SignatureCardException { + @Override + public byte[] createSignature(byte[] hash, KeyboxName keyboxName, PINProvider provider) throws SignatureCardException, InterruptedException { // KeyStore password String password = getPassword(keyboxName); diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java index 37bd7cf9..b6a453df 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java @@ -57,6 +57,7 @@ public interface SignatureCard { } } + @Override public boolean equals(Object obj) { if (obj instanceof String) { return obj.equals(keyboxName_); @@ -77,7 +78,7 @@ public interface SignatureCard { public void init(Card card); public byte[] getCertificate(KeyboxName keyboxName) - throws SignatureCardException; + throws SignatureCardException, InterruptedException; public void disconnect(boolean reset); @@ -88,12 +89,22 @@ public interface SignatureCard { * @param domainId may be null. * @return * @throws SignatureCardException + * @throws InterruptedException if applet is destroyed while in pin dialog */ public byte[] getInfobox(String infobox, PINProvider provider, String domainId) - throws SignatureCardException; + throws SignatureCardException, InterruptedException; + /** + * + * @param hash + * @param keyboxName + * @param provider + * @return + * @throws at.gv.egiz.smcc.SignatureCardException + * @throws java.lang.InterruptedException if applet is destroyed while in pin dialog + */ public byte[] createSignature(byte[] hash, KeyboxName keyboxName, - PINProvider provider) throws SignatureCardException; + PINProvider provider) throws SignatureCardException, InterruptedException; /** * Sets the local for evtl. required callbacks (e.g. PINSpec) diff --git a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java index b921a5d5..13210540 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java @@ -37,7 +37,7 @@ public class STARCOSCardTest { * @throws CardException * @throws NoSuchAlgorithmException */ - public static void main(String[] args) throws CardException, NoSuchAlgorithmException { + public static void main(String[] args) throws CardException, NoSuchAlgorithmException, InterruptedException { SMCCHelper helper = new SMCCHelper(); while (helper.getResultCode() != SMCCHelper.CARD_FOUND) { diff --git a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java index 5448fee2..38126a67 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java @@ -14,50 +14,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.smcc;
-
-import java.math.BigInteger;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import at.gv.egiz.smcc.SignatureCard.KeyboxName;
-
-public class SWCardTest implements PINProvider {
-
- SWCard swCard = new SWCard();
-
- public static void main(String[] args) throws Exception {
-
- SWCardTest swCardTest = new SWCardTest();
- swCardTest.test();
-
- }
-
- public void test() throws SignatureCardException, NoSuchAlgorithmException {
-
- swCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR);
- swCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR);
-
- BigInteger t = BigInteger.valueOf(System.currentTimeMillis());
-
- MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
- byte[] hash = messageDigest.digest(t.toByteArray());
-
- byte[] signature;
- signature = swCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, this);
- System.out.println(SignatureCardFactory.toString(signature));
-
- signature = swCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, this);
- System.out.println(SignatureCardFactory.toString(signature));
-
- byte[] infobox = swCard.getInfobox("IdentityLink", this, null);
- System.out.println(SignatureCardFactory.toString(infobox));
-
- }
-
- @Override
- public String providePIN(PINSpec spec, int retries) {
- return "buerger";
- }
-
-}
+package at.gv.egiz.smcc; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import at.gv.egiz.smcc.SignatureCard.KeyboxName; + +public class SWCardTest implements PINProvider { + + SWCard swCard = new SWCard(); + + public static void main(String[] args) throws Exception { + + SWCardTest swCardTest = new SWCardTest(); + swCardTest.test(); + + } + + public void test() throws SignatureCardException, NoSuchAlgorithmException, InterruptedException { + + swCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); + swCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); + + BigInteger t = BigInteger.valueOf(System.currentTimeMillis()); + + MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); + byte[] hash = messageDigest.digest(t.toByteArray()); + + byte[] signature; + signature = swCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, this); + System.out.println(SignatureCardFactory.toString(signature)); + + signature = swCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, this); + System.out.println(SignatureCardFactory.toString(signature)); + + byte[] infobox = swCard.getInfobox("IdentityLink", this, null); + System.out.println(SignatureCardFactory.toString(infobox)); + + } + + @Override + public String providePIN(PINSpec spec, int retries) { + return "buerger"; + } + +} 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); |