summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-02-15 17:05:00 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-07-07 17:42:19 +0200
commitff735db60efb15d397d2a7b26d8326489a90758d (patch)
treee67a3713dd38a9cbd5e6d253b55d4872428ac91d /xmlsecurity
parent80b10f44ddb784542686fa193df25451163be8bf (diff)
CppunitTest_xmlsecurity_signing: use DocumentSignatureManager
Change-Id: I97acb4a2e9aedb15671d65f6995faeab4ff5716f (cherry picked from commit 0d6328164e32dc8b5cd47e27bfcc2e2f6f906799)
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx83
1 files changed, 19 insertions, 64 deletions
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 7919a8f17af1..d9aec730472e 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/security/SerialNumberAdapter.hpp>
#include <com/sun/star/xml/crypto/SEInitializer.hpp>
#include <com/sun/star/io/TempFile.hpp>
+#include <com/sun/star/packages/manifest/ManifestReader.hpp>
#include <comphelper/processfactory.hxx>
#include <sax/tools/converter.hxx>
@@ -74,8 +75,6 @@ public:
private:
void createDoc(const OUString& rURL = OUString());
uno::Reference<security::XCertificate> getCertificate(XMLSignatureHelper& rSignatureHelper);
- void sign(utl::TempFile& rTempFile, XMLSignatureHelper& rSignatureHelper, const uno::Reference<io::XOutputStream>& xOutputStream);
- std::vector<SignatureInformation> verify(XMLSignatureHelper& rSignatureHelper, const uno::Reference<io::XInputStream>& xInputStream);
};
SigningTest::SigningTest()
@@ -126,58 +125,11 @@ uno::Reference<security::XCertificate> SigningTest::getCertificate(XMLSignatureH
return xSecurityEnvironment->createCertificateFromAscii(aCertificate);
}
-void SigningTest::sign(utl::TempFile& rTempFile, XMLSignatureHelper& rSignatureHelper, const uno::Reference<io::XOutputStream>& xOutputStream)
-{
- CPPUNIT_ASSERT(rSignatureHelper.Init());
-
- SvStream* pStream = utl::UcbStreamHelper::CreateStream(rTempFile.GetURL(), StreamMode::READ);
- uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pStream));
- uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromStream(ZIP_STORAGE_FORMAT_STRING, xStream);
- CPPUNIT_ASSERT(xStorage.is());
-
- rSignatureHelper.SetStorage(xStorage, "1.2");
- uno::Reference<security::XCertificate> xCertificate = getCertificate(rSignatureHelper);
- CPPUNIT_ASSERT(xCertificate.is());
-
- uno::Reference<security::XSerialNumberAdapter> xSerialNumberAdapter = security::SerialNumberAdapter::create(mxComponentContext);
- OUString aCertSerial = xSerialNumberAdapter->toString(xCertificate->getSerialNumber());
- CPPUNIT_ASSERT(!aCertSerial.isEmpty());
-
- rSignatureHelper.StartMission();
- sal_Int32 nSecurityId = rSignatureHelper.GetNewSecurityId();
- OUStringBuffer aStrBuffer;
- sax::Converter::encodeBase64(aStrBuffer, xCertificate->getEncoded());
- rSignatureHelper.SetX509Certificate(nSecurityId, xCertificate->getIssuerName(), aCertSerial, aStrBuffer.makeStringAndClear());
- DocumentSignatureMode eSignatureMode = SignatureModeDocumentContent;
- std::vector<OUString> aElements = DocumentSignatureHelper::CreateElementList(xStorage, eSignatureMode, OOo3_2Document);
- for (size_t i = 0; i < aElements.size(); ++i)
- {
- bool bBinaryMode = aElements[i].startsWith("Thumbnails/");
- rSignatureHelper.AddForSigning(nSecurityId, aElements[i], aElements[i], bBinaryMode);
- }
- rSignatureHelper.SetDateTime(nSecurityId, Date(Date::SYSTEM), tools::Time(tools::Time::SYSTEM));
- rSignatureHelper.SetDescription(nSecurityId, "SigningTest::sign");
-
- uno::Reference<xml::sax::XWriter> xWriter = rSignatureHelper.CreateDocumentHandlerWithHeader(xOutputStream);
- uno::Reference<xml::sax::XDocumentHandler> xDocumentHandler(xWriter, uno::UNO_QUERY);
- CPPUNIT_ASSERT(rSignatureHelper.CreateAndWriteSignature(xDocumentHandler));
- XMLSignatureHelper::CloseDocumentHandler(xDocumentHandler);
-
- rSignatureHelper.EndMission();
-}
-
-std::vector<SignatureInformation> SigningTest::verify(XMLSignatureHelper& rSignatureHelper, const uno::Reference<io::XInputStream>& xInputStream)
-{
- rSignatureHelper.StartMission();
- rSignatureHelper.ReadAndVerifySignature(xInputStream);
- rSignatureHelper.EndMission();
- return rSignatureHelper.GetSignatureInformations();
-}
-
void SigningTest::testDescription()
{
- // Create an empty document and store it to a tempfile.
+ // Create an empty document and store it to a tempfile, finally load it as a storage.
createDoc();
+
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
@@ -185,22 +137,25 @@ void SigningTest::testDescription()
aMediaDescriptor["FilterName"] <<= OUString("writer8");
xStorable->storeAsURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
- // Then sign the document, and store the signature it a second tempfile, so we don't write to the original storage when we read it as well.
- XMLSignatureHelper aSignatureHelper(mxComponentContext);
- uno::Reference<io::XStream> xSignatureStream(io::TempFile::create(mxComponentContext), uno::UNO_QUERY);
- uno::Reference<io::XOutputStream> xOutputStream(xSignatureStream, uno::UNO_QUERY);
- sign(aTempFile, aSignatureHelper, xOutputStream);
+ DocumentSignatureManager aManager(mxComponentContext, SignatureModeDocumentContent);
+ CPPUNIT_ASSERT(aManager.maSignatureHelper.Init());
+ uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
+ CPPUNIT_ASSERT(xStorage.is());
+ aManager.mxStore = xStorage;
+ aManager.maSignatureHelper.SetStorage(xStorage, "1.2");
- // Go back to the start of the signature.
- uno::Reference<io::XSeekable> xSeekable(xSignatureStream, uno::UNO_QUERY);
- CPPUNIT_ASSERT(xSeekable->getPosition() != 0);
- xSeekable->seek(0);
+ // Then add a signature document.
+ uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager.maSignatureHelper);
+ CPPUNIT_ASSERT(xCertificate.is());
+ OUString aDescription("SigningTest::testDescription");
+ sal_Int32 nSecurityId;
+ aManager.add(xCertificate, aDescription, nSecurityId);
// Read back the signature and make sure that the description survives the roundtrip.
- uno::Reference<io::XInputStream> xInputStream(xSignatureStream, uno::UNO_QUERY);
- std::vector<SignatureInformation> aSignatureInformations = verify(aSignatureHelper, xInputStream);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aSignatureInformations.size());
- CPPUNIT_ASSERT_EQUAL(OUString("SigningTest::sign"), aSignatureInformations[0].ouDescription);
+ aManager.read(/*bUseTempStream=*/true);
+ std::vector<SignatureInformation>& rInformations = aManager.maCurrentSignatureInformations;
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rInformations.size());
+ CPPUNIT_ASSERT_EQUAL(aDescription, rInformations[0].ouDescription);
}
void SigningTest::testOOXMLDescription()