cool#9992 lok doc sign: fix import of the private key
Once the signing key is taken from the matching SfxViewShell (not yet
done), signing with a certificate specified via initializeForRendering()
failed with:
warn:xmlsecurity.xmlsec:13020:13005:xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx:330: X509Certificate_NssImpl::getPrivateKey() cannot find private key
warn:xmlsecurity.xmlsec:13020:13005:xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx:812: Can't get the private key from the certificate.
warn:xmlsecurity.xmlsec:13020:13005:xmlsecurity/source/xmlsec/errorcallback.cxx:53: keys.c:1347: xmlSecKeysMngrGetKey() '' '' 45 'details=NULL'
warn:xmlsecurity.xmlsec:13020:13005:xmlsecurity/source/xmlsec/errorcallback.cxx:53: xmldsig.c:822: xmlSecDSigCtxProcessKeyInfoNode() '' '' 45 'details=NULL'
warn:xmlsecurity.xmlsec:13020:13005:xmlsecurity/source/xmlsec/errorcallback.cxx:53: xmldsig.c:537: xmlSecDSigCtxProcessSignatureNode() '' 'xmlSecDSigCtxProcessKeyInfoNode' 1 ' '
warn:xmlsecurity.xmlsec:13020:13005:xmlsecurity/source/xmlsec/errorcallback.cxx:53: xmldsig.c:301: xmlSecDSigCtxSign() '' 'xmlSecDSigCtxProcessSignatureNode' 1 ' '
The trouble was that we wanted to keep the private key in-memory,
presumably because initially the whole NSS database was in-memory for
the LOK case. This was changed in commit
87eec1b90b
(NSS: create a temporary
database instead of in-memory, 2018-12-31), so there is no problem with
a not-in-memory private key anymore.
Note that the problematic codepath was only triggered when first the
certificate chooser was ran and only then we signed. So the testcase
also gets the cert flags before signing, otherwise the test would
succeed even without the fix.
Change-Id: I5086b205c91b630ddd343c0eb91bd9e63b3ea238
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173892
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
parent
dd181a31d8
commit
d95ab8d3a3
7 changed files with 298 additions and 1 deletions
56
xmlsecurity/CppunitTest_xmlsecurity_xmlsec.mk
Normal file
56
xmlsecurity/CppunitTest_xmlsecurity_xmlsec.mk
Normal file
|
@ -0,0 +1,56 @@
|
|||
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
|
||||
#*************************************************************************
|
||||
#
|
||||
# This file is part of the LibreOffice project.
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
#*************************************************************************
|
||||
|
||||
$(eval $(call gb_CppunitTest_CppunitTest,xmlsecurity_xmlsec))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_externals,xmlsecurity_xmlsec,\
|
||||
boost_headers \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_add_exception_objects,xmlsecurity_xmlsec, \
|
||||
xmlsecurity/qa/xmlsec/xmlsec \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_libraries,xmlsecurity_xmlsec, \
|
||||
comphelper \
|
||||
cppu \
|
||||
cppuhelper \
|
||||
embobj \
|
||||
sal \
|
||||
sfx \
|
||||
subsequenttest \
|
||||
test \
|
||||
tl \
|
||||
unotest \
|
||||
utl \
|
||||
xmlsecurity \
|
||||
xsec_xmlsec \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_set_include,xmlsecurity_xmlsec,\
|
||||
-I$(SRCDIR)/xmlsecurity/inc \
|
||||
$$(INCLUDE) \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_sdk_api,xmlsecurity_xmlsec))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_ure,xmlsecurity_xmlsec))
|
||||
$(eval $(call gb_CppunitTest_use_vcl,xmlsecurity_xmlsec))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_rdb,xmlsecurity_xmlsec,services))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_custom_headers,xmlsecurity_xmlsec,\
|
||||
officecfg/registry \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_configuration,xmlsecurity_xmlsec))
|
||||
|
||||
# vim: set noet sw=4 ts=4:
|
|
@ -23,6 +23,12 @@ $(eval $(call gb_Module_add_slowcheck_targets,xmlsecurity,\
|
|||
CppunitTest_xmlsecurity_pdfsigning \
|
||||
))
|
||||
|
||||
ifeq ($(OS),LINUX)
|
||||
$(eval $(call gb_Module_add_slowcheck_targets,xmlsecurity,\
|
||||
CppunitTest_xmlsecurity_xmlsec \
|
||||
))
|
||||
endif
|
||||
|
||||
$(eval $(call gb_Module_add_subsequentcheck_targets,xmlsecurity,\
|
||||
CppunitTest_xmlsecurity_signing \
|
||||
CppunitTest_xmlsecurity_signing2 \
|
||||
|
|
70
xmlsecurity/qa/xmlsec/data/ca.pem
Normal file
70
xmlsecurity/qa/xmlsec/data/ca.pem
Normal file
|
@ -0,0 +1,70 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIGADCCA+igAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgYsxCzAJBgNVBAYTAlVL
|
||||
MRAwDgYDVQQIDAdFbmdsYW5kMTAwLgYDVQQKDCdDcHB1bml0VGVzdF94bWxzZWN1
|
||||
cml0eV94bWxzZWMgUlNBIFRlc3QxODA2BgNVBAMML0NwcHVuaXRUZXN0X3htbHNl
|
||||
Y3VyaXR5X3htbHNlYyBSU0EgVGVzdCBSb290IENBMCAXDTI0MDkyMzEzMzA0MloY
|
||||
DzIxMjQwODMwMTMzMDQyWjCBjzELMAkGA1UEBhMCVUsxEDAOBgNVBAgMB0VuZ2xh
|
||||
bmQxMDAuBgNVBAoMJ0NwcHVuaXRUZXN0X3htbHNlY3VyaXR5X3htbHNlYyBSU0Eg
|
||||
VGVzdDE8MDoGA1UEAwwzQ3BwdW5pdFRlc3RfeG1sc2VjdXJpdHlfeG1sc2VjIElu
|
||||
dGVybWVkaWF0ZSBSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AM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cWlvAp77swDwYDVR0TAQH/BAUwAwEB/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-----
|
31
xmlsecurity/qa/xmlsec/data/cert.pem
Normal file
31
xmlsecurity/qa/xmlsec/data/cert.pem
Normal file
|
@ -0,0 +1,31 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIFZjCCA06gAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVL
|
||||
MRAwDgYDVQQIDAdFbmdsYW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eGv91MRbH6vbE4W3cMYNMA4GA1UdDwEB
|
||||
/wQEAwIF4DAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwQwDQYJKoZIhvcN
|
||||
AQELBQADggIBABtgvYTKyfIZobgnsrO8PjbQIFdyx5YV0RJ8fshcSzSFSZYN0qbC
|
||||
J4U2i84Hx9HvzzFtHHEgJ4ot6VXsfEGqFkf8dvafqi1gAQ4cbIazdHQoELgFKJwL
|
||||
U5X/NGl0PQ46/l4vKHKrpAN1TRu7MGE0SwxRYM5KlzibXRL485ck/dzap8qSaxt/
|
||||
sSW6YxpttM3umPRL+5Mc+ttJBPYKAwfu/dHkBxGC47E/h2oazNOI2nhLsfbT2YmW
|
||||
yJpgt/hnqxB7LtZbnAnaMVEWGdlBp79vU6V0+JSznMmc4t1eX6mUl5tXQF+BSmpw
|
||||
f4agwi+uSE9WEXfhChjLfEtEGgK/+/tl012EqY8qt1SdwDDH8usEcrK2iyd14Wgs
|
||||
uH3swGqYdBaHnNaAgtuMDlQmJYaq5cKbaTj+PGLr5WU9VIXFSIM03dkyGA13I3ts
|
||||
cBpWfh3f89q6YoAqdgwUlCg1OqU4LsfS8n8EKvyM1+zb45JlNxzXpFp+/CwR7I2D
|
||||
Tk4QXELeFOl1KU7X9eTftliwAqctRGLCvr2VXA4FbkFhtreCctCQm/FUgIr01YrW
|
||||
mhr29Wwaz3DBeymbFXUdYQZqI0OSBBc1bDJkMHftpTBp79EoglKXqMb1/7jcV3bT
|
||||
oWXfkHN//B4B2gpv7DxHyP7H6teW/hGuCZeIhYDiL0TR1E68RO1sHRT1
|
||||
-----END CERTIFICATE-----
|
28
xmlsecurity/qa/xmlsec/data/key.pem
Normal file
28
xmlsecurity/qa/xmlsec/data/key.pem
Normal file
|
@ -0,0 +1,28 @@
|
|||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCVJ8MUN2UMm/Vh
|
||||
joA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8UbuxpNx5qGkmcdAgbOsQJ4m7BERrVQItDsv
|
||||
mbNpo4gzgQKBgBVmb+21TlGSay7LNxQYBThV5YqqWGk1cMTk8cBetc9vG8qv4zHT
|
||||
oGNvLOJZaPyCWPWGRsUXgJPosRUri1L+W9GCarajiP/rzroSWiH+IhJQl/dm6j5P
|
||||
9eiAP1Z4zOZ7U8ZGOQXm+dmDonkT8f3zArN8DduKRpf8h92CWJqk7IwBAoGAa7m7
|
||||
V3/i/zxmvbFzW5DhFo+zWejLO4LPVvPHy+ybmcT7G0+EwLhRa0XVFaNLYWZXTn3S
|
||||
2L7xKfXRGgK1UawhD4chOFVzSXVk8GoWbJ9u8+eeJWxy8u6OxMMi8iolTT3D0UkF
|
||||
CS9YsQRB49JfXZqsjQ3EAMv6xoRFVDkd506bM4ECgYBPN8B6QpENSsVoVGcS/gpR
|
||||
hLno9fIvIhABCDoYNTkNT6ILJ8BcU7+lv/zs8UQacqf6Fy7JozbBeEY/Dxr97DKg
|
||||
e5djZvWYLqmvAiPilN5YEt5WvuswzrGaTcol/E3X5B3aACFFE8+O9i8T2q0VlAot
|
||||
hC+h7nh0KmPyzL73JUX2Jg==
|
||||
-----END PRIVATE KEY-----
|
104
xmlsecurity/qa/xmlsec/xmlsec.cxx
Normal file
104
xmlsecurity/qa/xmlsec/xmlsec.cxx
Normal file
|
@ -0,0 +1,104 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <test/unoapi_test.hxx>
|
||||
|
||||
#include <com/sun/star/embed/XStorage.hpp>
|
||||
#include <com/sun/star/xml/crypto/SEInitializer.hpp>
|
||||
|
||||
#include <comphelper/storagehelper.hxx>
|
||||
#include <sfx2/lokhelper.hxx>
|
||||
|
||||
#include <documentsignaturemanager.hxx>
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
|
||||
namespace
|
||||
{
|
||||
/// Covers xmlsecurity/source/xmlsec/ fixes.
|
||||
class Test : public UnoApiTest
|
||||
{
|
||||
public:
|
||||
Test()
|
||||
: UnoApiTest("/xmlsecurity/qa/xmlsec/data/")
|
||||
{
|
||||
}
|
||||
|
||||
void setUp() override
|
||||
{
|
||||
UnoApiTest::setUp();
|
||||
MacrosTest::setUpX509(m_directories, "xmlsecurity_xmlsec");
|
||||
}
|
||||
};
|
||||
|
||||
OString ReadToString(const OUString& rUrl)
|
||||
{
|
||||
SvFileStream aStream(rUrl, StreamMode::READ);
|
||||
return read_uInt8s_ToOString(aStream, aStream.remainingSize());
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(Test, testInsertPrivateKey)
|
||||
{
|
||||
// Given a view that has CA/cert/key data data associated:
|
||||
uno::Reference<xml::crypto::XSEInitializer> mxSEInitializer
|
||||
= xml::crypto::SEInitializer::create(getComponentContext());
|
||||
uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext
|
||||
= mxSEInitializer->createSecurityContext(OUString());
|
||||
load("private:factory/swriter");
|
||||
save("writer8");
|
||||
DocumentSignatureManager aManager(getComponentContext(), DocumentSignatureMode::Content);
|
||||
CPPUNIT_ASSERT(aManager.init());
|
||||
uno::Reference<embed::XStorage> xStorage
|
||||
= comphelper::OStorageHelper::GetStorageOfFormatFromURL(
|
||||
ZIP_STORAGE_FORMAT_STRING, maTempFile.GetURL(), embed::ElementModes::READWRITE);
|
||||
CPPUNIT_ASSERT(xStorage.is());
|
||||
aManager.setStore(xStorage);
|
||||
aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
|
||||
OUString aCaPath = createFileURL(u"ca.pem");
|
||||
std::string aCa;
|
||||
aCa = ReadToString(aCaPath);
|
||||
std::vector<std::string> aCerts = SfxLokHelper::extractCertificates(aCa);
|
||||
SfxLokHelper::addCertificates(aCerts);
|
||||
OUString aCertPath = createFileURL(u"cert.pem");
|
||||
std::string aCert;
|
||||
aCert = ReadToString(aCertPath);
|
||||
OUString aKeyPath;
|
||||
aKeyPath = createFileURL(u"key.pem");
|
||||
std::string aKey;
|
||||
aKey = ReadToString(aKeyPath);
|
||||
uno::Reference<security::XCertificate> xCertificate
|
||||
= SfxLokHelper::getSigningCertificate(aCert, aKey);
|
||||
CPPUNIT_ASSERT(xCertificate.is());
|
||||
|
||||
// When getting the certificate flags and signing:
|
||||
uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment
|
||||
= xSecurityContext->getSecurityEnvironment();
|
||||
// Get the certificate flags, the certificate chooser dialog does this:
|
||||
xSecurityEnvironment->getCertificateCharacters(xCertificate);
|
||||
OUString aDescription;
|
||||
sal_Int32 nSecurityId;
|
||||
CPPUNIT_ASSERT(aManager.add(xCertificate, xSecurityContext, aDescription, nSecurityId, false));
|
||||
|
||||
// Then make sure that signing succeeds:
|
||||
aManager.read(/*bUseTempStream=*/true);
|
||||
std::vector<SignatureInformation>& rInformations = aManager.getCurrentSignatureInformations();
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(1), rInformations.size());
|
||||
// Without the accompanying fix in place, this test would have failed with:
|
||||
// - Expected: 0 (UNKNOWN)
|
||||
// - Actual : 1 (OPERATION_SUCCEEDED)
|
||||
// i.e. the signing failed with an incorrectly imported private key.
|
||||
CPPUNIT_ASSERT_EQUAL(
|
||||
xml::crypto::SecurityOperationStatus::SecurityOperationStatus_OPERATION_SUCCEEDED,
|
||||
rInformations[0].nStatus);
|
||||
}
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
|
@ -843,7 +843,9 @@ SECKEYPrivateKey* SecurityEnvironment_NssImpl::insertPrivateKey(css::uno::Sequen
|
|||
const unsigned int aKeyUsage = KU_ALL;
|
||||
SECKEYPrivateKey* pPrivateKey = nullptr;
|
||||
|
||||
bool bPermanent = PR_FALSE;
|
||||
// If the import is not permanent, then later we won't be able to find the private key when
|
||||
// searching for keys and signing will fail.
|
||||
bool bPermanent = PR_TRUE;
|
||||
bool bPrivate = PR_TRUE;
|
||||
|
||||
SECStatus nStatus = PK11_ImportDERPrivateKeyInfoAndReturnKey(
|
||||
|
|
Loading…
Reference in a new issue