Kaydet (Commit) 28a698db authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

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: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 178f5210
...@@ -118,7 +118,8 @@ public: ...@@ -118,7 +118,8 @@ public:
void testCommentsCallbacksWriter(); void testCommentsCallbacksWriter();
void testRunMacro(); void testRunMacro();
void testExtractParameter(); void testExtractParameter();
void testGetSignatureState(); void testGetSignatureState_NonSigned();
void testGetSignatureState_Signed();
void testInsertCertificate(); void testInsertCertificate();
void testABI(); void testABI();
...@@ -163,7 +164,8 @@ public: ...@@ -163,7 +164,8 @@ public:
CPPUNIT_TEST(testCommentsCallbacksWriter); CPPUNIT_TEST(testCommentsCallbacksWriter);
CPPUNIT_TEST(testRunMacro); CPPUNIT_TEST(testRunMacro);
CPPUNIT_TEST(testExtractParameter); CPPUNIT_TEST(testExtractParameter);
CPPUNIT_TEST(testGetSignatureState); CPPUNIT_TEST(testGetSignatureState_Signed);
CPPUNIT_TEST(testGetSignatureState_NonSigned);
CPPUNIT_TEST(testInsertCertificate); CPPUNIT_TEST(testInsertCertificate);
CPPUNIT_TEST(testABI); CPPUNIT_TEST(testABI);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -2246,7 +2248,49 @@ void DesktopLOKTest::testExtractParameter() ...@@ -2246,7 +2248,49 @@ void DesktopLOKTest::testExtractParameter()
comphelper::LibreOfficeKit::setActive(false); 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(); comphelper::LibreOfficeKit::setActive();
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
......
...@@ -3752,6 +3752,8 @@ static int doc_getSignatureState(LibreOfficeKitDocument* pThis) ...@@ -3752,6 +3752,8 @@ static int doc_getSignatureState(LibreOfficeKitDocument* pThis)
if (!pObjectShell) if (!pObjectShell)
return int(SignatureState::UNKNOWN); return int(SignatureState::UNKNOWN);
pObjectShell->RecheckSignature(false);
return int(pObjectShell->GetDocumentSignatureState()); return int(pObjectShell->GetDocumentSignatureState());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment