diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java index 48cffce4..fabaebe0 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java @@ -60,7 +60,7 @@ public MobileBKUConnector(@NonNull MobileBKUState state) { private static class UserDisplayedError extends Exception { private final @NonNull String msg; @Override public @NonNull String getMessage() { return this.msg; } - private UserDisplayedError(@NonNull String s) { this.msg = s; } + private UserDisplayedError(@NonNull String key, Object... values) { this.msg = Messages.formatString(key, values); } } public @NonNull UsernameAndPassword credentials = new UsernameAndPassword(); @@ -123,9 +123,9 @@ public String handleSLRequest(PdfAs4SLRequest slRequest) throws SignatureExcepti if (httpStatus != HttpStatus.SC_OK) { switch (httpStatus) { - case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED: throw new UserDisplayedError(Messages.getString("error.ProxyAuthRequired")); - case HttpStatus.SC_REQUEST_TOO_LONG: throw new UserDisplayedError(Messages.getString("atrusterror.http_413")); - default: throw new UserDisplayedError(Messages.formatString("atrusterror.http_generic", httpStatus, Optional.ofNullable(response.getReasonPhrase()).orElse("(null)"))); + case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED: throw new UserDisplayedError("error.ProxyAuthRequired"); + case HttpStatus.SC_REQUEST_TOO_LONG: throw new UserDisplayedError("atrusterror.http_413"); + default: throw new UserDisplayedError("atrusterror.http_generic", httpStatus, Optional.ofNullable(response.getReasonPhrase()).orElse("(null)")); } } @@ -151,6 +151,10 @@ public String handleSLRequest(PdfAs4SLRequest slRequest) throws SignatureExcepti log.debug("Failed to parse A-Trust server response as HTML:\n{}", entityBody); throw new IOException("Failed to parse HTML"); } + + if (resultDocument.selectFirst("body > *") == null) { + throw new UserDisplayedError("atrusterror.empty_document"); + } Element metaRefresh = resultDocument.selectFirst("meta[http-equiv=\"refresh\"i]"); if (metaRefresh != null) { @@ -160,6 +164,7 @@ public String handleSLRequest(PdfAs4SLRequest slRequest) throws SignatureExcepti continue; } } + return ATrustParser.Parse(resultDocument); } else { return ATrustParser.Parse(request.getUri(), contentType.getMimeType(), entityBody); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/ATrustConnectionException.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/ATrustConnectionException.java deleted file mode 100644 index 1b18c99c..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/ATrustConnectionException.java +++ /dev/null @@ -1,40 +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.exceptions; - -// Imports - -import at.asit.pdfover.commons.Messages; - -/** - * - */ -public class ATrustConnectionException extends Exception { - /** - * - */ - private static final long serialVersionUID = -5826910929587650685L; - - /** - * Constructor - * @param file - */ - public ATrustConnectionException() { - super(Messages.getString("error.ATrustConnection")); - } - - -} 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 e36a0054..005aef5b 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 @@ -523,13 +523,7 @@ public void run() { this.signingState.bkuConnector = new MobileBKUConnector(this); this.signingState.useBase64Request = false; - if (this.threadException != null) { - displayError(this.threadException); - return; - } - - getStateMachine().display( - this.getWaitingComposite()); + getStateMachine().display(this.getWaitingComposite()); this.setNextState(new SigningState(getStateMachine())); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java index c56869e9..adcf7fa6 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java @@ -76,18 +76,6 @@ private OutputComposite getOutputComposite() { @Override public void run() { - Status status = getStateMachine().status; - - if (status.signResult == null) { - ErrorDialog error = new ErrorDialog(getStateMachine().getMainShell(), - Messages.getString("error.Signatur"), BUTTONS.RETRY_CANCEL); - if(error.open() == SWT.RETRY) { - this.setNextState(new PrepareSigningState(getStateMachine())); - } else { - this.setNextState(new BKUSelectionState(getStateMachine())); - } - return; - } OutputComposite outputComposite = this.getOutputComposite(); 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 f5c800e9..0ddc358c 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 @@ -17,14 +17,16 @@ //Imports import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Objects; import org.eclipse.swt.SWT; -import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.ErrorDialog; -import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; import at.asit.pdfover.signer.SignatureException; @@ -57,7 +59,7 @@ public FinishSignThread(SigningState signingState) { public void run() { try { Status status = this.state.getStateMachine().status; - status.signResult = PdfAs4Signer.sign(status.signingState); + status.signResult = Objects.requireNonNull(PdfAs4Signer.sign(status.signingState)); } catch(Exception e) { this.state.threadException = e; } finally { @@ -87,14 +89,18 @@ public void run() { } if(this.threadException != null) { - String message = Messages.getString("error.Signatur"); + String message = Messages.formatString("error.Signatur", + this.threadException.getClass().getSimpleName(), + Objects.requireNonNullElse(this.threadException.getMessage(), "(null)")); if (this.threadException instanceof SignatureException) { Throwable cause = this.threadException; while (cause.getCause() != null) cause = cause.getCause(); - if (cause instanceof SocketException) { - message += ": " + cause.getMessage(); + if (cause instanceof UnknownHostException) { + message = Messages.formatString("error.CouldNotResolveHostname", cause.getMessage()); + } else if (cause instanceof SocketException) { + message = Messages.formatString("error.FailedToConnect", cause.getMessage()); } else if (cause instanceof SLPdfAsException) { var ex = ((SLPdfAsException)cause); message = Messages.formatString("error.SLError", ex.getCode(), ex.getInfo()); @@ -104,8 +110,7 @@ public void run() { // TODO legacy hack this.threadException = new UserCancelledException(); } - } - if (this.threadException instanceof UserCancelledException) { + } else if (this.threadException instanceof UserCancelledException) { // don't display error, clear remembered password and go back to BKU Selection if (this.getConfig().getRememberMobilePassword()) this.getConfig().setDefaultMobilePasswordOverlay(null); 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 f27d6ae7..c40348e6 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 @@ -126,8 +126,7 @@ dataSourceSelection.DropLabel2=or... dataSourceSelection.browse=&Browse for PDF on your computer dataSourceSelection.usePlaceholderText=A marker has been found where the creator of the document wants you to put your signature. Do you want to use it? dataSourceSelection.usePlaceholderTitle=Info -error.ATrustConnection=Connection to A-Trust could not be established -error.CouldNotResolveHostname=Could not resolve hostname '%s'.\nAre you connected to the internet? +error.CouldNotResolveHostname=Could not resolve hostname.\n%s\nAre you connected to the internet? error.CmdLineArgs=Error parsing the command-line arguments\: error.Details=Details error.EnteredReferenceValue=You entered the reference value\! @@ -161,7 +160,7 @@ error.PrepareDocument=Failed to prepare document for signature. error.Retry=Retry error.SWTLib=Error loading SWT library error.SaveOutputFolder=Failed to save signed document to configured output folder. -error.Signatur=Signature error +error.Signatur=Signature error (%s):\%s error.TanTooLong=Entered TAN too long error.SLError=Operation aborted by signature server (%d):\n%s error.Title=Error @@ -269,6 +268,7 @@ config.fido2.UnsupportedPlatform=FIDO2 authentication is currently unsupported o config.fido2.InfoURL=https://www.oesterreich.gv.at/id-austria/haeufige-fragen/allgemeines-zu-id-austria#fido config.fido2.Group=FIDO2 settings config.fido2.ByDefault=Select FIDO2 authentication by default -atrusterror.http_413=a-trust.at rejected request:\nProvided document exceeds size limit. -atrusterror.http_generic=a-trust.at rejected request:\nHTTP %d %s -atrusterror.message=a-trust.at reports:\n%s +atrusterror.empty_document=\n(The PDF document is potentially too large. (> 20 MB)) +atrusterror.http_413=PDF document exceeds size limit. +atrusterror.http_generic=Signature failed (HTTP %d %s) +atrusterror.message=a-trust.at rejected request:\n%s 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 fba357f6..69549305 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 @@ -160,14 +160,13 @@ error.PrepareDocument=Konnte Dokument nicht zur Signatur vorbereiten. error.Retry=Wiederholen error.SWTLib=Fehler beim Laden der SWT-Bibliothek error.SaveOutputFolder=Konnte Dokument nicht in den konfigurierten Ausgabeordner speichern. -error.Signatur=Signatur-Fehler +error.Signatur=Signatur-Fehler (%s):\n%s error.TanTooLong=Eingegebene TAN zu lang error.SLError=Vorgang vom Signaturserver abgebrochen (%d):\n%s error.Title=Fehler error.TitleFatal=Fataler Fehler error.Unexpected=Unerwarteter Fehler -error.ATrustConnection=Verbindung zu A-Trust konnte nicht aufgebaut werden -error.CouldNotResolveHostname=Server '%s' wurde nicht gefunden.\nÜberprüfen Sie Ihre Internetverbindung. +error.CouldNotResolveHostname=Server %s wurde nicht gefunden:\n%s\nÜberprüfen Sie Ihre Internetverbindung. error.FailedToConnect=Verbindung zum Signaturserver fehlgeschlagen:\n%s error.ProxyAuthRequired=HTTP-Proxy lehnt Verbindung ab:\nHTTP/1.1 407 Proxy Authentication Required exception.InvalidEmblemFile=%s ist eine ungültige Bildmarken-Datei\! @@ -266,6 +265,7 @@ config.UpdateStatus.CHECKING=Versions-Infos werden abgefragt... config.UpdateStatus.OUTDATED=Neue Version verfügbar. Herunterladen? config.UpdateStatus.UP_TO_DATE=Ihre Version ist aktuell. Nochmals prüfen? config.UpdateStatus.FAILED=Versions-Check fehlgeschlagen. Nochmal versuchen? -atrusterror.http_413=a-trust.at lehnt Anfrage ab:\nDateigröße des PDF-Dokuments überschreitet Grenzwert. -atrusterror.http_generic=a-trust.at lehnt Anfrage ab:\nHTTP %d %s -atrusterror.message=a-trust.at meldet:\n%s +atrusterror.empty_document=\n(Möglicherweise ist das ausgewählte PDF-Dokument zu groß. (> 20 MB)) +atrusterror.http_413=Dateigröße des PDF-Dokuments überschreitet Grenzwert. +atrusterror.http_generic=Signatur fehlgeschlagen (HTTP %d %s) +atrusterror.message=a-trust.at lehnt Anfrage ab:\n%s