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