diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-10-24 11:29:32 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-11-08 16:10:53 +0100 |
commit | b97f3988183dab39b2b0231d9fd0e55d078ac0b5 (patch) | |
tree | 2ee7a4aac291b67653c6cf8657114089cdac1f62 /desktop | |
parent | e9b8daaa8a454453c55ae518c746eafb63fb26d4 (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>
(cherry picked from commit 28a698db6f604137443053144dde94c9e553c0ef)
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/data/signed.odt | bin | 0 -> 13528 bytes | |||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 50 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 2 |
3 files changed, 49 insertions, 3 deletions
diff --git a/desktop/qa/data/signed.odt b/desktop/qa/data/signed.odt Binary files differnew file mode 100644 index 000000000000..49bd9dd240fe --- /dev/null +++ b/desktop/qa/data/signed.odt diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 802e1b7d2a71..57c89e134a97 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 e90fb96f3c0c..c471b89a4381 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -3803,6 +3803,8 @@ static int doc_getSignatureState(LibreOfficeKitDocument* pThis) if (!pObjectShell) return int(SignatureState::UNKNOWN); + pObjectShell->RecheckSignature(false); + return int(pObjectShell->GetDocumentSignatureState()); } |