From 9e50f1a103a37d9dcfbeb5ea45bcf6c6c0c0f6dd Mon Sep 17 00:00:00 2001 From: Tobias Kellner Date: Thu, 27 Nov 2014 20:57:33 +0100 Subject: Implement PDF-AS 4 changes --- .../pdfover/gui/workflow/states/LocalBKUState.java | 56 +--- .../gui/workflow/states/MobileBKUState.java | 281 +++++++++---------- .../workflow/states/PrepareConfigurationState.java | 6 +- .../pdfover/gui/workflow/states/SigningState.java | 19 +- .../workflow/states/mobilebku/ATrustHandler.java | 223 --------------- .../workflow/states/mobilebku/ATrustStatus.java | 86 ------ .../mobilebku/AbstractMobileBKUStatusImpl.java | 138 ---------- .../gui/workflow/states/mobilebku/IAIKHandler.java | 305 --------------------- .../gui/workflow/states/mobilebku/IAIKStatus.java | 80 ------ .../mobilebku/MobileBKUCommunicationState.java | 37 --- .../states/mobilebku/MobileBKUHandler.java | 252 ----------------- .../workflow/states/mobilebku/MobileBKUHelper.java | 188 ------------- .../workflow/states/mobilebku/MobileBKUStatus.java | 140 ---------- .../gui/workflow/states/mobilebku/MobileBKUs.java | 27 -- .../states/mobilebku/PostCredentialsThread.java | 68 ----- .../states/mobilebku/PostSLRequestThread.java | 80 ------ .../workflow/states/mobilebku/PostTanThread.java | 71 ----- .../states/mobilebku/SimpleXMLTrustManager.java | 225 --------------- .../states/mobilebku/TrustedSocketFactory.java | 192 ------------- 19 files changed, 171 insertions(+), 2303 deletions(-) delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/AbstractMobileBKUStatusImpl.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKStatus.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUs.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/SimpleXMLTrustManager.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java index 4ca27896..3962d836 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java @@ -21,24 +21,20 @@ import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.multipart.FilePart; -import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; -import org.apache.commons.httpclient.methods.multipart.Part; -import org.apache.commons.httpclient.methods.multipart.StringPart; import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.bku.BKUHelper; +import at.asit.pdfover.gui.bku.LocalBKUConnector; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.ErrorDialog; -import at.asit.pdfover.gui.utils.FileUploadSource; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; -import at.asit.pdfover.signator.SLRequest; import at.asit.pdfover.signator.SLResponse; /** @@ -91,9 +87,6 @@ public class LocalBKUState extends State { private LocalBKUState state; - /** Whether to use Base64 or FileUpload Request */ - private boolean useBase64Request = false; - /** * @param localBKUState @@ -105,13 +98,10 @@ public class LocalBKUState extends State { @Override public void run() { try { - SLRequest request = this.state.signingState - .getSignatureRequest(); - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); - PostMethod method = new PostMethod( - "http://127.0.0.1:3495/http-security-layer-request"); //$NON-NLS-1$ + PostMethod method = new PostMethod(Constants.LOCAL_BKU_URL); String sl_request = NULL_OPERATION_REQUEST; method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ @@ -119,34 +109,11 @@ public class LocalBKUState extends State { String userAgent = getResponseHeader(method, BKU_RESPONSE_HEADER_USERAGENT); String server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER); - if (server != null && server.contains("trustDeskbasic")) //$NON-NLS-1$ - this.useBase64Request = true; // TDB doesn't support MultiPart requests - - method = new PostMethod( - "http://127.0.0.1:3495/http-security-layer-request"); //$NON-NLS-1$ - if (this.useBase64Request) - { - sl_request = request.getBase64Request(); - method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ + if (returnCode != HttpStatus.SC_OK) { + this.state.threadException = new HttpException( + method.getResponseBodyAsString()); } else { - sl_request = request.getFileUploadRequest(); - StringPart xmlpart = new StringPart( - "XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$ - - FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$ - new FileUploadSource(request.getSignatureData())); - - Part[] parts = { xmlpart, filepart }; - - method.setRequestEntity(new MultipartRequestEntity(parts, method - .getParams())); - } - //log.debug("SL REQUEST: " + sl_request); //$NON-NLS-1$ - - returnCode = client.executeMethod(method); - - if (returnCode == HttpStatus.SC_OK) { server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER); if (server == null) server = ""; //$NON-NLS-1$ @@ -160,14 +127,10 @@ public class LocalBKUState extends State { SLResponse slResponse = new SLResponse(response, server, userAgent, signatureLayout); this.state.signingState.setSignatureResponse(slResponse); - } else { - this.state.threadException = new HttpException( - method.getResponseBodyAsString()); } - } catch (Exception e) { log.error("SignLocalBKUThread: ", e); //$NON-NLS-1$ - // + this.state.threadException = e; } finally { this.state.updateStateMachine(); @@ -206,6 +169,7 @@ public class LocalBKUState extends State { t.start(); return; } + this.signingState.setBKUConnector(new LocalBKUConnector()); if (this.threadException != null) { ErrorDialog dialog = new ErrorDialog( diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 823edae8..4a825d17 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -17,28 +17,26 @@ package at.asit.pdfover.gui.workflow.states; // Imports import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.bku.MobileBKUConnector; +import at.asit.pdfover.gui.bku.mobile.ATrustHandler; +import at.asit.pdfover.gui.bku.mobile.ATrustStatus; +import at.asit.pdfover.gui.bku.mobile.IAIKHandler; +import at.asit.pdfover.gui.bku.mobile.IAIKStatus; +import at.asit.pdfover.gui.bku.mobile.MobileBKUHandler; +import at.asit.pdfover.gui.bku.mobile.MobileBKUStatus; import at.asit.pdfover.gui.composites.MobileBKUEnterNumberComposite; import at.asit.pdfover.gui.composites.MobileBKUEnterTANComposite; import at.asit.pdfover.gui.composites.WaitingComposite; -import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHandler; -import at.asit.pdfover.gui.workflow.states.mobilebku.IAIKHandler; -import at.asit.pdfover.gui.workflow.states.mobilebku.IAIKStatus; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUCommunicationState; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler; -import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustStatus; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus; -import at.asit.pdfover.gui.workflow.states.mobilebku.PostCredentialsThread; -import at.asit.pdfover.gui.workflow.states.mobilebku.PostSLRequestThread; -import at.asit.pdfover.gui.workflow.states.mobilebku.PostTanThread; /** * Logical state for performing the BKU Request to the A-Trust Mobile BKU @@ -73,8 +71,6 @@ public class MobileBKUState extends State { Exception threadException = null; - MobileBKUCommunicationState communicationState = MobileBKUCommunicationState.POST_REQUEST; - MobileBKUStatus status = null; MobileBKUHandler handler = null; @@ -85,7 +81,7 @@ public class MobileBKUState extends State { WaitingComposite waitingComposite = null; - private WaitingComposite getWaitingComposite() { + WaitingComposite getWaitingComposite() { if (this.waitingComposite == null) { this.waitingComposite = getStateMachine().getGUIProvider() .createComposite(WaitingComposite.class, SWT.RESIZE, this); @@ -94,7 +90,7 @@ public class MobileBKUState extends State { return this.waitingComposite; } - private MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() { + MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() { if (this.mobileBKUEnterTANComposite == null) { this.mobileBKUEnterTANComposite = getStateMachine() .getGUIProvider().createComposite( @@ -104,7 +100,7 @@ public class MobileBKUState extends State { return this.mobileBKUEnterTANComposite; } - private MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() { + MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() { if (this.mobileBKUEnterNumberComposite == null) { this.mobileBKUEnterNumberComposite = getStateMachine() .getGUIProvider().createComposite( @@ -139,22 +135,6 @@ public class MobileBKUState extends State { return getStateMachine().getConfigProvider().getMobileBKUURL(); } - /** - * @return the communicationState - */ - public MobileBKUCommunicationState getCommunicationState() { - return this.communicationState; - } - - /** - * @param communicationState - * the communicationState to set - */ - public void setCommunicationState( - MobileBKUCommunicationState communicationState) { - this.communicationState = communicationState; - } - /** * @return the signingState */ @@ -170,93 +150,63 @@ public class MobileBKUState extends State { this.threadException = threadException; } - /* - * (non-Javadoc) + /** + * Display an error message * - * @see - * at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui - * .workflow.Workflow) + * @param e + * the exception */ - @Override - public void run() { - - this.signingState = getStateMachine().getStatus().getSigningState(); + public void displayError(Exception e) { + String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$ + log.error(message, e); + String errormsg = e.getLocalizedMessage(); + if (errormsg != null && !errormsg.isEmpty()) + message += ": " + errormsg; //$NON-NLS-1$ + displayError(message); + } - MobileBKUStatus mobileStatus = this.getStatus(); + /** + * Display an error message + * + * @param message + * the error message + */ + public void displayError(final String message) { + log.error(message); + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider() + .getMainShell(), message, BUTTONS.OK); + error.open(); + } + }); + } - if (this.threadException != null) { - String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$ - log.error(message, this.threadException); - String errormsg = this.threadException.getLocalizedMessage(); - if (errormsg != null && !errormsg.isEmpty()) - message += ": " + errormsg; //$NON-NLS-1$ - ErrorDialog error = new ErrorDialog( - getStateMachine().getGUIProvider().getMainShell(), - message, BUTTONS.OK); - // error.setException(this.threadException); - // this.setNextState(error); - error.open(); - getStateMachine().exit(); + /** + * Make sure phone number and password are set in the MobileBKUStatus + */ + public void checkCredentials() { + final MobileBKUStatus mobileStatus = this.getStatus(); + // check if we have everything we need! + if (mobileStatus.getPhoneNumber() != null && !mobileStatus.getPhoneNumber().isEmpty() && + mobileStatus.getMobilePassword() != null && !mobileStatus.getMobilePassword().isEmpty()) return; - } - switch (this.communicationState) { - case POST_REQUEST: - getStateMachine().getGUIProvider().display( - this.getWaitingComposite()); - Thread postSLRequestThread = new Thread( - new PostSLRequestThread(this)); - postSLRequestThread.start(); - break; - - case POST_NUMBER: - // Check if number and password is set ... - // if not show UI - // else start thread - - // check if we have everything we need! - if (mobileStatus.getPhoneNumber() != null - && !mobileStatus.getPhoneNumber().isEmpty() - && mobileStatus.getMobilePassword() != null - && !mobileStatus.getMobilePassword().isEmpty()) { - // post to bku - Thread postCredentialsThread = new Thread( - new PostCredentialsThread(this)); - postCredentialsThread.start(); - // resets password if incorrect to null - } else { - - MobileBKUEnterNumberComposite ui = this + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + MobileBKUEnterNumberComposite ui = MobileBKUState.this .getMobileBKUEnterNumberComposite(); - - if (ui.isUserAck()) { - // user hit ok - - ui.setUserAck(false); - - // get number and password from UI - mobileStatus.setPhoneNumber(ui.getMobileNumber()); - mobileStatus.setMobilePassword(ui.getMobilePassword()); - - // show waiting composite - getStateMachine().getGUIProvider().display( - this.getWaitingComposite()); - - // post to BKU - Thread postCredentialsThread = new Thread( - new PostCredentialsThread(this)); - postCredentialsThread.start(); - - } else { + + if (!ui.isUserAck()) { // We need number and password => show UI! - if (mobileStatus.getErrorMessage() != null && !mobileStatus.getErrorMessage().isEmpty()) { // set possible error message ui.setErrorMessage(mobileStatus.getErrorMessage()); mobileStatus.setErrorMessage(null); } - if (ui.getMobileNumber() == null || ui.getMobileNumber().isEmpty()) { @@ -271,17 +221,64 @@ public class MobileBKUState extends State { } ui.enableButton(); getStateMachine().getGUIProvider().display(ui); + + Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay(); + while (!ui.isUserAck()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } } - } - break; - case POST_TAN: - // Get TAN from UI + // user hit ok + ui.setUserAck(false); - MobileBKUEnterTANComposite tan = this - .getMobileBKUEnterTANComposite(); + // get number and password from UI + mobileStatus.setPhoneNumber(ui.getMobileNumber()); + mobileStatus.setMobilePassword(ui.getMobilePassword()); + + // show waiting composite + getStateMachine().getGUIProvider().display( + MobileBKUState.this.getWaitingComposite()); + } + }); + } + + /** + * Make sure TAN is set in the MobileBKUStatus + */ + public void checkTAN() { + final MobileBKUStatus mobileStatus = this.getStatus(); + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + MobileBKUEnterTANComposite tan = MobileBKUState.this + .getMobileBKUEnterTANComposite(); + + if (!tan.isUserAck()) { + // we need the TAN + tan.setRefVal(mobileStatus.getRefVal()); + tan.setSignatureData(mobileStatus.getSignatureDataURL()); + tan.setErrorMessage(mobileStatus.getErrorMessage()); + if (mobileStatus.getTanTries() < mobileStatus.getMaxTanTries() + && mobileStatus.getTanTries() > 0) { + // show warning message x tries left! + // overrides error message + + tan.setTries(mobileStatus.getTanTries()); + } + tan.enableButton(); + getStateMachine().getGUIProvider().display(tan); + + Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay(); + while (!tan.isUserAck()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } - if (tan.isUserAck()) { // user hit ok! tan.setUserAck(false); @@ -289,36 +286,44 @@ public class MobileBKUState extends State { // show waiting composite getStateMachine().getGUIProvider().display( - this.getWaitingComposite()); - - // post to BKU! - Thread postTanThread = new Thread(new PostTanThread(this)); - postTanThread.start(); - - } else { - tan.setRefVal(mobileStatus.getRefVal()); - tan.setSignatureData(mobileStatus.getSignatureDataURL()); - tan.setErrorMessage(mobileStatus.getErrorMessage()); - if (mobileStatus.getTanTries() < mobileStatus.getMaxTanTries() - && mobileStatus.getTanTries() > 0) { - // show warning message x tries left! - // overrides error message - - tan.setTries(mobileStatus.getTanTries()); - } - tan.enableButton(); - getStateMachine().getGUIProvider().display(tan); + MobileBKUState.this.getWaitingComposite()); } - break; + }); + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui + * .workflow.Workflow) + */ + @Override + public void run() { + this.signingState = getStateMachine().getStatus().getSigningState(); - case FINAL: - this.setNextState(new SigningState(getStateMachine())); - break; + this.signingState.setBKUConnector(new MobileBKUConnector(this)); - case CANCEL: - this.setNextState(new BKUSelectionState(getStateMachine())); - break; + if (this.threadException != null) { + String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$ + log.error(message, this.threadException); + String errormsg = this.threadException.getLocalizedMessage(); + if (errormsg != null && !errormsg.isEmpty()) + message += ": " + errormsg; //$NON-NLS-1$ + ErrorDialog error = new ErrorDialog( + getStateMachine().getGUIProvider().getMainShell(), + message, BUTTONS.OK); + // error.setException(this.threadException); + // this.setNextState(error); + error.open(); + getStateMachine().exit(); + return; } + + getStateMachine().getGUIProvider().display( + this.getWaitingComposite()); + + this.setNextState(new SigningState(getStateMachine())); } /* diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index 63c54c71..70895bfb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.Constants; +import at.asit.pdfover.gui.bku.BKUHelper; import at.asit.pdfover.gui.cliarguments.ArgumentHandler; import at.asit.pdfover.gui.cliarguments.AutomaticPositioningArgument; import at.asit.pdfover.gui.cliarguments.BKUArgument; @@ -58,7 +59,6 @@ import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.utils.Unzipper; import at.asit.pdfover.gui.utils.VersionComparator; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; import at.asit.pdfover.signator.Signator; /** @@ -340,7 +340,7 @@ public class PrepareConfigurationState extends State { // Check for updates if (getStateMachine().getConfigProvider().getUpdateCheck() && Constants.APP_VERSION != null) { - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); GetMethod method = new GetMethod(Constants.CURRENT_RELEASE_URL); try { client.executeMethod(method); @@ -370,7 +370,7 @@ public class PrepareConfigurationState extends State { // Set usedSignerLib ... getStateMachine().getPDFSigner().setUsedPDFSignerLibrary( - Signator.Signers.PDFAS); + Signator.Signers.PDFAS4); // Create PDF Signer getStateMachine().getStatus().setBKU( diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java index ab77881a..66680fc8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java @@ -16,18 +16,21 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import java.net.ConnectException; + import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; import at.asit.pdfover.signator.SignatureException; import at.asit.pdfover.signator.Signer; -import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; /** * Logical state for signing process, usually show BKU Dialog during this state. @@ -92,9 +95,17 @@ public class SigningState extends State { if(this.threadException != null) { String message = Messages.getString("error.Signatur"); //$NON-NLS-1$ if (this.threadException instanceof SignatureException) { - Throwable cause = this.threadException.getCause(); - if (cause instanceof ConnectorException) + Throwable cause = this.threadException; + while (cause.getCause() != null) + cause = cause.getCause(); + if (cause instanceof ConnectException) message += ": " + cause.getMessage(); //$NON-NLS-1$ + if (cause instanceof IllegalStateException) { + // Dummy exception - don't display error, go back to BKU Selection + this.setNextState(new BKUSelectionState(getStateMachine())); + return; + } + } ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider().getMainShell(), message, BUTTONS.RETRY_CANCEL); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java deleted file mode 100644 index 70502e64..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import java.io.IOException; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.PostMethod; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.controls.Dialog; -import at.asit.pdfover.gui.controls.Dialog.BUTTONS; -import at.asit.pdfover.gui.controls.Dialog.ICON; -import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.states.MobileBKUState; -import at.asit.pdfover.signator.SLResponse; - -/** - * A-Trust mobile BKU handler - */ -public class ATrustHandler extends MobileBKUHandler { - Shell shell; - - /** - * @param state - * @param shell - */ - public ATrustHandler(MobileBKUState state, Shell shell) { - super(state); - this.shell = shell; - } - - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(ATrustHandler.class); - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleSLRequestResponse(java.lang.String) - */ - @Override - public void handleSLRequestResponse(String responseData) throws Exception { - ATrustStatus status = getStatus(); - - // Extract infos: - String sessionID = MobileBKUHelper.extractTag(responseData, - "identification.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - String viewState = MobileBKUHelper.extractTag(responseData, - "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - String eventValidation = MobileBKUHelper.extractTag(responseData, - "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - log.info("sessionID: " + sessionID); //$NON-NLS-1$ - log.info("viewState: " + viewState); //$NON-NLS-1$ - log.info("eventValidation: " + eventValidation); //$NON-NLS-1$ - - status.setSessionID(sessionID); - - status.setViewstate(viewState); - - status.setEventvalidation(eventValidation); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#postCredentials() - */ - @Override - public String postCredentials() throws Exception { - ATrustStatus status = getStatus(); - - MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); - - PostMethod post = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ - post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ - post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ - post.addParameter("__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ - post.addParameter("handynummer", status.getPhoneNumber()); //$NON-NLS-1$ - post.addParameter("signaturpasswort", status.getMobilePassword()); //$NON-NLS-1$ - post.addParameter("Button_Identification", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ - - return executePost(client, post); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleCredentialsResponse(java.lang.String) - */ - @Override - public void handleCredentialsResponse(String responseData) throws Exception { - ATrustStatus status = getStatus(); - String viewState = status.getViewstate(); - String eventValidation = status.getEventvalidation(); - String sessionID = status.getSessionID(); - String refVal = null; - String signatureDataURL = null; - - status.setErrorMessage(null); - - if(responseData.contains("signature.aspx?sid=")) { //$NON-NLS-1$ - // credentials ok! TAN entry - sessionID = MobileBKUHelper.extractTag(responseData, "signature.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - viewState = MobileBKUHelper.extractTag(responseData, "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - eventValidation = MobileBKUHelper.extractTag(responseData, "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - refVal = MobileBKUHelper.extractTag(responseData, "id='vergleichswert'>Vergleichswert:", ""); //$NON-NLS-1$//$NON-NLS-2$ - signatureDataURL = status.getBaseURL() + "/ShowSigobj.aspx" + //$NON-NLS-1$ - MobileBKUHelper.extractTag(responseData, "ShowSigobj.aspx", "'"); //$NON-NLS-1$//$NON-NLS-2$ - - getState().setCommunicationState(MobileBKUCommunicationState.POST_TAN); - } else { - // error page - // extract error text! - String errorMessage = MobileBKUHelper.extractTag(responseData, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - status.setErrorMessage(errorMessage); - - // force UI again! - status.setMobilePassword(null); - } - - log.info("sessionID: " + sessionID); //$NON-NLS-1$ - log.info("Vergleichswert: " + refVal); //$NON-NLS-1$ - log.info("viewState: " + viewState); //$NON-NLS-1$ - log.info("eventValidation: " + eventValidation); //$NON-NLS-1$ - log.info("signatureDataURL: " + signatureDataURL); //$NON-NLS-1$ - - status.setSessionID(sessionID); - status.setRefVal(refVal); - status.setViewstate(viewState); - status.setEventvalidation(eventValidation); - status.setSignatureDataURL(signatureDataURL); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#postTAN() - */ - @Override - public String postTAN() throws IOException { - ATrustStatus status = getStatus(); - - MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); - - PostMethod post = new PostMethod(status.getBaseURL() - + "/signature.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ - post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ - post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ - post.addParameter( - "__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ - post.addParameter("input_tan", status.getTan()); //$NON-NLS-1$ - post.addParameter("SignButton", "Signieren"); //$NON-NLS-1$ //$NON-NLS-2$ - post.addParameter("Button1", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ - - return executePost(client, post); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleTANResponse(java.lang.String) - */ - @Override - public void handleTANResponse(String responseData) { - getStatus().setErrorMessage(null); - if (responseData.contains("sl:CreateXMLSignatureResponse xmlns:sl")) { //$NON-NLS-1$ - // success !! - - getSigningState().setSignatureResponse( - new SLResponse(responseData, getStatus().getServer(), null, null)); - getState().setCommunicationState(MobileBKUCommunicationState.FINAL); - } else { - try { - String tries = MobileBKUHelper.extractTag( - responseData, "Sie haben noch", "Versuch"); //$NON-NLS-1$ //$NON-NLS-2$ - getStatus().setTanTries(Integer.parseInt(tries.trim())); - } catch (Exception e) { - getStatus().setTanTries(getStatus().getTanTries() - 1); - log.debug("Error parsing TAN response", e); //$NON-NLS-1$ - } - - if (getStatus().getTanTries() <= 0) { - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - Dialog dialog = new Dialog(ATrustHandler.this.shell, Messages.getString("common.warning"), //$NON-NLS-1$ - Messages.getString("mobileBKU.tan_tries_exceeded"), //$NON-NLS-1$ - BUTTONS.OK_CANCEL, ICON.QUESTION); - if (dialog.open() == SWT.CANCEL) { - // Cancel - getState().setCommunicationState(MobileBKUCommunicationState.CANCEL); - } else { - // move to POST_REQUEST again - getState().setCommunicationState(MobileBKUCommunicationState.POST_REQUEST); - } - } - }); - } - } - } - - @Override - public ATrustStatus getStatus() { - return (ATrustStatus) getState().getStatus(); - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java deleted file mode 100644 index c4705227..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.config.ConfigProvider; - -/** - * A-Trust MobileBKUStatus implementation - */ -public class ATrustStatus extends AbstractMobileBKUStatusImpl { - /** - * SLF4J Logger instance - **/ - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory - .getLogger(ATrustStatus.class); - - /** Maximum number of TAN tries */ - public static final int MOBILE_MAX_TAN_TRIES = 3; - - private String viewstate; - private String eventvalidation; - - /** - * Constructor - * @param provider the ConfigProvider - */ - public ATrustStatus(ConfigProvider provider) { - setPhoneNumber(provider.getDefaultMobileNumber()); - setMobilePassword(provider.getDefaultMobilePassword()); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getMaxTanTries() - */ - @Override - public int getMaxTanTries() { - return MOBILE_MAX_TAN_TRIES; - } - - /** - * @return the viewstate - */ - public String getViewstate() { - return this.viewstate; - } - - /** - * @param viewstate - * the viewstate to set - */ - public void setViewstate(String viewstate) { - this.viewstate = viewstate; - } - - /** - * @return the eventvalidation - */ - public String getEventvalidation() { - return this.eventvalidation; - } - - /** - * @param eventvalidation the eventvalidation to set - */ - public void setEventvalidation(String eventvalidation) { - this.eventvalidation = eventvalidation; - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/AbstractMobileBKUStatusImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/AbstractMobileBKUStatusImpl.java deleted file mode 100644 index 37b99fba..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/AbstractMobileBKUStatusImpl.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -/** - * Basic implementation of a MobileBKUStatus - */ -public abstract class AbstractMobileBKUStatusImpl implements MobileBKUStatus { - - private String sessionID; - private String phoneNumber; - private String mobilePassword; - private String baseURL; - private String refVal; - private String errorMessage; - private String tan; - private String server; - private String signatureDataURL; - private int tanTries = getMaxTanTries(); - - @Override - public int getTanTries() { - return this.tanTries; - } - - @Override - public void setTanTries(int tries) { - this.tanTries = tries; - } - - @Override - public String getTan() { - return this.tan; - } - - @Override - public void setTan(String tan) { - this.tan = tan; - } - - @Override - public String getErrorMessage() { - return this.errorMessage; - } - - @Override - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - - @Override - public String getRefVal() { - return this.refVal; - } - - @Override - public void setRefVal(String refVal) { - this.refVal = refVal; - } - - @Override - public String getBaseURL() { - return this.baseURL; - } - - @Override - public void setBaseURL(String baseURL) { - this.baseURL = baseURL; - } - - @Override - public String getPhoneNumber() { - return this.phoneNumber; - } - - @Override - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - @Override - public String getMobilePassword() { - return this.mobilePassword; - } - - @Override - public void setMobilePassword(String mobilePassword) { - this.mobilePassword = mobilePassword; - } - - @Override - public String getSessionID() { - return this.sessionID; - } - - @Override - public void setSessionID(String sessionID) { - this.sessionID = sessionID; - } - - @Override - public String getServer() { - return this.server; - } - - @Override - public void setServer(String server) { - this.server = server; - } - - @Override - public String getSignatureDataURL() { - return this.signatureDataURL; - } - - @Override - public void setSignatureDataURL(String signatureDataURL) { - this.signatureDataURL = signatureDataURL; - } - - @Override - public String ensureSessionID(String url) { - return url; - } -} \ No newline at end of file diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java deleted file mode 100644 index 21f5e318..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import java.io.IOException; -import java.net.URL; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.controls.Dialog; -import at.asit.pdfover.gui.controls.Dialog.BUTTONS; -import at.asit.pdfover.gui.controls.Dialog.ICON; -import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.states.MobileBKUState; -import at.asit.pdfover.signator.SLResponse; - -/** - * - */ -public class IAIKHandler extends MobileBKUHandler { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(IAIKHandler.class); - - Shell shell; - - /** - * Constructor - * @param state the MobileBKUState - * @param shell the Shell - */ - public IAIKHandler(MobileBKUState state, Shell shell) { - super(state); - this.shell = shell; - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleSLRequestResponse(java.lang.String) - */ - @Override - public void handleSLRequestResponse(String responseData) throws Exception { - IAIKStatus status = getStatus(); - - // Extract infos: - String credentialURL = MobileBKUHelper.extractTag(responseData, - "name=\"userCredLogon\" method=\"post\" action=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - URL baseURL = new URL(status.getBaseURL()); - int p = baseURL.getPort(); - String port = ((p != -1) && (p != baseURL.getDefaultPort())) ? ":" + p : ""; //$NON-NLS-1$ //$NON-NLS-2$ - credentialURL = baseURL.getProtocol() + "://" + baseURL.getHost() + port + //$NON-NLS-1$ - (credentialURL.startsWith("/") ? "" : "/") + credentialURL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - String viewState = MobileBKUHelper.extractTag(responseData, - "id=\"javax.faces.ViewState\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - String sessionID = credentialURL.substring(credentialURL.indexOf("jsessionid=") + 11); //$NON-NLS-1$ - - log.info("credentialURL: " + credentialURL); //$NON-NLS-1$ - log.info("sessionID: " + sessionID); //$NON-NLS-1$ - log.info("viewState: " + viewState); //$NON-NLS-1$ - - status.setBaseURL(credentialURL); - status.setSessionID(sessionID); - status.setViewState(viewState); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#postCredentials() - */ - @Override - public String postCredentials() throws Exception { - IAIKStatus status = getStatus(); - - MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); - - PostMethod post = new PostMethod(status.getBaseURL()); - post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ - post.addParameter("javax.faces.ViewState", status.getViewState()); //$NON-NLS-1$ - post.addParameter("userCredLogon:phoneNR", status.getPhoneNumber()); //$NON-NLS-1$ - post.addParameter("userCredLogon:pwd", status.getMobilePassword()); //$NON-NLS-1$ - post.addParameter("userCredLogon:logonButton", "userCredLogon:logonButton"); //$NON-NLS-1$ //$NON-NLS-2$ - post.addParameter("javax.faces.partial.ajax", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - post.addParameter("javax.faces.source", "userCredLogon:logonButton"); //$NON-NLS-1$ //$NON-NLS-2$ - post.addParameter("javax.faces.partial.execute", "@all"); //$NON-NLS-1$ //$NON-NLS-2$ - post.addParameter("javax.faces.partial.render", "userCredLogon:errorMessagePanel userCredLogon:errorMessage"); //$NON-NLS-1$ //$NON-NLS-2$ - post.addParameter("userCredLogon", "userCredLogon"); //$NON-NLS-1$ //$NON-NLS-2$ - post.addParameter("userCredLogon:j_idt20_input", "de"); //$NON-NLS-1$ //$NON-NLS-2$ - - return executePost(client, post); -} - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleCredentialsResponse(java.lang.String) - */ - @Override - public void handleCredentialsResponse(String responseData) throws Exception { - IAIKStatus status = getStatus(); - - String refVal = null; - String signatureDataURL = null; - - status.setErrorMessage(null); - - if (!responseData.contains("referenceValueLogon.jsf")) { //$NON-NLS-1$ - // Assume that an error occurred - - String errorMessage; - try { - errorMessage = MobileBKUHelper.extractTag(responseData, ":errorMessage\">", ""); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (Exception e) { - errorMessage = Messages.getString("error.Unexpected"); //$NON-NLS-1$ - } - status.setErrorMessage(errorMessage); - - // force UI again! - status.setMobilePassword(null); - return; - } - - HttpClient client = MobileBKUHelper.getHttpClient(); - - String redirectURL = status.getBaseURL().substring(0, - status.getBaseURL().lastIndexOf('/', - status.getBaseURL().lastIndexOf('/') - 1) + 1); //Cut off last directory - redirectURL += MobileBKUHelper.extractTag(responseData, - "redirection_url\":\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - redirectURL = status.ensureSessionID(redirectURL); - - responseData = getRedirect(client, redirectURL); - - refVal = MobileBKUHelper.extractTag(responseData, - "id=\"j_idt6:refValue\" class=\"strong\">", "", ""); //$NON-NLS-1$ //$NON-NLS-2$ - getStatus().setErrorMessage(errorMessage); - } catch (Exception e) { - // Assume that wrong TAN was entered too many times - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - Dialog dialog = new Dialog(IAIKHandler.this.shell, Messages.getString("common.warning"), //$NON-NLS-1$ - Messages.getString("mobileBKU.tan_tries_exceeded"), //$NON-NLS-1$ - BUTTONS.OK_CANCEL, ICON.QUESTION); - if (dialog.open() == SWT.CANCEL) { - // Cancel - getState().setCommunicationState(MobileBKUCommunicationState.CANCEL); - } else { - // move to POST_REQUEST again - getState().setCommunicationState(MobileBKUCommunicationState.POST_REQUEST); - } - } - }); - } - } - } - - @Override - public IAIKStatus getStatus() { - return (IAIKStatus) getState().getStatus(); - } - - private String getRedirect(HttpClient client, String redirectURL) throws HttpException, IOException { - redirectURL = getStatus().ensureSessionID(redirectURL); - log.debug("Sending get request to URL " + redirectURL); //$NON-NLS-1$ - - GetMethod get = new GetMethod(redirectURL); - int returnCode = client.executeMethod(get); - if (returnCode != HttpStatus.SC_OK) { - throw new HttpException(HttpStatus.getStatusText(returnCode)); - } - String responseData = get.getResponseBodyAsString(); - log.debug("Response: " + responseData); //$NON-NLS-1$ - return responseData; - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKStatus.java deleted file mode 100644 index 52aacf82..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKStatus.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.config.ConfigProvider; - -/** - * IAIK MobileBKUStatus implementation - */ -public class IAIKStatus extends AbstractMobileBKUStatusImpl { - /** - * SLF4J Logger instance - **/ - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(IAIKStatus.class); - - /** Maximum number of TAN tries */ - public static final int MOBILE_MAX_TAN_TRIES = 3; - - private String viewState; - - /** - * Constructor - * @param provider the ConfigProvider - */ - public IAIKStatus(ConfigProvider provider) { - setPhoneNumber(provider.getDefaultMobileNumber()); - setMobilePassword(provider.getDefaultMobilePassword()); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getMaxTanTries() - */ - @Override - public int getMaxTanTries() { - return MOBILE_MAX_TAN_TRIES; - } - - /** - * @return the viewstate - */ - public String getViewState() { - return this.viewState; - } - - /** - * @param viewState - * the viewState to set - */ - public void setViewState(String viewState) { - this.viewState = viewState; - } - - @Override - public String ensureSessionID(String url) - { - if (url.contains("jsessionid=")) //$NON-NLS-1$ - return url; - - url += ";jsessionid=" + getSessionID(); //$NON-NLS-1$ - return url; - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java deleted file mode 100644 index de6e777c..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -/** - * Communication states for Mobile BKU - */ -public enum MobileBKUCommunicationState { - - /** POST SL Request to A-Trust BKU */ - POST_REQUEST, - - /** POST User informations (number, password) to A-Trust BKU */ - POST_NUMBER, - - /** POST tan to A-Trust BKU and retrieve SL Response */ - POST_TAN, - - /** Final state */ - FINAL, - - /** Cancel state */ - CANCEL -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java deleted file mode 100644 index e9cee855..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.multipart.FilePart; -import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; -import org.apache.commons.httpclient.methods.multipart.Part; -import org.apache.commons.httpclient.methods.multipart.StringPart; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.utils.FileUploadSource; -import at.asit.pdfover.gui.workflow.states.LocalBKUState; -import at.asit.pdfover.gui.workflow.states.MobileBKUState; -import at.asit.pdfover.signator.SLRequest; -import at.asit.pdfover.signator.SigningState; - -/** - * A mobile BKU Handler - */ -public abstract class MobileBKUHandler { - /** - * SLF4J Logger instance - **/ - static final Logger log = LoggerFactory - .getLogger(MobileBKUHandler.class); - - private MobileBKUState state; - - /** - * Constructor - * @param state the MobileBKUState - */ - public MobileBKUHandler(MobileBKUState state) - { - this.state = state; - } - - /** - * Post the SL request - * @param mobileBKUUrl mobile BKU URL - * @return the response - * @throws IOException IO error - */ - public String postSLRequest(String mobileBKUUrl) throws IOException { - /* - * String sl_request = this.state.getSigningState() - * .getSignatureRequest().getBase64Request(); - */ - String sl_request = getSignatureRequest().getFileUploadRequest(); - - log.debug("SL Request: " + sl_request); //$NON-NLS-1$ - - MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); - - PostMethod post = new PostMethod(mobileBKUUrl); - - //method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ - - StringPart xmlpart = new StringPart( - "XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$ - - FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$ - new FileUploadSource(getSignatureRequest().getSignatureData())); - - Part[] parts = { xmlpart, filepart }; - - post.setRequestEntity(new MultipartRequestEntity(parts, post - .getParams())); - - getState().getStatus().setBaseURL( - MobileBKUHelper.stripQueryString(mobileBKUUrl)); - - return executePost(client, post); - } - - /** - * Handle the response to the SL request post - * @param responseData response data - * @throws Exception Error during handling - */ - public abstract void handleSLRequestResponse(String responseData) throws Exception; - - - /** - * Post the credentials - * @return the response - * @throws Exception Error during posting - */ - public abstract String postCredentials() throws Exception; - - /** - * Handle the response to credentials post - * @param responseData response data - * @throws Exception Error during handling - */ - public abstract void handleCredentialsResponse(String responseData) throws Exception; - - /** - * Post the TAN - * @return the response - * @throws Exception Error during posting - */ - public abstract String postTAN() throws Exception; - - /** - * Handle the response to TAN post - * @param responseData response data - * @throws Exception Error during handling - */ - public abstract void handleTANResponse(String responseData) throws Exception; - - /** - * Get the MobileBKUState - * @return the MobileBKUState - */ - protected MobileBKUState getState() { - return this.state; - } - - /** - * Get the MobileBKUStatus - * @return the MobileBKUStatus - */ - protected MobileBKUStatus getStatus() { - return this.state.getStatus(); - } - - /** - * Get the SigningState - * @return the SigningState - */ - protected SigningState getSigningState() { - return getState().getSigningState(); - } - - /** - * Get the SLRequest - * @return the SLRequest - */ - private SLRequest getSignatureRequest() { - return getSigningState().getSignatureRequest(); - } - - /** - * Execute a post to the mobile BKU, following redirects - * @param client the HttpClient - * @param post the PostMethod - * @return the response - * @throws IOException IO error - */ - protected String executePost(HttpClient client, PostMethod post) throws IOException { - if (log.isDebugEnabled()) { - String req; - if (post.getRequestEntity().getContentLength() < 1024) { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - post.getRequestEntity().writeRequest(os); - req = os.toString(); - if (req.contains("passwort=")) //$NON-NLS-1$ - req = req.replaceAll("passwort=[^&]*", "passwort=******"); //$NON-NLS-1$ //$NON-NLS-2$ - if (req.contains(":pwd=")) //$NON-NLS-1$ - req = req.replaceAll(":pwd=[^&]*", ":pwd=******"); //$NON-NLS-1$ //$NON-NLS-2$ - os.close(); - } else { - req = post.getRequestEntity().getContentLength() + " bytes"; //$NON-NLS-1$ - } - log.debug("Posting to " + post.getURI() + ": " + req); //$NON-NLS-1$ //$NON-NLS-2$ - } - int returnCode = client.executeMethod(post); - - String redirectLocation = null; - - GetMethod get = null; - - String responseData = null; - - String server = null; - - // Follow redirects - do { - // check return code - if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY || - returnCode == HttpStatus.SC_MOVED_PERMANENTLY) { - - Header locationHeader = post.getResponseHeader("location"); //$NON-NLS-1$ - if (locationHeader != null) { - redirectLocation = locationHeader.getValue(); - } else { - throw new IOException( - "Got HTTP 302 but no location to follow!"); //$NON-NLS-1$ - } - } else if (returnCode == HttpStatus.SC_OK) { - if (get != null) { - responseData = get.getResponseBodyAsString(); - - Header serverHeader = get.getResponseHeader( - LocalBKUState.BKU_RESPONSE_HEADER_SERVER); - if (serverHeader != null) - server = serverHeader.getValue(); - } else { - responseData = post.getResponseBodyAsString(); - - Header serverHeader = post.getResponseHeader( - LocalBKUState.BKU_RESPONSE_HEADER_SERVER); - if (serverHeader != null) - server = serverHeader.getValue(); - } - redirectLocation = null; - } else { - throw new HttpException( - HttpStatus.getStatusText(returnCode)); - } - - if (redirectLocation != null) { - redirectLocation = getStatus().ensureSessionID(redirectLocation); - log.debug("Redirected to " + redirectLocation); //$NON-NLS-1$ - get = new GetMethod(redirectLocation); - get.setFollowRedirects(true); - returnCode = client.executeMethod(get); - } - } while (redirectLocation != null); - - getStatus().setServer(server); - if (server != null) - log.info("Server: " + server); //$NON-NLS-1$ - - return responseData; - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java deleted file mode 100644 index d4c510e1..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; -import org.apache.commons.httpclient.protocol.Protocol; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.Constants; -import at.asit.pdfover.gui.exceptions.InvalidNumberException; -import at.asit.pdfover.gui.exceptions.InvalidPasswordException; -import at.asit.pdfover.gui.exceptions.PasswordTooLongException; -import at.asit.pdfover.gui.exceptions.PasswordTooShortException; - -/** - * - */ -public class MobileBKUHelper { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(MobileBKUHelper.class); - - /** - * Regular expression for mobile phone numbers: this allows the entry of - * mobile numbers in the following formats: - * - * +(countryCode)99999999999 00(countryCode)99999999999 099999999999 - * 1030199999999999 (A-Trust Test bku) - */ - private static final String NUMBER_REGEX = "^((\\+[\\d]{2})|(00[\\d]{2})|(0)|(10301))([1-9][\\d]+)$"; //$NON-NLS-1$ - - /** - * Extracts a substring from data starting after start and ending with end - * - * @param data - * the whole data string - * @param start - * the start marker - * @param end - * the end marker - * @return the substring - * @throws Exception - */ - public static String extractTag(String data, String start, String end) - throws Exception { - int startidx = data.indexOf(start); - if (startidx > 0) { - startidx = startidx + start.length(); - int endidx = data.indexOf(end, startidx); - if (endidx > startidx) { - return data.substring(startidx, endidx); - } - log.error("extracting Tag: end tag not valid!: " + start + " ... " + end); //$NON-NLS-1$//$NON-NLS-2$ - throw new Exception("end tag not available!"); //$NON-NLS-1$ - } - log.error("extracting Tag: start tag not valid!: " + start + " ... " + end); //$NON-NLS-1$//$NON-NLS-2$ - throw new Exception("start tag not available!"); //$NON-NLS-1$ - } - - /** - * Validates the Mobile phone number - * - * @param number - * @return the normalized Phone number - * @throws InvalidNumberException - */ - public static String normalizeMobileNumber(String number) - throws InvalidNumberException { - // Verify number and normalize - - // Compile and use regular expression - Pattern pattern = Pattern.compile(NUMBER_REGEX); - Matcher matcher = pattern.matcher(number); - - if (!matcher.find()) { - throw new InvalidNumberException(); - } - - if (matcher.groupCount() != 6) { - throw new InvalidNumberException(); - } - - String countryCode = matcher.group(1); - - String normalNumber = matcher.group(6); - - if (countryCode.equals("10301")) { //$NON-NLS-1$ - // A-Trust Testnumber! Don't change - return number; - } - - countryCode = countryCode.replace("00", "+"); //$NON-NLS-1$ //$NON-NLS-2$ - - if (countryCode.equals("0")) { //$NON-NLS-1$ - countryCode = "+43"; //$NON-NLS-1$ - } - - return countryCode + normalNumber; - } - - /** - * Validate given Password for Mobile BKU - * - * @param password - * @throws InvalidPasswordException - */ - public static void validatePassword(String password) - throws InvalidPasswordException { - if (password.length() < 6 || password.length() > 20) { - if (password.length() < 6) { - throw new PasswordTooShortException(); - } - throw new PasswordTooLongException(); - } - } - - /** - * Removes file extension from URL - * - * @param query - * the url string - * @return the stripped url - */ - public static String stripQueryString(String query) { - int pathidx = query.lastIndexOf('/'); - if (pathidx > 0) { - return query.substring(0, pathidx); - } - return query; - } - - /** - * Get a HTTP Client instance - * @return the HttpClient - */ - public static HttpClient getHttpClient() { - HttpClient client = new HttpClient(); - client.getParams().setParameter("http.useragent", //$NON-NLS-1$ - Constants.USER_AGENT_STRING); - - String host = System.getProperty("http.proxyHost"); //$NON-NLS-1$ - String port = System.getProperty("http.proxyPort"); //$NON-NLS-1$ - if (host != null && !host.isEmpty() && - port != null && !port.isEmpty()) { - int p = Integer.parseInt(port); - client.getHostConfiguration().setProxy(host, p); - String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$ - String pass = System.getProperty("http.proxyPassword"); //$NON-NLS-1$ - if (user != null && !user.isEmpty() && pass != null) { - client.getState().setProxyCredentials(new AuthScope(host, p), - new UsernamePasswordCredentials(user, pass)); - } - } - - return client; - } - - /** - * Register our TrustedSocketFactory for https connections - */ - @SuppressWarnings("deprecation") - public static void registerTrustedSocketFactory() { - Protocol.registerProtocol("https", //$NON-NLS-1$ - new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$ - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java deleted file mode 100644 index 7ebf7b3e..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -/** - * - */ -public interface MobileBKUStatus { - /** - * @return the identification_url - */ - public String getSessionID(); - - /** - * @param sessionID the identification_url to set - */ - public void setSessionID(String sessionID); - - /** - * @return the phoneNumber - */ - public String getPhoneNumber(); - - /** - * @param phoneNumber the phoneNumber to set - */ - public void setPhoneNumber(String phoneNumber); - - /** - * @return the mobilePassword - */ - public String getMobilePassword(); - - /** - * @param mobilePassword the mobilePassword to set - */ - public void setMobilePassword(String mobilePassword); - - /** - * @return the reference value - */ - public String getRefVal(); - - /** - * @param refVal the reference value to set - */ - public void setRefVal(String refVal); - - /** - * @return the tan - */ - public String getTan(); - - /** - * @param tan the tan to set - */ - public void setTan(String tan); - - /** - * Get maximum number of TAN tries - * @return the maximum number of TAN tries - */ - public int getMaxTanTries(); - - /** - * Get number of TAN tries left - * @return the number of TAN tries left - */ - public int getTanTries(); - - /** - * Set number of TAN tries left - * @param tries the number of TAN tries left - */ - public void setTanTries(int tries); - - /** - * @return the errorMessage - */ - public String getErrorMessage(); - - /** - * @param errorMessage the errorMessage to set - */ - public void setErrorMessage(String errorMessage); - - /** - * @return the baseURL - */ - public String getBaseURL(); - - /** - * @param baseURL - */ - public void setBaseURL(String baseURL); - - /** - * Return the SL request server - * @return the SL request server - */ - public String getServer(); - - /** - * Set the SL request server - * @param server the SL request server - */ - public void setServer(String server); - - /** - * Get the signature data URL - * @return the signature data URL - */ - public String getSignatureDataURL(); - - /** - * Set the signature data URL - * @param signatureDataURL the signature data URL - */ - public void setSignatureDataURL(String signatureDataURL); - - /** - * Ensure that given URL contains a session ID (if necessary) - * @param url URL to check for session ID - * @return resulting URL - */ - public String ensureSessionID(String url); -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUs.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUs.java deleted file mode 100644 index ac4bdef9..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUs.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -/** - * Available mobile BKUs - */ -public enum MobileBKUs { - /** A-Trust BKU */ - A_TRUST, - - /** IAIK */ - IAIK -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java deleted file mode 100644 index 6e807df5..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.states.MobileBKUState; - -/** - * - */ -public class PostCredentialsThread implements Runnable { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(PostCredentialsThread.class); - - private MobileBKUState state; - - private MobileBKUHandler handler; - - /** - * Constructor - * - * @param state the MobileBKUState - */ - public PostCredentialsThread(MobileBKUState state) { - this.state = state; - this.handler = state.getHandler(); - } - - /* (non-Javadoc) - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - try { - String responseData = this.handler.postCredentials(); - - // Now we have received some data lets check it: - log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$ - - this.handler.handleCredentialsResponse(responseData); - } catch (Exception ex) { - log.error("Error in PostCredentialsThread", ex); //$NON-NLS-1$ - this.state.setThreadException(ex); - } finally { - this.state.invokeUpdate(); - } - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java deleted file mode 100644 index 09944acf..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.states.MobileBKUState; - -/** - * - */ -public class PostSLRequestThread implements Runnable { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(PostSLRequestThread.class); - - private MobileBKUState state; - - private String mobileBKUUrl; - - private MobileBKUHandler mobileBKUHandler; - - /** - * Constructor - * - * @param state the MobileBKUState - */ - public PostSLRequestThread(MobileBKUState state) { - this.state = state; - this.mobileBKUUrl = state.getURL(); - this.mobileBKUHandler = state.getHandler(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - try { - - String responseData = this.mobileBKUHandler.postSLRequest(this.mobileBKUUrl); - - // Now we have received some data lets check it: - log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$ - - this.mobileBKUHandler.handleSLRequestResponse(responseData); - - /* - * If all went well we can set the communication state to the new - * state - */ - this.state.setCommunicationState(MobileBKUCommunicationState.POST_NUMBER); - } catch (Exception ex) { - log.error("Error in PostSLRequestThread", ex); //$NON-NLS-1$ - this.state.setThreadException(ex); - } finally { - this.state.invokeUpdate(); - } - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java deleted file mode 100644 index 95ee0dbd..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.states.MobileBKUState; - -/** - * - */ -public class PostTanThread implements Runnable { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(PostTanThread.class); - - private MobileBKUState state; - - private MobileBKUHandler handler; - - /** - * Constructor - * - * @param state - */ - public PostTanThread(MobileBKUState state) { - this.state = state; - this.handler = state.getHandler(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - try { - String responseData = this.handler.postTAN(); - - // Now we have received some data lets check it: - log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$ - - this.handler.handleTANResponse(responseData); - - } catch (Exception ex) { - log.error("Error in PostTanThread", ex); //$NON-NLS-1$ - this.state.setThreadException(ex); - } finally { - this.state.invokeUpdate(); - } - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/SimpleXMLTrustManager.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/SimpleXMLTrustManager.java deleted file mode 100644 index 6d72e856..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/SimpleXMLTrustManager.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import java.security.KeyStore; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.util.Arrays; - -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; -import javax.net.ssl.X509TrustManager; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import at.asit.pdfover.gui.Constants; - -/** - * - */ -public class SimpleXMLTrustManager implements X509TrustManager { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(SimpleXMLTrustManager.class); - - /* - * The default X509TrustManager returned by SunX509. We'll delegate - * decisions to it, and fall back to the logic in this class if the default - * X509TrustManager doesn't trust it. - */ - X509TrustManager sunJSSEX509TrustManager; - - /** - * Trust Manager for A-Trust Certificates - */ - X509TrustManager atrustTrustManager; - - /** - * Constructs the TrustManager - * - * @throws Exception - */ - public SimpleXMLTrustManager() throws Exception { - // create a "default" JSSE X509TrustManager. - - TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); //$NON-NLS-1$ - tmf.init((KeyStore) null); - - TrustManager tms[] = tmf.getTrustManagers(); - - /* - * Iterate over the returned trustmanagers, look for an instance of - * X509TrustManager. If found, use that as our "default" trust manager. - */ - for (int i = 0; i < tms.length; i++) { - if (tms[i] instanceof X509TrustManager) { - this.sunJSSEX509TrustManager = (X509TrustManager) tms[i]; - break; - } - } - - /* - * A-Trust Certificates - */ - - KeyStore myKeyStore = KeyStore.getInstance(KeyStore - .getDefaultType()); - - myKeyStore.load(null); - - Document doc = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .parse(this.getClass().getResourceAsStream(Constants.RES_CERT_LIST)); - - Node certificates = doc.getFirstChild(); - - if (!certificates.getNodeName().equals("certificates")) { //$NON-NLS-1$ - throw new Exception( - "Used certificates xml is invalid! no certificates node"); //$NON-NLS-1$ - } - - NodeList certificateList = certificates.getChildNodes(); - - for (int i = 0; i < certificateList.getLength(); i++) { - try { - - Node certificateNode = certificateList.item(i); - - if (certificateNode.getNodeName().equals("#text")) { //$NON-NLS-1$ - continue; // Ignore dummy text node .. - } - - if (!certificateNode.getNodeName().equals("certificate")) { //$NON-NLS-1$ - log.warn("Ignoring XML node: " + certificateNode.getNodeName()); //$NON-NLS-1$ - continue; - } - - String certResource = Constants.RES_CERT_PATH + certificateNode.getTextContent(); - - X509Certificate cert = (X509Certificate) CertificateFactory - .getInstance("X509"). //$NON-NLS-1$ - generateCertificate( - this.getClass().getResourceAsStream( - certResource)); - - myKeyStore.setCertificateEntry(certificateNode.getTextContent(), cert); - - log.debug("Loaded certificate : " + certResource); //$NON-NLS-1$ - - } catch (Exception ex) { - log.error("Failed to load certificate [" + "]", ex); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - tmf.init(myKeyStore); - - tms = tmf.getTrustManagers(); - - /* - * Iterate over the returned trustmanagers, look for an instance of - * X509TrustManager. If found, use that as our "default" trust manager. - */ - for (int i = 0; i < tms.length; i++) { - if (tms[i] instanceof X509TrustManager) { - this.atrustTrustManager = (X509TrustManager) tms[i]; - break; - } - } - - if (this.sunJSSEX509TrustManager != null - && this.atrustTrustManager != null) { - return; - } - - /* - * Find some other way to initialize, or else we have to fail the - * constructor. - */ - throw new Exception("Couldn't initialize ASITTrustManager"); //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see - * javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert. - * X509Certificate[], java.lang.String) - */ - @Override - public void checkClientTrusted(X509Certificate[] arg0, String arg1) - throws CertificateException { - try { - this.atrustTrustManager.checkServerTrusted(arg0, arg1); - } catch (CertificateException ex) { - try { - this.sunJSSEX509TrustManager.checkClientTrusted(arg0, arg1); - } catch (CertificateException ex2) { - log.info("checkClientTrusted: ", ex2); //$NON-NLS-1$ - throw ex2; - } - } - } - - /* - * (non-Javadoc) - * - * @see - * javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert. - * X509Certificate[], java.lang.String) - */ - @Override - public void checkServerTrusted(X509Certificate[] arg0, String arg1) - throws CertificateException { - try { - this.atrustTrustManager.checkServerTrusted(arg0, arg1); - } catch (CertificateException ex) { - try { - this.sunJSSEX509TrustManager.checkServerTrusted(arg0, arg1); - } catch (CertificateException ex2) { - log.info("checkServerTrusted: ", ex2); //$NON-NLS-1$ - throw ex2; - } - } - } - - /* - * (non-Javadoc) - * - * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers() - */ - @Override - public X509Certificate[] getAcceptedIssuers() { - - X509Certificate[] default_certs = this.sunJSSEX509TrustManager.getAcceptedIssuers(); - - X509Certificate[] atrust_certs = this.atrustTrustManager.getAcceptedIssuers(); - - X509Certificate[] all_certs = Arrays.copyOf(default_certs, default_certs.length + atrust_certs.length); - System.arraycopy(atrust_certs, 0, all_certs, default_certs.length, atrust_certs.length); - return all_certs; - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java deleted file mode 100644 index ee521641..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.workflow.states.mobilebku; - -// Imports -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketAddress; -import java.net.UnknownHostException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; - -import org.apache.commons.httpclient.ConnectTimeoutException; -import org.apache.commons.httpclient.params.HttpConnectionParams; -import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.utils.Messages; - -/** - * - */ -public class TrustedSocketFactory implements SecureProtocolSocketFactory { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(TrustedSocketFactory.class); - - private static final String ENABLED_CS[] = { - "TLS_RSA_WITH_AES_128_CBC_SHA", //$NON-NLS-1$ - "SSL_RSA_WITH_RC4_128_SHA", //$NON-NLS-1$ - "SSL_RSA_WITH_3DES_EDE_CBC_SHA", //$NON-NLS-1$ - "SSL_RSA_WITH_RC4_128_MD5" //$NON-NLS-1$ - }; - - private static SSLSocketFactory getFactory() throws NoSuchAlgorithmException, - KeyManagementException, Exception { - SSLContext sslContext = SSLContext.getInstance("TLS"); //$NON-NLS-1$ - sslContext.init(null, new TrustManager[] { new SimpleXMLTrustManager() }, - new java.security.SecureRandom()); - - return sslContext.getSocketFactory(); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket - * (java.lang.String, int) - */ - @Override - public Socket createSocket(String host, int port) throws IOException, - UnknownHostException { - try { - SSLSocket sslSocket = (SSLSocket) getFactory().createSocket(host, - port); - sslSocket.setEnabledCipherSuites(ENABLED_CS); - return sslSocket; - } catch (Exception ex) { - log.error("TrustedSocketFactory: ", ex); //$NON-NLS-1$ - if (ex instanceof IOException) { - throw (IOException) ex; - } else if (ex instanceof UnknownHostException) { - throw (UnknownHostException) ex; - } else { - throw new IOException( - Messages.getString("TrustedSocketFactory.FailedToCreateSecureConnection"), ex); //$NON-NLS-1$ - } - } - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket - * (java.lang.String, int, java.net.InetAddress, int) - */ - @Override - public Socket createSocket(String host, int port, InetAddress clientHost, - int clientPort) throws IOException, UnknownHostException { - try { - SSLSocket sslSocket = (SSLSocket) getFactory().createSocket(host, - port, clientHost, clientPort); - sslSocket.setEnabledCipherSuites(ENABLED_CS); - return sslSocket; - } catch (Exception ex) { - log.error("TrustedSocketFactory: ", ex); //$NON-NLS-1$ - if (ex instanceof IOException) { - throw (IOException) ex; - } else if (ex instanceof UnknownHostException) { - throw (UnknownHostException) ex; - } else { - throw new IOException( - Messages.getString("TrustedSocketFactory.FailedToCreateSecureConnection"), ex); //$NON-NLS-1$ - } - } - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket - * (java.lang.String, int, java.net.InetAddress, int, - * org.apache.commons.httpclient.params.HttpConnectionParams) - */ - @Override - public Socket createSocket(String host, int port, InetAddress clientHost, - int clientPort, HttpConnectionParams params) throws IOException, - UnknownHostException, ConnectTimeoutException { - try { - if (params == null) { - throw new IllegalArgumentException("Parameters may not be null"); //$NON-NLS-1$ - } - int timeout = params.getConnectionTimeout(); - SSLSocket sslSocket = null; - - SSLSocketFactory socketfactory = getFactory(); - if (timeout == 0) { - sslSocket = (SSLSocket) socketfactory.createSocket(host, port, clientHost, - clientPort); - } else { - sslSocket = (SSLSocket) socketfactory.createSocket(); - SocketAddress localaddr = new InetSocketAddress(clientHost, - clientPort); - SocketAddress remoteaddr = new InetSocketAddress(host, port); - sslSocket.bind(localaddr); - sslSocket.connect(remoteaddr, timeout); - } - sslSocket.setEnabledCipherSuites(ENABLED_CS); - return sslSocket; - } catch (Exception ex) { - log.error("TrustedSocketFactory: ", ex); //$NON-NLS-1$ - if (ex instanceof IOException) { - throw (IOException) ex; - } else if (ex instanceof UnknownHostException) { - throw (UnknownHostException) ex; - } else { - throw new IOException( - Messages.getString("TrustedSocketFactory.FailedToCreateSecureConnection"), ex); //$NON-NLS-1$ - } - } - } - - /* (non-Javadoc) - * @see org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory#createSocket(java.net.Socket, java.lang.String, int, boolean) - */ - @Override - public Socket createSocket(Socket socket, String host, int port, - boolean autoClose) throws IOException, UnknownHostException { - try { - SSLSocket sslSocket = (SSLSocket) getFactory().createSocket(socket, host, port, autoClose); - sslSocket.setEnabledCipherSuites(ENABLED_CS); - return sslSocket; - } catch (Exception ex) { - log.error("TrustedSocketFactory: ", ex); //$NON-NLS-1$ - if (ex instanceof IOException) { - throw (IOException) ex; - } else if (ex instanceof UnknownHostException) { - throw (UnknownHostException) ex; - } else { - throw new IOException( - Messages.getString("TrustedSocketFactory.FailedToCreateSecureConnection"), ex); //$NON-NLS-1$ - } - } - } - -} -- cgit v1.2.3