diff options
author | Noel <noel.grandin@collabora.co.uk> | 2021-02-18 15:06:04 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-02-19 07:35:20 +0100 |
commit | 1e8e8327847c18e6dac09615d7d905298f608e8c (patch) | |
tree | 7f078a43921d7b1ad402a9f03df7420faac993b4 /xmlsecurity | |
parent | ce671c2275195f7545366ec9a11100c105ac366b (diff) |
loplugin:refcounting in xmlsecurity
Change-Id: Ic5227df4bd5b1f3dfe9cd13ae971d268a40f0fcf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111120
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlsecurity')
7 files changed, 54 insertions, 74 deletions
diff --git a/xmlsecurity/source/gpg/SecurityEnvironment.cxx b/xmlsecurity/source/gpg/SecurityEnvironment.cxx index 290529bc8ae6..98db7e420a38 100644 --- a/xmlsecurity/source/gpg/SecurityEnvironment.cxx +++ b/xmlsecurity/source/gpg/SecurityEnvironment.cxx @@ -15,6 +15,7 @@ #include <comphelper/servicehelper.hxx> #include <vector> +#include <rtl/ref.hxx> #ifdef _WIN32 #include <config_folders.h> @@ -116,9 +117,8 @@ OUString SecurityEnvironmentGpg::getSecurityEnvironmentInformation() Sequence< Reference < XCertificate > > SecurityEnvironmentGpg::getCertificatesImpl( bool bPrivateOnly ) { - CertificateImpl* xCert; std::vector< GpgME::Key > keyList; - std::vector< CertificateImpl* > certsList; + std::vector< rtl::Reference<CertificateImpl> > certsList; m_ctx->setKeyListMode(GPGME_KEYLIST_MODE_LOCAL); GpgME::Error err = m_ctx->startKeyListing("", bPrivateOnly ); @@ -135,14 +135,14 @@ Sequence< Reference < XCertificate > > SecurityEnvironmentGpg::getCertificatesIm m_ctx->endKeyListing(); for (auto const& key : keyList) { - xCert = new CertificateImpl(); + rtl::Reference<CertificateImpl> xCert = new CertificateImpl(); xCert->setCertificate(m_ctx.get(),key); certsList.push_back(xCert); } Sequence< Reference< XCertificate > > xCertificateSequence(certsList.size()); int i = 0; - for (auto const& cert : certsList) { + for (auto& cert : certsList) { xCertificateSequence[i++] = cert; } @@ -161,8 +161,6 @@ Sequence< Reference < XCertificate > > SecurityEnvironmentGpg::getAllCertificate Reference< XCertificate > SecurityEnvironmentGpg::getCertificate( const OUString& keyId, const Sequence< sal_Int8 >& /*serialNumber*/ ) { - CertificateImpl* xCert=nullptr; - //xmlChar* pSignatureValue=xmlNodeGetContent(cur); OString ostr = OUStringToOString( keyId , RTL_TEXTENCODING_UTF8 ); const xmlChar* strKeyId = reinterpret_cast<const xmlChar*>(ostr.getStr()); @@ -176,7 +174,7 @@ Reference< XCertificate > SecurityEnvironmentGpg::getCertificate( const OUString if (err) break; if (!k.isInvalid() && strcmp(k.primaryFingerprint(), reinterpret_cast<const char*>(strKeyId)) == 0) { - xCert = new CertificateImpl(); + rtl::Reference<CertificateImpl> xCert = new CertificateImpl(); xCert->setCertificate(m_ctx.get(), k); m_ctx->endKeyListing(); return xCert; diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx index 9977da48f72c..779f95119198 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -184,7 +184,7 @@ uno::Reference<xml::sax::XWriter> XMLSignatureHelper::CreateDocumentHandlerWithH /* * write the xml context for signatures */ - SvXMLAttributeList *pAttributeList = new SvXMLAttributeList(); + rtl::Reference<SvXMLAttributeList> pAttributeList = new SvXMLAttributeList(); OUString sNamespace; if (mbODFPre1_2) sNamespace = NS_DOCUMENTSIGNATURES; @@ -198,7 +198,7 @@ uno::Reference<xml::sax::XWriter> XMLSignatureHelper::CreateDocumentHandlerWithH xSaxWriter->startDocument(); xSaxWriter->startElement( "document-signatures", - uno::Reference< css::xml::sax::XAttributeList > (pAttributeList)); + pAttributeList); return xSaxWriter; } diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx index 1607539bb9d5..697d84a8e2a0 100644 --- a/xmlsecurity/source/helper/xsecctl.cxx +++ b/xmlsecurity/source/helper/xsecctl.cxx @@ -580,7 +580,7 @@ void XSecController::exportSignature( ******************************************************************************/ { const SignatureReferenceInformations& vReferenceInfors = signatureInfo.vSignatureReferenceInfors; - SvXMLAttributeList *pAttributeList; + rtl::Reference<SvXMLAttributeList> pAttributeList; /* * Write Signature element @@ -597,7 +597,7 @@ void XSecController::exportSignature( signatureInfo.ouSignatureId); } - xDocumentHandler->startElement( "Signature", css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList)); + xDocumentHandler->startElement( "Signature", pAttributeList); { /* Write SignedInfo element */ xDocumentHandler->startElement( @@ -609,7 +609,7 @@ void XSecController::exportSignature( pAttributeList->AddAttribute( "Algorithm", ALGO_C14N); - xDocumentHandler->startElement( "CanonicalizationMethod", css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList) ); + xDocumentHandler->startElement( "CanonicalizationMethod", pAttributeList ); xDocumentHandler->endElement( "CanonicalizationMethod" ); /* Write SignatureMethod element */ @@ -623,7 +623,7 @@ void XSecController::exportSignature( pAttributeList->AddAttribute( "Algorithm", getSignatureURI(signatureInfo.eAlgorithmID, vReferenceInfors[0].nDigestID)); - xDocumentHandler->startElement( "SignatureMethod", css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList) ); + xDocumentHandler->startElement( "SignatureMethod", pAttributeList ); xDocumentHandler->endElement( "SignatureMethod" ); /* Write Reference element */ @@ -662,7 +662,7 @@ void XSecController::exportSignature( } } - xDocumentHandler->startElement( "Reference", css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList) ); + xDocumentHandler->startElement( "Reference", pAttributeList ); { /* Write Transforms element */ if (refInfor.nType == SignatureReferenceType::XMLSTREAM) @@ -680,7 +680,7 @@ void XSecController::exportSignature( ALGO_C14N); xDocumentHandler->startElement( "Transform", - css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList) ); + pAttributeList ); xDocumentHandler->endElement( "Transform" ); } xDocumentHandler->endElement( "Transforms" ); @@ -693,7 +693,7 @@ void XSecController::exportSignature( getDigestURI(refInfor.nDigestID)); xDocumentHandler->startElement( "DigestMethod", - css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList) ); + pAttributeList ); xDocumentHandler->endElement( "DigestMethod" ); /* Write DigestValue element */ @@ -728,7 +728,7 @@ void XSecController::exportSignature( /* Write PGPData element */ xDocumentHandler->startElement( "PGPData", - css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList)); + pAttributeList); { /* Write keyid element */ xDocumentHandler->startElement( @@ -821,7 +821,7 @@ void XSecController::exportSignature( "#" + signatureInfo.ouSignatureId); xDocumentHandler->startElement( "SignatureProperty", - css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList)); + pAttributeList); { /* Write timestamp element */ @@ -832,7 +832,7 @@ void XSecController::exportSignature( xDocumentHandler->startElement( "dc:date", - css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList)); + pAttributeList); OUStringBuffer buffer; //If the xml signature was already contained in the document, @@ -864,14 +864,14 @@ void XSecController::exportSignature( pAttributeList = new SvXMLAttributeList(); pAttributeList->AddAttribute("Id", signatureInfo.ouDescriptionPropertyId); pAttributeList->AddAttribute("Target", "#" + signatureInfo.ouSignatureId); - xDocumentHandler->startElement("SignatureProperty", uno::Reference<xml::sax::XAttributeList>(pAttributeList)); + xDocumentHandler->startElement("SignatureProperty", pAttributeList); { // Description element. pAttributeList = new SvXMLAttributeList(); pAttributeList->AddAttribute("xmlns:dc", NS_DC); - xDocumentHandler->startElement("dc:description", uno::Reference<xml::sax::XAttributeList>(pAttributeList)); + xDocumentHandler->startElement("dc:description", pAttributeList); xDocumentHandler->characters(signatureInfo.ouDescription); xDocumentHandler->endElement("dc:description"); } @@ -890,13 +890,13 @@ void XSecController::exportSignature( pAttributeList->AddAttribute("xmlns:xd", NS_XD); xDocumentHandler->startElement( "Object", - css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList)); + pAttributeList); { pAttributeList = new SvXMLAttributeList(); pAttributeList->AddAttribute("Target", "#" + signatureInfo.ouSignatureId); xDocumentHandler->startElement( "xd:QualifyingProperties", - css::uno::Reference< css::xml::sax::XAttributeList > (pAttributeList)); + pAttributeList); DocumentSignatureHelper::writeSignedProperties(xDocumentHandler, signatureInfo, sDate, true); writeUnsignedProperties(xDocumentHandler, signatureInfo); xDocumentHandler->endElement( "xd:QualifyingProperties" ); diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx index 1d2a7c2ec08f..f982e136f5b2 100644 --- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx @@ -68,8 +68,8 @@ template <> struct default_delete<PRArenaPool> }; } -static X509Certificate_NssImpl* NssCertToXCert( CERTCertificate* cert ) ; -static X509Certificate_NssImpl* NssPrivKeyToXCert( SECKEYPrivateKey* ) ; +static rtl::Reference<X509Certificate_NssImpl> NssCertToXCert( CERTCertificate* cert ) ; +static rtl::Reference<X509Certificate_NssImpl> NssPrivKeyToXCert( SECKEYPrivateKey* ) ; namespace { @@ -98,11 +98,10 @@ static char* GetPasswordFunction( PK11SlotInfo* pSlot, PRBool bRetry, void* /*ar task::InteractionHandler::createWithParent(xContext, nullptr) ); task::PasswordRequestMode eMode = bRetry ? task::PasswordRequestMode_PASSWORD_REENTER : task::PasswordRequestMode_PASSWORD_ENTER; - ::comphelper::DocPasswordRequest* pPasswordRequest = new ::comphelper::DocPasswordRequest( + rtl::Reference<::comphelper::DocPasswordRequest> pPasswordRequest = new ::comphelper::DocPasswordRequest( ::comphelper::DocPasswordRequestType::Standard, eMode, OUString::createFromAscii(PK11_GetTokenName(pSlot)) ); - uno::Reference< task::XInteractionRequest > xRequest( pPasswordRequest ); - xInteractionHandler->handle( xRequest ); + xInteractionHandler->handle( pPasswordRequest ); if ( pPasswordRequest->isPassword() ) { @@ -272,8 +271,7 @@ Sequence< Reference < XCertificate > > SecurityEnvironment_NssImpl::getPersonalCertificates() { sal_Int32 length ; - X509Certificate_NssImpl* xcert ; - std::vector< X509Certificate_NssImpl* > certsList ; + std::vector< rtl::Reference<X509Certificate_NssImpl> > certsList ; updateSlots(); //firstly, we try to find private keys in slot @@ -298,7 +296,7 @@ SecurityEnvironment_NssImpl::getPersonalCertificates() !PRIVKEY_LIST_END( curPri, priKeyList ) && curPri != nullptr; curPri = PRIVKEY_LIST_NEXT(curPri)) { - xcert = NssPrivKeyToXCert( curPri->key ) ; + rtl::Reference<X509Certificate_NssImpl> xcert = NssPrivKeyToXCert( curPri->key ) ; if( xcert != nullptr ) certsList.push_back( xcert ) ; } @@ -313,7 +311,7 @@ SecurityEnvironment_NssImpl::getPersonalCertificates() int i = 0; Sequence< Reference< XCertificate > > certSeq( length ) ; - for( const auto& rXCert : certsList ) { + for( auto& rXCert : certsList ) { certSeq[i] = rXCert ; ++i; } @@ -326,7 +324,7 @@ SecurityEnvironment_NssImpl::getPersonalCertificates() Reference< XCertificate > SecurityEnvironment_NssImpl::getCertificate( const OUString& issuerName, const Sequence< sal_Int8 >& serialNumber ) { - X509Certificate_NssImpl* xcert = nullptr; + rtl::Reference<X509Certificate_NssImpl> xcert; if( m_pHandler != nullptr ) { CERTIssuerAndSN issuerAndSN ; @@ -365,16 +363,12 @@ Reference< XCertificate > SecurityEnvironment_NssImpl::getCertificate( const OUS cert = CERT_FindCertByIssuerAndSN( m_pHandler, &issuerAndSN ) ; if( cert != nullptr ) { xcert = NssCertToXCert( cert ) ; - } else { - xcert = nullptr ; } PL_strfree( chIssuer ) ; CERT_DestroyName( nmIssuer ) ; //SECITEM_FreeItem( derIssuer, PR_FALSE ) ; CERT_DestroyCertificate( cert ) ; - } else { - xcert = nullptr ; } return xcert ; @@ -411,7 +405,7 @@ Sequence< Reference < XCertificate > > SecurityEnvironment_NssImpl::buildCertifi std::vector<uno::Reference<security::XCertificate>> aCertChain; for (CERTCertListNode* node = CERT_LIST_HEAD(certChain); !CERT_LIST_END(node, certChain); node = CERT_LIST_NEXT(node)) { - X509Certificate_NssImpl* pCert = new X509Certificate_NssImpl(); + rtl::Reference<X509Certificate_NssImpl> pCert = new X509Certificate_NssImpl(); if( pCert == nullptr ) { CERT_DestroyCertList( certChain ) ; throw RuntimeException() ; @@ -430,7 +424,7 @@ Sequence< Reference < XCertificate > > SecurityEnvironment_NssImpl::buildCertifi return Sequence< Reference < XCertificate > >(); } -X509Certificate_NssImpl* SecurityEnvironment_NssImpl::createAndAddCertificateFromPackage( +rtl::Reference<X509Certificate_NssImpl> SecurityEnvironment_NssImpl::createAndAddCertificateFromPackage( const css::uno::Sequence<sal_Int8>& raDERCertificate, std::u16string_view raString) { @@ -479,14 +473,14 @@ X509Certificate_NssImpl* SecurityEnvironment_NssImpl::createAndAddCertificateFro PK11_FreeSlot(pSlot); - X509Certificate_NssImpl* pX509Certificate = new X509Certificate_NssImpl(); + rtl::Reference<X509Certificate_NssImpl> pX509Certificate = new X509Certificate_NssImpl(); pX509Certificate->setCert(pCERTCertificate); return pX509Certificate; } -X509Certificate_NssImpl* SecurityEnvironment_NssImpl::createX509CertificateFromDER(const css::uno::Sequence<sal_Int8>& aDerCertificate) +rtl::Reference<X509Certificate_NssImpl> SecurityEnvironment_NssImpl::createX509CertificateFromDER(const css::uno::Sequence<sal_Int8>& aDerCertificate) { - X509Certificate_NssImpl* pX509Certificate = nullptr; + rtl::Reference<X509Certificate_NssImpl> pX509Certificate; if (aDerCertificate.hasElements()) { @@ -803,39 +797,32 @@ sal_Int32 SecurityEnvironment_NssImpl::getCertificateCharacters( return characters ; } -X509Certificate_NssImpl* NssCertToXCert( CERTCertificate* cert ) +rtl::Reference<X509Certificate_NssImpl> NssCertToXCert( CERTCertificate* cert ) { - X509Certificate_NssImpl* xcert ; - if( cert != nullptr ) { - xcert = new X509Certificate_NssImpl() ; + rtl::Reference<X509Certificate_NssImpl> xcert = new X509Certificate_NssImpl() ; xcert->setCert( cert ) ; - } else { - xcert = nullptr ; + return xcert; } - return xcert ; + return nullptr; } -X509Certificate_NssImpl* NssPrivKeyToXCert( SECKEYPrivateKey* priKey ) +rtl::Reference<X509Certificate_NssImpl> NssPrivKeyToXCert( SECKEYPrivateKey* priKey ) { - X509Certificate_NssImpl* xcert ; - if( priKey != nullptr ) { + rtl::Reference<X509Certificate_NssImpl> xcert; CERTCertificate* cert = PK11_GetCertFromPrivateKey( priKey ) ; if( cert != nullptr ) { xcert = NssCertToXCert( cert ) ; - } else { - xcert = nullptr ; } CERT_DestroyCertificate( cert ) ; - } else { - xcert = nullptr ; + return xcert; } - return xcert ; + return nullptr; } xmlSecKeysMngrPtr SecurityEnvironment_NssImpl::createKeysManager() { @@ -924,18 +911,13 @@ uno::Reference<security::XCertificate> SecurityEnvironment_NssImpl::createDERCer if (!pPrivateKey) return uno::Reference<security::XCertificate>(); - X509Certificate_NssImpl* pX509Certificate = createAndAddCertificateFromPackage(raDERCertificate, u"TCu,TCu,TCu"); - if (!pX509Certificate) - return uno::Reference<security::XCertificate>(); - - return pX509Certificate; + return createAndAddCertificateFromPackage(raDERCertificate, u"TCu,TCu,TCu"); } uno::Reference<security::XCertificate> SecurityEnvironment_NssImpl::addDERCertificateToTheDatabase( uno::Sequence<sal_Int8> const & raDERCertificate, OUString const & raTrustString) { - X509Certificate_NssImpl* pX509Certificate = createAndAddCertificateFromPackage(raDERCertificate, raTrustString); - return pX509Certificate; + return createAndAddCertificateFromPackage(raDERCertificate, raTrustString); } extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx index fcc51072a690..d29e4a24f90b 100644 --- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx +++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx @@ -22,6 +22,7 @@ #include <sal/config.h> #include <rtl/ustring.hxx> +#include <rtl/ref.hxx> #include <cppuhelper/implbase.hxx> #include <com/sun/star/uno/Reference.hxx> @@ -131,12 +132,12 @@ private: void updateSlots(); - static X509Certificate_NssImpl* createAndAddCertificateFromPackage( + static rtl::Reference<X509Certificate_NssImpl> createAndAddCertificateFromPackage( const css::uno::Sequence<sal_Int8>& raDerCertificate, std::u16string_view raString); static SECKEYPrivateKey* insertPrivateKey(css::uno::Sequence<sal_Int8> const & raPrivateKey); - static X509Certificate_NssImpl* createX509CertificateFromDER(const css::uno::Sequence<sal_Int8>& raDerCertificate); + static rtl::Reference<X509Certificate_NssImpl> createX509CertificateFromDER(const css::uno::Sequence<sal_Int8>& raDerCertificate); /// @throws css::uno::Exception /// @throws css::uno::RuntimeException diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx index 1a323d33f32f..15ec8a346895 100644 --- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx @@ -210,13 +210,13 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension > if (objID == "2.5.29.17") { - SanExtensionImpl* pExtn = new SanExtensionImpl; + rtl::Reference<SanExtensionImpl> pExtn = new SanExtensionImpl; pExtn->setCertExtn(value, vlen, objid, objidlen, crit); xExtns[len] = pExtn ; } else { - CertificateExtension_XmlSecImpl* pExtn = new CertificateExtension_XmlSecImpl; + rtl::Reference<CertificateExtension_XmlSecImpl> pExtn = new CertificateExtension_XmlSecImpl; pExtn->setCertExtn(value, vlen, objid, objidlen, crit); xExtns[len] = pExtn; } diff --git a/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx b/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx index a9e95866d89f..430bb996fe21 100644 --- a/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx +++ b/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx @@ -27,6 +27,7 @@ #include "xmlelementwrapper_xmlsecimpl.hxx" #include <xmloff/attrlist.hxx> +#include <rtl/ref.hxx> #ifdef UNX #define stricmp strcasecmp @@ -173,8 +174,7 @@ void XMLDocumentWrapper_XmlSecImpl::sendStartElement( * This node must be an element type. ******************************************************************************/ { - SvXMLAttributeList* pAttributeList = new SvXMLAttributeList(); - uno::Reference < css::xml::sax::XAttributeList > xAttrList(pAttributeList); + rtl::Reference<SvXMLAttributeList> pAttributeList = new SvXMLAttributeList(); xmlNsPtr pNsDef = pNode->nsDef; @@ -230,12 +230,12 @@ void XMLDocumentWrapper_XmlSecImpl::sendStartElement( { xHandler->startElement( OUString::fromUtf8(sNodeName), - xAttrList); + pAttributeList); } xHandler2->startElement( OUString::fromUtf8(sNodeName), - xAttrList); + pAttributeList); } void XMLDocumentWrapper_XmlSecImpl::sendEndElement( @@ -578,8 +578,7 @@ void XMLDocumentWrapper_XmlSecImpl::rebuildIDLink(xmlNodePtr pNode) const /* XXMLDocumentWrapper */ uno::Reference< css::xml::wrapper::XXMLElementWrapper > SAL_CALL XMLDocumentWrapper_XmlSecImpl::getCurrentElement( ) { - XMLElementWrapper_XmlSecImpl* pElement = new XMLElementWrapper_XmlSecImpl(m_pCurrentElement); - return uno::Reference< css::xml::wrapper::XXMLElementWrapper >(pElement); + return new XMLElementWrapper_XmlSecImpl(m_pCurrentElement); } void SAL_CALL XMLDocumentWrapper_XmlSecImpl::setCurrentElement( const uno::Reference< css::xml::wrapper::XXMLElementWrapper >& element ) |