summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToma┼ż Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-10-24 11:29:32 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-11-06 17:20:41 +0100
commit28a698db6f604137443053144dde94c9e553c0ef (patch)
tree5543de4babfd2a07bf6f058ccf362029a30c3681
parent178f5210e658325a705dda675c7d0c05421eea9f (diff)
lok: trigger sign. verification in getSignatureState + update test
As the certificate chain can be added after the document was opened, we need to trigger signature verification every time the LOK API method getSignatureState is called. In addition update the tests so that they check the status of a document that's not signed, a document that was signed but the certificate chain is not available so the verification fails and later adding the certificate chain and the verification returns an OK status. Change-Id: I44578d0cece5bfc4a2e43fbbcd68b5ea1ccbc38b Reviewed-on: https://gerrit.libreoffice.org/62276 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--desktop/qa/data/signed.odtbin0 -> 13528 bytes
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx50
-rw-r--r--desktop/source/lib/init.cxx2
3 files changed, 49 insertions, 3 deletions
diff --git a/desktop/qa/data/signed.odt b/desktop/qa/data/signed.odt
new file mode 100644
index 000000000000..49bd9dd240fe
--- /dev/null
+++ b/desktop/qa/data/signed.odt
Binary files differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index ab0e98033b55..389d84a0cc31 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -118,7 +118,8 @@ public:
void testCommentsCallbacksWriter();
void testRunMacro();
void testExtractParameter();
- void testGetSignatureState();
+ void testGetSignatureState_NonSigned();
+ void testGetSignatureState_Signed();
void testInsertCertificate();
void testABI();
@@ -163,7 +164,8 @@ public:
CPPUNIT_TEST(testCommentsCallbacksWriter);
CPPUNIT_TEST(testRunMacro);
CPPUNIT_TEST(testExtractParameter);
- CPPUNIT_TEST(testGetSignatureState);
+ CPPUNIT_TEST(testGetSignatureState_Signed);
+ CPPUNIT_TEST(testGetSignatureState_NonSigned);
CPPUNIT_TEST(testInsertCertificate);
CPPUNIT_TEST(testABI);
CPPUNIT_TEST_SUITE_END();
@@ -2246,7 +2248,49 @@ void DesktopLOKTest::testExtractParameter()
comphelper::LibreOfficeKit::setActive(false);
}
-void DesktopLOKTest::testGetSignatureState()
+void DesktopLOKTest::testGetSignatureState_Signed()
+{
+ comphelper::LibreOfficeKit::setActive();
+ LibLODocument_Impl* pDocument = loadDoc("signed.odt");
+ Scheduler::ProcessEventsToIdle();
+ pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+ int nState = pDocument->m_pDocumentClass->getSignatureState(pDocument);
+ CPPUNIT_ASSERT_EQUAL(int(4), nState);
+
+ {
+ OUString aCertificateURL;
+ createFileURL("rootCA.der", aCertificateURL);
+ SvFileStream aCertificateStream(aCertificateURL, StreamMode::READ);
+ std::vector<unsigned char> aCertificate;
+ aCertificate.resize(aCertificateStream.remainingSize());
+ aCertificateStream.ReadBytes(aCertificate.data(), aCertificateStream.remainingSize());
+
+ bool bResult = pDocument->m_pDocumentClass->addCertificate(
+ pDocument, aCertificate.data(), int(aCertificate.size()));
+ CPPUNIT_ASSERT(bResult);
+ }
+
+ {
+ OUString aCertificateURL;
+ createFileURL("intermediateRootCA.der", aCertificateURL);
+ SvFileStream aCertificateStream(aCertificateURL, StreamMode::READ);
+ std::vector<unsigned char> aCertificate;
+ aCertificate.resize(aCertificateStream.remainingSize());
+ aCertificateStream.ReadBytes(aCertificate.data(), aCertificateStream.remainingSize());
+
+
+ bool bResult = pDocument->m_pDocumentClass->addCertificate(
+ pDocument, aCertificate.data(), int(aCertificate.size()));
+ CPPUNIT_ASSERT(bResult);
+ }
+
+ nState = pDocument->m_pDocumentClass->getSignatureState(pDocument);
+ CPPUNIT_ASSERT_EQUAL(int(1), nState);
+
+ comphelper::LibreOfficeKit::setActive(false);
+}
+
+void DesktopLOKTest::testGetSignatureState_NonSigned()
{
comphelper::LibreOfficeKit::setActive();
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index cc49f86e6d85..faf1dfa40936 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -3752,6 +3752,8 @@ static int doc_getSignatureState(LibreOfficeKitDocument* pThis)
if (!pObjectShell)
return int(SignatureState::UNKNOWN);
+ pObjectShell->RecheckSignature(false);
+
return int(pObjectShell->GetDocumentSignatureState());
}