summaryrefslogtreecommitdiff
path: root/smcc/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
authormcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-12-09 08:14:43 +0000
committermcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-12-09 08:14:43 +0000
commit2df9621154ad057f6cace73efe49c9ef42515fde (patch)
tree7f81b55a6f996586a3709e38f5bf8443dd2dc9a8 /smcc/src/main/java/at/gv/egiz
parent5bd89b042a7d72fbb94feeaac38d6d4519f50dcd (diff)
downloadmocca-2df9621154ad057f6cace73efe49c9ef42515fde.tar.gz
mocca-2df9621154ad057f6cace73efe49c9ef42515fde.tar.bz2
mocca-2df9621154ad057f6cace73efe49c9ef42515fde.zip
Refactored STAL interface. Additional infobox functionality.
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@236 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'smcc/src/main/java/at/gv/egiz')
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java30
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/SWCard.java12
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java12
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java8
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java4
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/util/SmartCardIO.java9
6 files changed, 65 insertions, 10 deletions
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 b828e8cd..e34c4899 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java
@@ -36,6 +36,7 @@ import javax.smartcardio.ATR;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
+import javax.smartcardio.CardTerminal;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
@@ -53,7 +54,12 @@ public abstract class AbstractSignatureCard implements SignatureCard {
int ifs_ = 254;
- Card card_;
+ private Card card_;
+
+ /**
+ * The card terminal that connects the {@link #card_}.
+ */
+ private CardTerminal cardTerminal;
protected AbstractSignatureCard(String resourceBundleName) {
this.resourceBundleName = resourceBundleName;
@@ -331,8 +337,9 @@ public abstract class AbstractSignatureCard implements SignatureCard {
}
- public void init(Card card) {
+ public void init(Card card, CardTerminal cardTerminal) {
card_ = card;
+ this.cardTerminal = cardTerminal;
ATR atr = card.getATR();
byte[] atrBytes = atr.getBytes();
if (atrBytes.length >= 6) {
@@ -340,6 +347,11 @@ public abstract class AbstractSignatureCard implements SignatureCard {
log.trace("Setting IFS (information field size) to " + ifs_);
}
}
+
+ @Override
+ public Card getCard() {
+ return card_;
+ }
protected CardChannel getCardChannel() {
return card_.getBasicChannel();
@@ -372,4 +384,18 @@ public abstract class AbstractSignatureCard implements SignatureCard {
}
}
+ @Override
+ public void reset() throws SignatureCardException {
+ try {
+ log.debug("Disconnect and reset smart card.");
+ card_.disconnect(true);
+ log.debug("Reconnect smart card.");
+ if (cardTerminal != null) {
+ card_ = cardTerminal.connect("*");
+ }
+ } catch (CardException e) {
+ throw new SignatureCardException("Failed to reset card.", e);
+ }
+ }
+
}
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 42943541..439be034 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java
@@ -40,6 +40,7 @@ import java.util.Enumeration;
import java.util.Locale;
import javax.smartcardio.Card;
+import javax.smartcardio.CardTerminal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -102,7 +103,12 @@ public class SWCard implements SignatureCard {
SWCard.swCardDir = swCardDir;
}
- public void init(Card card) {
+ public void init(Card card, CardTerminal cardTerminal) {
+ }
+
+ @Override
+ public Card getCard() {
+ return null;
}
private String getFileName(String fileName) {
@@ -379,4 +385,8 @@ public class SWCard implements SignatureCard {
public void disconnect(boolean reset) {
}
+ @Override
+ public void reset() throws SignatureCardException {
+ }
+
}
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 b6a453df..d7e76dd8 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java
@@ -31,6 +31,7 @@ package at.gv.egiz.smcc;
import java.util.Locale;
import javax.smartcardio.Card;
+import javax.smartcardio.CardTerminal;
public interface SignatureCard {
@@ -75,12 +76,21 @@ public interface SignatureCard {
}
- public void init(Card card);
+ public void init(Card card, CardTerminal cardTerminal);
+
+ public Card getCard();
public byte[] getCertificate(KeyboxName keyboxName)
throws SignatureCardException, InterruptedException;
public void disconnect(boolean reset);
+
+ /**
+ * Performs a reset of the card.
+ *
+ * @throws SignatureCardException if reset fails.
+ */
+ public void reset() throws SignatureCardException;
/**
*
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java
index 777299d9..ab66e9a1 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java
@@ -34,6 +34,7 @@ import java.util.List;
import javax.smartcardio.ATR;
import javax.smartcardio.Card;
+import javax.smartcardio.CardTerminal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -204,6 +205,7 @@ public class SignatureCardFactory {
* @param card
* the smart card, or <code>null</code> if a software card should be
* created
+ * @param cardTerminal TODO
*
* @return a SignatureCard instance
*
@@ -211,12 +213,12 @@ public class SignatureCardFactory {
* if no implementation of the given <code>card</code> could be
* found
*/
- public SignatureCard createSignatureCard(Card card)
+ public SignatureCard createSignatureCard(Card card, CardTerminal cardTerminal)
throws CardNotSupportedException {
if(card == null) {
SignatureCard sCard = new SWCard();
- sCard.init(card);
+ sCard.init(card, cardTerminal);
return sCard;
}
@@ -231,7 +233,7 @@ public class SignatureCardFactory {
try {
Class<?> scClass = cl.loadClass(supportedCard.getImplementationClassName());
sc = (SignatureCard) scClass.newInstance();
- sc.init(card);
+ sc.init(card, cardTerminal);
return sc;
} catch (ClassNotFoundException e) {
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java b/smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java
index 4dae7975..f7d3bab7 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java
@@ -57,7 +57,7 @@ public class SMCCHelper {
SignatureCardFactory factory = SignatureCardFactory.getInstance();
if (useSWCard) {
try {
- signatureCard = factory.createSignatureCard(null);
+ signatureCard = factory.createSignatureCard(null, null);
resultCode = CARD_FOUND;
} catch (CardNotSupportedException e) {
resultCode = CARD_NOT_SUPPORTED;
@@ -83,7 +83,7 @@ public class SMCCHelper {
if (c == null) {
throw new CardNotSupportedException();
}
- signatureCard = factory.createSignatureCard(c);
+ signatureCard = factory.createSignatureCard(c, cardTerminal);
ATR atr = newCards.get(cardTerminal).getATR();
log.trace("Found supported card (" + signatureCard.toString() + ") "
+ "in terminal '" + cardTerminal.getName() + "', ATR = "
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/util/SmartCardIO.java b/smcc/src/main/java/at/gv/egiz/smcc/util/SmartCardIO.java
index b70b44a7..b1866894 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/util/SmartCardIO.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/util/SmartCardIO.java
@@ -16,6 +16,7 @@
*/
package at.gv.egiz.smcc.util;
+import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -54,7 +55,13 @@ public class SmartCardIO {
CardTerminals cardTerminals_;
private void updateTerminalFactory() {
- TerminalFactory terminalFactory = TerminalFactory.getDefault();
+ TerminalFactory terminalFactory;
+ try {
+ terminalFactory = TerminalFactory.getInstance("PC/SC", null);
+ } catch (NoSuchAlgorithmException e) {
+ log.info("Failed to get TerminalFactory of type 'PC/SC'.", e);
+ terminalFactory = TerminalFactory.getDefault();
+ }
log.debug("TerminalFactory : " + terminalFactory);
if ("PC/SC".equals(terminalFactory.getType())) {
terminalFactory_ = terminalFactory;