diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-09-22 21:15:19 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-09-23 08:17:39 +0200 |
commit | c18356b49ce2f2a4f097b91cb74d578f9976d4d7 (patch) | |
tree | 7906c285a6b016d278b01e6be4cd6298b0976726 /xmlsecurity/workben/pdfverify.cxx | |
parent | 808e8a8e9e96b6c3fac3ddf291e3900a40846409 (diff) |
Executable_pdfverify: use PDFSignatureHelper for signature verification
Towards making vcl::filter::PDFDocument an implementation detail of
PDFSignatureHelper during signature verification: so pdfverify, cppunit
tests and the UI shares more code.
Change-Id: Ibb68933d754e392bce0ebbf06be8916ab3f7efdc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103214
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmlsecurity/workben/pdfverify.cxx')
-rw-r--r-- | xmlsecurity/workben/pdfverify.cxx | 61 |
1 files changed, 28 insertions, 33 deletions
diff --git a/xmlsecurity/workben/pdfverify.cxx b/xmlsecurity/workben/pdfverify.cxx index b5052502573f..78595bae0ef9 100644 --- a/xmlsecurity/workben/pdfverify.cxx +++ b/xmlsecurity/workben/pdfverify.cxx @@ -24,11 +24,10 @@ #include <vcl/graphicfilter.hxx> #include <vcl/filter/pdfdocument.hxx> #include <comphelper/scopeguard.hxx> - -#include <pdfio/pdfdocument.hxx> - #include <svl/sigstruct.hxx> +#include <pdfsignaturehelper.hxx> + using namespace com::sun::star; namespace @@ -114,6 +113,32 @@ int pdfVerify(int nArgc, char** pArgv) bRemoveSignature = true; SvFileStream aStream(aInURL, StreamMode::READ); + if (aOutURL.isEmpty() && !bRemoveSignature) + { + std::cerr << "verifying signatures" << std::endl; + PDFSignatureHelper aHelper; + aStream.Seek(0); + aHelper.ReadAndVerifySignatureSvStream(aStream); + if (aHelper.GetSignatureInformations().empty()) + std::cerr << "found no signatures" << std::endl; + else + { + std::cerr << "found " << aHelper.GetSignatureInformations().size() << " signatures" + << std::endl; + for (size_t i = 0; i < aHelper.GetSignatureInformations().size(); ++i) + { + const SignatureInformation& rInfo = aHelper.GetSignatureInformations()[i]; + bool bSuccess + = rInfo.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED; + std::cerr << "signature #" << i << ": digest match? " << bSuccess << std::endl; + std::cerr << "signature #" << i << ": partial? " << rInfo.bPartialDocumentSignature + << std::endl; + } + } + + return 0; + } + vcl::filter::PDFDocument aDocument; if (!aDocument.Read(aStream)) { @@ -148,36 +173,6 @@ int pdfVerify(int nArgc, char** pArgv) return 0; } - if (aOutURL.isEmpty()) - { - std::cerr << "verifying signatures" << std::endl; - std::vector<vcl::filter::PDFObjectElement*> aSignatures = aDocument.GetSignatureWidgets(); - if (aSignatures.empty()) - std::cerr << "found no signatures" << std::endl; - else - { - std::cerr << "found " << aSignatures.size() << " signatures" << std::endl; - for (size_t i = 0; i < aSignatures.size(); ++i) - { - SignatureInformation aInfo(i); - if (!xmlsecurity::pdfio::ValidateSignature(aStream, aSignatures[i], aInfo, - aDocument)) - { - SAL_WARN("xmlsecurity.pdfio", "failed to determine digest match"); - return 1; - } - - bool bSuccess - = aInfo.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED; - std::cerr << "signature #" << i << ": digest match? " << bSuccess << std::endl; - std::cerr << "signature #" << i << ": partial? " << aInfo.bPartialDocumentSignature - << std::endl; - } - } - - return 0; - } - std::cerr << "adding a new signature" << std::endl; uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment = xSecurityContext->getSecurityEnvironment(); |