cool#9992 lok doc sign: update sign status after modify the list of trusted CAs
Load a document, sign it, "green" icon on the status bar. Reload the document, turns into a "yellow" icon saying the CA is not trusted, when it was already trusted before. The trouble is that the document signature status is calculated on load, and the CA to be trusted is only given later, as part of the initialization of the LOK view. Fix the problem by invalidating the signature state when a new CA is trusted. The test document was produced by signing an empty document using the keys from xmlsecurity/qa/xmlsec/data/, which gives us a way to create a signature that is initially not trusted. Change-Id: I1e1dbf616ce54c4823d62104f838342de6870f52 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174307 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
parent
0a3e1df7af
commit
298c2d5c8a
4 changed files with 112 additions and 0 deletions
70
sfx2/qa/cppunit/data/ca.pem
Normal file
70
sfx2/qa/cppunit/data/ca.pem
Normal file
|
@ -0,0 +1,70 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIGADCCA+igAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgYsxCzAJBgNVBAYTAlVL
|
||||
MRAwDgYDVQQIDAdFbmdsYW5kMTAwLgYDVQQKDCdDcHB1bml0VGVzdF94bWxzZWN1
|
||||
cml0eV94bWxzZWMgUlNBIFRlc3QxODA2BgNVBAMML0NwcHVuaXRUZXN0X3htbHNl
|
||||
Y3VyaXR5X3htbHNlYyBSU0EgVGVzdCBSb290IENBMCAXDTI0MDkyMzEzMzA0MloY
|
||||
DzIxMjQwODMwMTMzMDQyWjCBjzELMAkGA1UEBhMCVUsxEDAOBgNVBAgMB0VuZ2xh
|
||||
bmQxMDAuBgNVBAoMJ0NwcHVuaXRUZXN0X3htbHNlY3VyaXR5X3htbHNlYyBSU0Eg
|
||||
VGVzdDE8MDoGA1UEAwwzQ3BwdW5pdFRlc3RfeG1sc2VjdXJpdHlfeG1sc2VjIElu
|
||||
dGVybWVkaWF0ZSBSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKC
|
||||
AgEAj9kribqN994f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AwEB/zAOBgNV
|
||||
HQ8BAf8EBAMCAYYwDQYJKoZIhvcNAQELBQADggIBAC4errXBxYjJGtxT+5+VwISk
|
||||
4ve5nGna8/SNxt7VB0mREG91gnsu3uJvW05zoU+UUOHaaDvAuox2GGEAq/vKJN5y
|
||||
TpgnSYSgzFYxd8N+GqFqE3xwIPa02ntPwwLozF3aph4YcqrtCdPPNIXK5CRopnvQ
|
||||
LuUHwFvmz/nkoCPg/VlwFjxNvwGehy5wrhd3zmqd9dga8k3MWA+cVVtNnZld5HZu
|
||||
rpHOb3H7SCG+3l/kMdnMQCLvUrbKGSVKX6bOaW+FGm+oTTwLen/HHB21wxfPLySQ
|
||||
QDEyR1qGNj7sKgGaWU8334boSSjW3OrnHDLlMBr/XQAMgvHfy43qxOmww47xg685
|
||||
HNQYtbHIgVLZ6ou8vgzrjzV+Wpu8H7by2HH/yAHwRqsy2nmVPwkrdmCfSwYfZdAW
|
||||
+Jzazg4gYVnBE89t8HarOXSiSh/YUS0V6F4koQKVv3b8MzmqO3ldRW2JcktrmZmU
|
||||
BYCh5UaK3X+Yyeus1UGrYCl6Yqj5M1JEmYmX/3EVeIcEK+H6Kx9Aeqr1WyJss0GT
|
||||
KVA5t+mOZ+SSvF3mFLxTo6ydTLOWA63NGuiLnhU1lbQRkTC0Dq0qenECx2gmG8XG
|
||||
FHlVbVsYqiaU6FdkFGzm+Scsl8UwygLV5KP0Y/54X8J6ZSRPHNRvBtRnZoRrjNFM
|
||||
wSJZ4vw/iDJO03o31TJ3
|
||||
-----END CERTIFICATE-----
|
BIN
sfx2/qa/cppunit/data/signed.odt
Normal file
BIN
sfx2/qa/cppunit/data/signed.odt
Normal file
Binary file not shown.
|
@ -20,6 +20,7 @@
|
|||
#include <sfx2/request.hxx>
|
||||
#include <sfx2/bindings.hxx>
|
||||
#include <sfx2/lokhelper.hxx>
|
||||
#include <sfx2/sfxbasemodel.hxx>
|
||||
|
||||
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<SfxBaseModel*>(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<std::string> 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: */
|
||||
|
|
|
@ -981,6 +981,15 @@ void SfxLokHelper::addCertificates(const std::vector<std::string>& 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)
|
||||
|
|
Loading…
Reference in a new issue