linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ima-evm-utils] First try to get keyid from cert then fall back to calculating
@ 2024-04-29 19:09 Stefan Berger
  0 siblings, 0 replies; only message in thread
From: Stefan Berger @ 2024-04-29 19:09 UTC (permalink / raw)
  To: linux-integrity; +Cc: zohar, roberto.sassu, Stefan Berger

When trying to verify signatures then verification may fail if the key id
derived from the subject key identifier (skid) is different from the one
that is being calculated from the public key. Therefore, first try to get
the key id from the skid of a certificate and only if this does not work
then fall back to calculating it from the public key. This way signature
verification will first use the same method to get the key id as the Linux
kernel does.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 src/libimaevm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/libimaevm.c b/src/libimaevm.c
index 89330c4..729be7b 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -71,6 +71,9 @@
 #include "imaevm.h"
 #include "hash_info.h"
 
+static int read_keyid_from_cert(uint32_t *keyid_be, const char *certfile,
+				int try_der);
+
 /* Names that are primary for OpenSSL. */
 static const char *const pkey_hash_algo[PKEY_HASH__LAST] = {
 	[PKEY_HASH_MD4]		= "md4",
@@ -458,7 +461,9 @@ int imaevm_init_public_keys(const char *keyfiles,
 			continue;
 		}
 
-		calc_keyid_v2(&entry->keyid, entry->name, entry->key);
+		if (read_keyid_from_cert(&entry->keyid, keyfile, 1) < 0)
+			calc_keyid_v2(&entry->keyid, entry->name, entry->key);
+
 		sprintf(entry->name, "%x", __be32_to_cpup(&entry->keyid));
 		log_info("key %d: %s %s\n", i++, entry->name, keyfile);
 		entry->next = *public_keys;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-29 19:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29 19:09 [PATCH ima-evm-utils] First try to get keyid from cert then fall back to calculating Stefan Berger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).