diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-10-13 16:11:02 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-10-13 18:18:16 +0000 |
commit | 3b6f7f38100c9c9d799756ffddbf281bf49364f4 (patch) | |
tree | 8dc82c34d4a91363d58c1f67b69f44d067ecd8f0 /xmlsecurity/source | |
parent | 52c79bbd1b4c58124738b59214a3f2b111ff0191 (diff) |
xmlsecuity: show PDF signature in the doc signatures dialog
It doesn't actually show any details yet, but it shows a selectable
empty line, to be filled in with details.
Change-Id: Ib35f13e5c779fe1a28933c1a0761682e9f5de62d
Reviewed-on: https://gerrit.libreoffice.org/29775
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'xmlsecurity/source')
-rw-r--r-- | xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 6 | ||||
-rw-r--r-- | xmlsecurity/source/helper/documentsignaturemanager.cxx | 42 | ||||
-rw-r--r-- | xmlsecurity/source/helper/pdfsignaturehelper.cxx | 25 |
3 files changed, 56 insertions, 17 deletions
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 0a74f2993c7a..d99590aea323 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -432,9 +432,9 @@ void DigitalSignaturesDialog::ImplFillSignaturesBox() { DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm( m_sODFVersion, maSignatureManager.maCurrentSignatureInformations[n]); - std::vector< OUString > aElementsToBeVerified = - DocumentSignatureHelper::CreateElementList( - maSignatureManager.mxStore, maSignatureManager.meSignatureMode, mode); + std::vector< OUString > aElementsToBeVerified; + if (maSignatureManager.mxStore.is()) + aElementsToBeVerified = DocumentSignatureHelper::CreateElementList(maSignatureManager.mxStore, maSignatureManager.meSignatureMode, mode); const SignatureInformation& rInfo = maSignatureManager.maCurrentSignatureInformations[n]; //First we try to get the certificate which is embedded in the XML Signature diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index a947ed55f745..5fa5f170027f 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -47,6 +47,17 @@ DocumentSignatureManager::~DocumentSignatureManager() { } +PDFSignatureHelper& DocumentSignatureManager::getPDFSignatureHelper() +{ + // It is important to create this only when dealing with PDF, in case both + // this and XMLSignatureHelper is created, xmlsec gets confused, and + // doesn't get correct result. + if (!mpPDFSignatureHelper) + mpPDFSignatureHelper.reset(new PDFSignatureHelper(mxContext)); + + return *mpPDFSignatureHelper; +} + /* Using the zip storage, we cannot get the properties "MediaType" and "IsEncrypted" We use the manifest to find out if a file is xml and if it is encrypted. The parameter is an encoded uri. However, the manifest contains paths. Therefore @@ -331,19 +342,30 @@ void DocumentSignatureManager::read(bool bUseTempStream, bool bCacheLastSignatur { maCurrentSignatureInformations.clear(); - maSignatureHelper.StartMission(); + if (mxStore.is()) + { + // ZIP-based: ODF or OOXML. + maSignatureHelper.StartMission(); - SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(embed::ElementModes::READ, bUseTempStream); - if (aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML && aStreamHelper.xSignatureStream.is()) + SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(embed::ElementModes::READ, bUseTempStream); + if (aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML && aStreamHelper.xSignatureStream.is()) + { + uno::Reference< io::XInputStream > xInputStream(aStreamHelper.xSignatureStream, uno::UNO_QUERY); + maSignatureHelper.ReadAndVerifySignature(xInputStream); + } + else if (aStreamHelper.nStorageFormat == embed::StorageFormats::OFOPXML && aStreamHelper.xSignatureStorage.is()) + maSignatureHelper.ReadAndVerifySignatureStorage(aStreamHelper.xSignatureStorage, bCacheLastSignature); + maSignatureHelper.EndMission(); + + maCurrentSignatureInformations = maSignatureHelper.GetSignatureInformations(); + } + else { - uno::Reference< io::XInputStream > xInputStream(aStreamHelper.xSignatureStream, uno::UNO_QUERY); - maSignatureHelper.ReadAndVerifySignature(xInputStream); + // Something not ZIP based, try PDF. + uno::Reference<io::XInputStream> xInputStream(mxSignatureStream, uno::UNO_QUERY); + if (getPDFSignatureHelper().ReadAndVerifySignature(xInputStream)) + maCurrentSignatureInformations = getPDFSignatureHelper().GetSignatureInformations(); } - else if (aStreamHelper.nStorageFormat == embed::StorageFormats::OFOPXML && aStreamHelper.xSignatureStorage.is()) - maSignatureHelper.ReadAndVerifySignatureStorage(aStreamHelper.xSignatureStorage, bCacheLastSignature); - maSignatureHelper.EndMission(); - - maCurrentSignatureInformations = maSignatureHelper.GetSignatureInformations(); } void DocumentSignatureManager::write() diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx index 9a5ec842f13d..2054f2b6f2d9 100644 --- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx +++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx @@ -52,7 +52,7 @@ bool PDFSignatureHelper::ReadAndVerifySignature(const uno::Reference<io::XInputS for (size_t i = 0; i < aSignatures.size(); ++i) { - security::DocumentSignatureInformation aInfo; + SignatureInformation aInfo(i); bool bDigestMatch; if (!xmlsecurity::pdfio::PDFDocument::ValidateSignature(*pStream, aSignatures[i], bDigestMatch)) @@ -61,16 +61,33 @@ bool PDFSignatureHelper::ReadAndVerifySignature(const uno::Reference<io::XInputS continue; } - aInfo.SignatureIsValid = bDigestMatch; + if (bDigestMatch) + aInfo.nStatus = xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED; + else + aInfo.nStatus = xml::crypto::SecurityOperationStatus_UNKNOWN; m_aSignatureInfos.push_back(aInfo); } return true; } -uno::Sequence<security::DocumentSignatureInformation> PDFSignatureHelper::GetDocumentSignatureInformations() +SignatureInformations PDFSignatureHelper::GetSignatureInformations() const { - return comphelper::containerToSequence(m_aSignatureInfos); + return m_aSignatureInfos; +} + +uno::Sequence<security::DocumentSignatureInformation> PDFSignatureHelper::GetDocumentSignatureInformations() const +{ + uno::Sequence<security::DocumentSignatureInformation> aRet(m_aSignatureInfos.size()); + + for (size_t i = 0; i < m_aSignatureInfos.size(); ++i) + { + const SignatureInformation& rInternal = m_aSignatureInfos[i]; + security::DocumentSignatureInformation& rExternal = aRet[i]; + rExternal.SignatureIsValid = rInternal.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED; + } + + return aRet; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |