diff options
5 files changed, 46 insertions, 1 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java index 8ab02028..cf57f742 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java @@ -3,6 +3,7 @@ package at.gv.egiz.pdfas.common.exceptions; public interface ErrorConstants { public static final String STATUS_INFO_SIGDEVICE = "SigDevice"; public static final String STATUS_INFO_SIGDEVICEVERSION = "SigDeviceVersion"; + public static final String STATUS_INFO_INVALIDSIG = "InvalidSignature"; // Code below 10000 are reserved for SL Error Codes diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/SettingsUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/SettingsUtils.java new file mode 100644 index 00000000..7628406d --- /dev/null +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/SettingsUtils.java @@ -0,0 +1,19 @@ +package at.gv.egiz.pdfas.common.utils; + +import at.gv.egiz.pdfas.common.settings.ISettings; + +public class SettingsUtils { + public static boolean getBooleanValue(ISettings setting, String key, boolean defaultValue) { + String theValue = setting.getValue(key); + if(theValue != null) { + if(theValue.equals("true")) { + return true; + } else if(theValue.equals("false")) { + return false; + } else { + return defaultValue; + } + } + return defaultValue; + } +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java index 03e72ecc..24af4ad8 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java @@ -83,6 +83,8 @@ public interface IConfigurationConstants { */ public static final String MOA_SIGN_URL = "moa.sign.url"; + public static final String KEEP_INVALID_SIGNATURE = "report.invalidSign"; + public static final String MOC_SIGN_URL = "moc.sign.url"; public static final String MOBILE_SIGN_URL = "mobile.sign.url"; diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java index 49a450af..0b6b1fff 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java @@ -28,6 +28,7 @@ import iaik.x509.X509Certificate; import java.security.cert.CertificateException; import java.util.Iterator; +import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,7 +37,9 @@ import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.exceptions.PdfAsErrorCarrier; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PdfAsSignatureException; +import at.gv.egiz.pdfas.common.utils.SettingsUtils; import at.gv.egiz.pdfas.common.utils.StreamUtils; +import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; @@ -109,11 +112,20 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector { break; } } - + VerifyResult verifyResult; try { verifyResult = SignatureUtils.verifySignature( response.getCMSSignature(), input); + if(SettingsUtils.getBooleanValue(requestedSignature.getStatus().getSettings(), + IConfigurationConstants.KEEP_INVALID_SIGNATURE, false)) { + Base64 b64 = new Base64(); + requestedSignature + .getStatus() + .getMetaInformations() + .put(ErrorConstants.STATUS_INFO_INVALIDSIG, + b64.encodeToString(response.getCMSSignature())); + } } catch (PDFASError e) { throw new PdfAsErrorCarrier(e); } diff --git a/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java b/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java index c3e417d2..212e4116 100644 --- a/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java +++ b/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java @@ -35,6 +35,7 @@ import java.security.cert.CertificateException; import javax.xml.ws.BindingProvider; +import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,6 +58,7 @@ import at.gv.egiz.pdfas.common.exceptions.PdfAsMOAException; import at.gv.egiz.pdfas.common.exceptions.PdfAsSignatureException; import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException; import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.common.utils.SettingsUtils; import at.gv.egiz.pdfas.common.utils.StreamUtils; import at.gv.egiz.pdfas.lib.api.Configuration; import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; @@ -232,6 +234,15 @@ public class MOAConnector implements ISignatureConnector, try { verifyResult = SignatureUtils.verifySignature(cmsSignatureData, input); + if(SettingsUtils.getBooleanValue(requestedSignature.getStatus().getSettings(), + IConfigurationConstants.KEEP_INVALID_SIGNATURE, false)) { + Base64 b64 = new Base64(); + requestedSignature + .getStatus() + .getMetaInformations() + .put(ErrorConstants.STATUS_INFO_INVALIDSIG, + b64.encodeToString(cmsSignatureData)); + } } catch (PDFASError e) { throw new PdfAsErrorCarrier(e); } |