diff --git a/sfx2/qa/cppunit/data/ca.pem b/sfx2/qa/cppunit/data/ca.pem new file mode 100644 index 000000000000..d08c9c67bcae --- /dev/null +++ b/sfx2/qa/cppunit/data/ca.pem @@ -0,0 +1,70 @@ +-----BEGIN CERTIFICATE----- +MIIGADCCA+igAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgYsxCzAJBgNVBAYTAlVL +MRAwDgYDVQQIDAdFbmdsYW5kMTAwLgYDVQQKDCdDcHB1bml0VGVzdF94bWxzZWN1 +cml0eV94bWxzZWMgUlNBIFRlc3QxODA2BgNVBAMML0NwcHVuaXRUZXN0X3htbHNl +Y3VyaXR5X3htbHNlYyBSU0EgVGVzdCBSb290IENBMCAXDTI0MDkyMzEzMzA0MloY +DzIxMjQwODMwMTMzMDQyWjCBjzELMAkGA1UEBhMCVUsxEDAOBgNVBAgMB0VuZ2xh +bmQxMDAuBgNVBAoMJ0NwcHVuaXRUZXN0X3htbHNlY3VyaXR5X3htbHNlYyBSU0Eg +VGVzdDE8MDoGA1UEAwwzQ3BwdW5pdFRlc3RfeG1sc2VjdXJpdHlfeG1sc2VjIElu +dGVybWVkaWF0ZSBSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKC +AgEAj9kribqN994fmGGnL7l3Y4DEVEBUBV2kNlq9fM9wJmOEtaNyKIjYxzCFUAnt +vKp0youu3tu48duDUez4I+Nc4gyez6IlyfPCXiEJulo0g6F3WZZg/xtk56JZnHFe +aBHq3vm3L7a5y8c9j9Y26/BPRAqY1CtBSFUWV1uGPCQkNGNsO7qqtOdcKn7dFJq3 +K2sRaXp4J3QUhtlsEQ4/sWtXjuV7f4wqep0PEjFJ8oF6Jao5QYFHuLx4YZmo9vfX +NSjv1TJbdQ+1zvw8sr3/SYyNt3B7Q3jXq8IC+Tfc1R9t/FaDeS9AiMuDJgq+aHWV +ej8sspl2+d7mFXCuOoy9nE9aCWAwD1v6Ce1nK97qVUKRKxBxlKSM3TULWaJT8VC9 +UK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63NGuiLnhU1lbQRkTC0Dq0qenECx2gmG8XG +FHlVbVsYqiaU6FdkFGzm+Scsl8UwygLV5KP0Y/54X8J6ZSRPHNRvBtRnZoRrjNFM +wSJZ4vw/iDJO03o31TJ3 +-----END CERTIFICATE----- diff --git a/sfx2/qa/cppunit/data/signed.odt b/sfx2/qa/cppunit/data/signed.odt new file mode 100644 index 000000000000..5fc1be981d37 Binary files /dev/null and b/sfx2/qa/cppunit/data/signed.odt differ diff --git a/sfx2/qa/cppunit/view.cxx b/sfx2/qa/cppunit/view.cxx index 8248a502e012..91dc6703595b 100644 --- a/sfx2/qa/cppunit/view.cxx +++ b/sfx2/qa/cppunit/view.cxx @@ -20,6 +20,7 @@ #include #include #include +#include using namespace com::sun::star; @@ -31,6 +32,12 @@ public: : UnoApiTest(u"/sfx2/qa/cppunit/data/"_ustr) { } + + void setUp() override + { + UnoApiTest::setUp(); + MacrosTest::setUpX509(m_directories, "sfx2_view"); + } }; CPPUNIT_TEST_FIXTURE(Sfx2ViewTest, testReloadPage) @@ -78,6 +85,32 @@ bar CPPUNIT_ASSERT_EQUAL(std::string("\nbar\n"), aRet[1]); } +#ifdef UNX +CPPUNIT_TEST_FIXTURE(Sfx2ViewTest, testLokHelperAddCertifices) +{ + // Given a loaded and signed document, CA is not trusted by default: + loadFromFile(u"signed.odt"); + auto pBaseModel = dynamic_cast(mxComponent.get()); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT_EQUAL(SignatureState::NOTVALIDATED, pObjectShell->GetDocumentSignatureState()); + + // When trusting the CA: + OUString aCaUrl = createFileURL(u"ca.pem"); + SvFileStream aCaStream(aCaUrl, StreamMode::READ); + std::string aCa; + aCa = read_uInt8s_ToOString(aCaStream, aCaStream.remainingSize()); + std::vector aCerts = SfxLokHelper::extractCertificates(aCa); + SfxLokHelper::addCertificates(aCerts); + + // Then make sure the signature state is updated: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 (OK) + // - Actual : 4 (SignatureState::NOTVALIDATED) + // i.e. the signature status for an opened document was not updated when trusting a CA. + CPPUNIT_ASSERT_EQUAL(SignatureState::OK, pObjectShell->GetDocumentSignatureState()); +} +#endif + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 136b72357ea2..ebee96a33952 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -981,6 +981,15 @@ void SfxLokHelper::addCertificates(const std::vector& rCerts) comphelper::Base64::decode(aCertificateSequence, aBase64OUString); addCertificate(xCertificateCreator, aCertificateSequence); } + + // Update the signature state, perhaps the signing certificate is now trusted. + SfxObjectShell* pObjectShell = SfxObjectShell::Current(); + if (!pObjectShell) + { + return; + } + + pObjectShell->RecheckSignature(false); } void SfxLokHelper::notifyUpdate(SfxViewShell const* pThisView, int nType)