Kaydet (Commit) 3b6f7f38 authored tarafından Miklos Vajna's avatar Miklos Vajna

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/29775Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 52c79bbd
...@@ -21,8 +21,12 @@ ...@@ -21,8 +21,12 @@
#define INCLUDED_XMLSECURITY_INC_DOCUMENTSIGNATUREMANAGER_HXX #define INCLUDED_XMLSECURITY_INC_DOCUMENTSIGNATUREMANAGER_HXX
#include "xmlsecuritydllapi.h" #include "xmlsecuritydllapi.h"
#include <memory>
#include <sigstruct.hxx> #include <sigstruct.hxx>
#include <xmlsignaturehelper.hxx> #include <xmlsignaturehelper.hxx>
#include <pdfsignaturehelper.hxx>
#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/embed/XStorage.hpp>
#include <documentsignaturehelper.hxx> #include <documentsignaturehelper.hxx>
...@@ -35,6 +39,7 @@ public: ...@@ -35,6 +39,7 @@ public:
css::uno::Reference<css::uno::XComponentContext> mxContext; css::uno::Reference<css::uno::XComponentContext> mxContext;
css::uno::Reference<css::embed::XStorage> mxStore; css::uno::Reference<css::embed::XStorage> mxStore;
XMLSignatureHelper maSignatureHelper; XMLSignatureHelper maSignatureHelper;
std::unique_ptr<PDFSignatureHelper> mpPDFSignatureHelper;
SignatureInformations maCurrentSignatureInformations; SignatureInformations maCurrentSignatureInformations;
DocumentSignatureMode meSignatureMode; DocumentSignatureMode meSignatureMode;
css::uno::Sequence< css::uno::Sequence<css::beans::PropertyValue> > m_manifest; css::uno::Sequence< css::uno::Sequence<css::beans::PropertyValue> > m_manifest;
...@@ -59,6 +64,8 @@ public: ...@@ -59,6 +64,8 @@ public:
void read(bool bUseTempStream, bool bCacheLastSignature = true); void read(bool bUseTempStream, bool bCacheLastSignature = true);
/// Write signatures back to the persistent storage. /// Write signatures back to the persistent storage.
void write(); void write();
/// Lazy creation of PDF helper.
PDFSignatureHelper& getPDFSignatureHelper();
}; };
#endif // INCLUDED_XMLSECURITY_INC_DOCUMENTSIGNATUREMANAGER_HXX #endif // INCLUDED_XMLSECURITY_INC_DOCUMENTSIGNATUREMANAGER_HXX
......
...@@ -13,26 +13,27 @@ ...@@ -13,26 +13,27 @@
#include <xmlsecuritydllapi.h> #include <xmlsecuritydllapi.h>
#include <vector>
#include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/security/DocumentSignatureInformation.hpp> #include <com/sun/star/security/DocumentSignatureInformation.hpp>
#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/xml/crypto/XSEInitializer.hpp> #include <com/sun/star/xml/crypto/XSEInitializer.hpp>
#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp> #include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
#include <sigstruct.hxx>
/// Handles signatures of a PDF file. /// Handles signatures of a PDF file.
class XMLSECURITY_DLLPUBLIC PDFSignatureHelper class XMLSECURITY_DLLPUBLIC PDFSignatureHelper
{ {
css::uno::Reference<css::uno::XComponentContext> m_xComponentContext; css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
css::uno::Reference<css::xml::crypto::XSEInitializer> m_xSEInitializer; css::uno::Reference<css::xml::crypto::XSEInitializer> m_xSEInitializer;
css::uno::Reference<css::xml::crypto::XXMLSecurityContext> m_xSecurityContext; css::uno::Reference<css::xml::crypto::XXMLSecurityContext> m_xSecurityContext;
std::vector<css::security::DocumentSignatureInformation> m_aSignatureInfos; SignatureInformations m_aSignatureInfos;
public: public:
PDFSignatureHelper(const css::uno::Reference<css::uno::XComponentContext>& xComponentContext); PDFSignatureHelper(const css::uno::Reference<css::uno::XComponentContext>& xComponentContext);
bool ReadAndVerifySignature(const css::uno::Reference<css::io::XInputStream>& xInputStream); bool ReadAndVerifySignature(const css::uno::Reference<css::io::XInputStream>& xInputStream);
css::uno::Sequence<css::security::DocumentSignatureInformation> GetDocumentSignatureInformations(); css::uno::Sequence<css::security::DocumentSignatureInformation> GetDocumentSignatureInformations() const;
SignatureInformations GetSignatureInformations() const;
}; };
#endif // INCLUDED_XMLSECURITY_INC_PDFSIGNATUREHELPER_HXX #endif // INCLUDED_XMLSECURITY_INC_PDFSIGNATUREHELPER_HXX
......
...@@ -432,9 +432,9 @@ void DigitalSignaturesDialog::ImplFillSignaturesBox() ...@@ -432,9 +432,9 @@ void DigitalSignaturesDialog::ImplFillSignaturesBox()
{ {
DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm( DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm(
m_sODFVersion, maSignatureManager.maCurrentSignatureInformations[n]); m_sODFVersion, maSignatureManager.maCurrentSignatureInformations[n]);
std::vector< OUString > aElementsToBeVerified = std::vector< OUString > aElementsToBeVerified;
DocumentSignatureHelper::CreateElementList( if (maSignatureManager.mxStore.is())
maSignatureManager.mxStore, maSignatureManager.meSignatureMode, mode); aElementsToBeVerified = DocumentSignatureHelper::CreateElementList(maSignatureManager.mxStore, maSignatureManager.meSignatureMode, mode);
const SignatureInformation& rInfo = maSignatureManager.maCurrentSignatureInformations[n]; const SignatureInformation& rInfo = maSignatureManager.maCurrentSignatureInformations[n];
//First we try to get the certificate which is embedded in the XML Signature //First we try to get the certificate which is embedded in the XML Signature
......
...@@ -47,6 +47,17 @@ DocumentSignatureManager::~DocumentSignatureManager() ...@@ -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" /* 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. 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 The parameter is an encoded uri. However, the manifest contains paths. Therefore
...@@ -331,19 +342,30 @@ void DocumentSignatureManager::read(bool bUseTempStream, bool bCacheLastSignatur ...@@ -331,19 +342,30 @@ void DocumentSignatureManager::read(bool bUseTempStream, bool bCacheLastSignatur
{ {
maCurrentSignatureInformations.clear(); maCurrentSignatureInformations.clear();
maSignatureHelper.StartMission(); if (mxStore.is())
{
// ZIP-based: ODF or OOXML.
maSignatureHelper.StartMission();
SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(embed::ElementModes::READ, bUseTempStream); SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(embed::ElementModes::READ, bUseTempStream);
if (aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML && aStreamHelper.xSignatureStream.is()) 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); // Something not ZIP based, try PDF.
maSignatureHelper.ReadAndVerifySignature(xInputStream); 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() void DocumentSignatureManager::write()
......
...@@ -52,7 +52,7 @@ bool PDFSignatureHelper::ReadAndVerifySignature(const uno::Reference<io::XInputS ...@@ -52,7 +52,7 @@ bool PDFSignatureHelper::ReadAndVerifySignature(const uno::Reference<io::XInputS
for (size_t i = 0; i < aSignatures.size(); ++i) for (size_t i = 0; i < aSignatures.size(); ++i)
{ {
security::DocumentSignatureInformation aInfo; SignatureInformation aInfo(i);
bool bDigestMatch; bool bDigestMatch;
if (!xmlsecurity::pdfio::PDFDocument::ValidateSignature(*pStream, aSignatures[i], bDigestMatch)) if (!xmlsecurity::pdfio::PDFDocument::ValidateSignature(*pStream, aSignatures[i], bDigestMatch))
...@@ -61,16 +61,33 @@ bool PDFSignatureHelper::ReadAndVerifySignature(const uno::Reference<io::XInputS ...@@ -61,16 +61,33 @@ bool PDFSignatureHelper::ReadAndVerifySignature(const uno::Reference<io::XInputS
continue; 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); m_aSignatureInfos.push_back(aInfo);
} }
return true; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment