[Libreoffice-commits] core.git: 8 commits - xmlsecurity/inc xmlsecurity/qa xmlsecurity/source xmlsecurity/uiconfig
Miklos Vajna
vmiklos at collabora.co.uk
Mon Mar 7 14:03:34 UTC 2016
xmlsecurity/inc/documentsignaturemanager.hxx | 2
xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx | 4 -
xmlsecurity/qa/unit/signing/signing.cxx | 53 ++++++++++++++
xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 44 -----------
xmlsecurity/source/helper/documentsignaturemanager.cxx | 63 ++++++++++++++---
xmlsecurity/source/helper/xmlsignaturehelper.cxx | 43 +++++++++--
xmlsecurity/uiconfig/ui/selectcertificatedialog.ui | 4 -
7 files changed, 148 insertions(+), 65 deletions(-)
New commits:
commit 3dda6452f190f9196eee845bbe0d5d28346a1e52
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 7 13:47:48 2016 +0100
xmlsecurity: default to OK instead of Cancel in CertificateChooser
Change-Id: I2dd2d2caf772cf5a0e564367acff0c5522b2c286
diff --git a/xmlsecurity/uiconfig/ui/selectcertificatedialog.ui b/xmlsecurity/uiconfig/ui/selectcertificatedialog.ui
index 1869bb8..c9e5b42 100644
--- a/xmlsecurity/uiconfig/ui/selectcertificatedialog.ui
+++ b/xmlsecurity/uiconfig/ui/selectcertificatedialog.ui
@@ -23,6 +23,8 @@
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
@@ -37,8 +39,6 @@
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
commit 88b1a724311a2f9b2c75e8ea9c1494be61433371
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 7 12:30:26 2016 +0100
CppunitTest_xmlsecurity_signing: add remove all testcase
Fails without the previous commit.
Change-Id: I7606b9a5ef3509077b1a3a6e884f0e2bb4c79614
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index aa77fa0..1894cb9 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -36,6 +36,7 @@
#include <sfx2/sfxbasemodel.hxx>
#include <sfx2/objsh.hxx>
#include <osl/file.hxx>
+#include <comphelper/ofopxmlhelper.hxx>
#include <xmlsecurity/documentsignaturehelper.hxx>
#include <xmlsecurity/xmlsignaturehelper.hxx>
@@ -69,6 +70,8 @@ public:
void testOOXMLAppend();
/// Test removing a signature from existing ones.
void testOOXMLRemove();
+ /// Test removing all signatures from a document.
+ void testOOXMLRemoveAll();
CPPUNIT_TEST_SUITE(SigningTest);
CPPUNIT_TEST(testDescription);
@@ -77,6 +80,7 @@ public:
CPPUNIT_TEST(testOOXMLDescription);
CPPUNIT_TEST(testOOXMLAppend);
CPPUNIT_TEST(testOOXMLRemove);
+ CPPUNIT_TEST(testOOXMLRemoveAll);
CPPUNIT_TEST_SUITE_END();
private:
@@ -253,6 +257,48 @@ void SigningTest::testOOXMLRemove()
CPPUNIT_ASSERT_EQUAL(OUString("purpose1"), rInformations[0].ouDescription);
}
+void SigningTest::testOOXMLRemoveAll()
+{
+ // Copy the test document to a temporary file, as it'll be modified.
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ OUString aURL = aTempFile.GetURL();
+ osl::File::copy(getURLFromSrc(DATA_DIRECTORY) + "partial.docx", aURL);
+ // Load the test document as a storage and read its single signature.
+ DocumentSignatureManager aManager(mxComponentContext, SignatureModeDocumentContent);
+ CPPUNIT_ASSERT(aManager.maSignatureHelper.Init());
+ uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL, embed::ElementModes::READWRITE);
+ CPPUNIT_ASSERT(xStorage.is());
+ aManager.mxStore = xStorage;
+ aManager.maSignatureHelper.SetStorage(xStorage, "1.2");
+ aManager.read(/*bUseTempStream=*/false);
+ std::vector<SignatureInformation>& rInformations = aManager.maCurrentSignatureInformations;
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rInformations.size());
+
+ // Then remove the only signature in the document.
+ uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager.maSignatureHelper);
+ CPPUNIT_ASSERT(xCertificate.is());
+ aManager.remove(0);
+ aManager.read(/*bUseTempStream=*/true);
+ aManager.write();
+
+ // Make sure that the signature count is zero and the whole signature storage is removed completely.
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rInformations.size());
+ uno::Reference<container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(!xNameAccess->hasByName("_xmlsignatures"));
+
+ // And that content types no longer contains signature types.
+ sal_Int32 nOpenMode = embed::ElementModes::READWRITE;
+ uno::Reference<io::XStream> xStream(xStorage->openStreamElement("[Content_Types].xml", nOpenMode), uno::UNO_QUERY);
+ uno::Reference<io::XInputStream> xInputStream = xStream->getInputStream();
+ uno::Sequence< uno::Sequence<beans::StringPair> > aContentTypeInfo = comphelper::OFOPXMLHelper::ReadContentTypeSequence(xInputStream, mxComponentContext);
+ uno::Sequence<beans::StringPair>& rOverrides = aContentTypeInfo[1];
+ CPPUNIT_ASSERT_EQUAL(rOverrides.end(), std::find_if(rOverrides.begin(), rOverrides.end(), [](const beans::StringPair& rPair)
+ {
+ return rPair.First.startsWith("/_xmlsignatures/sig");
+ }));
+}
+
void SigningTest::testOOXMLPartial()
{
createDoc(getURLFromSrc(DATA_DIRECTORY) + "partial.docx");
commit 1a04b1e4f2086bfdeaba04d7b67e8b8e21e5037f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 7 12:09:44 2016 +0100
xmlsecurity OOXML export: remove signature content types when removing ...
... signatures.
ExportSignatureContentTypes() was already a "remove all, and then re-add
necessary entries" operation, so just make sure we still call it for
zero signatures and it'll do the right thing.
Change-Id: If9182b39ac6d8f2cf66f33a02d9ddcab170ba5ea
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index 505554e..47d416f 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -374,11 +374,9 @@ void DocumentSignatureManager::write()
{
// OOXML
size_t nSignatureCount = maCurrentSignatureInformations.size();
+ maSignatureHelper.ExportSignatureContentTypes(mxStore, nSignatureCount);
if (nSignatureCount > 0)
- {
- maSignatureHelper.ExportSignatureContentTypes(mxStore, nSignatureCount);
maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
- }
else
{
// Removing all signatures: then need to remove the signature relation as well.
commit 7d7cd95840bd3dec2e1e7e8e5f99c69673767215
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 7 11:44:28 2016 +0100
CppunitTest_xmlsecurity_signing: avoid modifying tracked test document
Without this, running the test modified
xmlsecurity/qa/unit/signing/data/partial.docx.
Change-Id: I3dd5cb6c90037fce0c550be9b1c189959b848ebe
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index aa062d0..aa77fa0 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -35,6 +35,7 @@
#include <tools/time.hxx>
#include <sfx2/sfxbasemodel.hxx>
#include <sfx2/objsh.hxx>
+#include <osl/file.hxx>
#include <xmlsecurity/documentsignaturehelper.hxx>
#include <xmlsecurity/xmlsignaturehelper.hxx>
@@ -199,10 +200,14 @@ void SigningTest::testOOXMLDescription()
void SigningTest::testOOXMLAppend()
{
+ // Copy the test document to a temporary file, as it'll be modified.
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ OUString aURL = aTempFile.GetURL();
+ osl::File::copy(getURLFromSrc(DATA_DIRECTORY) + "partial.docx", aURL);
// Load the test document as a storage and read its single signature.
DocumentSignatureManager aManager(mxComponentContext, SignatureModeDocumentContent);
CPPUNIT_ASSERT(aManager.maSignatureHelper.Init());
- OUString aURL = getURLFromSrc(DATA_DIRECTORY) + "partial.docx";
uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL, embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.mxStore = xStorage;
commit e60abe659d7448ae6f839740dcfe87fd8b1520d7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 7 11:10:53 2016 +0100
xmlsecurity OOXML export: remove signature storage with the last signature
So that no empty _xmlsignatures directory is left around after removing
signatures.
Change-Id: I3af77ba943a483a009a4eebaf40a58404f479e5a
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index 8a568bd..505554e 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -383,6 +383,9 @@ void DocumentSignatureManager::write()
{
// Removing all signatures: then need to remove the signature relation as well.
maSignatureHelper.EnsureSignaturesRelation(mxStore, /*bAdd=*/false);
+ // Also remove the whole signature sub-storage: release our read-write reference + remove the element.
+ aStreamHelper = SignatureStreamHelper();
+ mxStore->removeElement("_xmlsignatures");
}
for (size_t i = 0; i < nSignatureCount; ++i)
@@ -390,7 +393,7 @@ void DocumentSignatureManager::write()
}
// If stream was not provided, we are responsible for committing it....
- if (!mxSignatureStream.is())
+ if (!mxSignatureStream.is() && aStreamHelper.xSignatureStorage.is())
{
uno::Reference<embed::XTransactedObject> xTrans(aStreamHelper.xSignatureStorage, uno::UNO_QUERY);
xTrans->commit();
commit 57e6b9f3f4861f6283841e24a189eae3c02db9e8
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 7 10:57:45 2016 +0100
xmlsecurity OOXML export: remove signature relation with the last signature
The signature relation refers to _xmlsignatures/origin.sigs, but
that's not written when all signatures are removed.
Change-Id: I5ee1c8849962cba4b338e6f43243bcf89aedad36
diff --git a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx
index a8cdf93..9b00b55 100644
--- a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx
+++ b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx
@@ -181,8 +181,8 @@ public:
bool ReadAndVerifySignatureStorage(const css::uno::Reference<css::embed::XStorage>& xStorage, bool bCacheLastSignature = true);
/// Read and verify a single OOXML signature.
bool ReadAndVerifySignatureStorageStream(const css::uno::Reference<css::io::XInputStream>& xInputStream);
- /// Adds an OOXML digital signature relation to _rels/.rels if there wasn't any before.
- void EnsureSignaturesRelation(css::uno::Reference<css::embed::XStorage> xStorage);
+ /// Adds or removes an OOXML digital signature relation to _rels/.rels if there wasn't any before.
+ void EnsureSignaturesRelation(css::uno::Reference<css::embed::XStorage> xStorage, bool bAdd);
/// Given that xStorage is an OOXML _xmlsignatures storage, create origin.sigs and its relations.
void ExportSignatureRelations(css::uno::Reference<css::embed::XStorage> xStorage, int nSignatureCount);
/// Given that xSignatureStorage is an OOXML _xmlsignatures storage, create and write a new signature.
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index 218bb60..8a568bd 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -264,7 +264,7 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>&
// OOXML
// Handle relations.
- maSignatureHelper.EnsureSignaturesRelation(mxStore);
+ maSignatureHelper.EnsureSignaturesRelation(mxStore, /*bAdd=*/true);
// Old signatures + the new one.
int nSignatureCount = maCurrentSignatureInformations.size() + 1;
maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
@@ -379,6 +379,11 @@ void DocumentSignatureManager::write()
maSignatureHelper.ExportSignatureContentTypes(mxStore, nSignatureCount);
maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
}
+ else
+ {
+ // Removing all signatures: then need to remove the signature relation as well.
+ maSignatureHelper.EnsureSignaturesRelation(mxStore, /*bAdd=*/false);
+ }
for (size_t i = 0; i < nSignatureCount; ++i)
maSignatureHelper.ExportOOXMLSignature(mxStore, aStreamHelper.xSignatureStorage, maCurrentSignatureInformations[i], i + 1);
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
index 4b60731..aeee71a 100644
--- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
@@ -487,7 +487,7 @@ bool XMLSignatureHelper::ReadAndVerifySignatureStorageStream(const css::uno::Ref
return !mbError;
}
-void XMLSignatureHelper::EnsureSignaturesRelation(css::uno::Reference<css::embed::XStorage> xStorage)
+void XMLSignatureHelper::EnsureSignaturesRelation(css::uno::Reference<css::embed::XStorage> xStorage, bool bAdd)
{
sal_Int32 nOpenMode = embed::ElementModes::READWRITE;
uno::Reference<embed::XStorage> xSubStorage = xStorage->openStorageElement("_rels", nOpenMode);
@@ -496,21 +496,40 @@ void XMLSignatureHelper::EnsureSignaturesRelation(css::uno::Reference<css::embed
aRelationsInfo = comphelper::sequenceToContainer< std::vector< uno::Sequence<beans::StringPair> > >(comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(xRelStream, ".rels", mxCtx));
// Do we have a relation already?
+ bool bHaveRelation = false;
int nCount = 0;
for (const uno::Sequence<beans::StringPair>& rRelation : aRelationsInfo)
{
auto aRelation = comphelper::sequenceToContainer< std::vector<beans::StringPair> >(rRelation);
if (std::find_if(aRelation.begin(), aRelation.end(), lcl_isSignatureOriginType) != aRelation.end())
- return;
+ {
+ bHaveRelation = true;
+ break;
+ }
++nCount;
}
- // No, then add one.
- std::vector<beans::StringPair> aRelation;
- aRelation.push_back(beans::StringPair("Id", "rId" + OUString::number(++nCount)));
- aRelation.push_back(beans::StringPair("Type", OOXML_SIGNATURE_ORIGIN));
- aRelation.push_back(beans::StringPair("Target", "_xmlsignatures/origin.sigs"));
- aRelationsInfo.push_back(comphelper::containerToSequence(aRelation));
+ if (!bHaveRelation && bAdd)
+ {
+ // No, and have to add one.
+ std::vector<beans::StringPair> aRelation;
+ aRelation.push_back(beans::StringPair("Id", "rId" + OUString::number(++nCount)));
+ aRelation.push_back(beans::StringPair("Type", OOXML_SIGNATURE_ORIGIN));
+ aRelation.push_back(beans::StringPair("Target", "_xmlsignatures/origin.sigs"));
+ aRelationsInfo.push_back(comphelper::containerToSequence(aRelation));
+ }
+ else if (bHaveRelation && !bAdd)
+ {
+ // Yes, and need to remove it.
+ for (std::vector< uno::Sequence<beans::StringPair> >::iterator it = aRelationsInfo.begin(); it != aRelationsInfo.end();)
+ {
+ auto aRelation = comphelper::sequenceToContainer< std::vector<beans::StringPair> >(*it);
+ if (std::find_if(aRelation.begin(), aRelation.end(), lcl_isSignatureOriginType) != aRelation.end())
+ it = aRelationsInfo.erase(it);
+ else
+ ++it;
+ }
+ }
// Write it back.
uno::Reference<io::XTruncate> xTruncate(xRelStream, uno::UNO_QUERY);
commit 64f86c7fec0a0e88d7d91703ea1aab68714608d1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 7 10:16:58 2016 +0100
xmlsecurity OOXML export: don't write signature relations when all ...
... signatures are removed.
With this, the _xmlsignatures/ sub-storage inside the document is empty
when all signatures are removed.
Change-Id: I391bd1d3b6fdb724952a7158a043b1e602d532a9
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index 667eba2..218bb60 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -374,8 +374,11 @@ void DocumentSignatureManager::write()
{
// OOXML
size_t nSignatureCount = maCurrentSignatureInformations.size();
- maSignatureHelper.ExportSignatureContentTypes(mxStore, nSignatureCount);
- maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
+ if (nSignatureCount > 0)
+ {
+ maSignatureHelper.ExportSignatureContentTypes(mxStore, nSignatureCount);
+ maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
+ }
for (size_t i = 0; i < nSignatureCount; ++i)
maSignatureHelper.ExportOOXMLSignature(mxStore, aStreamHelper.xSignatureStorage, maCurrentSignatureInformations[i], i + 1);
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
index 57474f2..4b60731 100644
--- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
@@ -388,6 +388,13 @@ bool lcl_isSignatureOriginType(const beans::StringPair& rPair)
bool XMLSignatureHelper::ReadAndVerifySignatureStorage(const uno::Reference<embed::XStorage>& xStorage, bool bCacheLastSignature)
{
sal_Int32 nOpenMode = embed::ElementModes::READ;
+ uno::Reference<container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY);
+ if (xNameAccess.is() && !xNameAccess->hasByName("_rels"))
+ {
+ SAL_WARN("xmlsecurity.helper", "expected stream, in signature storage but not found: _rels");
+ return false;
+ }
+
uno::Reference<embed::XStorage> xSubStorage = xStorage->openStorageElement("_rels", nOpenMode);
uno::Reference<io::XInputStream> xRelStream(xSubStorage->openStreamElement("origin.sigs.rels", nOpenMode), uno::UNO_QUERY);
uno::Sequence< uno::Sequence<beans::StringPair> > aRelationsInfo;
@@ -402,7 +409,6 @@ 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())
{
- uno::Reference<container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY);
if (xNameAccess.is() && !xNameAccess->hasByName(it->Second))
{
SAL_WARN("xmlsecurity.helper", "expected stream, but not found: " << it->Second);
commit 170e0e028085745564c2755ba7e02b0a327b9e7d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 7 09:58:12 2016 +0100
xmlsecurity: extract final signature export logic from DigitalSignaturesDialog
To be able to unit-test this later without creating a vcl dialog.
Change-Id: I4794e212ffefc2efa3bddaf58e6c6bf2a4ea8d9a
diff --git a/xmlsecurity/inc/documentsignaturemanager.hxx b/xmlsecurity/inc/documentsignaturemanager.hxx
index 918c02e..361de61 100644
--- a/xmlsecurity/inc/documentsignaturemanager.hxx
+++ b/xmlsecurity/inc/documentsignaturemanager.hxx
@@ -57,6 +57,8 @@ public:
void remove(sal_uInt16 nPosition);
/// Read signatures from either a temp stream or the real storage.
void read(bool bUseTempStream, bool bCacheLastSignature = true);
+ /// Write signatures back to the persistent storage.
+ void write();
};
#endif // INCLUDED_XMLSECURITY_INC_XMLSECURITY_DOCUMENTSIGNATUREMANAGER_HXX
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 1dc929d..97cd7cd 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -24,12 +24,7 @@
#include <sax/tools/converter.hxx>
#include <com/sun/star/embed/XStorage.hpp>
-#include <com/sun/star/embed/StorageFormats.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <com/sun/star/io/XTruncate.hpp>
-#include <com/sun/star/io/TempFile.hpp>
-#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/security/NoPasswordException.hpp>
@@ -333,44 +328,7 @@ IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, SignatureHighlightHdl, SvTreeList
IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, OKButtonHdl, Button*, void)
{
- // Export all other signatures...
- SignatureStreamHelper aStreamHelper = maSignatureManager.ImplOpenSignatureStream(embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false);
-
- if (aStreamHelper.xSignatureStream.is() && aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
- {
- // ODF
- uno::Reference< io::XOutputStream > xOutputStream(
- aStreamHelper.xSignatureStream, uno::UNO_QUERY );
- uno::Reference< com::sun::star::xml::sax::XWriter> xSaxWriter =
- maSignatureManager.maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
-
- uno::Reference< xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, UNO_QUERY_THROW);
- size_t nInfos = maSignatureManager.maCurrentSignatureInformations.size();
- for( size_t n = 0 ; n < nInfos ; ++n )
- XMLSignatureHelper::ExportSignature(
- xDocumentHandler, maSignatureManager.maCurrentSignatureInformations[ n ] );
-
- XMLSignatureHelper::CloseDocumentHandler( xDocumentHandler);
-
- }
- else if (aStreamHelper.xSignatureStorage.is() && aStreamHelper.nStorageFormat == embed::StorageFormats::OFOPXML)
- {
- // OOXML
- size_t nSignatureCount = maSignatureManager.maCurrentSignatureInformations.size();
- maSignatureManager.maSignatureHelper.ExportSignatureContentTypes(maSignatureManager.mxStore, nSignatureCount);
- maSignatureManager.maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
-
- for (size_t i = 0; i < nSignatureCount; ++i)
- maSignatureManager.maSignatureHelper.ExportOOXMLSignature(maSignatureManager.mxStore, aStreamHelper.xSignatureStorage, maSignatureManager.maCurrentSignatureInformations[i], i + 1);
- }
-
- // If stream was not provided, we are responsible for committing it....
- if ( !maSignatureManager.mxSignatureStream.is() )
- {
- uno::Reference< embed::XTransactedObject > xTrans(
- aStreamHelper.xSignatureStorage, uno::UNO_QUERY );
- xTrans->commit();
- }
+ maSignatureManager.write();
EndDialog(RET_OK);
}
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index f22d937..667eba2 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -69,12 +69,12 @@ bool DocumentSignatureManager::isXML(const OUString& rURI)
for (int i = 0; i < m_manifest.getLength(); i++)
{
- const uno::Sequence<css::beans::PropertyValue>& entry = m_manifest[i];
+ const uno::Sequence<beans::PropertyValue>& entry = m_manifest[i];
OUString sPath, sMediaType;
bool bEncrypted = false;
for (int j = 0; j < entry.getLength(); j++)
{
- const css::beans::PropertyValue& prop = entry[j];
+ const beans::PropertyValue& prop = entry[j];
if (prop.Name.equals(sPropFullPath))
prop.Value >>= sPath;
@@ -127,10 +127,10 @@ SignatureStreamHelper DocumentSignatureManager::ImplOpenSignatureStream(sal_Int3
if (bTempStream)
{
- if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE)
+ if (nStreamOpenMode & embed::ElementModes::TRUNCATE)
{
//We write always into a new temporary stream.
- mxTempSignatureStream.set(css::io::TempFile::create(mxContext), uno::UNO_QUERY_THROW);
+ mxTempSignatureStream.set(io::TempFile::create(mxContext), uno::UNO_QUERY_THROW);
if (aHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
aHelper.xSignatureStream = mxTempSignatureStream;
else
@@ -167,11 +167,11 @@ SignatureStreamHelper DocumentSignatureManager::ImplOpenSignatureStream(sal_Int3
}
}
- if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE)
+ if (nStreamOpenMode & embed::ElementModes::TRUNCATE)
{
if (aHelper.xSignatureStream.is() && aHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
{
- css::uno::Reference<css::io::XTruncate> xTruncate(aHelper.xSignatureStream, uno::UNO_QUERY_THROW);
+ uno::Reference<io::XTruncate> xTruncate(aHelper.xSignatureStream, uno::UNO_QUERY_THROW);
xTruncate->truncate();
}
}
@@ -338,7 +338,7 @@ void DocumentSignatureManager::read(bool bUseTempStream, bool bCacheLastSignatur
maSignatureHelper.StartMission();
- SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(css::embed::ElementModes::READ, bUseTempStream);
+ 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);
@@ -351,4 +351,42 @@ void DocumentSignatureManager::read(bool bUseTempStream, bool bCacheLastSignatur
maCurrentSignatureInformations = maSignatureHelper.GetSignatureInformations();
}
+void DocumentSignatureManager::write()
+{
+ // Export all other signatures...
+ SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false);
+
+ if (aStreamHelper.xSignatureStream.is() && aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
+ {
+ // ODF
+ uno::Reference< io::XOutputStream > xOutputStream(aStreamHelper.xSignatureStream, uno::UNO_QUERY);
+ uno::Reference<xml::sax::XWriter> xSaxWriter = maSignatureHelper.CreateDocumentHandlerWithHeader(xOutputStream);
+
+ uno::Reference< xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, uno::UNO_QUERY_THROW);
+ size_t nInfos = maCurrentSignatureInformations.size();
+ for (size_t n = 0 ; n < nInfos ; ++n)
+ XMLSignatureHelper::ExportSignature(xDocumentHandler, maCurrentSignatureInformations[n]);
+
+ XMLSignatureHelper::CloseDocumentHandler(xDocumentHandler);
+
+ }
+ else if (aStreamHelper.xSignatureStorage.is() && aStreamHelper.nStorageFormat == embed::StorageFormats::OFOPXML)
+ {
+ // OOXML
+ size_t nSignatureCount = maCurrentSignatureInformations.size();
+ maSignatureHelper.ExportSignatureContentTypes(mxStore, nSignatureCount);
+ maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
+
+ for (size_t i = 0; i < nSignatureCount; ++i)
+ maSignatureHelper.ExportOOXMLSignature(mxStore, aStreamHelper.xSignatureStorage, maCurrentSignatureInformations[i], i + 1);
+ }
+
+ // If stream was not provided, we are responsible for committing it....
+ if (!mxSignatureStream.is())
+ {
+ uno::Reference<embed::XTransactedObject> xTrans(aStreamHelper.xSignatureStorage, uno::UNO_QUERY);
+ xTrans->commit();
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list