From 9be498dac23a48f45d6a63e69dfca83622c9cdf5 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 21 Mar 2017 16:26:11 +0100 Subject: [PATCH] xmlsecurity: separate signature verification from PDF tokenizer Signature verification code depends on sax and xmloff, but the rest of the PDF tokenizer could be otherwise moved down to lower layers without problems. Change-Id: Ieca57279e9517935821c1d34f217fd10548035ef Reviewed-on: https://gerrit.libreoffice.org/35512 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- include/xmlsecurity/pdfio/pdfdocument.hxx | 17 +++++++++-------- xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx | 4 ++-- .../source/helper/pdfsignaturehelper.cxx | 2 +- xmlsecurity/source/pdfio/pdfdocument.cxx | 2 +- xmlsecurity/workben/pdfverify.cxx | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/xmlsecurity/pdfio/pdfdocument.hxx b/include/xmlsecurity/pdfio/pdfdocument.hxx index 5f64b650ed17..f5179fd4af6d 100644 --- a/include/xmlsecurity/pdfio/pdfdocument.hxx +++ b/include/xmlsecurity/pdfio/pdfdocument.hxx @@ -254,8 +254,6 @@ class XMLSECURITY_DLLPUBLIC PDFDocument SvMemoryStream m_aEditBuffer; static int AsHex(char ch); - /// Decode a hex dump. - static std::vector DecodeHexString(PDFHexStringElement* pElement); /// Suggest a minimal, yet free signature ID to use for the next signature. sal_uInt32 GetNextSignature(); /// Write the signature object as part of signing. @@ -277,6 +275,8 @@ public: PDFDocument(const PDFDocument&) = delete; /// @name Low-level functions, to be used by PDFElement subclasses. //@{ + /// Decode a hex dump. + static std::vector DecodeHexString(PDFHexStringElement* pElement); static OString ReadKeyword(SvStream& rStream); static size_t FindStartXRef(SvStream& rStream); void ReadXRef(SvStream& rStream); @@ -309,17 +309,18 @@ public: bool Write(SvStream& rStream); /// Get a list of signatures embedded into this document. std::vector GetSignatureWidgets(); - /** - * @param rInformation The actual result. - * @param bLast If this is the last signature in the file, so it covers the whole file physically. - * @return If we can determinate a result. - */ - static bool ValidateSignature(SvStream& rStream, PDFObjectElement* pSignature, SignatureInformation& rInformation, bool bLast); /// Remove the nth signature from read document in the edit buffer. bool RemoveSignature(size_t nPosition); //@} }; +/** + * @param rInformation The actual result. + * @param bLast If this is the last signature in the file, so it covers the whole file physically. + * @return If we can determinate a result. + */ +XMLSECURITY_DLLPUBLIC bool ValidateSignature(SvStream& rStream, PDFObjectElement* pSignature, SignatureInformation& rInformation, bool bLast); + } // namespace pdfio } // namespace xmlsecurity diff --git a/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx b/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx index ca17aa29faa8..8d572ea6b53d 100644 --- a/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx +++ b/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx @@ -131,7 +131,7 @@ std::vector PDFSigningTest::verify(const OUString& rURL, s { SignatureInformation aInfo(i); bool bLast = i == aSignatures.size() - 1; - CPPUNIT_ASSERT(xmlsecurity::pdfio::PDFDocument::ValidateSignature(aStream, aSignatures[i], aInfo, bLast)); + CPPUNIT_ASSERT(xmlsecurity::pdfio::ValidateSignature(aStream, aSignatures[i], aInfo, bLast)); aRet.push_back(aInfo); if (!rExpectedSubFilter.isEmpty()) @@ -233,7 +233,7 @@ void PDFSigningTest::testPDFRemove() std::vector aSignatures = aDocument.GetSignatureWidgets(); CPPUNIT_ASSERT_EQUAL(static_cast(1), aSignatures.size()); SignatureInformation aInfo(0); - CPPUNIT_ASSERT(xmlsecurity::pdfio::PDFDocument::ValidateSignature(aStream, aSignatures[0], aInfo, /*bLast=*/true)); + CPPUNIT_ASSERT(xmlsecurity::pdfio::ValidateSignature(aStream, aSignatures[0], aInfo, /*bLast=*/true)); } // Remove the signature and write out the result as remove.pdf. diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx index 18bf89e7f1a2..d97d76c52adc 100644 --- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx +++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx @@ -53,7 +53,7 @@ bool PDFSignatureHelper::ReadAndVerifySignature(const uno::ReferenceLookupObject("V"); if (!pValue) diff --git a/xmlsecurity/workben/pdfverify.cxx b/xmlsecurity/workben/pdfverify.cxx index 5e19601ea284..2b43c1ef3137 100644 --- a/xmlsecurity/workben/pdfverify.cxx +++ b/xmlsecurity/workben/pdfverify.cxx @@ -224,7 +224,7 @@ int pdfVerify(int nArgc, char** pArgv) { SignatureInformation aInfo(i); bool bLast = i == aSignatures.size() - 1; - if (!xmlsecurity::pdfio::PDFDocument::ValidateSignature(aStream, aSignatures[i], aInfo, bLast)) + if (!xmlsecurity::pdfio::ValidateSignature(aStream, aSignatures[i], aInfo, bLast)) { SAL_WARN("xmlsecurity.pdfio", "failed to determine digest match"); return 1;