summaryrefslogtreecommitdiffstats
path: root/xmlsecurity
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-01-13 09:36:06 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-01-13 09:54:50 +0100
commit5524754e9f7c936f7152f49815af0e11d9c92613 (patch)
tree1e7346ff0e82bcb512bda9b3dff08cd4ed5415b4 /xmlsecurity
parentxmlsecurity: read OOXML signature relations (diff)
downloadcore-5524754e9f7c936f7152f49815af0e11d9c92613.tar.gz
core-5524754e9f7c936f7152f49815af0e11d9c92613.zip
xmlsecurity: initial XMLSignatureHelper::ReadAndVerifySignatureStorageStream()
Change-Id: Ida3f77a763c55a7ec8a52a3de4521d18a952e752
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx4
-rw-r--r--xmlsecurity/source/helper/xmlsignaturehelper.cxx45
2 files changed, 47 insertions, 2 deletions
diff --git a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx
index bf5cfea7cb44..ea954d1e470a 100644
--- a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx
+++ b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx
@@ -178,8 +178,10 @@ public:
static void CloseDocumentHandler( const ::com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler>& xDocumentHandler );
static void ExportSignature( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler, const SignatureInformation& signatureInfo );
- /// Read and verify an OOXML signature.
+ /// Read and verify OOXML signatures.
bool ReadAndVerifySignatureStorage(const css::uno::Reference<css::embed::XStorage>& xStorage);
+ /// Read and verify a single OOXML signature.
+ bool ReadAndVerifySignatureStorageStream(const css::uno::Reference<css::io::XInputStream>& xInputStream);
};
#endif // INCLUDED_XMLSECURITY_INC_XMLSECURITY_XMLSIGNATUREHELPER_HXX
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
index 89d5d95215fd..95f26e3f54de 100644
--- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
@@ -368,7 +368,9 @@ bool XMLSignatureHelper::ReadAndVerifySignatureStorage(const uno::Reference<embe
std::vector<beans::StringPair>::iterator it = std::find_if(aRelation.begin(), aRelation.end(), [](const beans::StringPair& rPair) { return rPair.First == "Target"; });
if (it != aRelation.end())
{
- // TODO now handle it->Second
+ uno::Reference<io::XInputStream> xInputStream(xStorage->openStreamElement(it->Second, nOpenMode), uno::UNO_QUERY);
+ if (!ReadAndVerifySignatureStorageStream(xInputStream))
+ return false;
}
}
}
@@ -376,4 +378,45 @@ bool XMLSignatureHelper::ReadAndVerifySignatureStorage(const uno::Reference<embe
return true;
}
+bool XMLSignatureHelper::ReadAndVerifySignatureStorageStream(const css::uno::Reference<css::io::XInputStream>& xInputStream)
+{
+ mbError = false;
+
+ // Create the input source.
+ xml::sax::InputSource aParserInput;
+ aParserInput.aInputStream = xInputStream;
+
+ // Create the sax parser.
+ uno::Reference<xml::sax::XParser> xParser = xml::sax::Parser::create(mxCtx);
+
+ // Create the signature reader.
+ uno::Reference<xml::sax::XDocumentHandler> xHandler = mpXSecController->createSignatureReader();
+
+ // Create the signature listener.
+ ImplXMLSignatureListener* pSignatureListener = new ImplXMLSignatureListener(
+ LINK(this, XMLSignatureHelper, SignatureCreationResultListener),
+ LINK(this, XMLSignatureHelper, SignatureVerifyResultListener),
+ LINK(this, XMLSignatureHelper, StartVerifySignatureElement));
+ uno::Reference<xml::sax::XDocumentHandler> xSignatureListener(pSignatureListener);
+
+ // Parser -> signature listener -> signature reader.
+ pSignatureListener->setNextHandler(xHandler);
+ xParser->setDocumentHandler(xSignatureListener);
+
+ // Parse the stream.
+ try
+ {
+ xParser->parseStream(aParserInput);
+ }
+ catch(const uno::Exception& rException)
+ {
+ SAL_WARN("xmlsecurity.helper", "XMLSignatureHelper::ReadAndVerifySignatureStorageStream: " << rException.Message);
+ }
+
+ pSignatureListener->setNextHandler(nullptr);
+ mpXSecController->releaseSignatureReader();
+
+ return !mbError;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */