[PATCH] only use X509Data
authorCaolán McNamara <caolanm@redhat.com>
Mon, 20 Dec 2021 17:05:44 +0000 (17:05 +0000)
committerRene Engelhard <rene@debian.org>
Sat, 25 Mar 2023 13:04:55 +0000 (13:04 +0000)
Change-Id: I52e6588f5fac04bb26d77c1f3af470db73e41f72
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127193
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit be446d81e07b5499152efeca6ca23034e51ea5ff)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127178
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Gbp-Pq: Name b0404f80577de9ff69e58390c6f6ef949fdb0139.patch

xmlsecurity/inc/xmlsec-wrapper.h
xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx
xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx

index c060c8bf23b8e76b13ce45ab799411f419e1b185..2d06dcfdd54954fb9974d30fcb1f1831e6a5bb0c 100644 (file)
 #include <xmlsec/nss/app.h>
 #include <xmlsec/nss/crypto.h>
 #include <xmlsec/nss/pkikeys.h>
+#include <xmlsec/nss/x509.h>
+#endif
+#ifdef XMLSEC_CRYPTO_MSCRYPTO
+#include <xmlsec/mscng/x509.h>
 #endif
 
 #endif
index c699c950f35154b120e68f026642598deea4a451..359e4ce2dd4964aa177631ae672415874f496594 100644 (file)
@@ -233,6 +233,10 @@ SAL_CALL XMLSignature_MSCryptImpl::validate(
     // We do certificate verification ourselves.
     pDsigCtx->keyInfoReadCtx.flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_DONT_VERIFY_CERTS;
 
+    // limit possible key data to valid X509 certificates only, no KeyValues
+    if (xmlSecPtrListAdd(&(pDsigCtx->keyInfoReadCtx.enabledKeyData), BAD_CAST xmlSecMSCngKeyDataX509GetKlass()) < 0)
+        throw RuntimeException("failed to limit allowed key data");
+
     //Verify signature
     //The documentation says that the signature is only valid if the return value is 0 (that is, not < 0)
     //AND pDsigCtx->status == xmlSecDSigStatusSucceeded. That is, we must not make any assumptions, if
index b41d754f740725e47645a5073fe2b06dbef4598b..fde4b747e9322b61ed2bc763dae24403920db07d 100644 (file)
@@ -247,6 +247,10 @@ SAL_CALL XMLSignature_NssImpl::validate(
         // We do certificate verification ourselves.
         pDsigCtx->keyInfoReadCtx.flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_DONT_VERIFY_CERTS;
 
+        // limit possible key data to valid X509 certificates only, no KeyValues
+        if (xmlSecPtrListAdd(&(pDsigCtx->keyInfoReadCtx.enabledKeyData), BAD_CAST xmlSecNssKeyDataX509GetKlass()) < 0)
+            throw RuntimeException("failed to limit allowed key data");
+
         //Verify signature
         int rs = xmlSecDSigCtxVerify( pDsigCtx.get() , pNode );