diff options
12 files changed, 57 insertions, 34 deletions
diff --git a/xmlsecurity/Library_xsec_xmlsec.mk b/xmlsecurity/Library_xsec_xmlsec.mk index 615c3eba0032..23997aa2bfae 100644 --- a/xmlsecurity/Library_xsec_xmlsec.mk +++ b/xmlsecurity/Library_xsec_xmlsec.mk @@ -64,6 +64,7 @@ $(eval $(call gb_Library_use_externals,xsec_xmlsec,\ $(eval $(call gb_Library_add_exception_objects,xsec_xmlsec,\ xmlsecurity/source/xmlsec/biginteger \ + xmlsecurity/source/xmlsec/certificate \ xmlsecurity/source/xmlsec/certificateextension_certextn \ xmlsecurity/source/xmlsec/errorcallback \ xmlsecurity/source/xmlsec/saxhelper \ diff --git a/xmlsecurity/inc/certificate.hxx b/xmlsecurity/inc/certificate.hxx index 8357f50651a1..885fcc8bd5ff 100644 --- a/xmlsecurity/inc/certificate.hxx +++ b/xmlsecurity/inc/certificate.hxx @@ -11,7 +11,13 @@ #include <sal/types.h> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/security/XCertificate.hpp> #include <com/sun/star/uno/Sequence.hxx> +#include <cppuhelper/implbase.hxx> + +#include "xsecxmlsecdllapi.h" namespace svl { @@ -23,8 +29,10 @@ enum class SignatureMethodAlgorithm; namespace xmlsecurity { -/// Extension of css::security::XCertificate for module-internal purposes. -class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI SAL_LOPLUGIN_ANNOTATE("crosscast") Certificate +/// Base class of css::security::XCertificate implementations, for module-internal purposes. +class XSECXMLSEC_DLLPUBLIC Certificate + : public ::cppu::WeakImplHelper<css::security::XCertificate, css::lang::XUnoTunnel, + css::lang::XServiceInfo> { public: /// Returns the SHA-256 thumbprint. @@ -35,6 +43,9 @@ public: /// Same as getSubjectPublicKeyAlgorithm(), but returns an ID, not a string. virtual svl::crypto::SignatureMethodAlgorithm getSignatureMethodAlgorithm() = 0; + sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const& aIdentifier) override; + static css::uno::Sequence<sal_Int8> const& getUnoTunnelId(); + protected: ~Certificate() noexcept = default; }; diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index d8518ece0f9b..d75c93de1a4a 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -33,6 +33,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> +#include <comphelper/servicehelper.hxx> #include <unotools/mediadescriptor.hxx> #include <unotools/tempfile.hxx> #include <unotools/ucbstreamhelper.hxx> @@ -127,7 +128,7 @@ SigningTest::getCertificate(DocumentSignatureManager& rSignatureManager, for (const auto& xCertificate : aCertificates) { - auto pCertificate = dynamic_cast<xmlsecurity::Certificate*>(xCertificate.get()); + auto pCertificate = comphelper::getFromUnoTunnel<xmlsecurity::Certificate>(xCertificate); CPPUNIT_ASSERT(pCertificate); if (pCertificate->getSignatureMethodAlgorithm() == eAlgo && IsValid(xCertificate, xSecurityEnvironment)) diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index 990fa5dea739..d6b5782ba74f 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -52,6 +52,7 @@ #include <comphelper/documentconstants.hxx> #include <comphelper/propertyvalue.hxx> #include <comphelper/sequence.hxx> +#include <comphelper/servicehelper.hxx> #include <cppuhelper/implbase.hxx> #include <comphelper/xmlsechelper.hxx> #include <cppuhelper/supportsservice.hxx> @@ -685,8 +686,8 @@ sal_Bool DocumentDigitalSignatures::isAuthorTrusted( return false; uno::Reference<css::security::XCertificate> xCert = aSignatureManager.getSecurityEnvironment()->createCertificateFromAscii(rAuthor.RawData); - auto pAuthor = dynamic_cast<xmlsecurity::Certificate*>(xAuthor.get()); - auto pCert = dynamic_cast<xmlsecurity::Certificate*>(xCert.get()); + auto pAuthor = comphelper::getFromUnoTunnel<xmlsecurity::Certificate>(xAuthor); + auto pCert = comphelper::getFromUnoTunnel<xmlsecurity::Certificate>(xCert); if (pAuthor && pCert) return pCert->getSHA256Thumbprint() == pAuthor->getSHA256Thumbprint(); diff --git a/xmlsecurity/source/gpg/CertificateImpl.cxx b/xmlsecurity/source/gpg/CertificateImpl.cxx index a0a08fc807a8..ae2c4544e001 100644 --- a/xmlsecurity/source/gpg/CertificateImpl.cxx +++ b/xmlsecurity/source/gpg/CertificateImpl.cxx @@ -196,7 +196,8 @@ sal_Int32 SAL_CALL CertificateImpl::getCertificateUsage() /* XUnoTunnel */ sal_Int64 SAL_CALL CertificateImpl::getSomething(const Sequence< sal_Int8 >& aIdentifier) { - return comphelper::getSomethingImpl(aIdentifier, this); + return comphelper::getSomethingImpl( + aIdentifier, this, comphelper::FallbackToGetSomethingOf<xmlsecurity::Certificate>{}); } /* XUnoTunnel extension */ diff --git a/xmlsecurity/source/gpg/CertificateImpl.hxx b/xmlsecurity/source/gpg/CertificateImpl.hxx index b6c50cb2ed5c..1c845f5dc103 100644 --- a/xmlsecurity/source/gpg/CertificateImpl.hxx +++ b/xmlsecurity/source/gpg/CertificateImpl.hxx @@ -14,13 +14,9 @@ #include <sal/types.h> #include <sal/config.h> #include <rtl/ustring.hxx> -#include <cppuhelper/implbase.hxx> #include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/security/CertificateKind.hpp> -#include <com/sun/star/security/XCertificate.hpp> #if defined _MSC_VER && defined __clang__ #pragma clang diagnostic push @@ -31,10 +27,7 @@ #pragma clang diagnostic pop #endif -class CertificateImpl : public cppu::WeakImplHelper< css::security::XCertificate, - css::lang::XUnoTunnel, - css::lang::XServiceInfo >, - public xmlsecurity::Certificate +class CertificateImpl : public xmlsecurity::Certificate { private: GpgME::Key m_pKey; diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index cd08aadacc13..5c6c9efea726 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -37,6 +37,7 @@ #include <com/sun/star/frame/XModel.hpp> #include <comphelper/base64.hxx> +#include <comphelper/servicehelper.hxx> #include <comphelper/storagehelper.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> @@ -331,7 +332,7 @@ bool DocumentSignatureManager::add( comphelper::Base64::encode(aStrBuffer, xCert->getEncoded()); OUString aKeyId; - if (auto pCertificate = dynamic_cast<xmlsecurity::Certificate*>(xCert.get())) + if (auto pCertificate = comphelper::getFromUnoTunnel<xmlsecurity::Certificate>(xCert)) { OUStringBuffer aBuffer; comphelper::Base64::encode(aBuffer, pCertificate->getSHA256Thumbprint()); @@ -378,7 +379,7 @@ bool DocumentSignatureManager::add( OUString aCertDigest; svl::crypto::SignatureMethodAlgorithm eAlgorithmID = svl::crypto::SignatureMethodAlgorithm::RSA; - if (auto pCertificate = dynamic_cast<xmlsecurity::Certificate*>(xCert.get())) + if (auto pCertificate = comphelper::getFromUnoTunnel<xmlsecurity::Certificate>(xCert)) { OUStringBuffer aBuffer; comphelper::Base64::encode(aBuffer, pCertificate->getSHA256Thumbprint()); diff --git a/xmlsecurity/source/xmlsec/certificate.cxx b/xmlsecurity/source/xmlsec/certificate.cxx new file mode 100644 index 000000000000..f43273a47518 --- /dev/null +++ b/xmlsecurity/source/xmlsec/certificate.cxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <sal/config.h> + +#include <comphelper/servicehelper.hxx> + +#include <certificate.hxx> + +sal_Int64 xmlsecurity::Certificate::getSomething(css::uno::Sequence<sal_Int8> const& aIdentifier) +{ + return comphelper::getSomethingImpl(aIdentifier, this); +} + +css::uno::Sequence<sal_Int8> const& xmlsecurity::Certificate::getUnoTunnelId() +{ + static comphelper::UnoIdInit const id; + return id.getSeq(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx index 88bf6169bf11..96d4b691d3d4 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx +++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx @@ -458,7 +458,7 @@ void X509Certificate_MSCryptImpl::setRawCert( Sequence< sal_Int8 > const & rawCe } /* XUnoTunnel */ -UNO3_GETIMPLEMENTATION_IMPL(X509Certificate_MSCryptImpl); +UNO3_GETIMPLEMENTATION2_IMPL(X509Certificate_MSCryptImpl, Certificate); static OUString findOIDDescription(char const *oid) { diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx index 9bd6a34ce68e..53016dd6c438 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx +++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx @@ -27,20 +27,13 @@ #include <sal/config.h> #include <rtl/ustring.hxx> #include <cppuhelper/factory.hxx> -#include <cppuhelper/implbase.hxx> #include <comphelper/servicehelper.hxx> #include <com/sun/star/uno/Exception.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/SecurityException.hpp> #include <com/sun/star/security/CertificateKind.hpp> -#include <com/sun/star/security/XCertificate.hpp> #include <certificate.hxx> -class X509Certificate_MSCryptImpl : public ::cppu::WeakImplHelper< - css::security::XCertificate , - css::lang::XUnoTunnel, - css::lang::XServiceInfo > , public xmlsecurity::Certificate +class X509Certificate_MSCryptImpl : public xmlsecurity::Certificate { private: const CERT_CONTEXT* m_pCertContext ; diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx index 79441da1edf5..b737a845fb45 100644 --- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx @@ -334,7 +334,8 @@ SECKEYPrivateKey* X509Certificate_NssImpl::getPrivateKey() /* XUnoTunnel */ sal_Int64 SAL_CALL X509Certificate_NssImpl::getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) { - return comphelper::getSomethingImpl(aIdentifier, this); + return comphelper::getSomethingImpl( + aIdentifier, this, comphelper::FallbackToGetSomethingOf<xmlsecurity::Certificate>{}); } /* XUnoTunnel extension */ diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx index dbfb6c6b07ed..26d85a09f491 100644 --- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx +++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx @@ -21,20 +21,13 @@ #include <sal/config.h> #include <rtl/ustring.hxx> -#include <cppuhelper/implbase.hxx> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/security/CertificateKind.hpp> -#include <com/sun/star/security/XCertificate.hpp> #include <certificate.hxx> #include <certt.h> #include <keythi.h> -class X509Certificate_NssImpl : public ::cppu::WeakImplHelper< - css::security::XCertificate , - css::lang::XUnoTunnel, - css::lang::XServiceInfo > , public xmlsecurity::Certificate +class X509Certificate_NssImpl : public xmlsecurity::Certificate { private: CERTCertificate* m_pCert; |