907366
From ae1bd20a2d4d7b7d64edc3b06d7f901c05175b7d Mon Sep 17 00:00:00 2001
907366
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
907366
Date: Mon, 20 Dec 2021 17:05:44 +0000
907366
Subject: [PATCH] only use X509Data
907366
907366
Change-Id: I52e6588f5fac04bb26d77c1f3af470db73e41f72
907366
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127193
907366
Tested-by: Jenkins
907366
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
907366
(cherry picked from commit be446d81e07b5499152efeca6ca23034e51ea5ff)
907366
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127178
907366
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
907366
(cherry picked from commit b0404f80577de9ff69e58390c6f6ef949fdb0139)
907366
---
907366
 .../source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx      | 6 ++++++
907366
 xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx      | 6 ++++++
907366
 2 files changed, 12 insertions(+)
907366
907366
diff --git a/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx
907366
index db400e6..39f9d7f 100644
907366
--- a/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx
907366
+++ b/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx
907366
@@ -21,6 +21,8 @@
907366
 #include <sal/log.hxx>
907366
 #include <rtl/uuid.h>
907366
 
907366
+#include <xmlsec/mscng/x509.h>
907366
+
907366
 #include <com/sun/star/xml/crypto/SecurityOperationStatus.hpp>
907366
 #include <com/sun/star/xml/crypto/XXMLSignature.hpp>
907366
 
907366
@@ -229,6 +231,10 @@ SAL_CALL XMLSignature_MSCryptImpl::validate(
907366
     // We do certificate verification ourselves.
907366
     pDsigCtx->keyInfoReadCtx.flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_DONT_VERIFY_CERTS;
907366
 
907366
+    // limit possible key data to valid X509 certificates only, no KeyValues
907366
+    if (xmlSecPtrListAdd(&(pDsigCtx->keyInfoReadCtx.enabledKeyData), BAD_CAST xmlSecMSCngKeyDataX509GetKlass()) < 0)
907366
+        throw RuntimeException("failed to limit allowed key data");
907366
+
907366
     //Verify signature
907366
     //The documentation says that the signature is only valid if the return value is 0 (that is, not < 0)
907366
     //AND pDsigCtx->status == xmlSecDSigStatusSucceeded. That is, we must not make any assumptions, if
907366
diff --git a/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx
907366
index 827580b..8f4d6f8 100644
907366
--- a/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx
907366
+++ b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx
907366
@@ -19,6 +19,8 @@
907366
 
907366
 #include <sal/config.h>
907366
 
907366
+#include <xmlsec/nss/x509.h>
907366
+
907366
 #include <xmlelementwrapper_xmlsecimpl.hxx>
907366
 #include <xmlsec/xmlstreamio.hxx>
907366
 #include <xmlsec/errorcallback.hxx>
907366
@@ -243,6 +245,10 @@ SAL_CALL XMLSignature_NssImpl::validate(
907366
         // We do certificate verification ourselves.
907366
         pDsigCtx->keyInfoReadCtx.flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_DONT_VERIFY_CERTS;
907366
 
907366
+        // limit possible key data to valid X509 certificates only, no KeyValues
907366
+        if (xmlSecPtrListAdd(&(pDsigCtx->keyInfoReadCtx.enabledKeyData), BAD_CAST xmlSecNssKeyDataX509GetKlass()) < 0)
907366
+            throw RuntimeException("failed to limit allowed key data");
907366
+
907366
         //Verify signature
907366
         int rs = xmlSecDSigCtxVerify( pDsigCtx.get() , pNode );
907366
 
907366
-- 
907366
2.33.1
907366