From: Mimi Zohar <zohar@linux.vnet.ibm.com>
To: David Howells <dhowells@redhat.com>
Cc: Dmitry Kasatkin <d.kasatkin@samsung.com>,
keyrings <keyrings@linux-nfs.org>,
linux-security-module <linux-security-module@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Josh Boyer <jwboyer@redhat.com>,
Matthew Garrett <mjg59@srcf.ucam.org>,
Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
Mimi Zohar <zohar@linux.vnet.ibm.com>
Subject: [PATCH v6 3/6] KEYS: make partial key id matching as a dedicated function
Date: Tue, 24 Jun 2014 10:40:49 -0400 [thread overview]
Message-ID: <1403620852-16476-4-git-send-email-zohar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1403620852-16476-1-git-send-email-zohar@linux.vnet.ibm.com>
From: Dmitry Kasatkin <d.kasatkin@samsung.com>
To avoid code duplication this patch refactors asymmetric_key_match(),
making partial ID string match a separate function.
This patch also implicitly fixes a bug in the code. asymmetric_key_match()
allows to match the key by its subtype. But subtype matching could be
undone if asymmetric_key_id(key) would return NULL. This patch first
checks for matching spec and then for its value.
Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
---
crypto/asymmetric_keys/asymmetric_keys.h | 2 ++
crypto/asymmetric_keys/asymmetric_type.c | 50 ++++++++++++++++++++------------
2 files changed, 33 insertions(+), 19 deletions(-)
diff --git a/crypto/asymmetric_keys/asymmetric_keys.h b/crypto/asymmetric_keys/asymmetric_keys.h
index 515b634..a63c551 100644
--- a/crypto/asymmetric_keys/asymmetric_keys.h
+++ b/crypto/asymmetric_keys/asymmetric_keys.h
@@ -9,6 +9,8 @@
* 2 of the Licence, or (at your option) any later version.
*/
+int asymmetric_keyid_match(const char *kid, const char *id);
+
static inline const char *asymmetric_key_id(const struct key *key)
{
return key->type_data.p[1];
diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c
index b77eb53..1fd1d30 100644
--- a/crypto/asymmetric_keys/asymmetric_type.c
+++ b/crypto/asymmetric_keys/asymmetric_type.c
@@ -23,6 +23,34 @@ static LIST_HEAD(asymmetric_key_parsers);
static DECLARE_RWSEM(asymmetric_key_parsers_sem);
/*
+ * Match asymmetric key id with partial match
+ * @id: key id to match in a form "id:<id>"
+ */
+int asymmetric_keyid_match(const char *kid, const char *id)
+{
+ size_t idlen, kidlen;
+
+ if (!kid || !id)
+ return 0;
+
+ /* make it possible to use id as in the request: "id:<id>" */
+ if (strncmp(id, "id:", 3) == 0)
+ id += 3;
+
+ /* Anything after here requires a partial match on the ID string */
+ idlen = strlen(id);
+ kidlen = strlen(kid);
+ if (idlen > kidlen)
+ return 0;
+
+ kid += kidlen - idlen;
+ if (strcasecmp(id, kid) != 0)
+ return 0;
+
+ return 1;
+}
+
+/*
* Match asymmetric keys on (part of) their name
* We have some shorthand methods for matching keys. We allow:
*
@@ -34,9 +62,8 @@ static int asymmetric_key_match(const struct key *key, const void *description)
{
const struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key);
const char *spec = description;
- const char *id, *kid;
+ const char *id;
ptrdiff_t speclen;
- size_t idlen, kidlen;
if (!subtype || !spec || !*spec)
return 0;
@@ -55,23 +82,8 @@ static int asymmetric_key_match(const struct key *key, const void *description)
speclen = id - spec;
id++;
- /* Anything after here requires a partial match on the ID string */
- kid = asymmetric_key_id(key);
- if (!kid)
- return 0;
-
- idlen = strlen(id);
- kidlen = strlen(kid);
- if (idlen > kidlen)
- return 0;
-
- kid += kidlen - idlen;
- if (strcasecmp(id, kid) != 0)
- return 0;
-
- if (speclen == 2 &&
- memcmp(spec, "id", 2) == 0)
- return 1;
+ if (speclen == 2 && memcmp(spec, "id", 2) == 0)
+ return asymmetric_keyid_match(asymmetric_key_id(key), id);
if (speclen == subtype->name_len &&
memcmp(spec, subtype->name, speclen) == 0)
--
1.8.1.4
next prev parent reply other threads:[~2014-06-24 14:42 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 14:40 [PATCH v6 0/6] ima: extending secure boot certificate chain of trust Mimi Zohar
2014-06-24 14:40 ` [PATCH v6 1/6] KEYS: special dot prefixed keyring name bug fix Mimi Zohar
2014-06-24 14:40 ` [PATCH v6 2/6] KEYS: verify a certificate is signed by a 'trusted' key Mimi Zohar
2014-06-24 14:40 ` Mimi Zohar [this message]
2014-06-24 14:40 ` [PATCH v6 4/6] KEYS: validate certificate trust only with selected owner key Mimi Zohar
2014-06-24 14:40 ` [PATCH v6 5/6] KEYS: validate certificate trust only with builtin keys Mimi Zohar
2014-06-24 14:40 ` [PATCH v6 6/6] ima: define '.ima' as a builtin 'trusted' keyring Mimi Zohar
2014-06-27 13:24 ` [PATCH v6 1/6] KEYS: special dot prefixed keyring name bug fix David Howells
2014-06-27 13:38 ` [PATCH v6 3/6] KEYS: make partial key id matching as a dedicated function David Howells
2014-06-30 13:14 ` Dmitry Kasatkin
2014-06-30 19:20 ` Mimi Zohar
2014-06-27 13:54 ` [PATCH v6 5/6] KEYS: validate certificate trust only with builtin keys David Howells
2014-06-27 17:50 ` Mimi Zohar
2014-06-27 13:55 ` [PATCH v6 4/6] KEYS: validate certificate trust only with selected owner key David Howells
2014-06-27 17:44 ` Mimi Zohar
2014-06-30 13:47 ` Dmitry Kasatkin
2014-06-30 13:57 ` Mimi Zohar
2014-06-27 14:17 ` [PATCH v6 6/6] ima: define '.ima' as a builtin 'trusted' keyring David Howells
2014-07-09 15:31 ` [PATCH v6 0/6] ima: extending secure boot certificate chain of trust David Howells
2014-07-09 16:40 ` Mimi Zohar
2014-07-09 18:56 ` David Howells
2014-07-09 21:29 ` Mimi Zohar
2014-07-10 14:47 ` Dmitry Kasatkin
2014-07-13 21:06 ` David Howells
2014-07-16 13:15 ` Mimi Zohar
2014-07-17 19:43 ` David Howells
2014-07-17 20:07 ` Mimi Zohar
2014-07-17 20:37 ` David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1403620852-16476-4-git-send-email-zohar@linux.vnet.ibm.com \
--to=zohar@linux.vnet.ibm.com \
--cc=d.kasatkin@samsung.com \
--cc=dhowells@redhat.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=jwboyer@redhat.com \
--cc=keyrings@linux-nfs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mjg59@srcf.ucam.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome