From 95d45e8a19babfc319b3e92ee89bb13fd9924631 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 8 Feb 2016 12:41:07 +0100 Subject: xmlsecurity: export OOXML Change-Id: I1cac26d1133722285abe038085ad81dc16be6d8f --- xmlsecurity/source/helper/xsecctl.cxx | 6 ++++ xmlsecurity/source/helper/xsecctl.hxx | 2 ++ xmlsecurity/source/helper/xsecsign.cxx | 51 +++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) (limited to 'xmlsecurity') diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx index cc6a2e14cd68..fcbd8284247a 100644 --- a/xmlsecurity/source/helper/xsecctl.cxx +++ b/xmlsecurity/source/helper/xsecctl.cxx @@ -975,6 +975,12 @@ void XSecController::exportSignature( xDocumentHandler->endElement( tag_Signature ); } +void XSecController::exportOOXMLSignature(const uno::Reference& xDocumentHandler, const SignatureInformation& /*rInformation*/) +{ + xDocumentHandler->startElement(TAG_SIGNEDINFO, uno::Reference(new SvXMLAttributeList())); + xDocumentHandler->endElement(TAG_SIGNEDINFO); +} + SignatureInformation XSecController::getSignatureInformation( sal_Int32 nSecurityId ) const { SignatureInformation aInf( 0 ); diff --git a/xmlsecurity/source/helper/xsecctl.hxx b/xmlsecurity/source/helper/xsecctl.hxx index ff7ee0e72890..967e6036e5e7 100644 --- a/xmlsecurity/source/helper/xsecctl.hxx +++ b/xmlsecurity/source/helper/xsecctl.hxx @@ -506,6 +506,8 @@ public: /// Writes XML elements inside a single OOXML signature's element. bool WriteOOXMLSignature(const css::uno::Reference& xDocumentHandler); + /// Exports an OOXML signature, called by WriteOOXMLSignature(). + static void exportOOXMLSignature(const css::uno::Reference& xDocumentHandler, const SignatureInformation& rInformation); }; #endif diff --git a/xmlsecurity/source/helper/xsecsign.cxx b/xmlsecurity/source/helper/xsecsign.cxx index 8b658df31cb2..4f1e523a526c 100644 --- a/xmlsecurity/source/helper/xsecsign.cxx +++ b/xmlsecurity/source/helper/xsecsign.cxx @@ -357,10 +357,59 @@ bool XSecController::WriteSignature( return rc; } -bool XSecController::WriteOOXMLSignature(const uno::Reference& /*xDocumentHandler*/) +bool XSecController::WriteOOXMLSignature(const uno::Reference& xDocumentHandler) { bool bRet = false; + SAL_WARN_IF(!xDocumentHandler.is(), "xmlsecurity.helper", "empty xDocumentHandler reference"); + + // Chain the SAXEventKeeper to the SAX chain. + chainOn(/*bRetrievingLastEvent=*/true); + + if (m_nStatusOfSecurityComponents == INITIALIZED) + { + m_bIsSAXEventKeeperSticky = true; + m_xSAXEventKeeper->setNextHandler(xDocumentHandler); + + try + { + // Export the signature template. + cssu::Reference xSEKHandler(m_xSAXEventKeeper, uno::UNO_QUERY); + + for (size_t i = 0; i < m_vInternalSignatureInformations.size(); ++i) + { + InternalSignatureInformation& rInformation = m_vInternalSignatureInformations[i]; + + // Prepare the signature creator. + rInformation.xReferenceResolvedListener = prepareSignatureToWrite(rInformation); + + exportOOXMLSignature(xSEKHandler, rInformation.signatureInfor); + } + + m_bIsSAXEventKeeperSticky = false; + chainOff(); + + bRet = true; + } + catch (const xml::sax::SAXException&) + { + m_pErrorMessage = ERROR_SAXEXCEPTIONDURINGCREATION; + } + catch(const io::IOException&) + { + m_pErrorMessage = ERROR_IOEXCEPTIONDURINGCREATION; + } + catch(const uno::Exception&) + { + m_pErrorMessage = ERROR_EXCEPTIONDURINGCREATION; + } + + m_xSAXEventKeeper->setNextHandler(nullptr); + m_bIsSAXEventKeeperSticky = false; + } + else + m_pErrorMessage = ERROR_CANNOTCREATEXMLSECURITYCOMPONENT; + return bRet; } -- cgit