1458e3
From c2cf13da3bbf756ef3f78251c40d45fc23c27f36 Mon Sep 17 00:00:00 2001
1458e3
From: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
1458e3
Date: Wed, 29 Apr 2020 07:42:24 +0200
1458e3
Subject: [PATCH 1/6] backports to ease CVE backporting
1458e3
1458e3
Remove unnecessary if block
1458e3
1458e3
And format code inside
1458e3
1458e3
Change-Id: Ied0d98935134bf6f7bc8c929645ad5faac9affa3
1458e3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93116
1458e3
Tested-by: Jenkins
1458e3
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
1458e3
(cherry picked from commit cf36fe5eb41910c26d58fb25e54ccf2e0ee01365)
1458e3
1458e3
space out the namespace constant values
1458e3
1458e3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88938
1458e3
(cherry picked from commit 5352d45dd4a04f8f02cf7f6ad4169126d3b3586a)
1458e3
1458e3
Change-Id: I30f54bfc1389e91b18e4fee8b83e1b297419899b
1458e3
---
1458e3
 include/xmloff/xmlnmspe.hxx                   |  16 +--
1458e3
 .../component/documentdigitalsignatures.cxx   | 130 +++++++++---------
1458e3
 .../source/helper/xmlsignaturehelper.cxx      |   1 +
1458e3
 3 files changed, 75 insertions(+), 72 deletions(-)
1458e3
1458e3
diff --git a/include/xmloff/xmlnmspe.hxx b/include/xmloff/xmlnmspe.hxx
1458e3
index a00628b6b999..b079053c38d3 100644
1458e3
--- a/include/xmloff/xmlnmspe.hxx
1458e3
+++ b/include/xmloff/xmlnmspe.hxx
1458e3
@@ -69,7 +69,7 @@ XML_NAMESPACE( XML_NAMESPACE_VERSIONS_LIST,   37U )
1458e3
 
1458e3
 // namespaces for odf extended formats
1458e3
 
1458e3
-#define XML_NAMESPACE_EXT_BASE 38U
1458e3
+#define XML_NAMESPACE_EXT_BASE 50U
1458e3
 #define XML_NAMESPACE_EXT( prefix, index ) \
1458e3
 const sal_uInt16 prefix = (XML_NAMESPACE_EXT_BASE+index);
1458e3
 
1458e3
@@ -82,7 +82,7 @@ XML_NAMESPACE_EXT( XML_NAMESPACE_LO_EXT,           5U )
1458e3
 
1458e3
 // namespaces for OOo formats
1458e3
 
1458e3
-#define XML_NAMESPACE_OOO_BASE 44U
1458e3
+#define XML_NAMESPACE_OOO_BASE 60U
1458e3
 #define XML_NAMESPACE_OOO( prefix, index ) \
1458e3
 const sal_uInt16 prefix = (XML_NAMESPACE_OOO_BASE+index);
1458e3
 
1458e3
@@ -100,7 +100,7 @@ XML_NAMESPACE_OOO( XML_NAMESPACE_CONFIG_OOO,        10U )
1458e3
 XML_NAMESPACE_OOO( XML_NAMESPACE_FORM_OOO,          11U )
1458e3
 XML_NAMESPACE_OOO( XML_NAMESPACE_SCRIPT_OOO,        12U )
1458e3
 
1458e3
-#define XML_NAMESPACE_COMPAT_BASE 57U
1458e3
+#define XML_NAMESPACE_COMPAT_BASE 80U
1458e3
 #define XML_NAMESPACE_COMPAT( prefix, index ) \
1458e3
 const sal_uInt16 prefix = (XML_NAMESPACE_COMPAT_BASE+index);
1458e3
 
1458e3
@@ -108,14 +108,14 @@ XML_NAMESPACE_COMPAT( XML_NAMESPACE_SVG_COMPAT,      0U )
1458e3
 XML_NAMESPACE_COMPAT( XML_NAMESPACE_FO_COMPAT,       1U )
1458e3
 XML_NAMESPACE_COMPAT( XML_NAMESPACE_SMIL_COMPAT,     2U )
1458e3
 
1458e3
-#define XML_NAMESPACE_OASIS_BASE 60U
1458e3
+#define XML_NAMESPACE_OASIS_BASE 90U
1458e3
 #define XML_NAMESPACE_OASIS( prefix, index ) \
1458e3
 const sal_uInt16 prefix = (XML_NAMESPACE_OASIS_BASE+index);
1458e3
 
1458e3
 XML_NAMESPACE_OASIS( XML_NAMESPACE_DB_OASIS,         0U )
1458e3
 XML_NAMESPACE_OASIS( XML_NAMESPACE_REPORT_OASIS,     1U )
1458e3
 
1458e3
-#define XML_OLD_NAMESPACE_BASE 62U
1458e3
+#define XML_OLD_NAMESPACE_BASE 100U
1458e3
 #define XML_OLD_NAMESPACE( prefix, index ) \
1458e3
 const sal_uInt16 prefix = (XML_OLD_NAMESPACE_BASE+index);
1458e3
 
1458e3
@@ -134,9 +134,9 @@ XML_OLD_NAMESPACE( XML_OLD_NAMESPACE_CHART,         10U )
1458e3
 XML_OLD_NAMESPACE( XML_OLD_NAMESPACE_SMIL,          11U )
1458e3
 
1458e3
 // experimental namespaces
1458e3
-XML_NAMESPACE( XML_NAMESPACE_FIELD,           100U )
1458e3
-XML_NAMESPACE( XML_NAMESPACE_CSS3TEXT,        103U )  // CSS Text Level 3
1458e3
-XML_NAMESPACE( XML_NAMESPACE_FORMX,           101U )  // form interop extensions
1458e3
+XML_NAMESPACE( XML_NAMESPACE_FIELD,           120U )
1458e3
+XML_NAMESPACE( XML_NAMESPACE_CSS3TEXT,        123U )  // CSS Text Level 3
1458e3
+XML_NAMESPACE( XML_NAMESPACE_FORMX,           121U )  // form interop extensions
1458e3
 
1458e3
 
1458e3
 #endif // INCLUDED_XMLOFF_XMLNMSPE_HXX
1458e3
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx
1458e3
index dcfaad0af773..52cb938a8e0a 100644
1458e3
--- a/xmlsecurity/source/component/documentdigitalsignatures.cxx
1458e3
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
1458e3
@@ -500,85 +500,87 @@ DocumentDigitalSignatures::ImplVerifySignatures(
1458e3
     Sequence< css::security::DocumentSignatureInformation > aInfos(nInfos);
1458e3
     css::security::DocumentSignatureInformation* arInfos = aInfos.getArray();
1458e3
 
1458e3
-    if ( nInfos )
1458e3
+    for (int n = 0; n < nInfos; ++n)
1458e3
     {
1458e3
-        for( int n = 0; n < nInfos; ++n )
1458e3
-        {
1458e3
-            DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm(
1458e3
-                m_sODFVersion, aSignInfos[n]);
1458e3
-            const std::vector< OUString > aElementsToBeVerified =
1458e3
-                DocumentSignatureHelper::CreateElementList(
1458e3
-                rxStorage, eMode, mode);
1458e3
+        DocumentSignatureAlgorithm mode
1458e3
+            = DocumentSignatureHelper::getDocumentAlgorithm(m_sODFVersion, aSignInfos[n]);
1458e3
+        const std::vector<OUString> aElementsToBeVerified
1458e3
+            = DocumentSignatureHelper::CreateElementList(rxStorage, eMode, mode);
1458e3
 
1458e3
-            const SignatureInformation& rInfo = aSignInfos[n];
1458e3
-            css::security::DocumentSignatureInformation& rSigInfo = arInfos[n];
1458e3
+        const SignatureInformation& rInfo = aSignInfos[n];
1458e3
+        css::security::DocumentSignatureInformation& rSigInfo = arInfos[n];
1458e3
 
1458e3
-            if (rInfo.ouGpgCertificate.isEmpty()) // X.509
1458e3
+        if (rInfo.ouGpgCertificate.isEmpty()) // X.509
1458e3
+        {
1458e3
+            if (!rInfo.ouX509Certificate.isEmpty())
1458e3
+                rSigInfo.Signer = xSecEnv->createCertificateFromAscii(rInfo.ouX509Certificate);
1458e3
+            if (!rSigInfo.Signer.is())
1458e3
+                rSigInfo.Signer = xSecEnv->getCertificate(
1458e3
+                    rInfo.ouX509IssuerName,
1458e3
+                    xmlsecurity::numericStringToBigInteger(rInfo.ouX509SerialNumber));
1458e3
+
1458e3
+            // On Windows checking the certificate path is buggy. It does name matching (issuer, subject name)
1458e3
+            // to find the parent certificate. It does not take into account that there can be several certificates
1458e3
+            // with the same subject name.
1458e3
+            try
1458e3
             {
1458e3
-                if (!rInfo.ouX509Certificate.isEmpty())
1458e3
-                    rSigInfo.Signer = xSecEnv->createCertificateFromAscii( rInfo.ouX509Certificate ) ;
1458e3
-                if (!rSigInfo.Signer.is())
1458e3
-                    rSigInfo.Signer = xSecEnv->getCertificate( rInfo.ouX509IssuerName,
1458e3
-                                                               xmlsecurity::numericStringToBigInteger( rInfo.ouX509SerialNumber ) );
1458e3
-
1458e3
-                // On Windows checking the certificate path is buggy. It does name matching (issuer, subject name)
1458e3
-                // to find the parent certificate. It does not take into account that there can be several certificates
1458e3
-                // with the same subject name.
1458e3
-
1458e3
-                try {
1458e3
-                    rSigInfo.CertificateStatus = xSecEnv->verifyCertificate(rSigInfo.Signer,
1458e3
-                                                                            Sequence<Reference<css::security::XCertificate> >());
1458e3
-                } catch (SecurityException& ) {
1458e3
-                    OSL_FAIL("Verification of certificate failed");
1458e3
-                    rSigInfo.CertificateStatus = css::security::CertificateValidity::INVALID;
1458e3
-                }
1458e3
+                rSigInfo.CertificateStatus = xSecEnv->verifyCertificate(
1458e3
+                    rSigInfo.Signer, Sequence<Reference<css::security::XCertificate>>());
1458e3
             }
1458e3
-            else if (xGpgSecEnv.is()) // GPG
1458e3
+            catch (SecurityException&)
1458e3
             {
1458e3
-                // TODO not ideal to retrieve cert by keyID, might
1458e3
-                // collide, or PGPKeyID format might change - can't we
1458e3
-                // keep the xCert itself in rInfo?
1458e3
-                rSigInfo.Signer = xGpgSecEnv->getCertificate( rInfo.ouGpgKeyID, xmlsecurity::numericStringToBigInteger("") );
1458e3
-                rSigInfo.CertificateStatus = xGpgSecEnv->verifyCertificate(rSigInfo.Signer,
1458e3
-                                                                           Sequence<Reference<css::security::XCertificate> >());
1458e3
+                OSL_FAIL("Verification of certificate failed");
1458e3
+                rSigInfo.CertificateStatus = css::security::CertificateValidity::INVALID;
1458e3
             }
1458e3
+        }
1458e3
+        else if (xGpgSecEnv.is()) // GPG
1458e3
+        {
1458e3
+            // TODO not ideal to retrieve cert by keyID, might
1458e3
+            // collide, or PGPKeyID format might change - can't we
1458e3
+            // keep the xCert itself in rInfo?
1458e3
+            rSigInfo.Signer = xGpgSecEnv->getCertificate(
1458e3
+                rInfo.ouGpgKeyID, xmlsecurity::numericStringToBigInteger(""));
1458e3
+            rSigInfo.CertificateStatus = xGpgSecEnv->verifyCertificate(
1458e3
+                rSigInfo.Signer, Sequence<Reference<css::security::XCertificate>>());
1458e3
+        }
1458e3
 
1458e3
-            // Time support again (#i38744#)
1458e3
-            Date aDate( rInfo.stDateTime.Day, rInfo.stDateTime.Month, rInfo.stDateTime.Year );
1458e3
-            tools::Time aTime( rInfo.stDateTime.Hours, rInfo.stDateTime.Minutes,
1458e3
-                        rInfo.stDateTime.Seconds, rInfo.stDateTime.NanoSeconds );
1458e3
-            rSigInfo.SignatureDate = aDate.GetDate();
1458e3
-            rSigInfo.SignatureTime = aTime.GetTime() / tools::Time::nanoPerCenti;
1458e3
+        // Time support again (#i38744#)
1458e3
+        Date aDate(rInfo.stDateTime.Day, rInfo.stDateTime.Month, rInfo.stDateTime.Year);
1458e3
+        tools::Time aTime(rInfo.stDateTime.Hours, rInfo.stDateTime.Minutes,
1458e3
+                          rInfo.stDateTime.Seconds, rInfo.stDateTime.NanoSeconds);
1458e3
+        rSigInfo.SignatureDate = aDate.GetDate();
1458e3
+        rSigInfo.SignatureTime = aTime.GetTime() / tools::Time::nanoPerCenti;
1458e3
 
1458e3
-            rSigInfo.SignatureIsValid = ( rInfo.nStatus == css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED );
1458e3
+        rSigInfo.SignatureIsValid
1458e3
+            = (rInfo.nStatus == css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED);
1458e3
 
1458e3
-            // Signature line info (ID + Images)
1458e3
-            if (!rInfo.ouSignatureLineId.isEmpty())
1458e3
-                rSigInfo.SignatureLineId = rInfo.ouSignatureLineId;
1458e3
+        // Signature line info (ID + Images)
1458e3
+        if (!rInfo.ouSignatureLineId.isEmpty())
1458e3
+            rSigInfo.SignatureLineId = rInfo.ouSignatureLineId;
1458e3
 
1458e3
-            if (rInfo.aValidSignatureImage.is())
1458e3
-                rSigInfo.ValidSignatureLineImage = rInfo.aValidSignatureImage;
1458e3
+        if (rInfo.aValidSignatureImage.is())
1458e3
+            rSigInfo.ValidSignatureLineImage = rInfo.aValidSignatureImage;
1458e3
 
1458e3
-            if (rInfo.aInvalidSignatureImage.is())
1458e3
-                rSigInfo.InvalidSignatureLineImage = rInfo.aInvalidSignatureImage;
1458e3
-
1458e3
-            // OOXML intentionally doesn't sign metadata.
1458e3
-            if ( rSigInfo.SignatureIsValid && aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
1458e3
-            {
1458e3
-                 rSigInfo.SignatureIsValid =
1458e3
-                      DocumentSignatureHelper::checkIfAllFilesAreSigned(
1458e3
-                      aElementsToBeVerified, rInfo, mode);
1458e3
-            }
1458e3
-            if (eMode == DocumentSignatureMode::Content)
1458e3
-            {
1458e3
-                if (aStreamHelper.nStorageFormat == embed::StorageFormats::OFOPXML)
1458e3
-                    rSigInfo.PartialDocumentSignature = true;
1458e3
-                else
1458e3
-                    rSigInfo.PartialDocumentSignature = !DocumentSignatureHelper::isOOo3_2_Signature(aSignInfos[n]);
1458e3
-            }
1458e3
+        if (rInfo.aInvalidSignatureImage.is())
1458e3
+            rSigInfo.InvalidSignatureLineImage = rInfo.aInvalidSignatureImage;
1458e3
 
1458e3
+        // OOXML intentionally doesn't sign metadata.
1458e3
+        if (rSigInfo.SignatureIsValid
1458e3
+            && aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
1458e3
+        {
1458e3
+            rSigInfo.SignatureIsValid = DocumentSignatureHelper::checkIfAllFilesAreSigned(
1458e3
+                aElementsToBeVerified, rInfo, mode);
1458e3
+        }
1458e3
+        if (eMode == DocumentSignatureMode::Content)
1458e3
+        {
1458e3
+            if (aStreamHelper.nStorageFormat == embed::StorageFormats::OFOPXML)
1458e3
+                rSigInfo.PartialDocumentSignature = true;
1458e3
+            else
1458e3
+                rSigInfo.PartialDocumentSignature
1458e3
+                    = !DocumentSignatureHelper::isOOo3_2_Signature(aSignInfos[n]);
1458e3
         }
1458e3
     }
1458e3
+
1458e3
     return aInfos;
1458e3
 
1458e3
 }
1458e3
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
1458e3
index 6ec834053a17..22c056e70da1 100644
1458e3
--- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx
1458e3
+++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
1458e3
@@ -402,6 +402,7 @@ bool XMLSignatureHelper::ReadAndVerifySignatureStorageStream(const css::uno::Ref
1458e3
     catch(const uno::Exception&)
1458e3
     {
1458e3
         DBG_UNHANDLED_EXCEPTION("xmlsecurity.helper");
1458e3
+        mbError = true;
1458e3
     }
1458e3
 
1458e3
     mpXSecController->releaseSignatureReader();
1458e3
-- 
1458e3
2.32.0
1458e3