[Libreoffice-commits] core.git: 2 commits - desktop/CppunitTest_desktop_lib.mk desktop/qa xmlsecurity/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Oct 29 06:12:27 UTC 2018


 desktop/CppunitTest_desktop_lib.mk                            |   33 -------
 desktop/qa/data/certificate.der                               |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx                   |   43 ++++++++++
 xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx |   17 ++-
 4 files changed, 57 insertions(+), 36 deletions(-)

New commits:
commit d2242cb1b88cc7d7af1990965925d19557b9f347
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Oct 15 10:15:32 2018 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Oct 29 07:12:14 2018 +0100

    lokit: test for the new signing API functions
    
    Change-Id: I3ab2f3986955eb82451704fc2386b64f208da554
    Reviewed-on: https://gerrit.libreoffice.org/61782
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk
index d0cc7f829cb8..b25ab04bda8d 100644
--- a/desktop/CppunitTest_desktop_lib.mk
+++ b/desktop/CppunitTest_desktop_lib.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_lib, \
 	test \
 	unotest \
 	utl \
+	tl \
 	vcl \
 ))
 
@@ -48,37 +49,7 @@ $(eval $(call gb_CppunitTest_use_ure,desktop_lib))
 
 $(eval $(call gb_CppunitTest_use_vcl,desktop_lib))
 
-$(eval $(call gb_CppunitTest_use_components,desktop_lib,\
-    comphelper/util/comphelp \
-    configmgr/source/configmgr \
-    dtrans/util/mcnttype \
-    filter/source/config/cache/filterconfig1 \
-    filter/source/storagefilterdetect/storagefd \
-    framework/util/fwk \
-    i18npool/util/i18npool \
-    package/source/xstor/xstor \
-    package/util/package2 \
-    sax/source/expatwrap/expwrap \
-    sfx2/util/sfx \
-    svl/source/fsstor/fsstorage \
-    svtools/util/svt \
-    sw/util/sw \
-    sw/util/swd \
-    sc/util/sc \
-    sc/util/scd \
-    sd/util/sd \
-    sd/util/sdd \
-    toolkit/util/tk \
-    ucb/source/core/ucb1 \
-    ucb/source/ucp/file/ucpfile1 \
-    unoxml/source/service/unoxml \
-    uui/util/uui \
-    vcl/vcl.common \
-    xmloff/util/xo \
-    i18npool/source/search/i18nsearch \
-    filter/source/graphic/graphicfilter \
-    linguistic/source/lng \
-))
+$(eval $(call gb_CppunitTest_use_rdb,desktop_lib,services))
 
 $(eval $(call gb_CppunitTest_use_configuration,desktop_lib))
 
diff --git a/desktop/qa/data/certificate.der b/desktop/qa/data/certificate.der
new file mode 100644
index 000000000000..2a750ab281af
Binary files /dev/null and b/desktop/qa/data/certificate.der differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 9a8d7b88b0b7..bd8b08f9fac8 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -19,6 +19,8 @@
 #include <com/sun/star/text/TextContentAnchorType.hpp>
 #include <boost/property_tree/json_parser.hpp>
 
+#include <com/sun/star/frame/XStorable.hpp>
+
 #include <vcl/scheduler.hxx>
 #include <comphelper/processfactory.hxx>
 #include <rtl/uri.hxx>
@@ -116,6 +118,8 @@ public:
     void testCommentsCallbacksWriter();
     void testRunMacro();
     void testExtractParameter();
+    void testGetSignatureState();
+    void testInsertCertificate();
     void testABI();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
@@ -159,6 +163,8 @@ public:
     CPPUNIT_TEST(testCommentsCallbacksWriter);
     CPPUNIT_TEST(testRunMacro);
     CPPUNIT_TEST(testExtractParameter);
+    CPPUNIT_TEST(testGetSignatureState);
+    CPPUNIT_TEST(testInsertCertificate);
     CPPUNIT_TEST(testABI);
     CPPUNIT_TEST_SUITE_END();
 
@@ -2240,6 +2246,43 @@ void DesktopLOKTest::testExtractParameter()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void DesktopLOKTest::testGetSignatureState()
+{
+    comphelper::LibreOfficeKit::setActive();
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
+    Scheduler::ProcessEventsToIdle();
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+    int nState = pDocument->m_pDocumentClass->getSignatureState(pDocument);
+    CPPUNIT_ASSERT_EQUAL(int(0), nState);
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
+void DesktopLOKTest::testInsertCertificate()
+{
+    comphelper::LibreOfficeKit::setActive();
+
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
+
+    Scheduler::ProcessEventsToIdle();
+    CPPUNIT_ASSERT(mxComponent.is());
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+
+    OUString aFileURL;
+    createFileURL("certificate.der", aFileURL);
+
+    SvFileStream aStream(aFileURL, StreamMode::READ);
+    sal_uInt64 nSize = aStream.remainingSize();
+
+    std::vector<unsigned char> aCertificate;
+    aCertificate.resize(nSize);
+    aStream.ReadBytes(aCertificate.data(), nSize);
+
+    bool bResult = pDocument->m_pDocumentClass->insertCertificate(pDocument, aCertificate.data(), int(aCertificate.size()));
+    CPPUNIT_ASSERT(bResult);
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 namespace {
 
 constexpr size_t documentClassOffset(int i)
commit 2077c5e4e10a8254206945520f084e6216464d6a
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Oct 15 10:14:04 2018 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Oct 29 07:12:04 2018 +0100

    xmlsecurity: prevent seg. fault if there is no private key
    
    Change-Id: I8c6917c63bbdcf0d9bb2eb1c89745186feb263f8
    Reviewed-on: https://gerrit.libreoffice.org/61781
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
index 86d68c522ed7..cae2675db64a 100644
--- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
@@ -816,11 +816,18 @@ xmlSecKeysMngrPtr SecurityEnvironment_NssImpl::createKeysManager() {
     {
         if (auto pCERTCertificate = const_cast<CERTCertificate*>(pCertificate->getNssCert()))
         {
-            SECKEYPrivateKey* pPrivateKey = PK11_FindPrivateKeyFromCert(pCERTCertificate->slot, pCERTCertificate, nullptr);
-            xmlSecKeyDataPtr pKeyData = xmlSecNssPKIAdoptKey(pPrivateKey, nullptr);
-            xmlSecKeyPtr pKey = xmlSecKeyCreate();
-            xmlSecKeySetValue(pKey, pKeyData);
-            xmlSecNssAppDefaultKeysMngrAdoptKey(pKeysMngr, pKey);
+            if (pCERTCertificate && pCERTCertificate->slot)
+            {
+                SECKEYPrivateKey* pPrivateKey = PK11_FindPrivateKeyFromCert(pCERTCertificate->slot, pCERTCertificate, nullptr);
+                xmlSecKeyDataPtr pKeyData = xmlSecNssPKIAdoptKey(pPrivateKey, nullptr);
+                xmlSecKeyPtr pKey = xmlSecKeyCreate();
+                xmlSecKeySetValue(pKey, pKeyData);
+                xmlSecNssAppDefaultKeysMngrAdoptKey(pKeysMngr, pKey);
+            }
+            else
+            {
+                SAL_WARN("xmlsecurity.xmlsec", "Can't get the private key from the certificate.");
+            }
         }
     }
 


More information about the Libreoffice-commits mailing list