diff options
author | Tobias Kellner <tobias.kellner@iaik.tugraz.at> | 2015-02-23 15:35:24 +0100 |
---|---|---|
committer | Tobias Kellner <tobias.kellner@iaik.tugraz.at> | 2015-02-23 15:35:24 +0100 |
commit | ce8d2589fb976cb4d00c0c9acad5eb6dfc253df0 (patch) | |
tree | 156cf8bf68f54b867b9e16cc8ec7e0c8a13446fb /pdf-over-gui/src/main | |
parent | 5edda2d93aa78e22972ab3b6638393ff688d398f (diff) | |
download | pdf-over-ce8d2589fb976cb4d00c0c9acad5eb6dfc253df0.tar.gz pdf-over-ce8d2589fb976cb4d00c0c9acad5eb6dfc253df0.tar.bz2 pdf-over-ce8d2589fb976cb4d00c0c9acad5eb6dfc253df0.zip |
Handle a-trust certificate validity warning
Diffstat (limited to 'pdf-over-gui/src/main')
4 files changed, 68 insertions, 3 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java index 43a4002e..be7464fc 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java @@ -16,11 +16,15 @@ package at.asit.pdfover.gui.bku.mobile; // Imports +import java.awt.Desktop; import java.io.IOException; +import java.net.URI; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.lang3.StringEscapeUtils; import org.eclipse.swt.SWT; +import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.slf4j.Logger; @@ -55,9 +59,13 @@ public class ATrustHandler extends MobileBKUHandler { /** * SLF4J Logger instance **/ - private static final Logger log = LoggerFactory + static final Logger log = LoggerFactory .getLogger(ATrustHandler.class); + private static boolean expiryNoticeDisplayed = false; + + private static final String ACTIVATION_URL = "https://www.handy-signatur.at/"; //$NON-NLS-1$ + private boolean useBase64 = false; /* (non-Javadoc) @@ -123,6 +131,54 @@ public class ATrustHandler extends MobileBKUHandler { status.setErrorMessage(null); + if (responseData.contains("ExpiresInfo.aspx?sid=")) { //$NON-NLS-1$ + // Certification expiration interstitial - skip + String notice = Messages.getString("mobileBKU.notice") + " " + //$NON-NLS-1$ //$NON-NLS-2$ + StringEscapeUtils.unescapeHtml4(MobileBKUHelper.extractTag(responseData, "<span id=\"Label2\">", "</span>")) //$NON-NLS-1$ //$NON-NLS-2$ + .replaceAll("\\<.*?\\>", ""); //$NON-NLS-1$ //$NON-NLS-2$ + log.info(notice); + + if (!expiryNoticeDisplayed) { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + Dialog d = new Dialog(ATrustHandler.this.shell, Messages.getString("common.info"), Messages.getString("mobileBKU.certExpiresSoon"), BUTTONS.YES_NO, ICON.WARNING); //$NON-NLS-1$ //$NON-NLS-2$ + if (d.open() == SWT.YES) { + log.debug("Trying to open " + ACTIVATION_URL); //$NON-NLS-1$ + if (Desktop.isDesktopSupported()) { + try { + Desktop.getDesktop().browse(new URI(ACTIVATION_URL)); + return; + } catch (Exception e) { + log.debug("Error opening URL", e); //$NON-NLS-1$ + } + } + log.info("SWT Desktop is not supported on this platform"); //$NON-NLS-1$ + Program.launch(ACTIVATION_URL); + } + } + }); + expiryNoticeDisplayed = true; + } + + String t_sessionID = MobileBKUHelper.extractTag(responseData, "ExpiresInfo.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + String t_viewState = MobileBKUHelper.extractTag(responseData, "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + String t_eventValidation = MobileBKUHelper.extractTag(responseData, "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + + // Post again to skip + MobileBKUHelper.registerTrustedSocketFactory(); + HttpClient client = BKUHelper.getHttpClient(); + + PostMethod post = new PostMethod(status.getBaseURL() + "/ExpiresInfo.aspx?sid=" + t_sessionID); //$NON-NLS-1$ + post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ + post.addParameter("__VIEWSTATE", t_viewState); //$NON-NLS-1$ + post.addParameter("__EVENTVALIDATION", t_eventValidation); //$NON-NLS-1$ + post.addParameter("Button_Next", "Weiter"); //$NON-NLS-1$ //$NON-NLS-2$ + + responseData = executePost(client, post); + log.trace("Response from mobile BKU: " + responseData); //$NON-NLS-1$ + } + if (responseData.contains("signature.aspx?sid=")) { //$NON-NLS-1$ // credentials ok! TAN entry log.debug("Credentials accepted - TAN required"); //$NON-NLS-1$ @@ -139,7 +195,6 @@ public class ATrustHandler extends MobileBKUHandler { new SLResponse(responseData, getStatus().getServer(), null, null)); return; } else { - // error page // extract error text! try { diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/Dialog.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/Dialog.java index c86b0e31..6d14dbd7 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/Dialog.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/Dialog.java @@ -38,7 +38,9 @@ public class Dialog { /** Display retry and cancel buttons */ RETRY_CANCEL, /** Display abort, retry and ignore buttons */ - ABORT_RETRY_IGNORE + ABORT_RETRY_IGNORE, + /** Display yes and no buttons */ + YES_NO }; /** @@ -101,6 +103,8 @@ public class Dialog { case ABORT_RETRY_IGNORE: boxstyle |= SWT.RETRY | SWT.ABORT | SWT.IGNORE; break; + case YES_NO: + boxstyle |= SWT.YES | SWT.NO; } this.box = new MessageBox(parent, boxstyle); diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties index 42744584..3bc09db0 100644 --- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties +++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties @@ -78,6 +78,7 @@ common.PDFExtension_Description=PDF documents common.PNGExtension_Description=PNG files common.Save=&Save common.browse=&Browse +common.info=Information common.open=Open common.warning=Warning config.Advanced=Ad&vanced @@ -129,6 +130,8 @@ main.hide=Hide %s main.position=Positioning main.quit=Quit %s main.signature=Signing +mobileBKU.certExpiresSoon=Since the validity of your certificate expires in the next few days, a new activation is necessary (free of charge). Press "Yes" to visit https://www.handy-signatur.at/ now, and then sign in to your account. +mobileBKU.notice=Notice from server: mobileBKU.number=Number: mobileBKU.password=Password: mobileBKU.show=<a>Show signature data</a> diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties index d99aaa7e..41ebf30c 100644 --- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties +++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties @@ -78,6 +78,7 @@ common.PDFExtension_Description=PDF-Dokumente common.PNGExtension_Description=PNG-Bilder common.Save=&Speichern common.browse=&Durchsuchen +common.info=Information common.open=Öffnen common.warning=Warnung config.Advanced=Er&weitert @@ -129,6 +130,8 @@ main.hide=%s ausblenden main.position=Positionierung main.quit=%s beenden main.signature=Signatur +mobileBKU.certExpiresSoon=Da die Gültigkeit Ihres Zertifikats in den nächsten Tagen endet, ist eine erneute Aktivierung erforderlich (gebührenfrei). Wählen Sie "Ja" um https://www.handy-signatur.at/ zu öffnen, und loggen Sie sich dann in Ihr Konto ein. +mobileBKU.notice=Nachricht vom Server: mobileBKU.number=Nummer: mobileBKU.password=Passwort: mobileBKU.show=<a>Signaturdaten anzeigen</a> |