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