/** * @param packaging {@code SignaturePackaging} to be checked * @throws DSSException if the packaging is not supported for this kind of signature */ private void assertSignaturePackaging(final SignaturePackaging packaging) throws DSSException { if (packaging != SignaturePackaging.ENVELOPING && packaging != SignaturePackaging.DETACHED) { throw new DSSException("Unsupported signature packaging: " + packaging); } } }
private static void zipWriteBytes(final ZipOutputStream outZip, final byte[] bytes) throws DSSException { try { outZip.write(bytes); } catch (IOException e) { throw new DSSException(e); } }
public static byte[] getUtf8Bytes(final String string) { if (string == null) { return null; } try { final byte[] bytes = string.getBytes("UTF-8"); return bytes; } catch (UnsupportedEncodingException e) { throw new DSSException(e); } }
private static ZipEntry getNextZipEntry(final ZipInputStream zipInputStream) throws DSSException { try { return zipInputStream.getNextEntry(); } catch (IOException e) { throw new DSSException(e); } }
private void isInitialised() { if (diagnosticData == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "diagnosticData")); } if (signatureContext == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "signatureContext")); } }
public static void writeToURLConnection(final URLConnection urlConnection, final byte[] bytes) throws DSSException { try { final OutputStream out = urlConnection.getOutputStream(); out.write(bytes); out.close(); } catch (IOException e) { throw new DSSException(e); } }
/** * */ private void isInitialised() { if (constraintData == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "validationPolicy")); } }
private void isInitialised() { if (constraintData == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "validationPolicy")); } if (signatureContext == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "signatureContext")); } if (currentTime == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "currentTime")); } }
private void isInitialised(final ProcessParameters params) { if (diagnosticData == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "diagnosticData")); } if (params.getValidationPolicy() == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "validationPolicy")); } if (currentTime == null) { throw new DSSException(String.format(EXCEPTION_TCOPPNTBI, getClass().getSimpleName(), "currentTime")); } }
public static byte[] getEncoded(final AlgorithmIdentifier algorithmIdentifier) throws DSSException { try { return algorithmIdentifier.getEncoded(ASN1Encoding.DER); } catch (IOException e) { throw new DSSException(e); } }
private void storeXmlDom(final OutputStream outZip, final Document xml) throws DSSException { try { final DOMSource xmlSource = new DOMSource(xml); final StreamResult outputTarget = new StreamResult(outZip); TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget); } catch (TransformerException e) { throw new DSSException(e); } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) { transformerFactoryConfigurationError.printStackTrace(); } }
public int getIntValue(final String xPath, final Object... params) { String value = getValue(xPath, params); try { return Integer.parseInt(value); } catch (Exception e) { throw new DSSException(e); } }
private static X509CRLObject getX509CRLObject(final CertificateList certificateList) throws DSSException { try { return new X509CRLObject(certificateList); } catch (CRLException e) { throw new DSSException(e); } } }
public static byte[] getEncoded(final ASN1Sequence signPolicyInfo) throws DSSException { try { return signPolicyInfo.getEncoded(ASN1Encoding.DER); } catch (IOException e) { throw new DSSException(e); } }
protected byte[] getContent(final HttpEntity responseEntity) throws DSSException { try { final InputStream content = responseEntity.getContent(); final byte[] bytes = DSSUtils.toByteArray(content); return bytes; } catch (IOException e) { throw new DSSException(e); } }
/** * Checks if the extension is possible. */ private void assertExtendSignaturePossible() throws DSSException { final SignatureLevel signatureLevel = params.getSignatureLevel(); if (SignatureLevel.XAdES_BASELINE_LT.equals(signatureLevel) && xadesSignature.hasLTAProfile()) { final String exceptionMessage = "Cannot extend signature. The signedData is already extended with [%s]."; throw new DSSException(String.format(exceptionMessage, "XAdES LTA")); } } }
/** * This method checks the signature integrity and throws a {@code DSSException} if the signature is broken. * * @throws eu.europa.ec.markt.dss.exception.DSSException */ protected void checkSignatureIntegrity() throws DSSException { final SignatureCryptographicVerification signatureCryptographicVerification = xadesSignature.checkSignatureIntegrity(); if (!signatureCryptographicVerification.isSignatureIntact()) { final String errorMessage = signatureCryptographicVerification.getErrorMessage(); throw new DSSException("Cryptographic signature verification has failed" + (errorMessage.isEmpty() ? "." : (" / " + errorMessage))); } }
private void assertSignatureValid(final CAdESSignature cadesSignature, final SignatureParameters parameters) { // TODO: (Bob: 2014 Jan 22) To be changed to enum check and not string! if (!parameters.getSignatureLevel().toString().toLowerCase().startsWith("pades")) { final SignatureCryptographicVerification signatureCryptographicVerification = cadesSignature.checkSignatureIntegrity(); if (!signatureCryptographicVerification.isSignatureIntact()) { final String errorMessage = signatureCryptographicVerification.getErrorMessage(); throw new DSSException("Cryptographic signature verification has failed" + (errorMessage.isEmpty() ? "." : (" / " + errorMessage))); } } }
private void addNewToken(final Token crlToken, final PdfArray pdfArray) throws DSSException { try { final PdfStream stream = factory.newStream(crlToken.getEncoded()); pdfArray.add(stream); } catch (IOException e) { throw new DSSException(e); } } }
private void storesSignature(final ASiCParameters asicParameters, final DSSDocument signature, final ZipOutputStream outZip) { if (isXAdESForm(asicParameters)) { buildXAdES(asicParameters, signature, outZip); } else if (isCAdESForm(asicParameters)) { buildCAdES(asicParameters, signature, outZip); } else { throw new DSSException("ASiC signature form must be XAdES or CAdES!"); } }