summaryrefslogtreecommitdiff
path: root/BKUAppletExt/src
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-03-18 22:27:28 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-03-18 22:27:28 +0000
commit2a1df5e58e44f8d77f34eb80df74e8c0d27caceb (patch)
tree5603a81674a1fe60373ba0a3ca37b03473eeb92a /BKUAppletExt/src
parent2f49ed7ea3649a51a9457b99004c8cb0ca443432 (diff)
downloadmocca-2a1df5e58e44f8d77f34eb80df74e8c0d27caceb.tar.gz
mocca-2a1df5e58e44f8d77f34eb80df74e8c0d27caceb.tar.bz2
mocca-2a1df5e58e44f8d77f34eb80df74e8c0d27caceb.zip
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
Diffstat (limited to 'BKUAppletExt/src')
-rw-r--r--BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java365
-rw-r--r--BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java46
-rw-r--r--BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java10
-rw-r--r--BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java53
-rw-r--r--BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java319
-rw-r--r--BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java126
-rw-r--r--BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/SoftwarePINProviderFactory.java148
-rw-r--r--BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties17
-rw-r--r--BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties15
-rw-r--r--BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java4
-rw-r--r--BKUAppletExt/src/test/java/at/gv/egiz/bku/smccstal/ext/FileSystemTest.java435
11 files changed, 746 insertions, 792 deletions
diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java
index c904be0c..159dd29d 100644
--- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java
+++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java
@@ -56,8 +56,6 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
/** remember the pinSpec to return to worker */
protected PINSpec pinSpec;
- protected enum DIALOG { VERIFY, ACTIVATE, CHANGE, UNBLOCK };
-
public PINManagementGUI(Container contentPane,
Locale locale,
Style guiStyle,
@@ -235,43 +233,110 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
}
@Override
- public void showActivatePINDialog(final PINSpec pin,
- final ActionListener okListener, final String okCommand,
- final ActionListener cancelListener, final String cancelCommand) {
- log.debug("scheduling activate pin dialog");
- showPINDialog(DIALOG.ACTIVATE, pin, okListener, okCommand, cancelListener, cancelCommand);
+ public void showPINDialog(DIALOG type, PINSpec pinSpec,
+ ActionListener okListener, String okCommand,
+ ActionListener cancelListener, String cancelCommand) {
+ showPINDialog(type, pinSpec, -1, false,
+ okListener, okCommand, cancelListener, cancelCommand);
+ }
+
+ @Override
+ public void showPINDialog(DIALOG type, PINSpec pinSpec, int retries,
+ ActionListener okListener, String okCommand,
+ ActionListener cancelListener, String cancelCommand) {
+ showPINDialog(type, pinSpec, retries, false,
+ okListener, okCommand, cancelListener, cancelCommand);
}
+ @Override
+ public void showPinpadPINDialog(DIALOG type, PINSpec pinSpec, int retries) {
+ String title, msg;
+ Object[] params;
+ if (retries < 0) {
+ params = new Object[2];
+ if (shortText) {
+ params[0] = "PIN";
+ } else {
+ params[0] = pinSpec.getLocalizedName();
+ }
+ String pinSize = String.valueOf(pinSpec.getMinLength());
+ if (pinSpec.getMinLength() != pinSpec.getMaxLength()) {
+ pinSize += "-" + pinSpec.getMaxLength();
+ }
+ params[1] = pinSize;
+ if (type == DIALOG.CHANGE) {
+ log.debug("show change pin dialog");
+ title = TITLE_CHANGE_PIN;
+ msg = MESSAGE_CHANGEPIN_PINPAD;
+ } else if (type == DIALOG.ACTIVATE) {
+ log.debug("show activate pin dialog");
+ title = TITLE_ACTIVATE_PIN;
+ msg = MESSAGE_ENTERPIN_PINPAD;
+ } else if (type == DIALOG.VERIFY) {
+ log.debug("show verify pin dialog");
+ title = TITLE_VERIFY_PIN;
+ msg = MESSAGE_ENTERPIN_PINPAD;
+ } else {
+ log.debug("show unblock pin dialog");
+ title = TITLE_UNBLOCK_PIN;
+ msg = MESSAGE_ENTERPIN_PINPAD;
+ }
+
+ } else {
+ log.debug("show retry pin dialog");
+ title = TITLE_RETRY;
+ msg = (retries < 2) ?
+ MESSAGE_LAST_RETRY : MESSAGE_RETRIES;
+ params = new Object[] {String.valueOf(retries)};
+ }
+ showMessageDialog(title, msg, params);
+ }
private void showPINDialog(final DIALOG type, final PINSpec pinSpec,
+ final int retries, final boolean pinpad,
final ActionListener okListener, final String okCommand,
final ActionListener cancelListener, final String cancelCommand) {
+ log.debug("scheduling pin dialog");
+
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
- String HELP_TOPIC, TITLE, MESSAGE_MGMT;
+ String HELP_TOPIC, TITLE, MESSAGE_MGMT, MESSAGE_MGMT_PARAM;
HELP_TOPIC = HELP_PINMGMT;
- if (type == DIALOG.CHANGE) {
- log.debug("show change pin dialog");
- TITLE = TITLE_CHANGE_PIN;
- MESSAGE_MGMT = MESSAGE_CHANGE_PIN;
- } else if (type == DIALOG.ACTIVATE) {
- log.debug("show activate pin dialog");
- TITLE = TITLE_ACTIVATE_PIN;
- MESSAGE_MGMT = MESSAGE_ACTIVATE_PIN;
- oldPinField = null;
- } else if (type == DIALOG.VERIFY) {
- log.debug("show verify pin dialog");
- TITLE = TITLE_VERIFY_PIN;
- MESSAGE_MGMT = MESSAGE_VERIFY_PIN;
+ if (retries < 0) {
+ if (type == DIALOG.CHANGE) {
+ log.debug("show change pin dialog");
+ TITLE = TITLE_CHANGE_PIN;
+ MESSAGE_MGMT = MESSAGE_CHANGE_PIN;
+ } else if (type == DIALOG.ACTIVATE) {
+ log.debug("show activate pin dialog");
+ TITLE = TITLE_ACTIVATE_PIN;
+ MESSAGE_MGMT = MESSAGE_ACTIVATE_PIN;
+ oldPinField = null;
+ } else if (type == DIALOG.VERIFY) {
+ log.debug("show verify pin dialog");
+ TITLE = TITLE_VERIFY_PIN;
+ MESSAGE_MGMT = MESSAGE_VERIFY_PIN;
+ } else {
+ log.debug("show unblock pin dialog");
+ TITLE = TITLE_UNBLOCK_PIN;
+ MESSAGE_MGMT = MESSAGE_UNBLOCK_PIN;
+ }
+ if (shortText) {
+ MESSAGE_MGMT_PARAM = "PIN";
+ } else {
+ MESSAGE_MGMT_PARAM = pinSpec.getLocalizedName();
+ }
} else {
- log.debug("show unblock pin dialog");
- TITLE = TITLE_UNBLOCK_PIN;
- MESSAGE_MGMT = MESSAGE_UNBLOCK_PIN;
+ log.debug("show retry pin dialog");
+ TITLE = TITLE_RETRY;
+ MESSAGE_MGMT = (retries < 2) ?
+ MESSAGE_LAST_RETRY : MESSAGE_RETRIES;
+ MESSAGE_MGMT_PARAM = String.valueOf(retries);
}
mainPanel.removeAll();
@@ -280,24 +345,67 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
helpListener.setHelpTopic(HELP_TOPIC);
JLabel mgmtLabel = new JLabel();
- mgmtLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() & ~Font.BOLD));
+ if (retries < 0) {
+ mgmtLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() & ~Font.BOLD));
+ } else {
+ mgmtLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() | Font.BOLD));
+ mgmtLabel.setForeground(ERROR_COLOR);
+ helpListener.setHelpTopic(HELP_RETRY);
+ }
if (renderHeaderPanel) {
titleLabel.setText(getMessage(TITLE));
String mgmtPattern = getMessage(MESSAGE_MGMT);
- if (shortText) {
- mgmtLabel.setText(MessageFormat.format(mgmtPattern, "PIN"));
- } else {
- mgmtLabel.setText(MessageFormat.format(mgmtPattern, pinSpec.getLocalizedName()));
- }
+ mgmtLabel.setText(MessageFormat.format(mgmtPattern, MESSAGE_MGMT_PARAM));
} else {
mgmtLabel.setText(getMessage(TITLE));
}
+ String pinSize = String.valueOf(pinSpec.getMinLength());
+ if (pinSpec.getMinLength() != pinSpec.getMaxLength()) {
+ pinSize += "-" + pinSpec.getMaxLength();
+ }
+
+ ////////////////////////////////////////////////////////////////
+ // COMMON LAYOUT SECTION
+ ////////////////////////////////////////////////////////////////
+
+ GroupLayout mainPanelLayout = new GroupLayout(mainPanel);
+ mainPanel.setLayout(mainPanelLayout);
+
+ GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup()
+ .addComponent(mgmtLabel);
+ GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
+ .addComponent(mgmtLabel);
+
+ if (!renderHeaderPanel) {
+ infoHorizontal
+ .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE)
+ .addComponent(helpLabel);
+ infoVertical
+ .addComponent(helpLabel);
+ }
+
+ GroupLayout.ParallelGroup pinHorizontal;
+ GroupLayout.SequentialGroup pinVertical;
+
+ if (pinpad) {
+ JLabel pinpadLabel = new JLabel();
+ pinpadLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() & ~Font.BOLD));
+ String pinpadPattern = getMessage(MESSAGE_PINPAD);
+ pinpadLabel.setText(MessageFormat.format(pinpadPattern,
+ new Object[] { pinSpec.getLocalizedName(), pinSize }));
+
+ pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
+ .addComponent(pinpadLabel);
+ pinVertical = mainPanelLayout.createSequentialGroup()
+ .addComponent(pinpadLabel);
+ } else {
+
JButton okButton = new JButton();
okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~Font.BOLD));
okButton.setText(getMessage(BUTTON_OK));
- okButton.setEnabled(type == DIALOG.VERIFY && pinSpec.getMinLength() == 0);
+ okButton.setEnabled(pinSpec.getMinLength() <= 0);
okButton.setActionCommand(okCommand);
okButton.addActionListener(okListener);
@@ -334,7 +442,7 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
repeatPinLabel.setText(MessageFormat.format(repeatPinLabelPattern, new Object[]{pinSpec.getLocalizedName()}));
repeatPinField.setText("");
- repeatPinField.setDocument(new PINDocument(pinSpec, okButton, pinField.getDocument()));
+// repeatPinField.setDocument(new PINDocument(pinSpec, okButton, pinField.getDocument()));
repeatPinField.setActionCommand(okCommand);
repeatPinField.addActionListener(new ActionListener() {
@@ -365,7 +473,15 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
}
}
});
- } // else -> ACTIVATE (not verify, not change)
+
+ repeatPinField.setDocument(new PINDocument(
+ pinSpec, okButton,
+ pinField.getDocument(), oldPinField.getDocument()));
+ } else {
+ // else -> ACTIVATE (not verify, not change)
+ repeatPinField.setDocument(new PINDocument(
+ pinSpec, okButton, pinField.getDocument()));
+ }
} else {
pinField.setDocument(new PINDocument(pinSpec, okButton));
}
@@ -373,30 +489,14 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
JLabel pinsizeLabel = new JLabel();
pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~Font.BOLD, pinsizeLabel.getFont().getSize()-2));
String pinsizePattern = getMessage(LABEL_PINSIZE);
- String pinSize = String.valueOf(pinSpec.getMinLength());
- if (pinSpec.getMinLength() != pinSpec.getMaxLength()) {
- pinSize += "-" + pinSpec.getMaxLength();
- }
pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize}));
- GroupLayout mainPanelLayout = new GroupLayout(mainPanel);
- mainPanel.setLayout(mainPanelLayout);
-
- GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup()
- .addComponent(mgmtLabel);
- GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(mgmtLabel);
-
- if (!renderHeaderPanel) {
- infoHorizontal
- .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE)
- .addComponent(helpLabel);
- infoVertical
- .addComponent(helpLabel);
- }
+ ////////////////////////////////////////////////////////////////
+ // NON-PINPAD SPECIFIC LAYOUT SECTION
+ ////////////////////////////////////////////////////////////////
- GroupLayout.ParallelGroup pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
- GroupLayout.SequentialGroup pinVertical = mainPanelLayout.createSequentialGroup();
+ pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
+ pinVertical = mainPanelLayout.createSequentialGroup();
// if (pinLabelPos == PinLabelPosition.ABOVE) {
// if (changePin) {
@@ -495,7 +595,38 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
.addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
pinVertical
.addComponent(pinsizeLabel);
-// }
+
+ GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel);
+ buttonPanel.setLayout(buttonPanelLayout);
+
+ GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup()
+ .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE);
+ GroupLayout.Group buttonVertical;
+
+ JButton cancelButton = new JButton();
+ cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD));
+ cancelButton.setText(getMessage(BUTTON_CANCEL));
+ cancelButton.setActionCommand(cancelCommand);
+ cancelButton.addActionListener(cancelListener);
+
+ buttonHorizontal
+ .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE);
+ buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+ .addComponent(okButton)
+ .addComponent(cancelButton);
+
+ buttonPanelLayout.setHorizontalGroup(buttonHorizontal);
+ buttonPanelLayout.setVerticalGroup(buttonVertical);
+
+ if (oldPinField != null) {
+ oldPinField.requestFocusInWindow();
+ } else {
+ pinField.requestFocusInWindow();
+ }
+
+ } // END NON-PINPAD SECTION
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
@@ -508,35 +639,6 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pinVertical));
- GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel);
- buttonPanel.setLayout(buttonPanelLayout);
-
- GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup()
- .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE);
- GroupLayout.Group buttonVertical;
-
- JButton cancelButton = new JButton();
- cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD));
- cancelButton.setText(getMessage(BUTTON_CANCEL));
- cancelButton.setActionCommand(cancelCommand);
- cancelButton.addActionListener(cancelListener);
-
- buttonHorizontal
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE);
- buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(okButton)
- .addComponent(cancelButton);
-
- buttonPanelLayout.setHorizontalGroup(buttonHorizontal);
- buttonPanelLayout.setVerticalGroup(buttonVertical);
-
- if (oldPinField != null) {
- oldPinField.requestFocusInWindow();
- } else {
- pinField.requestFocusInWindow();
- }
contentPanel.validate();
}
@@ -544,97 +646,6 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
}
@Override
- public void showChangePINDialog(final PINSpec pin,
- final ActionListener okListener, final String okCommand,
- final ActionListener cancelListener, final String cancelCommand) {
-
- log.debug("scheduling change pin dialog");
- showPINDialog(DIALOG.CHANGE, pin, okListener, okCommand, cancelListener, cancelCommand);
- }
-
- @Override
- public void showUnblockPINDialog(final PINSpec pin,
- final ActionListener okListener, final String okCommand,
- final ActionListener cancelListener, final String cancelCommand) {
-
- log.debug("scheduling unblock PIN dialog");
-
- SwingUtilities.invokeLater(new Runnable() {
-
- @Override
- public void run() {
-
- log.debug("show unblock PIN dialog");
-
- log.error("unblock pin not supported");
-
- mainPanel.removeAll();
- buttonPanel.removeAll();
-
- if (renderHeaderPanel) {
- titleLabel.setText(getMessage(TITLE_ERROR));
- }
-
- helpListener.setHelpTopic(HELP_PINMGMT);
-
- String errorMsgPattern = getMessage(ERR_UNBLOCK);
- String errorMsg = MessageFormat.format(errorMsgPattern, pin.getLocalizedName());
-
- JLabel errorMsgLabel = new JLabel();
- errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD));
- errorMsgLabel.setText(errorMsg);
-
- GroupLayout mainPanelLayout = new GroupLayout(mainPanel);
- mainPanel.setLayout(mainPanelLayout);
-
- GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
- GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup();
-
- if (!renderHeaderPanel) {
- JLabel errorTitleLabel = new JLabel();
- errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD));
- errorTitleLabel.setText(getMessage(TITLE_ERROR));
- errorTitleLabel.setForeground(ERROR_COLOR);
-
- mainHorizontal
- .addGroup(mainPanelLayout.createSequentialGroup()
- .addComponent(errorTitleLabel)
- .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE)
- .addComponent(helpLabel));
- mainVertical
- .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(errorTitleLabel)
- .addComponent(helpLabel));
- }
-
- mainPanelLayout.setHorizontalGroup(mainHorizontal
- .addComponent(errorMsgLabel));
- mainPanelLayout.setVerticalGroup(mainVertical
- .addComponent(errorMsgLabel));
-
- JButton okButton = new JButton();
- okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD));
- okButton.setText(getMessage(BUTTON_OK));
- okButton.setActionCommand(cancelCommand);
- okButton.addActionListener(cancelListener);
-
- GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel);
- buttonPanel.setLayout(buttonPanelLayout);
-
- buttonPanelLayout.setHorizontalGroup(
- buttonPanelLayout.createSequentialGroup()
- .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE));
- buttonPanelLayout.setVerticalGroup(
- buttonPanelLayout.createSequentialGroup()
- .addComponent(okButton));
-
- contentPanel.validate();
- }
- });
- }
-
- @Override
protected int initButtonSize() {
int bs = super.initButtonSize();
@@ -659,8 +670,4 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac
return bs;
}
- @Override
- public void showVerifyPINDialog(PINSpec pin, ActionListener okListener, String okCmd, ActionListener cancelListener, String cancelCmd) {
- showPINDialog(DIALOG.VERIFY, pin, okListener, okCmd, cancelListener, cancelCmd);
- }
}
diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java
index 9c630431..45313f42 100644
--- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java
+++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java
@@ -35,13 +35,18 @@ public interface PINManagementGUIFacade extends BKUGUIFacade {
public static final String TITLE_UNBLOCK_PIN = "title.unblock.pin";
public static final String TITLE_ACTIVATE_SUCCESS = "title.activate.success";
public static final String TITLE_CHANGE_SUCCESS = "title.change.success";
- public static final String MESSAGE_ACTIVATE_SUCCESS = "message.activate.success";
- public static final String MESSAGE_CHANGE_SUCCESS = "message.change.success";
- public static final String MESSAGE_PINMGMT = "message.pin.mgmt";
- public static final String MESSAGE_ACTIVATE_PIN = "message.activate.pin";
- public static final String MESSAGE_CHANGE_PIN = "message.change.pin";
- public static final String MESSAGE_VERIFY_PIN = "message.verify.pin";
- public static final String MESSAGE_UNBLOCK_PIN = "message.unblock.pin";
+
+ // removed message.* prefix to reuse keys as help keys
+ public static final String MESSAGE_ACTIVATE_SUCCESS = "activate.success";
+ public static final String MESSAGE_CHANGE_SUCCESS = "change.success";
+ public static final String MESSAGE_PINMGMT = "pin.mgmt";
+ public static final String MESSAGE_PINPAD = "pinpad";
+ public static final String MESSAGE_CHANGEPIN_PINPAD = "pinpad.change";
+ public static final String MESSAGE_ACTIVATE_PIN = "activate.pin";
+ public static final String MESSAGE_CHANGE_PIN = "change.pin";
+ public static final String MESSAGE_VERIFY_PIN = "verify.pin";
+ public static final String MESSAGE_UNBLOCK_PIN = "unblock.pin";
+
public static final String LABEL_OLD_PIN = "label.old.pin";
public static final String LABEL_NEW_PIN = "label.new.pin";
public static final String LABEL_REPEAT_PIN = "label.repeat.pin";
@@ -66,26 +71,37 @@ public interface PINManagementGUIFacade extends BKUGUIFacade {
public static final String STATUS_UNKNOWN = "status.unknown";
public enum STATUS { ACTIV, NOT_ACTIV, BLOCKED, UNKNOWN };
+ public enum DIALOG { VERIFY, ACTIVATE, CHANGE, UNBLOCK };
public void showPINManagementDialog(Map<PINSpec, STATUS> pins,
ActionListener activateListener, String activateCmd, String changeCmd, String unblockCmd, String verifyCmd,
ActionListener cancelListener, String cancelCmd);
- public void showActivatePINDialog(PINSpec pin,
+ public void showPINDialog(DIALOG type, PINSpec pin,
ActionListener okListener, String okCmd,
ActionListener cancelListener, String cancelCmd);
- public void showChangePINDialog(PINSpec pin,
+ public void showPINDialog(DIALOG type, PINSpec pin, int retries,
ActionListener okListener, String okCmd,
ActionListener cancelListener, String cancelCmd);
- public void showUnblockPINDialog(PINSpec pin,
- ActionListener okListener, String okCmd,
- ActionListener cancelListener, String cancelCmd);
+ public void showPinpadPINDialog(DIALOG type, PINSpec pin, int retries);
- public void showVerifyPINDialog(PINSpec pin,
- ActionListener okListener, String okCmd,
- ActionListener cancelListener, String cancelCmd);
+// public void showActivatePINDialog(PINSpec pin,
+// ActionListener okListener, String okCmd,
+// ActionListener cancelListener, String cancelCmd);
+//
+// public void showChangePINDialog(PINSpec pin,
+// ActionListener okListener, String okCmd,
+// ActionListener cancelListener, String cancelCmd);
+//
+// public void showUnblockPINDialog(PINSpec pin,
+// ActionListener okListener, String okCmd,
+// ActionListener cancelListener, String cancelCmd);
+//
+// public void showVerifyPINDialog(PINSpec pin,
+// ActionListener okListener, String okCmd,
+// ActionListener cancelListener, String cancelCmd);
public char[] getOldPin();
diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java
index 85892026..81b635f8 100644
--- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java
+++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java
@@ -42,7 +42,8 @@ public class PINManagementBKUWorker extends AppletBKUWorker {
@Override
public void run() {
- gui.showWelcomeDialog();
+ gui.showMessageDialog(BKUGUIFacade.TITLE_WELCOME,
+ BKUGUIFacade.MESSAGE_WELCOME);
try {
List<STALResponse> responses = handleRequest(Collections.singletonList(new PINManagementRequest()));
@@ -53,7 +54,6 @@ public class PINManagementBKUWorker extends AppletBKUWorker {
log.debug("PIN management dialog terminated");
} else if (response instanceof ErrorResponse) {
log.debug("PIN management dialog terminated with error");
- showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, null);
} else {
throw new RuntimeException("Invalid STAL response: " + response.getClass().getName());
}
@@ -62,7 +62,11 @@ public class PINManagementBKUWorker extends AppletBKUWorker {
}
} catch (RuntimeException ex) {
- log.error("unexpected error: " + ex.getMessage(), ex);
+ log.error(ex.getMessage());
+ Throwable cause = ex.getCause();
+ if (cause != null) { // && cause instanceof InterruptedException) {
+ log.info(cause.getMessage());
+ }
showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, null);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java
new file mode 100644
index 00000000..b0dd8766
--- /dev/null
+++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java
@@ -0,0 +1,53 @@
+/*
+ * 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.ext;
+
+import at.gv.egiz.smcc.ChangePINProvider;
+import at.gv.egiz.bku.gui.PINManagementGUIFacade;
+import at.gv.egiz.smcc.PINProvider;
+import at.gv.egiz.smcc.SignatureCard;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public abstract class ManagementPINProviderFactory {
+// extends at.gv.egiz.bku.smccstal.PINProviderFactory {
+
+ PINManagementGUIFacade gui;
+
+ public static ManagementPINProviderFactory getInstance(SignatureCard forCard,
+ PINManagementGUIFacade gui) {
+// if (forCard.ifdSupportsFeature(SignatureCard.FEATURE_VERIFY_PIN_DIRECT)) {
+//// forCard.ifdSupportsFeature(SignatureCard.FEATURE_MODIFY_PIN_DIRECT)
+// return new PinpadPINProviderFactory(gui);
+//
+// } else {
+ return new SoftwarePINProviderFactory(gui);
+// }
+ }
+
+ public abstract PINProvider getVerifyPINProvider();
+
+ public abstract PINProvider getActivatePINProvider();
+
+ public abstract ChangePINProvider getChangePINProvider();
+
+ public abstract PINProvider getUnblockPINProvider();
+
+}
diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java
index 66db0484..6b565b26 100644
--- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java
+++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java
@@ -18,13 +18,19 @@ package at.gv.egiz.bku.smccstal.ext;
import at.gv.egiz.bku.gui.BKUGUIFacade;
import at.gv.egiz.bku.gui.PINManagementGUIFacade;
+import at.gv.egiz.bku.gui.PINManagementGUIFacade.DIALOG;
import at.gv.egiz.bku.gui.PINManagementGUIFacade.STATUS;
import at.gv.egiz.bku.smccstal.AbstractRequestHandler;
+import at.gv.egiz.bku.smccstal.PINProviderFactory;
+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.STARCOSCard;
+import at.gv.egiz.smcc.SignatureCard;
import at.gv.egiz.smcc.SignatureCardException;
+import at.gv.egiz.smcc.TimeoutException;
import at.gv.egiz.smcc.VerificationFailedException;
import at.gv.egiz.smcc.util.SMCCHelper;
import at.gv.egiz.stal.ErrorResponse;
@@ -35,8 +41,6 @@ import at.gv.egiz.stal.ext.PINManagementResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
@@ -53,7 +57,8 @@ public class PINManagementRequestHandler extends AbstractRequestHandler {
protected static final Log log = LogFactory.getLog(PINManagementRequestHandler.class);
- Map<PINSpec, STATUS> pinStatuses;
+ protected Map<PINSpec, STATUS> pinStatuses;
+ private ManagementPINProviderFactory pinProviderFactory;
@Override
public STALResponse handleRequest(STALRequest request) throws InterruptedException {
@@ -61,9 +66,12 @@ public class PINManagementRequestHandler extends AbstractRequestHandler {
PINManagementGUIFacade gui = (PINManagementGUIFacade) this.gui;
+ PINSpec selectedPIN = null;
+
try {
- pinStatuses = getPINStatuses();
+ pinStatuses = getPINStatuses();
+
gui.showPINManagementDialog(pinStatuses,
this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
this, "cancel");
@@ -74,175 +82,100 @@ public class PINManagementRequestHandler extends AbstractRequestHandler {
if ("cancel".equals(actionCommand)) {
return new PINManagementResponse();
- } else if ("back".equals(actionCommand)) {
- gui.showPINManagementDialog(pinStatuses,
- this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
- this, "cancel");
} else {
- PINSpec selectedPIN = gui.getSelectedPINSpec();
+ selectedPIN = gui.getSelectedPINSpec();
if (selectedPIN == null) {
- throw new RuntimeException("no PIN selected for activation/change");
+ throw new NullPointerException("no PIN selected for activation/change");
}
- if ("activate_enterpin".equals(actionCommand)) {
- gui.showActivatePINDialog(selectedPIN,
- this, "activate", this, "back");
- } else if ("change_enterpin".equals(actionCommand)) {
- gui.showChangePINDialog(selectedPIN,
- this, "change", this, "back");
- } else if ("unblock_enterpuk".equals(actionCommand)) {
- gui.showUnblockPINDialog(selectedPIN,
- this, "unblock", this, "back");
- } else if ("verify_enterpin".equals(actionCommand)) {
- gui.showVerifyPINDialog(selectedPIN,
- this, "verify", this, "back");
- } else if ("activate".equals(actionCommand)) {
- try {
- log.debug("activate " + selectedPIN.getLocalizedName());
- card.activatePIN(selectedPIN,
- String.valueOf(gui.getPin()));
+ if (pinProviderFactory == null) {
+ pinProviderFactory =
+ ManagementPINProviderFactory.getInstance(card, gui);
+ }
+
+ try {
+ if ("activate_enterpin".equals(actionCommand)) {
+ log.info("activate " + selectedPIN.getLocalizedName());
+ card.activatePIN(selectedPIN,
+ pinProviderFactory.getActivatePINProvider());
updatePINStatus(selectedPIN, STATUS.ACTIV);
gui.showMessageDialog(PINManagementGUIFacade.TITLE_ACTIVATE_SUCCESS,
PINManagementGUIFacade.MESSAGE_ACTIVATE_SUCCESS,
new Object[] {selectedPIN.getLocalizedName()},
- this, "ok");
+ BKUGUIFacade.BUTTON_OK, this, "ok");
waitForAction();
- gui.showPINManagementDialog(pinStatuses,
- this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
- this, "cancel");
- } catch (GetPINStatusException ex) {
- log.error("failed to get " + selectedPIN.getLocalizedName() +
- " status: " + ex.getMessage());
- gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, null,
- this, "cancel");
- } catch (SignatureCardException ex) {
- log.error("failed to activate " + selectedPIN.getLocalizedName() +
- ": " + ex.getMessage());
- gui.showErrorDialog(PINManagementGUIFacade.ERR_ACTIVATE,
- new Object[] {selectedPIN.getLocalizedName()},
- this, "cancel");
- }
- } else if ("change".equals(actionCommand)) {
- log.info("change " + selectedPIN.getLocalizedName());
- try {
- card.changePIN(selectedPIN,
- String.valueOf(gui.getOldPin()),
- String.valueOf(gui.getPin()));
+ } else if ("change_enterpin".equals(actionCommand)) {
+ log.info("change " + selectedPIN.getLocalizedName());
+ card.changePIN(selectedPIN,
+ pinProviderFactory.getChangePINProvider());
updatePINStatus(selectedPIN, STATUS.ACTIV);
gui.showMessageDialog(PINManagementGUIFacade.TITLE_CHANGE_SUCCESS,
PINManagementGUIFacade.MESSAGE_CHANGE_SUCCESS,
new Object[] {selectedPIN.getLocalizedName()},
- this, "ok");
- waitForAction();
- gui.showPINManagementDialog(pinStatuses,
- this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
- this, "cancel");
- } catch (GetPINStatusException ex) {
- log.error("failed to get " + selectedPIN.getLocalizedName() +
- " status: " + ex.getMessage());
- gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, null,
- this, "cancel");
- } catch (LockedException ex) {
- log.error("failed to change " + selectedPIN.getLocalizedName() +
- ": PIN locked");
- updatePINStatus(selectedPIN, STATUS.BLOCKED);
- gui.showErrorDialog(PINManagementGUIFacade.ERR_LOCKED,
- new Object[] {selectedPIN.getLocalizedName()},
- this, "ok");
- waitForAction();
- gui.showPINManagementDialog(pinStatuses,
- this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
- this, "cancel");
- } catch (VerificationFailedException ex) {
- log.error("failed to change " + selectedPIN.getLocalizedName() +
- ": " + ex.getMessage());
- gui.showErrorDialog(PINManagementGUIFacade.ERR_RETRIES,
- new Object[] {selectedPIN.getLocalizedName(), ex.getRetries()},
- this, "change_enterpin");
- } catch (NotActivatedException ex) {
- log.error("failed to change " + selectedPIN.getLocalizedName() +
- ": PIN not active");
- updatePINStatus(selectedPIN, STATUS.NOT_ACTIV);
- gui.showErrorDialog(PINManagementGUIFacade.ERR_NOT_ACTIVE,
- new Object[] {selectedPIN.getLocalizedName()},
- this, "ok");
+ BKUGUIFacade.BUTTON_OK, this, "ok");
waitForAction();
- gui.showPINManagementDialog(pinStatuses,
- this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
- this, "cancel");
- } catch (SignatureCardException ex) {
- log.error("failed to change " + selectedPIN.getLocalizedName() +
- ": " + ex.getMessage());
- gui.showErrorDialog(PINManagementGUIFacade.ERR_CHANGE,
- new Object[] {selectedPIN.getLocalizedName()},
- this, "cancel");
- }
- } else if ("unblock".equals(actionCommand)) {
- log.info("unblock " + selectedPIN.getLocalizedName());
- log.error("unblock PIN not implemented");
- gui.showErrorDialog(PINManagementGUIFacade.ERR_UNBLOCK, null, this, "cancel");
- } else if ("verify".equals(actionCommand)) {
- try {
+
+ } else if ("unblock_enterpuk".equals(actionCommand)) {
+ log.info("unblock " + selectedPIN.getLocalizedName());
+ card.unblockPIN(selectedPIN,
+ pinProviderFactory.getUnblockPINProvider());
+ } else if ("verify_enterpin".equals(actionCommand)) {
log.info("verify " + selectedPIN.getLocalizedName());
- int retries = card.verifyPIN(selectedPIN, String.valueOf(gui.getPin()));
- log.trace(retries + " retries");
- if (retries < 0) {
- updatePINStatus(selectedPIN, STATUS.ACTIV);
- gui.showPINManagementDialog(pinStatuses,
- this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
- this, "cancel");
- } else {
- log.error("failed to verify " + selectedPIN.getLocalizedName() +
- ": " + retries + " retries left");
- gui.showErrorDialog(PINManagementGUIFacade.ERR_RETRIES,
- new Object[] {selectedPIN.getLocalizedName(), retries},
- this, "verify_enterpin");
- }
- } catch (GetPINStatusException ex) {
- log.error("failed to get " + selectedPIN.getLocalizedName() +
- " status: " + ex.getMessage());
- gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, null,
- this, "cancel");
- } catch (LockedException ex) {
- log.error("failed to verify " + selectedPIN.getLocalizedName() +
- ": PIN locked");
- updatePINStatus(selectedPIN, STATUS.BLOCKED);
- gui.showPINManagementDialog(pinStatuses,
- this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
- this, "cancel");
- } catch (NotActivatedException ex) {
- log.error("failed to verify " + selectedPIN.getLocalizedName() +
- ": PIN not active");
- updatePINStatus(selectedPIN, STATUS.NOT_ACTIV);
- gui.showPINManagementDialog(pinStatuses,
- this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
- this, "cancel");
- } catch (SignatureCardException ex) {
- log.error("failed to verify " + selectedPIN.getLocalizedName() +
- ": " + ex.getMessage());
- gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS,
- new Object[] {selectedPIN.getLocalizedName()},
- this, "cancel");
+ card.verifyPIN(selectedPIN,
+ pinProviderFactory.getVerifyPINProvider());
+ updatePINStatus(selectedPIN, STATUS.ACTIV);
}
-
- } else {
- throw new RuntimeException("unsupported action " + actionCommand);
+ } catch (CancelledException ex) {
+ log.trace("cancelled");
+ } catch (TimeoutException ex) {
+ log.error("Timeout during pin entry");
+ gui.showMessageDialog(BKUGUIFacade.TITLE_ENTRY_TIMEOUT,
+ BKUGUIFacade.ERR_PIN_TIMEOUT,
+ new Object[] {selectedPIN.getLocalizedName()},
+ BKUGUIFacade.BUTTON_OK, this, null);
+ waitForAction();
+ } catch (LockedException ex) {
+ log.error(selectedPIN.getLocalizedName() + " locked");
+ updatePINStatus(selectedPIN, STATUS.BLOCKED);
+ gui.showErrorDialog(PINManagementGUIFacade.ERR_LOCKED,
+ new Object[] {selectedPIN.getLocalizedName()},
+ this, null);
+ waitForAction();
+ } catch (NotActivatedException ex) {
+ log.error(selectedPIN.getLocalizedName() + " not active");
+ updatePINStatus(selectedPIN, STATUS.NOT_ACTIV);
+ gui.showErrorDialog(PINManagementGUIFacade.ERR_NOT_ACTIVE,
+ new Object[] {selectedPIN.getLocalizedName()},
+ this, null);
+ waitForAction();
}
- }
- }
+ } // end if
+
+ selectedPIN = null;
+ gui.showPINManagementDialog(pinStatuses,
+ this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin",
+ this, "cancel");
+ } // end while
+
} catch (GetPINStatusException ex) {
- log.error("Failed to get PIN statuses: " + ex.getMessage());
+ String pin = (selectedPIN != null) ? selectedPIN.getLocalizedName() : "pin";
+ log.error("failed to get " + pin + " status: " + ex.getMessage());
gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, null,
this, "ok");
waitForAction();
return new ErrorResponse(1000);
+ } catch (SignatureCardException ex) {
+ log.error(ex.getMessage(), ex);
+ gui.showErrorDialog(PINManagementGUIFacade.ERR_UNKNOWN, null,
+ this, "ok");
+ waitForAction();
+ return new ErrorResponse(1000);
}
} else {
log.error("Got unexpected STAL request: " + request);
return new ErrorResponse(1000);
}
-
}
@Override
@@ -375,4 +308,100 @@ public class PINManagementRequestHandler extends AbstractRequestHandler {
pinStatuses.put(pinSpec, status);
}
}
+
+// /**
+// * provides oldPin and newPin from one dialog,
+// * and don't know whether providePIN() or provideOldPIN() is called first.
+// */
+// class SoftwarePinProvider implements PINProvider {
+//
+// private PINManagementGUIFacade.DIALOG type;
+// private boolean retry = false;
+//
+// private char[] newPin;
+// private char[] oldPin;
+//
+// public SoftwarePinProvider(DIALOG type) {
+// this.type = type;
+// }
+//
+// @Override
+// public char[] providePIN(PINSpec spec, int retries)
+// throws CancelledException, InterruptedException {
+// if (newPin == null) {
+// getPINs(spec, retries);
+// }
+// char[] pin = newPin;
+// newPin = null;
+// return pin;
+// }
+//
+// @Override
+// public char[] provideOldPIN(PINSpec spec, int retries)
+// throws CancelledException, InterruptedException {
+// if (oldPin == null) {
+// getPINs(spec, retries);
+// }
+// char[] pin = oldPin;
+// oldPin = null;
+// return pin;
+// }
+//
+// private void getPINs(PINSpec spec, int retries)
+// throws InterruptedException, CancelledException {
+// PINManagementGUIFacade gui =
+// (PINManagementGUIFacade) PINManagementRequestHandler.this.gui;
+//
+// if (retry) {
+// gui.showPINDialog(type, spec, retries,
+// PINManagementRequestHandler.this, "exec",
+// PINManagementRequestHandler.this, "back");
+// } else {
+// gui.showPINDialog(type, spec,
+// PINManagementRequestHandler.this, "exec",
+// PINManagementRequestHandler.this, "back");
+// }
+// waitForAction();
+//
+// if (actionCommand.equals("exec")) {
+// gui.showWaitDialog(null);
+// retry = true;
+// oldPin = gui.getOldPin();
+// newPin = gui.getPin();
+// } else if (actionCommand.equals("back")) {
+// throw new CancelledException();
+// } else {
+// log.error("unsupported command " + actionCommand);
+// throw new CancelledException();
+// }
+// }
+// }
+//
+//
+// class PinpadPinProvider implements PINProvider {
+//
+// private PINManagementGUIFacade.DIALOG type;
+// private boolean retry = false;
+//
+// public PinpadPinProvider(DIALOG type) {
+// this.type = type;
+// }
+//
+// @Override
+// public char[] providePIN(PINSpec spec, int retries) {
+// log.debug("provide pin for " + type);
+// if (retry) {
+// ((PINManagementGUIFacade) gui).showPinpadPINDialog(type, spec, retries);
+// } else {
+// ((PINManagementGUIFacade) gui).showPinpadPINDialog(type, spec, -1);
+// retry = true;
+// }
+// return null;
+// }
+//
+// @Override
+// public char[] provideOldPIN(PINSpec spec, int retries) {
+// return null;
+// }
+// }
}
diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java
new file mode 100644
index 00000000..4176e0a9
--- /dev/null
+++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java
@@ -0,0 +1,126 @@
+/*
+ * 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.ext;
+
+import at.gv.egiz.smcc.ChangePINProvider;
+import at.gv.egiz.bku.gui.BKUGUIFacade;
+import at.gv.egiz.bku.gui.PINManagementGUIFacade;
+import at.gv.egiz.bku.gui.PINManagementGUIFacade.DIALOG;
+import at.gv.egiz.bku.smccstal.AbstractPINProvider;
+import at.gv.egiz.smcc.CancelledException;
+import at.gv.egiz.smcc.PINProvider;
+import at.gv.egiz.smcc.PINSpec;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public class PinpadPINProviderFactory extends ManagementPINProviderFactory {
+
+ protected PinpadPINProviderFactory(PINManagementGUIFacade gui) {
+ this.gui = gui;
+ }
+
+ @Override
+ public PINProvider getVerifyPINProvider() {
+ return new SimplePinProvider(DIALOG.VERIFY);
+ }
+
+ @Override
+ public PINProvider getActivatePINProvider() {
+ return new SimplePinProvider(DIALOG.ACTIVATE);
+ }
+
+ @Override
+ public ChangePINProvider getChangePINProvider() {
+ return new SimplePinProvider(DIALOG.CHANGE);
+ }
+
+ @Override
+ public PINProvider getUnblockPINProvider() {
+ return new SimplePinProvider(DIALOG.UNBLOCK);
+ }
+
+
+ class SimplePinProvider extends AbstractPINProvider
+ implements ChangePINProvider {
+
+// protected PINManagementGUIFacade gui;
+ protected PINManagementGUIFacade.DIALOG type;
+
+ private SimplePinProvider(PINManagementGUIFacade.DIALOG type) {
+ this.type = type;
+ }
+
+ @Override
+ public char[] providePIN(PINSpec spec, int retries)
+ throws CancelledException, InterruptedException {
+
+ showPinpadPINDialog(retries, spec);
+ retry = true;
+ return null;
+
+// gui.showPINDialog(type, spec, (retry) ? retries : -1,
+// this, "exec",
+// this, "back");
+//
+// waitForAction();
+//
+// if ("exec".equals(action)) {
+// gui.showWaitDialog(null);
+// retry = true;
+// return gui.getPin();
+// } else if ("back".equals(action)) {
+// throw new CancelledException();
+// } else {
+// log.error("unsupported command " + action);
+// throw new CancelledException();
+// }
+ }
+
+ /**
+ * do not call this method without calling providePIN()
+ * (no message is displayed)
+ * @param spec
+ * @param retries
+ * @return
+ */
+ @Override
+ public char[] provideOldPIN(PINSpec spec, int retries) {
+ 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_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);
+ }
+ }
+}
diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/SoftwarePINProviderFactory.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/SoftwarePINProviderFactory.java
new file mode 100644
index 00000000..e87512d0
--- /dev/null
+++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/SoftwarePINProviderFactory.java
@@ -0,0 +1,148 @@
+/*
+ * 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.ext;
+
+import at.gv.egiz.bku.gui.BKUGUIFacade;
+import at.gv.egiz.smcc.ChangePINProvider;
+import at.gv.egiz.bku.gui.PINManagementGUIFacade;
+import at.gv.egiz.bku.gui.PINManagementGUIFacade.DIALOG;
+import at.gv.egiz.bku.smccstal.AbstractPINProvider;
+import at.gv.egiz.smcc.CancelledException;
+import at.gv.egiz.smcc.PINProvider;
+import at.gv.egiz.smcc.PINSpec;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public class SoftwarePINProviderFactory extends ManagementPINProviderFactory {
+
+ protected SoftwarePINProviderFactory(PINManagementGUIFacade gui) {
+ this.gui = gui;
+ }
+
+ @Override
+ public PINProvider getVerifyPINProvider() {
+ return new SimplePinProvider(DIALOG.VERIFY);
+ }
+
+ @Override
+ public PINProvider getActivatePINProvider() {
+ return new SimplePinProvider(DIALOG.ACTIVATE);
+ }
+
+ @Override
+ public ChangePINProvider getChangePINProvider() {
+ return new ChangePinProvider();
+ }
+
+ @Override
+ public PINProvider getUnblockPINProvider() {
+ return new SimplePinProvider(DIALOG.UNBLOCK);
+ }
+
+ class SimplePinProvider extends AbstractPINProvider {
+
+// protected PINManagementGUIFacade gui;
+ protected PINManagementGUIFacade.DIALOG type;
+
+ private SimplePinProvider(DIALOG type) {
+ this.type = type;
+ }
+
+ @Override
+ public char[] providePIN(PINSpec spec, int retries)
+ throws CancelledException, InterruptedException {
+
+ gui.showPINDialog(type, spec, (retry) ? retries : -1,
+ this, "exec",
+ this, "back");
+
+ waitForAction();
+
+ if ("exec".equals(action)) {
+ gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT,
+ BKUGUIFacade.MESSAGE_WAIT);
+ retry = true;
+ return gui.getPin();
+ } else if ("back".equals(action)) {
+ throw new CancelledException();
+ } else {
+ log.error("unsupported command " + action);
+ throw new CancelledException();
+ }
+ }
+ }
+
+ class ChangePinProvider extends AbstractPINProvider
+ implements ChangePINProvider {
+
+// protected PINManagementGUIFacade gui;
+
+ private char[] oldPin;
+ private char[] newPin;
+
+ private ChangePinProvider() {
+ }
+
+ @Override
+ public char[] providePIN(PINSpec spec, int retries)
+ throws CancelledException, InterruptedException {
+ if (newPin == null) {
+ getPINs(spec, retries);
+ }
+ char[] pin = newPin;
+ newPin = null;
+ return pin;
+ }
+
+ @Override
+ public char[] provideOldPIN(PINSpec spec, int retries)
+ throws CancelledException, InterruptedException {
+ if (oldPin == null) {
+ getPINs(spec, retries);
+ }
+ char[] pin = oldPin;
+ oldPin = null;
+ return pin;
+ }
+
+ private void getPINs(PINSpec spec, int retries)
+ throws InterruptedException, CancelledException {
+
+ gui.showPINDialog(PINManagementGUIFacade.DIALOG.CHANGE, spec,
+ (retry) ? retries : -1,
+ this, "exec",
+ this, "back");
+
+ waitForAction();
+
+ if ("exec".equals(action)) {
+ gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT,
+ BKUGUIFacade.MESSAGE_WAIT);
+ retry = true;
+ oldPin = gui.getOldPin();
+ newPin = gui.getPin();
+ } else if ("back".equals(action)) {
+ throw new CancelledException();
+ } else {
+ log.error("unsupported command " + action);
+ throw new CancelledException();
+ }
+ }
+ }
+}
diff --git a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties
index 69d231f7..4ceacb21 100644
--- a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties
+++ b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties
@@ -22,13 +22,16 @@ title.verify.pin=<html>PIN Eingeben</html>
title.activate.success=<html>Erfolg</html>
title.change.success=<html>Erfolg</html>
-message.pin.mgmt=<html>Die Karte verf\u00FCgt \u00FCber {0} PINs</html>
-message.activate.pin=<html>{0} eingeben und best\u00E4tigen</html>
-message.change.pin=<html>{0} eingeben und best\u00E4tigen</html>
-message.unblock.pin=<html>PUK zu {0} eingeben</html>
-message.verify.pin=<html>{0} eingeben (TODO: Warning not activated)</html>
-message.activate.success=<html>{0} wurde erfolgreich aktiviert.</html>
-message.change.success=<html>{0} wurde erfolgreich ge\u00E4ndert.</html>
+# removed message.* prefix to reuse keys as help keys
+pin.mgmt=<html>Die Karte verf\u00FCgt \u00FCber {0} PINs</html>
+pinpad=<html>{0} ({1} stellig) am Kartenleser eingeben und best\u00E4tigen.</html>
+pinpad.change=<html>{0} ({1} stellig) am Kartenleser eingeben und best\u00E4tigen.</html>
+activate.pin=<html>{0} eingeben und best\u00E4tigen</html>
+change.pin=<html>{0} eingeben und best\u00E4tigen</html>
+unblock.pin=<html>PUK zu {0} eingeben</html>
+verify.pin=<html>{0} eingeben (TODO: Warning not activated)</html>
+activate.success=<html>{0} wurde erfolgreich aktiviert.</html>
+change.success=<html>{0} wurde erfolgreich ge\u00E4ndert.</html>
label.activation=<html>e-card Aktivierungsprozess</html>
label.activation.step=<html>Schritt {0}</html>
diff --git a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties
index 920f7d5b..9178d65c 100644
--- a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties
+++ b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties
@@ -21,12 +21,15 @@ title.unblock.pin=<html>Unblock PIN</html>
title.activate.success=<html>Success</html>
title.change.success=<html>Success</html>
-message.pin.mgmt=<html>The smartcard has {0} PINs</html>
-message.activate.pin=<html>Enter and confirm {0}</html>
-message.change.pin=<html>Enter and confirm {0}</html>
-message.unblock.pin=<html>Enter PUK for {0}</html>
-message.activate.success=<html>{0} successfully activated</html>
-message.change.success=<html>{0} successfully changed</html>
+# removed message.* prefix to reuse keys as help keys
+pin.mgmt=<html>The smartcard has {0} PINs</html>
+pinpad=<html>Enter {0} ({1} digits) on pinpad and confirm.</html>
+pinpad.change=<html>Enter {0} ({1} digits) on pinpad and confirm.</html>
+activate.pin=<html>Enter and confirm {0}</html>
+change.pin=<html>Enter and confirm {0}</html>
+unblock.pin=<html>Enter PUK for {0}</html>
+activate.success=<html>{0} successfully activated</html>
+change.success=<html>{0} successfully changed</html>
label.activation=<html>e-card activation process</html>
label.activation.step=<html>Step {0}</html>
diff --git a/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java b/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java
index ef8c87e4..b01abe72 100644
--- a/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java
+++ b/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java
@@ -74,7 +74,7 @@ public class BKUGUIWorker implements Runnable {
@Override
public void actionPerformed(ActionEvent e) {
- gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", null, "hashdata");
+ gui.showSignaturePINDialog(signPinSpec, -1, signListener, "sign", cancelListener, "cancel", null, "hashdata");
}
};
HashDataInput signedRef1 = new ByteArrayHashDataInput(
@@ -112,7 +112,7 @@ public class BKUGUIWorker implements Runnable {
// signedRefs.add(signedRef4);
// signedRefs.add(signedRef4);
// signedRefs = Collections.singletonList(signedRef1);
- gui.showHashDataInputDialog(signedRefs, returnListener, "return");
+ gui.showSecureViewer(signedRefs, returnListener, "return");
}
};
diff --git a/BKUAppletExt/src/test/java/at/gv/egiz/bku/smccstal/ext/FileSystemTest.java b/BKUAppletExt/src/test/java/at/gv/egiz/bku/smccstal/ext/FileSystemTest.java
deleted file mode 100644
index 5fa3cbd7..00000000
--- a/BKUAppletExt/src/test/java/at/gv/egiz/bku/smccstal/ext/FileSystemTest.java
+++ /dev/null
@@ -1,435 +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.ext;
-
-import at.gv.egiz.smcc.FileNotFoundException;
-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.util.SMCCHelper;
-import at.gv.egiz.smcc.util.SmartCardIO;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.Locale;
-import java.util.Map;
-import javax.smartcardio.Card;
-import javax.smartcardio.CardChannel;
-import javax.smartcardio.CardException;
-import javax.smartcardio.CardTerminal;
-import javax.smartcardio.CommandAPDU;
-import javax.smartcardio.ResponseAPDU;
-import org.junit.Ignore;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-/**
- *
- * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
- */
-@Ignore
-public class FileSystemTest {
-
- /** asign premium */
- public static final byte[] AID_DEC = new byte[] { (byte) 0xA0, (byte) 0x00,
- (byte) 0x00, (byte) 0x01, (byte) 0x18, (byte) 0x45, (byte) 0x4E };
-
- @Test
-// @Ignore
- public void testCard() throws CardException, SignatureCardException, InterruptedException {
-
- SMCCHelper smccHelper = new SMCCHelper();
- switch (smccHelper.getResultCode()) {
- case SMCCHelper.CARD_FOUND:
- System.out.println("card found ");
- }
- SignatureCard signatureCard = smccHelper.getSignatureCard(new Locale("de"));
- Card card = signatureCard.getCard();
-
-// SmartCardIO scIO = new SmartCardIO();
-// Map<CardTerminal, Card> terminalCardMap = scIO.getCards();
-//
-// for (CardTerminal ct : terminalCardMap.keySet()) {
-// Card card = terminalCardMap.get(ct);
-// System.out.println("found card (" + ct.getName() + "): " + Formatter.byteArrayToHexString(card.getATR().getBytes()));
-
- System.out.println("found card " + Formatter.byteArrayToHexString(card.getATR().getBytes()));
-
- CardChannel cardchannel;
-
- //RESET
- System.out.println("RESET");
- signatureCard.reset();
- card = signatureCard.getCard();
-// card.disconnect(true);
-// card = ct.connect("*");
-
- System.out.println("begin exclusive");
- card.beginExclusive();
- System.out.println("get cardchannel");
- cardchannel = card.getBasicChannel();
-
- testECard(cardchannel, signatureCard, card);
-// testASignPremium(cardchannel, signatureCard, card);
-
-// }
-
- }
-
- public static class TestCard {
-
- protected CardChannel channel;
- protected int ifs_ = 254;
-
- public TestCard(CardChannel channel) {
- this.channel = channel;
- }
-
- protected byte[] readTLVFile(byte[] aid, byte[] ef, String pin, byte kid, int maxLength)
- throws SignatureCardException, InterruptedException, CardException {
-
-
- // SELECT FILE (AID)
- selectFileAID(aid);
-
- // SELECT FILE (EF)
- ResponseAPDU resp = selectFileFID(ef);
- if (resp.getSW() == 0x6a82) {
- // EF not found
- throw new FileNotFoundException("EF " + toString(ef) + " not found.");
- } else if (resp.getSW() != 0x9000) {
- throw new SignatureCardException("SELECT FILE with " + "FID=" + toString(ef) + " failed (" + "SW=" + Integer.toHexString(resp.getSW()) + ").");
- }
-
- // VERIFY
- if (pin != null) {
- int retries = verifyPIN(pin, kid);
- if (retries != -1) {
- throw new at.gv.egiz.smcc.VerificationFailedException(retries);
- }
- }
-
- return readBinaryTLV(maxLength, (byte) 0x30);
- }
-
- protected byte[] readBinary(CardChannel channel, int offset, int len)
- throws CardException, SignatureCardException {
-
- //transmit(channel,apdu)
- ResponseAPDU resp = channel.transmit(new CommandAPDU(0x00, 0xB0,
- 0x7F & (offset >> 8), offset & 0xFF, len));
- if (resp.getSW() == 0x9000) {
- return resp.getData();
- } else if (resp.getSW() == 0x6982) {
- throw new at.gv.egiz.smcc.SecurityStatusNotSatisfiedException();
- } else {
- throw new SignatureCardException("Failed to read bytes (" + offset + "+" + len + "): SW=" + Integer.toHexString(resp.getSW()));
- }
-
- }
-
- protected byte[] readBinaryTLV(int maxSize, byte expectedType) throws CardException,
- SignatureCardException {
-
-// CardChannel channel = getCardChannel();
-
- // read first chunk
- int len = Math.min(maxSize, ifs_);
- byte[] chunk = readBinary(channel, 0, len);
- if (chunk.length > 0 && chunk[0] != expectedType) {
- return null;
- }
- int offset = chunk.length;
- int actualSize = maxSize;
- if (chunk.length > 3) {
- if ((chunk[1] & 0x80) > 0) {
- int octets = (0x0F & chunk[1]);
- actualSize = 2 + octets;
- for (int i = 1; i <= octets; i++) {
- actualSize += (0xFF & chunk[i + 1]) << ((octets - i) * 8);
- }
- } else {
- actualSize = 2 + chunk[1];
- }
- }
- ByteBuffer buffer = ByteBuffer.allocate(actualSize);
- buffer.put(chunk, 0, Math.min(actualSize, chunk.length));
- while (offset < actualSize) {
- len = Math.min(ifs_, actualSize - offset);
- chunk = readBinary(channel, offset, len);
- buffer.put(chunk);
- offset += chunk.length;
- }
- return buffer.array();
-
- }
-
- protected byte[] selectFileAID(byte[] dfName) throws CardException, SignatureCardException {
-// CardChannel channel = getCardChannel();
- ResponseAPDU resp = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x04,
- 0x00, dfName, 256));
- if (resp.getSW() != 0x9000) {
- throw new SignatureCardException("Failed to select application AID=" + toString(dfName) + ": SW=" + Integer.toHexString(resp.getSW()) + ".");
- } else {
- return resp.getBytes();
- }
- }
-
- protected ResponseAPDU selectFileFID(byte[] fid) throws CardException, SignatureCardException {
-// CardChannel channel = getCardChannel();
- return channel.transmit(new CommandAPDU(0x00, 0xA4, 0x02,
- 0x04, fid, 256));
- }
-
- protected String toString(byte[] b) {
- StringBuffer sb = new StringBuffer();
- if (b != null && b.length > 0) {
- sb.append(Integer.toHexString((b[0] & 240) >> 4));
- sb.append(Integer.toHexString(b[0] & 15));
- }
- for (int i = 1; i < b.length; i++) {
- sb.append(':');
- sb.append(Integer.toHexString((b[i] & 240) >> 4));
- sb.append(Integer.toHexString(b[i] & 15));
- }
- return sb.toString();
- }
-
- protected int verifyPIN(String pin, byte kid) throws CardException, SignatureCardException {
-
-// CardChannel channel = getCardChannel();
-
- ResponseAPDU resp;
- if (pin == null) {
- //
- resp = channel.transmit(new CommandAPDU(0x00, 0x20, 0x00, kid));
- } else {
- // PIN length in bytes
- int len = (int) Math.ceil(pin.length() / 2);
-
- // BCD encode PIN and marshal PIN block
- byte[] pinBytes = new BigInteger(pin, 16).toByteArray();
- byte[] pinBlock = new byte[8];
- if (len < pinBytes.length) {
- System.arraycopy(pinBytes, pinBytes.length - len, pinBlock, 1, len);
- } else {
- System.arraycopy(pinBytes, 0, pinBlock, len - pinBytes.length + 1,
- pinBytes.length);
- }
- pinBlock[0] = (byte) (0x20 + len * 2);
- Arrays.fill(pinBlock, len + 1, 8, (byte) 0xff);
-
- resp = channel.transmit(new CommandAPDU(0x00, 0x20, 0x00, kid, pinBlock));//, false);
-
- }
-
- if (resp.getSW() == 0x63c0) {
- throw new LockedException("PIN locked.");
- } else if (resp.getSW1() == 0x63 && resp.getSW2() >> 4 == 0xc) {
- // return number of possible retries
- return resp.getSW2() & 0x0f;
- } else if (resp.getSW() == 0x6983) {
- throw new LockedException();
- } else if (resp.getSW() == 0x6984) {
- // PIN LCS = "Initialized" (-> not activated)
- throw new NotActivatedException("PIN not set.");
- } else if (resp.getSW() == 0x9000) {
- return -1; // success
- } else {
- throw new SignatureCardException("Failed to verify pin: SW=" + Integer.toHexString(resp.getSW()));
- }
- }
- }
-
- public static class Formatter {
-
- private static String[] alphabet = {"0", "1", "2",
- "3", "4", "5", "6", "7", "8",
- "9", "A", "B", "C", "D", "E",
- "F"};
-
- public static String byteArrayToHexString(byte[] bytes) {
-
- if (bytes == null || bytes.length <= 0) {
- return null;
- }
-
- StringBuffer buf = new StringBuffer(2 * bytes.length);
-
- byte c = 0x00;
-
- for (int i = 0; i < bytes.length; i++) {
-
- // high nibble
- c = (byte) (bytes[i] & 0xf0);
-
- // shift down
- c = (byte) (c >>> 4);
-
- // cut high order bits
- c = (byte) (c & 0x0f);
-
- buf.append(alphabet[(int) c]);
-
- // low nibble
- c = (byte) (bytes[i] & 0x0f);
-
- buf.append(alphabet[(int) c]);
- if (i < bytes.length - 1) {
- buf.append(':');
- }
- }
-
- return buf.toString();
-
- }
- }
-
- protected void testASignPremium(CardChannel cardchannel, SignatureCard signatureCard, Card card) throws CardException {
- byte[] selectMF = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0x3F, (byte) 0x00};
- byte[] selectDF_DEC = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0xdf, (byte) 0x71 };
- byte[] selectAID_DEC = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x07, (byte) 0xA0, (byte) 0x00,
- (byte) 0x00, (byte) 0x01, (byte) 0x18, (byte) 0x45, (byte) 0x4E };
-
- CommandAPDU cAPDU;
- ResponseAPDU rAPDU;
- byte[] sw;
-
- cAPDU = new CommandAPDU(selectMF);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
-
- cAPDU = new CommandAPDU(selectAID_DEC);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
-
- cAPDU = new CommandAPDU(selectDF_DEC);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
-
-
- }
-
- protected void testECard(CardChannel cardchannel, SignatureCard signatureCard, Card card) throws CardException, InterruptedException, SignatureCardException {
-// if (cardTerminal != null) {
-// card_ = cardTerminal.connect("*");
-// }
- byte[] selectMF = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0x3F, (byte) 0x00};
- byte[] readEF_GDO = new byte[]{(byte) 0x00, (byte) 0xB0, (byte) 0x82, (byte) 0x00, (byte) 0x00};
- CommandAPDU cAPDU;
- ResponseAPDU rAPDU;
- byte[] sw;
- cAPDU = new CommandAPDU(selectMF);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
- cAPDU = new CommandAPDU(readEF_GDO);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
- byte[] EF_GDO = rAPDU.getData();
- //RESET
- System.out.println("RESET");
- signatureCard.reset();
- card = signatureCard.getCard();
-// card.disconnect(true);
-// card = ct.connect("*");
- System.out.println("begin exclusive");
- card.beginExclusive();
- System.out.println("get cardchannel");
- cardchannel = card.getBasicChannel();
- byte[] getCLC = new byte[]{(byte) 0x00, (byte) 0xCA, (byte) 0xDF, (byte) 0x20, (byte) 0x00};
- byte[] verifyKartenPIN = new byte[]{(byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x01};
- byte[] selectDF_SichereSignatur = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x08, (byte) 0xD0, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x12, (byte) 0x01, (byte) 0x00};
- byte[] verifySignaturPIN = new byte[]{(byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x81};
- cAPDU = new CommandAPDU(getCLC);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
- byte[] clc = rAPDU.getData();
- cAPDU = new CommandAPDU(verifyKartenPIN);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
- cAPDU = new CommandAPDU(selectDF_SichereSignatur);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
- cAPDU = new CommandAPDU(verifySignaturPIN);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
- //RESET
- System.out.println("RESET");
- signatureCard.reset();
- card = signatureCard.getCard();
- System.out.println("InfoboxReadRequests...");
- PINProvider pinProvider = new PINProvider() {
-
- @Override
- public String providePIN(PINSpec spec, int retries) throws InterruptedException {
- if (retries >= 3) {
- return "2540";
- } else {
- throw new InterruptedException("TOO FEW PIN RETRIES LEFT, ABORTING");
- }
- }
- };
- byte[] ehic = signatureCard.getInfobox("EHIC", pinProvider, null);
- System.out.println("EHIC: " + Formatter.byteArrayToHexString(ehic));
- byte[] grunddaten = signatureCard.getInfobox("Grunddaten", pinProvider, null);
- System.out.println("Grunddaten: " + Formatter.byteArrayToHexString(grunddaten));
- //RESET
- System.out.println("RESET");
- signatureCard.reset();
- card = signatureCard.getCard();
-// card.disconnect(true);
-// card = ct.connect("*");
- System.out.println("begin exclusive");
- card.beginExclusive();
- System.out.println("get cardchannel");
- cardchannel = card.getBasicChannel();
- cAPDU = new CommandAPDU(getCLC);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
- assertTrue(Arrays.equals(clc, rAPDU.getData()));
- cAPDU = new CommandAPDU(readEF_GDO);
- rAPDU = cardchannel.transmit(cAPDU);
- sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())};
- System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes()));
- System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData()));
- assertTrue(Arrays.equals(EF_GDO, rAPDU.getData()));
-// }
- }
-}