public void addAttribute(String name, String value) { NameValuePair attribute = new NameValuePair(name, value); this.attributes.add(attribute); }
public static boolean browserViewable(final List<MimeType> mimeTypes, final String fileName) { String mimeTypeString = new MimetypesFileTypeMap().getContentType(fileName); LOG.debug("File " + fileName + " -> mimeType: " + mimeTypeString); if (mimeTypeString.toLowerCase().startsWith("image/")) { return true; } for (MimeType mimeType : mimeTypes) { if (mimeType.getType().toLowerCase().startsWith(mimeTypeString.toLowerCase())) { return true; } } return false; } }
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { LOG.debug("resolve resource"); LOG.debug("type: " + type); LOG.debug("namespace URI: " + namespaceURI); LOG.debug("public Id: " + publicId); LOG.debug("system Id: " + systemId); LOG.debug("base URI: " + baseURI); if (false == "http://www.w3.org/2001/XMLSchema".equals(type)) { throw new RuntimeException("unsupported type: " + type); } byte[] xsd = this.context.getXmlSchema(namespaceURI); if (null != xsd) { SignatureServiceLSInput lsInput = new SignatureServiceLSInput(xsd, publicId, systemId, baseURI); return lsInput; } throw new RuntimeException("unsupported namespace: " + namespaceURI); /* * Cannot return null here, else the system starts downloading the file. */ } }
Element nsElement = getNsElement(document); .findQualifyingPropertiesElement(nsElement, xmlSignature, signatureElement); if (null == qualifyingPropertiesElement) { throw new XAdESValidationException( "no matching xades:QualifyingProperties present"); .unmarshall(qualifyingPropertiesElement, QualifyingPropertiesType.class); if (false == qualifyingProperties.getTarget().equals( "#" + xmlSignature.getId())) { throw new XAdESValidationException( "xades:QualifyingProperties/@Target incorrect"); XAdESUtils.checkSigningCertificate(signingCertificate, signedSignatureProperties); .findUnsignedSignaturePropertyElement( qualifyingPropertiesElement, "SignatureTimeStamp"); if (null == signatureTimeStampElement) { throw new XAdESValidationException( "no xades:SignatureTimeStamp present"); XAdESTimeStampType signatureTimeStamp = XAdESUtils.unmarshall( signatureTimeStampElement, XAdESTimeStampType.class); List<TimeStampToken> signatureTimeStampTokens = XAdESSignatureTimeStampValidation .verify(signatureTimeStamp, signatureElement);
public OOXMLSignatureService(InputStream documentInputStream, OutputStream documentOutputStream, SignatureFacet signatureFacet, String role, IdentityDTO identity, byte[] photo, RevocationDataService revocationDataService, TimeStampService timeStampService, DigestAlgo signatureDigestAlgo, DSSDocumentContext documentContext) throws IOException { super(signatureDigestAlgo); this.temporaryDataStorage = new HttpSessionTemporaryDataStorage(); this.documentOutputStream = documentOutputStream; this.tmpFile = File.createTempFile("eid-dss-", ".ooxml"); documentContext.deleteWhenSessionDestroyed(this.tmpFile); FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(this.tmpFile); IOUtils.copy(documentInputStream, fileOutputStream); addSignatureFacet(signatureFacet); addSignatureFacet(new XAdESXLSignatureFacet(timeStampService, revocationDataService, getSignatureDigestAlgorithm())); XAdESSignatureFacet xadesSignatureFacet = super .getXAdESSignatureFacet(); xadesSignatureFacet.setRole(role); if (null != identity) { IdentitySignatureFacet identitySignatureFacet = new IdentitySignatureFacet( identity, photo, getSignatureDigestAlgorithm()); addSignatureFacet(identitySignatureFacet); } }
public DocumentVisualization visualizeDocument(byte[] document, String language, List<MimeType> mimeTypes, String documentViewerServlet) throws Exception { // per default we do nothing byte[] browserData = document; String browserContentType = "text/xml"; ByteArrayInputStream documentInputStream = new ByteArrayInputStream( document); Document dom = this.documentBuilder.parse(documentInputStream); String namespace = dom.getDocumentElement().getNamespaceURI(); if (null != namespace) { LOG.debug("document namespace: " + namespace); byte[] xsl = this.context.getXmlStyleSheet(namespace); if (null != xsl) { LOG.debug("XML style sheet present"); browserContentType = "text/html"; Transformer transformer = this.transformerFactory .newTransformer(new StreamSource( new ByteArrayInputStream(xsl))); if (null != language) { transformer.setParameter("language", language); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); transformer.transform(new DOMSource(dom), new StreamResult( outputStream)); browserData = outputStream.toByteArray(); } } return new DocumentVisualization(browserContentType, browserData); }
BrowserPOSTResponse browserPOSTResponse = new BrowserPOSTResponse( target); browserPOSTResponse.addAttribute("SignatureStatus", signatureStatus.getStatus()); browserPOSTResponse.addAttribute("RelayState", relayState); browserPOSTResponse.addAttribute("SignatureResponse", encodedSignedDocument); } else { browserPOSTResponse.addAttribute("SignatureResponseId", artifact); String encodedSignatureCertificate = Base64 .encodeBase64String(derSignerCertificate); browserPOSTResponse.addAttribute("SignatureCertificate", encodedSignatureCertificate); .getIdentity(); if (null != identityPrivateKeyEntry) { LOG.debug("signing the response"); browserPOSTResponse.addAttribute("ServiceSigned", URLEncoder.encode("target,SignatureRequest," + "SignatureResponse," + "SignatureCertificate", "UTF-8")); } else { browserPOSTResponse.addAttribute("ServiceSigned",
boolean browserViewable = MimeTypeMapper.browserViewable(mimeTypes, zipEntryName); String image = browserViewable ? "view.png" : "download.png"; stringBuilder.append("</body></html>"); return new DocumentVisualization("text/html;charset=utf-8", stringBuilder.toString().getBytes());
public DocumentVisualization findDocument(byte[] parentDocument, String resourceId) throws Exception { ZipInputStream zipInputStream = new ZipInputStream( new ByteArrayInputStream(parentDocument)); ZipEntry zipEntry; while (null != (zipEntry = zipInputStream.getNextEntry())) { if (getResourceId(zipEntry).equals(resourceId)) { LOG.debug("Found file: " + resourceId); byte[] data = IOUtils.toByteArray(zipInputStream); return new DocumentVisualization( new MimetypesFileTypeMap().getContentType(zipEntry.getName()), data); } } return null; }
public List<SignatureInfo> verify(byte[] data, String mimeType, byte[] originalData) throws DocumentFormatException, InvalidSignatureException { LOG.debug("content type: " + mimeType); DSSDocumentService documentService = this.servicesManager .getDocumentService(mimeType); if (null == documentService) { LOG.error("no document service for content type: " + mimeType); throw new DocumentFormatException(); } try { documentService.checkIncomingDocument(data); } catch (Exception e) { LOG.error("document check error: " + e.getMessage(), e); throw new DocumentFormatException(); } List<SignatureInfo> signatureInfos; try { signatureInfos = documentService.verifySignatures(data, originalData); } catch (Exception e) { LOG.error("error verifying signatures: " + e.getMessage(), e); throw new InvalidSignatureException(); } return signatureInfos; } }
this.trustValidationService, this.configuration); try { documentService.init(documentContext, contentType); } catch (Exception e) { throw new RuntimeException(
return new DSSRequest(decodedSignatureRequest, contentType, signatureRequestId, language, target, serviceCertificateChain);
.getXmlStyleSheet(namespace); if (null == stylesheetData) { return;
SignatureServiceEx signatureService; try { signatureService = documentService.getSignatureService( documentInputStream, timeStampService, timeStampServiceValidator, revocationDataService,
this.documentOutputStream = documentOutputStream; this.tmpFile = File.createTempFile("eid-dss-", ".odf"); documentContext.deleteWhenSessionDestroyed(this.tmpFile); FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(this.tmpFile);
return new DocumentVisualization("text/html;charset=utf-8", stringBuffer.toString().getBytes());
public void checkIncomingDocument(byte[] document) throws Exception { LOG.debug("checking incoming document"); ByteArrayInputStream documentInputStream = new ByteArrayInputStream( document); Document dom = this.documentBuilder.parse(documentInputStream); String namespace = dom.getDocumentElement().getNamespaceURI(); if (null == namespace) { LOG.debug("no namespace defined"); return; } byte[] xsd = this.context.getXmlSchema(namespace); if (null == xsd) { LOG.debug("no XML schema available for namespace: " + namespace); return; } LOG.debug("validating against XML schema: " + namespace); SchemaFactory schemaFactory = SchemaFactory .newInstance("http://www.w3.org/2001/XMLSchema"); schemaFactory .setResourceResolver(new SignatureServiceLSResourceResolver( this.context)); StreamSource schemaSource = new StreamSource(new ByteArrayInputStream( xsd)); Schema schema = schemaFactory.newSchema(schemaSource); Validator validator = schema.newValidator(); DOMSource domSource = new DOMSource(dom); validator.validate(domSource); }
documentContext.deleteWhenSessionDestroyed(this.tmpFile); FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(this.tmpFile);