diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-02 20:07:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-02 22:44:36 +0200 |
commit | f0da01e59ffe1f7f1b5446f111994be6cf6f7d4a (patch) | |
tree | eea592416cf701d1f45b2fe5b2d410f20b7643de /xmlsecurity | |
parent | 5ef5c1b294063d1d2d6554d5fcf1d4cfb4d3f06d (diff) |
loplugin:flatten in xmlsecurity
Change-Id: Ic9e410c77a04edbd58485d4177da22e17efa8720
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99964
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlsecurity')
-rw-r--r-- | xmlsecurity/source/component/documentdigitalsignatures.cxx | 38 | ||||
-rw-r--r-- | xmlsecurity/source/dialogs/certificateviewer.cxx | 70 | ||||
-rw-r--r-- | xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 66 | ||||
-rw-r--r-- | xmlsecurity/source/dialogs/macrosecurity.cxx | 122 | ||||
-rw-r--r-- | xmlsecurity/source/framework/buffernode.cxx | 90 | ||||
-rw-r--r-- | xmlsecurity/source/framework/saxeventkeeperimpl.cxx | 229 | ||||
-rw-r--r-- | xmlsecurity/source/framework/signatureengine.cxx | 46 | ||||
-rw-r--r-- | xmlsecurity/source/helper/ooxmlsecexporter.cxx | 26 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecctl.cxx | 64 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecverify.cxx | 122 | ||||
-rw-r--r-- | xmlsecurity/source/xmlsec/nss/digestcontext.cxx | 28 | ||||
-rw-r--r-- | xmlsecurity/source/xmlsec/nss/nssinitializer.cxx | 24 | ||||
-rw-r--r-- | xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx | 74 | ||||
-rw-r--r-- | xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx | 54 |
14 files changed, 526 insertions, 527 deletions
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index 3baab59e03ac..68e1aa704441 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -236,25 +236,25 @@ void DocumentDigitalSignatures::initialize( const Sequence< Any >& aArguments) m_nArgumentsCount = aArguments.getLength(); - if (aArguments.hasElements()) - { - if (!(aArguments[0] >>= m_sODFVersion)) - throw css::lang::IllegalArgumentException( - "DocumentDigitalSignatures::initialize: the first arguments must be a string", - static_cast<XInitialization*>(this), 0); - - if (aArguments.getLength() == 2 - && !(aArguments[1] >>= m_bHasDocumentSignature)) - throw css::lang::IllegalArgumentException( - "DocumentDigitalSignatures::initialize: the second arguments must be a bool", - static_cast<XInitialization*>(this), 1); - - //the Version is supported as of ODF1.2, so for and 1.1 document or older we will receive the - //an empty string. In this case we set it to ODFVER_010_TEXT. Then we can later check easily - //if initialize was called. Only then m_sODFVersion.getLength() is greater than 0 - if (m_sODFVersion.isEmpty()) - m_sODFVersion = ODFVER_010_TEXT; - } + if (!aArguments.hasElements()) + return; + + if (!(aArguments[0] >>= m_sODFVersion)) + throw css::lang::IllegalArgumentException( + "DocumentDigitalSignatures::initialize: the first arguments must be a string", + static_cast<XInitialization*>(this), 0); + + if (aArguments.getLength() == 2 + && !(aArguments[1] >>= m_bHasDocumentSignature)) + throw css::lang::IllegalArgumentException( + "DocumentDigitalSignatures::initialize: the second arguments must be a bool", + static_cast<XInitialization*>(this), 1); + + //the Version is supported as of ODF1.2, so for and 1.1 document or older we will receive the + //an empty string. In this case we set it to ODFVER_010_TEXT. Then we can later check easily + //if initialize was called. Only then m_sODFVersion.getLength() is greater than 0 + if (m_sODFVersion.isEmpty()) + m_sODFVersion = ODFVER_010_TEXT; } OUString DocumentDigitalSignatures::getImplementationName() diff --git a/xmlsecurity/source/dialogs/certificateviewer.cxx b/xmlsecurity/source/dialogs/certificateviewer.cxx index 0dc981b052db..0ae9679dd00c 100644 --- a/xmlsecurity/source/dialogs/certificateviewer.cxx +++ b/xmlsecurity/source/dialogs/certificateviewer.cxx @@ -271,48 +271,48 @@ CertificateViewerCertPathTP::CertificateViewerCertPathTP(weld::Container* pParen void CertificateViewerCertPathTP::ActivatePage() { - if ( !mbFirstActivateDone ) + if ( mbFirstActivateDone ) + return; + + mbFirstActivateDone = true; + Sequence< Reference< security::XCertificate > > aCertPath = + mpParent->mxSecurityEnvironment->buildCertificatePath( mpParent->mxCert ); + const Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray(); + + sal_Int32 i, nCnt = aCertPath.getLength(); + std::unique_ptr<weld::TreeIter> xParent; + for (i = nCnt-1; i >= 0; i--) { - mbFirstActivateDone = true; - Sequence< Reference< security::XCertificate > > aCertPath = - mpParent->mxSecurityEnvironment->buildCertificatePath( mpParent->mxCert ); - const Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray(); - - sal_Int32 i, nCnt = aCertPath.getLength(); - std::unique_ptr<weld::TreeIter> xParent; - for (i = nCnt-1; i >= 0; i--) + const Reference< security::XCertificate > rCert = pCertPath[ i ]; + OUString sName = xmlsec::GetContentPart( rCert->getSubjectName(), rCert->getCertificateKind() ); + //Verify the certificate + sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(rCert, + Sequence<Reference<css::security::XCertificate> >()); + bool bCertValid = certStatus == css::security::CertificateValidity::VALID; + InsertCert(xParent.get(), sName, rCert, bCertValid); + if (!xParent) { - const Reference< security::XCertificate > rCert = pCertPath[ i ]; - OUString sName = xmlsec::GetContentPart( rCert->getSubjectName(), rCert->getCertificateKind() ); - //Verify the certificate - sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(rCert, - Sequence<Reference<css::security::XCertificate> >()); - bool bCertValid = certStatus == css::security::CertificateValidity::VALID; - InsertCert(xParent.get(), sName, rCert, bCertValid); - if (!xParent) - { - xParent = mxCertPathLB->make_iterator(); - (void)mxCertPathLB->get_iter_first(*xParent); - } - else - { - (void)mxCertPathLB->iter_children(*xParent); - } + xParent = mxCertPathLB->make_iterator(); + (void)mxCertPathLB->get_iter_first(*xParent); } - - if (xParent) - mxCertPathLB->select(*xParent); - mxViewCertPB->set_sensitive(false); // Own certificate selected - - while (xParent) + else { - mxCertPathLB->expand_row(*xParent); - if (!mxCertPathLB->iter_parent(*xParent)) - xParent.reset(); + (void)mxCertPathLB->iter_children(*xParent); } + } + + if (xParent) + mxCertPathLB->select(*xParent); + mxViewCertPB->set_sensitive(false); // Own certificate selected - CertSelectHdl(*mxCertPathLB); + while (xParent) + { + mxCertPathLB->expand_row(*xParent); + if (!mxCertPathLB->iter_parent(*xParent)) + xParent.reset(); } + + CertSelectHdl(*mxCertPathLB); } IMPL_LINK_NOARG(CertificateViewerCertPathTP, ViewCertHdl, weld::Button&, void) diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 3d81083978f5..615d526f509e 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -428,24 +428,24 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, RemoveButtonHdl, weld::Button&, void) if (!canRemove()) return; int nEntry = m_xSignaturesLB->get_selected_index(); - if (nEntry != -1) + if (nEntry == -1) + return; + + try { - try - { - sal_uInt16 nSelected = m_xSignaturesLB->get_id(nEntry).toUInt32(); - maSignatureManager.remove(nSelected); + sal_uInt16 nSelected = m_xSignaturesLB->get_id(nEntry).toUInt32(); + maSignatureManager.remove(nSelected); - mbSignaturesChanged = true; + mbSignaturesChanged = true; - ImplFillSignaturesBox(); - } - catch ( uno::Exception& ) - { - OSL_FAIL( "Exception while removing a signature!" ); - // Don't keep invalid entries... - ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/true); - ImplFillSignaturesBox(); - } + ImplFillSignaturesBox(); + } + catch ( uno::Exception& ) + { + OSL_FAIL( "Exception while removing a signature!" ); + // Don't keep invalid entries... + ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/true); + ImplFillSignaturesBox(); } } @@ -730,25 +730,25 @@ void DigitalSignaturesDialog::ImplGetSignatureInformations(bool bUseTempStream, void DigitalSignaturesDialog::ImplShowSignaturesDetails() { int nEntry = m_xSignaturesLB->get_selected_index(); - if (nEntry != -1) - { - sal_uInt16 nSelected = m_xSignaturesLB->get_id(nEntry).toUInt32(); - const SignatureInformation& rInfo = maSignatureManager.getCurrentSignatureInformations()[ nSelected ]; - uno::Reference<security::XCertificate> xCert = getCertificate(rInfo); + if (nEntry == -1) + return; - if ( xCert.is() ) - { - uno::Reference<xml::crypto::XSecurityEnvironment> xSecEnv = getSecurityEnvironmentForCertificate(xCert); - CertificateViewer aViewer(m_xDialog.get(), xSecEnv, xCert, false, nullptr); - aViewer.run(); - } - else - { - std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(), - VclMessageType::Info, VclButtonsType::Ok, - XsResId(STR_XMLSECDLG_NO_CERT_FOUND))); - xInfoBox->run(); - } + sal_uInt16 nSelected = m_xSignaturesLB->get_id(nEntry).toUInt32(); + const SignatureInformation& rInfo = maSignatureManager.getCurrentSignatureInformations()[ nSelected ]; + uno::Reference<security::XCertificate> xCert = getCertificate(rInfo); + + if ( xCert.is() ) + { + uno::Reference<xml::crypto::XSecurityEnvironment> xSecEnv = getSecurityEnvironmentForCertificate(xCert); + CertificateViewer aViewer(m_xDialog.get(), xSecEnv, xCert, false, nullptr); + aViewer.run(); + } + else + { + std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(), + VclMessageType::Info, VclButtonsType::Ok, + XsResId(STR_XMLSECDLG_NO_CERT_FOUND))); + xInfoBox->run(); } } diff --git a/xmlsecurity/source/dialogs/macrosecurity.cxx b/xmlsecurity/source/dialogs/macrosecurity.cxx index 1596e327dc6f..39863ed8faa2 100644 --- a/xmlsecurity/source/dialogs/macrosecurity.cxx +++ b/xmlsecurity/source/dialogs/macrosecurity.cxx @@ -209,41 +209,41 @@ void MacroSecurityTrustedSourcesTP::ShowBrokenCertificateError(const OUString& r IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, ViewCertPBHdl, weld::Button&, void) { int nEntry = m_xTrustCertLB->get_selected_index(); - if (nEntry != -1) + if (nEntry == -1) + return; + + const sal_uInt16 nSelected = m_xTrustCertLB->get_id(nEntry).toUInt32(); + uno::Reference< css::security::XCertificate > xCert; + try + { + xCert = m_pDlg->m_xSecurityEnvironment->getCertificate(m_aTrustedAuthors[nSelected][0], + xmlsecurity::numericStringToBigInteger(m_aTrustedAuthors[nSelected][1])); + } + catch (...) + { + TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "matching certificate not found for: " << m_aTrustedAuthors[nSelected][0]); + } + + if (!xCert.is()) { - const sal_uInt16 nSelected = m_xTrustCertLB->get_id(nEntry).toUInt32(); - uno::Reference< css::security::XCertificate > xCert; try { - xCert = m_pDlg->m_xSecurityEnvironment->getCertificate(m_aTrustedAuthors[nSelected][0], - xmlsecurity::numericStringToBigInteger(m_aTrustedAuthors[nSelected][1])); + xCert = m_pDlg->m_xSecurityEnvironment->createCertificateFromAscii(m_aTrustedAuthors[nSelected][2]); } catch (...) { - TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "matching certificate not found for: " << m_aTrustedAuthors[nSelected][0]); - } - - if (!xCert.is()) - { - try - { - xCert = m_pDlg->m_xSecurityEnvironment->createCertificateFromAscii(m_aTrustedAuthors[nSelected][2]); - } - catch (...) - { - TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "certificate data couldn't be parsed: " << m_aTrustedAuthors[nSelected][2]); - } + TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "certificate data couldn't be parsed: " << m_aTrustedAuthors[nSelected][2]); } + } - if ( xCert.is() ) - { - CertificateViewer aViewer(m_pDlg->getDialog(), m_pDlg->m_xSecurityEnvironment, xCert, false, nullptr); - aViewer.run(); - } - else - // should never happen, as we parsed the certificate data when we added it! - ShowBrokenCertificateError(m_aTrustedAuthors[nSelected][2]); + if ( xCert.is() ) + { + CertificateViewer aViewer(m_pDlg->getDialog(), m_pDlg->m_xSecurityEnvironment, xCert, false, nullptr); + aViewer.run(); } + else + // should never happen, as we parsed the certificate data when we added it! + ShowBrokenCertificateError(m_aTrustedAuthors[nSelected][2]); } IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, RemoveCertPBHdl, weld::Button&, void) @@ -298,20 +298,20 @@ IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, AddLocPBHdl, weld::Button&, void) IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, RemoveLocPBHdl, weld::Button&, void) { sal_Int32 nSel = m_xTrustFileLocLB->get_selected_index(); - if (nSel != -1) + if (nSel == -1) + return; + + m_xTrustFileLocLB->remove(nSel); + // Trusted Path could not be removed (#i33584#) + // after remove an entry, select another one if exists + int nNewCount = m_xTrustFileLocLB->n_children(); + if (nNewCount > 0) { - m_xTrustFileLocLB->remove(nSel); - // Trusted Path could not be removed (#i33584#) - // after remove an entry, select another one if exists - int nNewCount = m_xTrustFileLocLB->n_children(); - if (nNewCount > 0) - { - if (nSel >= nNewCount) - nSel = nNewCount - 1; - m_xTrustFileLocLB->select(nSel); - } - ImplCheckButtons(); + if (nSel >= nNewCount) + nSel = nNewCount - 1; + m_xTrustFileLocLB->select(nSel); } + ImplCheckButtons(); } IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, TrustCertLBSelectHdl, weld::TreeView&, void) @@ -330,32 +330,32 @@ void MacroSecurityTrustedSourcesTP::FillCertLB(const bool bShowWarnings) sal_uInt32 nEntries = m_aTrustedAuthors.getLength(); - if ( nEntries && m_pDlg->m_xSecurityEnvironment.is() ) + if ( !(nEntries && m_pDlg->m_xSecurityEnvironment.is()) ) + return; + + for( sal_uInt32 nEntry = 0 ; nEntry < nEntries ; ++nEntry ) { - for( sal_uInt32 nEntry = 0 ; nEntry < nEntries ; ++nEntry ) - { - css::uno::Sequence< OUString >& rEntry = m_aTrustedAuthors[ nEntry ]; + css::uno::Sequence< OUString >& rEntry = m_aTrustedAuthors[ nEntry ]; - try - { - // create from RawData - uno::Reference< css::security::XCertificate > xCert = m_pDlg->m_xSecurityEnvironment->createCertificateFromAscii(rEntry[2]); - m_xTrustCertLB->append(OUString::number(nEntry), xmlsec::GetContentPart(xCert->getSubjectName(), xCert->getCertificateKind())); - m_xTrustCertLB->set_text(nEntry, xmlsec::GetContentPart(xCert->getIssuerName(), xCert->getCertificateKind()), 1); - m_xTrustCertLB->set_text(nEntry, utl::GetDateTimeString(xCert->getNotValidAfter()), 2); - } - catch (...) + try + { + // create from RawData + uno::Reference< css::security::XCertificate > xCert = m_pDlg->m_xSecurityEnvironment->createCertificateFromAscii(rEntry[2]); + m_xTrustCertLB->append(OUString::number(nEntry), xmlsec::GetContentPart(xCert->getSubjectName(), xCert->getCertificateKind())); + m_xTrustCertLB->set_text(nEntry, xmlsec::GetContentPart(xCert->getIssuerName(), xCert->getCertificateKind()), 1); + m_xTrustCertLB->set_text(nEntry, utl::GetDateTimeString(xCert->getNotValidAfter()), 2); + } + catch (...) + { + if (bShowWarnings) { - if (bShowWarnings) - { - TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "certificate data couldn't be parsed: " << rEntry[2]); - OUString sData = rEntry[2]; - css::uno::Any tools_warn_exception(DbgGetCaughtException()); - OUString sException = OStringToOUString(exceptionToString(tools_warn_exception), RTL_TEXTENCODING_UTF8); - if (!sException.isEmpty()) - sData += " / " + sException; - ShowBrokenCertificateError(sData); - } + TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "certificate data couldn't be parsed: " << rEntry[2]); + OUString sData = rEntry[2]; + css::uno::Any tools_warn_exception(DbgGetCaughtException()); + OUString sException = OStringToOUString(exceptionToString(tools_warn_exception), RTL_TEXTENCODING_UTF8); + if (!sException.isEmpty()) + sData += " / " + sException; + ShowBrokenCertificateError(sData); } } } diff --git a/xmlsecurity/source/framework/buffernode.cxx b/xmlsecurity/source/framework/buffernode.cxx index 0a0a58421dbb..359c4a2f3f44 100644 --- a/xmlsecurity/source/framework/buffernode.cxx +++ b/xmlsecurity/source/framework/buffernode.cxx @@ -666,60 +666,60 @@ void BufferNode::elementCollectorNotify() * BufferNode. ******************************************************************************/ { - if (!m_vElementCollectors.empty()) - { - css::xml::crypto::sax::ElementMarkPriority nMaxPriority = css::xml::crypto::sax::ElementMarkPriority_MINIMUM; - css::xml::crypto::sax::ElementMarkPriority nPriority; + if (m_vElementCollectors.empty()) + return; - /* - * get the max priority among ElementCollectors on this BufferNode - */ - for( const ElementCollector* pElementCollector : m_vElementCollectors ) + css::xml::crypto::sax::ElementMarkPriority nMaxPriority = css::xml::crypto::sax::ElementMarkPriority_MINIMUM; + css::xml::crypto::sax::ElementMarkPriority nPriority; + + /* + * get the max priority among ElementCollectors on this BufferNode + */ + for( const ElementCollector* pElementCollector : m_vElementCollectors ) + { + nPriority = pElementCollector->getPriority(); + if (nPriority > nMaxPriority) { - nPriority = pElementCollector->getPriority(); - if (nPriority > nMaxPriority) - { - nMaxPriority = nPriority; - } + nMaxPriority = nPriority; } + } - std::vector< const ElementCollector* > vElementCollectors( m_vElementCollectors ); + std::vector< const ElementCollector* > vElementCollectors( m_vElementCollectors ); - for( const ElementCollector* ii : vElementCollectors ) - { - ElementCollector* pElementCollector = const_cast<ElementCollector*>(ii); - nPriority = pElementCollector->getPriority(); - bool bToModify = pElementCollector->getModify(); + for( const ElementCollector* ii : vElementCollectors ) + { + ElementCollector* pElementCollector = const_cast<ElementCollector*>(ii); + nPriority = pElementCollector->getPriority(); + bool bToModify = pElementCollector->getModify(); + /* + * Only ElementCollector with the max priority can + * perform notify operation. + * Moreover, if any blocker exists in the subtree of + * this BufferNode, this ElementCollector can't do notify + * unless its priority is BEFOREMODIFY. + */ + if (nPriority == nMaxPriority && + (nPriority == css::xml::crypto::sax::ElementMarkPriority_BEFOREMODIFY || + !isBlockerInSubTreeIncluded(pElementCollector->getSecurityId()))) + { /* - * Only ElementCollector with the max priority can - * perform notify operation. - * Moreover, if any blocker exists in the subtree of - * this BufferNode, this ElementCollector can't do notify - * unless its priority is BEFOREMODIFY. + * If this ElementCollector will modify the buffered element, then + * special attention must be paid. + * + * If there is any ElementCollector in the subtree or any ancestor + * ElementCollector with PRI_BEFPREMODIFY priority, this + * ElementCollector can't perform notify operation, otherwise, it + * will destroy the buffered element, in turn, ElementCollectors + * mentioned above can't perform their mission. */ - if (nPriority == nMaxPriority && - (nPriority == css::xml::crypto::sax::ElementMarkPriority_BEFOREMODIFY || - !isBlockerInSubTreeIncluded(pElementCollector->getSecurityId()))) + //if (!(nMaxPriority == css::xml::crypto::sax::ElementMarkPriority_PRI_MODIFY && + if (!(bToModify && + (isECInSubTreeIncluded(pElementCollector->getSecurityId()) || + isECOfBeforeModifyInAncestorIncluded(pElementCollector->getSecurityId())) + )) { - /* - * If this ElementCollector will modify the buffered element, then - * special attention must be paid. - * - * If there is any ElementCollector in the subtree or any ancestor - * ElementCollector with PRI_BEFPREMODIFY priority, this - * ElementCollector can't perform notify operation, otherwise, it - * will destroy the buffered element, in turn, ElementCollectors - * mentioned above can't perform their mission. - */ - //if (!(nMaxPriority == css::xml::crypto::sax::ElementMarkPriority_PRI_MODIFY && - if (!(bToModify && - (isECInSubTreeIncluded(pElementCollector->getSecurityId()) || - isECOfBeforeModifyInAncestorIncluded(pElementCollector->getSecurityId())) - )) - { - pElementCollector->notifyListener(); - } + pElementCollector->notifyListener(); } } } diff --git a/xmlsecurity/source/framework/saxeventkeeperimpl.cxx b/xmlsecurity/source/framework/saxeventkeeperimpl.cxx index cde39d929959..fee60ce925bd 100644 --- a/xmlsecurity/source/framework/saxeventkeeperimpl.cxx +++ b/xmlsecurity/source/framework/saxeventkeeperimpl.cxx @@ -83,22 +83,22 @@ void SAXEventKeeperImpl::setCurrentBufferNode(BufferNode* pBufferNode) * pBufferNode - a BufferNode which will be the new active BufferNode ******************************************************************************/ { - if (pBufferNode != m_pCurrentBufferNode) - { - if ( m_pCurrentBufferNode == m_pRootBufferNode.get() && - m_xSAXEventKeeperStatusChangeListener.is()) - { - m_xSAXEventKeeperStatusChangeListener->collectionStatusChanged(true); - } + if (pBufferNode == m_pCurrentBufferNode) + return; - if (pBufferNode->getParent() == nullptr) - { - m_pCurrentBufferNode->addChild(std::unique_ptr<BufferNode>(pBufferNode)); - pBufferNode->setParent(m_pCurrentBufferNode); - } + if ( m_pCurrentBufferNode == m_pRootBufferNode.get() && + m_xSAXEventKeeperStatusChangeListener.is()) + { + m_xSAXEventKeeperStatusChangeListener->collectionStatusChanged(true); + } - m_pCurrentBufferNode = pBufferNode; + if (pBufferNode->getParent() == nullptr) + { + m_pCurrentBufferNode->addChild(std::unique_ptr<BufferNode>(pBufferNode)); + pBufferNode->setParent(m_pCurrentBufferNode); } + + m_pCurrentBufferNode = pBufferNode; } BufferNode* SAXEventKeeperImpl::addNewElementMarkBuffers() @@ -389,110 +389,109 @@ void SAXEventKeeperImpl::smashBufferNode( * needed by the Blocker to be deleted. ******************************************************************************/ { - if (!pBufferNode->hasAnything()) + if (pBufferNode->hasAnything()) + return; + + BufferNode* pParent = const_cast<BufferNode*>(pBufferNode->getParent()); + + /* + * delete the XML data + */ + if (pParent == m_pRootBufferNode.get()) { - BufferNode* pParent = const_cast<BufferNode*>(pBufferNode->getParent()); + bool bIsNotBlocking = (m_pCurrentBlockingBufferNode == nullptr); + bool bIsBlockInside = false; + bool bIsBlockingAfterward = false; /* - * delete the XML data + * If this is a blocker, then remove any out-element data + * which caused by blocking. The removal process will stop + * at the next blocker to avoid removing any useful data. */ - if (pParent == m_pRootBufferNode.get()) + if (bClearRoot) { - bool bIsNotBlocking = (m_pCurrentBlockingBufferNode == nullptr); - bool bIsBlockInside = false; - bool bIsBlockingAfterward = false; + css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > + aChildElements = collectChildWorkingElement(m_pRootBufferNode.get()); /* - * If this is a blocker, then remove any out-element data - * which caused by blocking. The removal process will stop - * at the next blocker to avoid removing any useful data. + * the clearUselessData only clearup the content in the + * node, not the node itself. */ - if (bClearRoot) - { - css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > - aChildElements = collectChildWorkingElement(m_pRootBufferNode.get()); + m_xXMLDocument->clearUselessData(m_pRootBufferNode->getXMLElement(), + aChildElements, + bIsNotBlocking?nullptr: + (m_pCurrentBlockingBufferNode->getXMLElement())); - /* - * the clearUselessData only clearup the content in the - * node, not the node itself. - */ - m_xXMLDocument->clearUselessData(m_pRootBufferNode->getXMLElement(), - aChildElements, - bIsNotBlocking?nullptr: - (m_pCurrentBlockingBufferNode->getXMLElement())); + /* + * remove the node if it is empty, then if its parent is also + * empty, remove it, then if the next parent is also empty, + * remove it,..., until parent become null. + */ + m_xXMLDocument->collapse( m_pRootBufferNode->getXMLElement() ); + } - /* - * remove the node if it is empty, then if its parent is also - * empty, remove it, then if the next parent is also empty, - * remove it,..., until parent become null. - */ - m_xXMLDocument->collapse( m_pRootBufferNode->getXMLElement() ); - } + /* + * if blocking, check the relationship between this BufferNode and + * the current blocking BufferNode. + */ + if ( !bIsNotBlocking ) + { + /* + * the current blocking BufferNode is a descendant of this BufferNode. + */ + bIsBlockInside = (nullptr != pBufferNode->isAncestor(m_pCurrentBlockingBufferNode)); /* - * if blocking, check the relationship between this BufferNode and - * the current blocking BufferNode. + * the current blocking BufferNode locates behind this BufferNode in tree + * order. */ - if ( !bIsNotBlocking ) - { - /* - * the current blocking BufferNode is a descendant of this BufferNode. - */ - bIsBlockInside = (nullptr != pBufferNode->isAncestor(m_pCurrentBlockingBufferNode)); + bIsBlockingAfterward = pBufferNode->isPrevious(m_pCurrentBlockingBufferNode); + } - /* - * the current blocking BufferNode locates behind this BufferNode in tree - * order. - */ - bIsBlockingAfterward = pBufferNode->isPrevious(m_pCurrentBlockingBufferNode); - } + /* + * this BufferNode's working element needs to be deleted only when + * 1. there is no blocking, or + * 2. the current blocking BufferNode is a descendant of this BufferNode, + * (then in the BufferNode's working element, the useless data before the blocking + * element should be deleted.) or + * 3. the current blocking BufferNode is locates behind this BufferNode in tree, + * (then the useless data between the blocking element and the working element + * should be deleted.). + * Otherwise, this working element should not be deleted. + */ + if ( bIsNotBlocking || bIsBlockInside || bIsBlockingAfterward ) + { + css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > + aChildElements = collectChildWorkingElement(pBufferNode); /* - * this BufferNode's working element needs to be deleted only when - * 1. there is no blocking, or - * 2. the current blocking BufferNode is a descendant of this BufferNode, - * (then in the BufferNode's working element, the useless data before the blocking - * element should be deleted.) or - * 3. the current blocking BufferNode is locates behind this BufferNode in tree, - * (then the useless data between the blocking element and the working element - * should be deleted.). - * Otherwise, this working element should not be deleted. + * the clearUselessData only clearup the content in the + * node, not the node itself. */ - if ( bIsNotBlocking || bIsBlockInside || bIsBlockingAfterward ) - { - css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > - aChildElements = collectChildWorkingElement(pBufferNode); - - /* - * the clearUselessData only clearup the content in the - * node, not the node itself. - */ - m_xXMLDocument->clearUselessData(pBufferNode->getXMLElement(), - aChildElements, - bIsBlockInside?(m_pCurrentBlockingBufferNode->getXMLElement()): - nullptr); + m_xXMLDocument->clearUselessData(pBufferNode->getXMLElement(), + aChildElements, + bIsBlockInside?(m_pCurrentBlockingBufferNode->getXMLElement()): + nullptr); - /* - * remove the node if it is empty, then if its parent is also - * empty, remove it, then if the next parent is also empty, - * remove it,..., until parent become null. - */ - m_xXMLDocument->collapse( pBufferNode->getXMLElement() ); - } + /* + * remove the node if it is empty, then if its parent is also + * empty, remove it, then if the next parent is also empty, + * remove it,..., until parent become null. + */ + m_xXMLDocument->collapse( pBufferNode->getXMLElement() ); } + } - sal_Int32 nIndex = pParent->indexOfChild(pBufferNode); + sal_Int32 nIndex = pParent->indexOfChild(pBufferNode); - std::vector< std::unique_ptr<BufferNode> > vChildren = pBufferNode->releaseChildren(); - pParent->removeChild(pBufferNode); // delete buffernode - - for( auto& i : vChildren ) - { - i->setParent(pParent); - pParent->addChild(std::move(i), nIndex); - nIndex++; - } + std::vector< std::unique_ptr<BufferNode> > vChildren = pBufferNode->releaseChildren(); + pParent->removeChild(pBufferNode); // delete buffernode + for( auto& i : vChildren ) + { + i->setParent(pParent); + pParent->addChild(std::move(i), nIndex); + nIndex++; } } @@ -1072,18 +1071,18 @@ void SAL_CALL SAXEventKeeperImpl::endElement( const OUString& aName ) void SAL_CALL SAXEventKeeperImpl::characters( const OUString& aChars ) { - if (!m_bIsForwarding) + if (m_bIsForwarding) + return; + + if ((m_pCurrentBlockingBufferNode == nullptr) && m_xNextHandler.is()) { - if ((m_pCurrentBlockingBufferNode == nullptr) && m_xNextHandler.is()) - { - m_xNextHandler->characters(aChars); - } + m_xNextHandler->characters(aChars); + } - if ((m_pCurrentBlockingBufferNode != nullptr) || - (m_pCurrentBufferNode != m_pRootBufferNode.get())) - { - m_xCompressedDocumentHandler->compressedCharacters(aChars); - } + if ((m_pCurrentBlockingBufferNode != nullptr) || + (m_pCurrentBufferNode != m_pRootBufferNode.get())) + { + m_xCompressedDocumentHandler->compressedCharacters(aChars); } } @@ -1095,18 +1094,18 @@ void SAL_CALL SAXEventKeeperImpl::ignorableWhitespace( const OUString& aWhitespa void SAL_CALL SAXEventKeeperImpl::processingInstruction( const OUString& aTarget, const OUString& aData ) { - if (!m_bIsForwarding) + if (m_bIsForwarding) + return; + + if ((m_pCurrentBlockingBufferNode == nullptr) && m_xNextHandler.is()) { - if ((m_pCurrentBlockingBufferNode == nullptr) && m_xNextHandler.is()) - { - m_xNextHandler->processingInstruction(aTarget, aData); - } + m_xNextHandler->processingInstruction(aTarget, aData); + } - if ((m_pCurrentBlockingBufferNode != nullptr) || - (m_pCurrentBufferNode != m_pRootBufferNode.get())) - { - m_xCompressedDocumentHandler->compressedProcessingInstruction(aTarget, aData); - } + if ((m_pCurrentBlockingBufferNode != nullptr) || + (m_pCurrentBufferNode != m_pRootBufferNode.get())) + { + m_xCompressedDocumentHandler->compressedProcessingInstruction(aTarget, aData); } } diff --git a/xmlsecurity/source/framework/signatureengine.cxx b/xmlsecurity/source/framework/signatureengine.cxx index 095b2d04d4d7..0390ea7e61c1 100644 --- a/xmlsecurity/source/framework/signatureengine.cxx +++ b/xmlsecurity/source/framework/signatureengine.cxx @@ -86,37 +86,37 @@ void SignatureEngine::tryToPerform( ) * 5. sets the "accomplishment" flag. ******************************************************************************/ { - if (checkReady()) - { - rtl::Reference<XMLSignatureTemplateImpl> xSignatureTemplate = new XMLSignatureTemplateImpl(); + if (!checkReady()) + return; - css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > - xXMLElement = m_xSAXEventKeeper->getElement( m_nIdOfTemplateEC ); + rtl::Reference<XMLSignatureTemplateImpl> xSignatureTemplate = new XMLSignatureTemplateImpl(); - xSignatureTemplate->setTemplate(xXMLElement); + css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > + xXMLElement = m_xSAXEventKeeper->getElement( m_nIdOfTemplateEC ); - for( const auto i : m_vReferenceIds ) - { - xXMLElement = m_xSAXEventKeeper->getElement( i ); - xSignatureTemplate->setTarget(xXMLElement); - } + xSignatureTemplate->setTemplate(xXMLElement); - /* - * set the Uri binding - */ - xSignatureTemplate->setBinding( this ); + for( const auto i : m_vReferenceIds ) + { + xXMLElement = m_xSAXEventKeeper->getElement( i ); + xSignatureTemplate->setTarget(xXMLElement); + } - startEngine(xSignatureTemplate); + /* + * set the Uri binding + */ + xSignatureTemplate->setBinding( this ); - /* - * done - */ - clearUp( ); + startEngine(xSignatureTemplate); - notifyResultListener(); + /* + * done + */ + clearUp( ); - m_bMissionDone = true; - } + notifyResultListener(); + + m_bMissionDone = true; } void SignatureEngine::clearUp( ) const diff --git a/xmlsecurity/source/helper/ooxmlsecexporter.cxx b/xmlsecurity/source/helper/ooxmlsecexporter.cxx index a857665a0493..8a356a5bb44e 100644 --- a/xmlsecurity/source/helper/ooxmlsecexporter.cxx +++ b/xmlsecurity/source/helper/ooxmlsecexporter.cxx @@ -497,19 +497,19 @@ void OOXMLSecExporter::Impl::writeSignatureLineImages() m_xDocumentHandler->characters(aGraphicInBase64); m_xDocumentHandler->endElement("Object"); } - if (m_rInformation.aInvalidSignatureImage.is()) - { - rtl::Reference<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList()); - pAttributeList->AddAttribute("Id", "idInvalidSigLnImg"); - m_xDocumentHandler->startElement( - "Object", uno::Reference<xml::sax::XAttributeList>(pAttributeList.get())); - OUString aGraphicInBase64; - Graphic aGraphic(m_rInformation.aInvalidSignatureImage); - if (!XOutBitmap::GraphicToBase64(aGraphic, aGraphicInBase64, false, ConvertDataFormat::EMF)) - SAL_WARN("xmlsecurity.helper", "could not convert graphic to base64"); - m_xDocumentHandler->characters(aGraphicInBase64); - m_xDocumentHandler->endElement("Object"); - } + if (!m_rInformation.aInvalidSignatureImage.is()) + return; + + rtl::Reference<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList()); + pAttributeList->AddAttribute("Id", "idInvalidSigLnImg"); + m_xDocumentHandler->startElement( + "Object", uno::Reference<xml::sax::XAttributeList>(pAttributeList.get())); + OUString aGraphicInBase64; + Graphic aGraphic(m_rInformation.aInvalidSignatureImage); + if (!XOutBitmap::GraphicToBase64(aGraphic, aGraphicInBase64, false, ConvertDataFormat::EMF)) + SAL_WARN("xmlsecurity.helper", "could not convert graphic to base64"); + m_xDocumentHandler->characters(aGraphicInBase64); + m_xDocumentHandler->endElement("Object"); } OOXMLSecExporter::OOXMLSecExporter( diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx index cac30006b6a7..af9776b9dcc1 100644 --- a/xmlsecurity/source/helper/xsecctl.cxx +++ b/xmlsecurity/source/helper/xsecctl.cxx @@ -196,22 +196,22 @@ void XSecController::createXSecComponent( ) bSuccess &= m_xSAXEventKeeper.is(); - if (bSuccess) + if (!bSuccess) /* * SAXEventKeeper created successfully. */ - { - css::uno::Sequence <css::uno::Any> arg(1); - arg[0] <<= uno::Reference<xml::wrapper::XXMLDocumentWrapper>(m_xXMLDocumentWrapper.get()); - m_xSAXEventKeeper->initialize(arg); + return; - css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener > - xStatusChangeListener = this; + css::uno::Sequence <css::uno::Any> arg(1); + arg[0] <<= uno::Reference<xml::wrapper::XXMLDocumentWrapper>(m_xXMLDocumentWrapper.get()); + m_xSAXEventKeeper->initialize(arg); - m_xSAXEventKeeper->addSAXEventKeeperStatusChangeListener( xStatusChangeListener ); + css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener > + xStatusChangeListener = this; - m_eStatusOfSecurityComponents = InitializationState::INITIALIZED; - } + m_xSAXEventKeeper->addSAXEventKeeperStatusChangeListener( xStatusChangeListener ); + + m_eStatusOfSecurityComponents = InitializationState::INITIALIZED; } bool XSecController::chainOn() @@ -313,33 +313,33 @@ void XSecController::chainOff() * chainOff -- disconnects the SAXEventKeeper from the SAX chain. ******************************************************************************/ { - if (!m_bIsSAXEventKeeperSticky ) - { - if (m_bIsSAXEventKeeperConnected) - { - m_xSAXEventKeeper->setNextHandler( nullptr ); + if (m_bIsSAXEventKeeperSticky ) + return; - if ( m_xPreviousNodeOnSAXChain.is() ) - { - if ( m_bIsPreviousNodeInitializable ) - { - css::uno::Reference< css::lang::XInitialization > xInitialization - (m_xPreviousNodeOnSAXChain, css::uno::UNO_QUERY); + if (!m_bIsSAXEventKeeperConnected) + return; - css::uno::Sequence<css::uno::Any> aArgs( 1 ); - aArgs[0] <<= uno::Reference<xml::sax::XDocumentHandler>(); - xInitialization->initialize(aArgs); - } - else - { - css::uno::Reference< css::xml::sax::XParser > xParser(m_xPreviousNodeOnSAXChain, css::uno::UNO_QUERY); - xParser->setDocumentHandler(uno::Reference<xml::sax::XDocumentHandler>()); - } - } + m_xSAXEventKeeper->setNextHandler( nullptr ); - m_bIsSAXEventKeeperConnected = false; + if ( m_xPreviousNodeOnSAXChain.is() ) + { + if ( m_bIsPreviousNodeInitializable ) + { + css::uno::Reference< css::lang::XInitialization > xInitialization + (m_xPreviousNodeOnSAXChain, css::uno::UNO_QUERY); + + css::uno::Sequence<css::uno::Any> aArgs( 1 ); + aArgs[0] <<= uno::Reference<xml::sax::XDocumentHandler>(); + xInitialization->initialize(aArgs); + } + else + { + css::uno::Reference< css::xml::sax::XParser > xParser(m_xPreviousNodeOnSAXChain, css::uno::UNO_QUERY); + xParser->setDocumentHandler(uno::Reference<xml::sax::XDocumentHandler>()); } } + + m_bIsSAXEventKeeperConnected = false; } void XSecController::checkChainingStatus() diff --git a/xmlsecurity/source/helper/xsecverify.cxx b/xmlsecurity/source/helper/xsecverify.cxx index c826971b1c7d..24cf8b33091a 100644 --- a/xmlsecurity/source/helper/xsecverify.cxx +++ b/xmlsecurity/source/helper/xsecverify.cxx @@ -125,18 +125,18 @@ void XSecController::switchGpgSignature() #if HAVE_FEATURE_GPGME // swap signature verifier for the Gpg one m_xXMLSignature.set(new XMLSignature_GpgImpl()); - if (!m_vInternalSignatureInformations.empty()) + if (m_vInternalSignatureInformations.empty()) + return; + + SignatureVerifierImpl* pImpl= + dynamic_cast<SignatureVerifierImpl*>( + m_vInternalSignatureInformations.back().xReferenceResolvedListener.get()); + if (pImpl) { - SignatureVerifierImpl* pImpl= - dynamic_cast<SignatureVerifierImpl*>( - m_vInternalSignatureInformations.back().xReferenceResolvedListener.get()); - if (pImpl) - { - css::uno::Reference<css::xml::crypto::XSEInitializer> xGpgSEInitializer( - new SEInitializerGpg()); - pImpl->updateSignature(new XMLSignature_GpgImpl(), - xGpgSEInitializer->createSecurityContext(OUString())); - } + css::uno::Reference<css::xml::crypto::XSEInitializer> xGpgSEInitializer( + new SEInitializerGpg()); + pImpl->updateSignature(new XMLSignature_GpgImpl(), + xGpgSEInitializer->createSecurityContext(OUString())); } #else (void) this; @@ -197,28 +197,28 @@ void XSecController::setReferenceCount() const const InternalSignatureInformation &isi = m_vInternalSignatureInformations.back(); - if ( isi.xReferenceResolvedListener.is() ) - { - const SignatureReferenceInformations &refInfors = isi.signatureInfor.vSignatureReferenceInfors; + if ( !isi.xReferenceResolvedListener.is() ) + return; - int refNum = refInfors.size(); - sal_Int32 referenceCount = 0; + const SignatureReferenceInformations &refInfors = isi.signatureInfor.vSignatureReferenceInfors; - for(int i=0 ; i<refNum; ++i) + int refNum = refInfors.size(); + sal_Int32 referenceCount = 0; + + for(int i=0 ; i<refNum; ++i) + { + if (refInfors[i].nType == SignatureReferenceType::SAMEDOCUMENT ) + /* + * same-document reference + */ { - if (refInfors[i].nType == SignatureReferenceType::SAMEDOCUMENT ) - /* - * same-document reference - */ - { - referenceCount++; - } + referenceCount++; } - - css::uno::Reference<css::xml::crypto::sax::XReferenceCollector> xReferenceCollector - (isi.xReferenceResolvedListener, css::uno::UNO_QUERY); - xReferenceCollector->setReferenceCount( referenceCount ); } + + css::uno::Reference<css::xml::crypto::sax::XReferenceCollector> xReferenceCollector + (isi.xReferenceResolvedListener, css::uno::UNO_QUERY); + xReferenceCollector->setReferenceCount( referenceCount ); } void XSecController::setX509IssuerName( OUString const & ouX509IssuerName ) @@ -455,55 +455,55 @@ void XSecController::collectToVerify( const OUString& referenceId ) { /* SAL_WARN_IF( !m_xSAXEventKeeper.is(), "xmlsecurity", "the SAXEventKeeper is NULL" ); */ - if ( m_eStatusOfSecurityComponents == InitializationState::INITIALIZED ) + if ( m_eStatusOfSecurityComponents != InitializationState::INITIALIZED ) /* * if all security components are ready, verify the signature. */ - { - bool bJustChainingOn = false; - css::uno::Reference< css::xml::sax::XDocumentHandler > xHandler; + return; + + bool bJustChainingOn = false; + css::uno::Reference< css::xml::sax::XDocumentHandler > xHandler; - int i,j; - int sigNum = m_vInternalSignatureInformations.size(); + int i,j; + int sigNum = m_vInternalSignatureInformations.size(); + + for (i=0; i<sigNum; ++i) + { + InternalSignatureInformation& isi = m_vInternalSignatureInformations[i]; + SignatureReferenceInformations& vReferenceInfors = isi.signatureInfor.vSignatureReferenceInfors; + int refNum = vReferenceInfors.size(); - for (i=0; i<sigNum; ++i) + for (j=0; j<refNum; ++j) { - InternalSignatureInformation& isi = m_vInternalSignatureInformations[i]; - SignatureReferenceInformations& vReferenceInfors = isi.signatureInfor.vSignatureReferenceInfors; - int refNum = vReferenceInfors.size(); + SignatureReferenceInformation &refInfor = vReferenceInfors[j]; - for (j=0; j<refNum; ++j) + if (refInfor.ouURI == referenceId) { - SignatureReferenceInformation &refInfor = vReferenceInfors[j]; - - if (refInfor.ouURI == referenceId) + if (chainOn()) { - if (chainOn()) - { - bJustChainingOn = true; - xHandler = m_xSAXEventKeeper->setNextHandler(nullptr); - } + bJustChainingOn = true; + xHandler = m_xSAXEventKeeper->setNextHandler(nullptr); + } - sal_Int32 nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector( - css::xml::crypto::sax::ElementMarkPriority_BEFOREMODIFY, false ); + sal_Int32 nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector( + css::xml::crypto::sax::ElementMarkPriority_BEFOREMODIFY, false ); - css::uno::Reference<css::xml::crypto::sax::XReferenceCollector> xReferenceCollector - ( isi.xReferenceResolvedListener, css::uno::UNO_QUERY ); + css::uno::Reference<css::xml::crypto::sax::XReferenceCollector> xReferenceCollector + ( isi.xReferenceResolvedListener, css::uno::UNO_QUERY ); - m_xSAXEventKeeper->setSecurityId(nKeeperId, isi.signatureInfor.nSecurityId); - m_xSAXEventKeeper->addReferenceResolvedListener( nKeeperId, isi.xReferenceResolvedListener); - xReferenceCollector->setReferenceId( nKeeperId ); + m_xSAXEventKeeper->setSecurityId(nKeeperId, isi.signatureInfor.nSecurityId); + m_xSAXEventKeeper->addReferenceResolvedListener( nKeeperId, isi.xReferenceResolvedListener); + xReferenceCollector->setReferenceId( nKeeperId ); - isi.vKeeperIds[j] = nKeeperId; - break; - } + isi.vKeeperIds[j] = nKeeperId; + break; } } + } - if ( bJustChainingOn ) - { - m_xSAXEventKeeper->setNextHandler(xHandler); - } + if ( bJustChainingOn ) + { + m_xSAXEventKeeper->setNextHandler(xHandler); } } diff --git a/xmlsecurity/source/xmlsec/nss/digestcontext.cxx b/xmlsecurity/source/xmlsec/nss/digestcontext.cxx index 40d871ac6543..d8c46543c0ae 100644 --- a/xmlsecurity/source/xmlsec/nss/digestcontext.cxx +++ b/xmlsecurity/source/xmlsec/nss/digestcontext.cxx @@ -45,22 +45,22 @@ void SAL_CALL ODigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& a if ( m_bDisposed ) throw lang::DisposedException(); - if ( !m_b1KData || m_nDigested < 1024 ) + if (m_b1KData && m_nDigested >= 1024) + return; + + uno::Sequence< sal_Int8 > aToDigest = aData; + if ( m_b1KData && m_nDigested + aData.getLength() > 1024 ) + aToDigest.realloc( 1024 - m_nDigested ); + + if ( PK11_DigestOp( m_pContext, reinterpret_cast< const unsigned char* >( aToDigest.getConstArray() ), aToDigest.getLength() ) != SECSuccess ) { - uno::Sequence< sal_Int8 > aToDigest = aData; - if ( m_b1KData && m_nDigested + aData.getLength() > 1024 ) - aToDigest.realloc( 1024 - m_nDigested ); - - if ( PK11_DigestOp( m_pContext, reinterpret_cast< const unsigned char* >( aToDigest.getConstArray() ), aToDigest.getLength() ) != SECSuccess ) - { - PK11_DestroyContext( m_pContext, PR_TRUE ); - m_pContext = nullptr; - m_bBroken = true; - throw uno::RuntimeException(); - } - - m_nDigested += aToDigest.getLength(); + PK11_DestroyContext( m_pContext, PR_TRUE ); + m_pContext = nullptr; + m_bBroken = true; + throw uno::RuntimeException(); } + + m_nDigested += aToDigest.getLength(); } uno::Sequence< ::sal_Int8 > SAL_CALL ODigestContext::finalizeDigestAndDispose() diff --git a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx index c43abe14569f..f5ed1bc001cd 100644 --- a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx +++ b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx @@ -130,20 +130,20 @@ void deleteRootsModule() } SECMOD_ReleaseReadLock(lock); - if (RootsModule) + if (!RootsModule) + return; + + PRInt32 modType; + if (SECSuccess == SECMOD_DeleteModule(RootsModule->commonName, &modType)) { - PRInt32 modType; - if (SECSuccess == SECMOD_DeleteModule(RootsModule->commonName, &modType)) - { - SAL_INFO("xmlsecurity.xmlsec", "Deleted module \"" << RootsModule->commonName << "\"."); - } - else - { - SAL_INFO("xmlsecurity.xmlsec", "Failed to delete \"" << RootsModule->commonName << "\": " << RootsModule->dllName); - } - SECMOD_DestroyModule(RootsModule); - RootsModule = nullptr; + SAL_INFO("xmlsecurity.xmlsec", "Deleted module \"" << RootsModule->commonName << "\"."); + } + else + { + SAL_INFO("xmlsecurity.xmlsec", "Failed to delete \"" << RootsModule->commonName << "\": " << RootsModule->dllName); } + SECMOD_DestroyModule(RootsModule); + RootsModule = nullptr; } #endif diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx index 5b0291642999..1a0444f638bc 100644 --- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx @@ -195,21 +195,21 @@ void SecurityEnvironment_NssImpl::setCertDb( CERTCertDBHandle* aCertDb ) { } void SecurityEnvironment_NssImpl::adoptSymKey( PK11SymKey* aSymKey ) { - if( aSymKey != nullptr ) { - //First try to find the key in the list - if (std::find(m_tSymKeyList.begin(), m_tSymKeyList.end(), aSymKey) != m_tSymKeyList.end()) - return; - - //If we do not find the key in the list, add a new node - PK11SymKey* symkey = PK11_ReferenceSymKey( aSymKey ) ; - if( symkey == nullptr ) - throw RuntimeException() ; + if( aSymKey == nullptr ) return; - try { - m_tSymKeyList.push_back( symkey ) ; - } catch ( Exception& ) { - PK11_FreeSymKey( symkey ) ; - } + //First try to find the key in the list + if (std::find(m_tSymKeyList.begin(), m_tSymKeyList.end(), aSymKey) != m_tSymKeyList.end()) + return; + + //If we do not find the key in the list, add a new node + PK11SymKey* symkey = PK11_ReferenceSymKey( aSymKey ) ; + if( symkey == nullptr ) + throw RuntimeException() ; + + try { + m_tSymKeyList.push_back( symkey ) ; + } catch ( Exception& ) { + PK11_FreeSymKey( symkey ) ; } } @@ -222,18 +222,19 @@ void SecurityEnvironment_NssImpl::updateSlots() m_tSymKeyList.clear(); PK11SlotList * soltList = PK11_GetAllTokens( CKM_INVALID_MECHANISM, PR_FALSE, PR_FALSE, nullptr ) ; - if( soltList != nullptr ) + if( soltList == nullptr ) + return; + + for (PK11SlotListElement* soltEle = soltList->head ; soltEle != nullptr; soltEle = soltEle->next) { - for (PK11SlotListElement* soltEle = soltList->head ; soltEle != nullptr; soltEle = soltEle->next) - { - PK11SlotInfo * pSlot = soltEle->slot ; + PK11SlotInfo * pSlot = soltEle->slot ; - if(pSlot != nullptr) - { - SAL_INFO( - "xmlsecurity.xmlsec", - "Found a slot: SlotName=" << PK11_GetSlotName(pSlot) - << ", TokenName=" << PK11_GetTokenName(pSlot)); + if(pSlot != nullptr) + { + SAL_INFO( + "xmlsecurity.xmlsec", + "Found a slot: SlotName=" << PK11_GetSlotName(pSlot) + << ", TokenName=" << PK11_GetTokenName(pSlot)); //The following code which is commented out checks if a slot, that is a smart card for example, is // able to generate a symmetric key of type CKM_DES3_CBC. If this fails then this token @@ -245,27 +246,26 @@ void SecurityEnvironment_NssImpl::updateSlots() // By doing this, the encryption may fail if a smart card is being used which does not // support this key generation. // - PK11SymKey * pSymKey = PK11_KeyGen( pSlot , CKM_DES3_CBC, nullptr, 128, nullptr ) ; + PK11SymKey * pSymKey = PK11_KeyGen( pSlot , CKM_DES3_CBC, nullptr, 128, nullptr ) ; // if( pSymKey == NULL ) // { // PK11_FreeSlot( pSlot ) ; // SAL_INFO( "xmlsecurity", "XMLSEC: Error - pSymKey is NULL" ); // continue; // } - addCryptoSlot(pSlot); - PK11_FreeSlot( pSlot ) ; - pSlot = nullptr; + addCryptoSlot(pSlot); + PK11_FreeSlot( pSlot ) ; + pSlot = nullptr; - if (pSymKey != nullptr) - { - adoptSymKey( pSymKey ) ; - PK11_FreeSymKey( pSymKey ) ; - pSymKey = nullptr; - } + if (pSymKey != nullptr) + { + adoptSymKey( pSymKey ) ; + PK11_FreeSymKey( pSymKey ) ; + pSymKey = nullptr; + } - }// end of if(pSlot != NULL) - }// end of for - }// end of if( soltList != NULL ) + }// end of if(pSlot != NULL) + }// end of for } Sequence< Reference < XCertificate > > diff --git a/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx b/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx index 2d98e44d0908..b7313cbad8ff 100644 --- a/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx +++ b/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx @@ -669,41 +669,41 @@ void SAL_CALL XMLDocumentWrapper_XmlSecImpl::collapse( const uno::Reference< css void SAL_CALL XMLDocumentWrapper_XmlSecImpl::getTree( const uno::Reference< css::xml::sax::XDocumentHandler >& handler ) { - if (m_pRootElement != nullptr) - { - xmlNodePtr pTempCurrentElement = m_pCurrentElement; - sal_Int32 nTempCurrentPosition = m_nCurrentPosition; + if (m_pRootElement == nullptr) + return; - m_pCurrentElement = m_pRootElement; + xmlNodePtr pTempCurrentElement = m_pCurrentElement; + sal_Int32 nTempCurrentPosition = m_nCurrentPosition; - m_nCurrentPosition = NODEPOSITION_STARTELEMENT; + m_pCurrentElement = m_pRootElement; - while(true) - { - switch (m_nCurrentPosition) - { - case NODEPOSITION_STARTELEMENT: - sendStartElement(nullptr, handler, m_pCurrentElement); - break; - case NODEPOSITION_ENDELEMENT: - sendEndElement(nullptr, handler, m_pCurrentElement); - break; - case NODEPOSITION_NORMAL: - sendNode(nullptr, handler, m_pCurrentElement); - break; - } + m_nCurrentPosition = NODEPOSITION_STARTELEMENT; - if ( (m_pCurrentElement == m_pRootElement) && (m_nCurrentPosition == NODEPOSITION_ENDELEMENT )) - { - break; - } + while(true) + { + switch (m_nCurrentPosition) + { + case NODEPOSITION_STARTELEMENT: + sendStartElement(nullptr, handler, m_pCurrentElement); + break; + case NODEPOSITION_ENDELEMENT: + sendEndElement(nullptr, handler, m_pCurrentElement); + break; + case NODEPOSITION_NORMAL: + sendNode(nullptr, handler, m_pCurrentElement); + break; + } - getNextSAXEvent(); + if ( (m_pCurrentElement == m_pRootElement) && (m_nCurrentPosition == NODEPOSITION_ENDELEMENT )) + { + break; } - m_pCurrentElement = pTempCurrentElement; - m_nCurrentPosition = nTempCurrentPosition; + getNextSAXEvent(); } + + m_pCurrentElement = pTempCurrentElement; + m_nCurrentPosition = nTempCurrentPosition; } void SAL_CALL XMLDocumentWrapper_XmlSecImpl::generateSAXEvents( |