]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
CRMF: make create_popo_signature() check that pubkey and pkey match
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Mon, 1 Aug 2022 16:54:06 +0000 (18:54 +0200)
committerDr. David von Oheimb <dev@ddvo.net>
Wed, 24 Aug 2022 09:27:12 +0000 (11:27 +0200)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/18930)

crypto/crmf/crmf_lib.c

index e28c7fe9bebe11ed8e94e526f8f26a4034c305bf..aaafda4ba3ccfc0b3f5e56e91049030849c35089 100644 (file)
@@ -31,6 +31,7 @@
 #include "crmf_local.h"
 #include "internal/constant_time.h"
 #include "internal/sizes.h"
+#include "crypto/x509.h"
 
 /* explicit #includes not strictly needed since implied by the above: */
 #include <openssl/crmf.h>
@@ -370,11 +371,16 @@ static int create_popo_signature(OSSL_CRMF_POPOSIGNINGKEY *ps,
                                  OSSL_LIB_CTX *libctx, const char *propq)
 {
     char name[80] = "";
+    EVP_PKEY *pub;
 
     if (ps == NULL || cr == NULL || pkey == NULL) {
         ERR_raise(ERR_LIB_CRMF, CRMF_R_NULL_ARGUMENT);
         return 0;
     }
+    pub = X509_PUBKEY_get0(cr->certTemplate->publicKey);
+    if (!ossl_x509_check_private_key(pub, pkey))
+        return 0;
+
     if (ps->poposkInput != NULL) {
         /* We do not support cases 1+2 defined in RFC 4211, section 4.1 */
         ERR_raise(ERR_LIB_CRMF, CRMF_R_POPOSKINPUT_NOT_SUPPORTED);