From: James Prestwood <prestwoj@gmail.com>
To: ell@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [RFC 2/8] unit: add key search test
Date: Fri, 18 Nov 2022 13:16:18 -0800 [thread overview]
Message-ID: <20221118211624.19298-3-prestwoj@gmail.com> (raw)
In-Reply-To: <20221118211624.19298-1-prestwoj@gmail.com>
Creates a keyring and key using syscall directly as this is the
intended use case of l_key_search() (keys outside of ELL). Then
verifies that l_key_search() returns the same ID as the created key.
---
unit/test-key.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/unit/test-key.c b/unit/test-key.c
index 240a02c..0e09cf4 100644
--- a/unit/test-key.c
+++ b/unit/test-key.c
@@ -24,6 +24,9 @@
#include <config.h>
#endif
+#include <sys/syscall.h>
+#include <linux/keyctl.h>
+#include <unistd.h>
#include <assert.h>
#include <ell/ell.h>
@@ -661,6 +664,27 @@ static void test_key_crypto(const void *data)
l_key_free(pubkey);
}
+static void test_key_search(const void *data)
+{
+ long keyring_id;
+ long key_id;
+
+ /*
+ * Search is used to find a key out side of ELL's internal keyring. So
+ * manually create a keyring/key here rather than using l_key APIs
+ */
+
+ keyring_id = syscall(__NR_add_key, "keyring", "my-keyring", NULL,
+ 0, KEY_SPEC_USER_KEYRING);
+ assert(keyring_id >= 0);
+
+ key_id = syscall(__NR_add_key, "user", "my-key",
+ KEY1_STR, KEY1_LEN, keyring_id);
+ assert(key_id >= 0);
+
+ assert(key_id == l_key_search(L_KEY_RAW, "my-keyring", "my-key"));
+}
+
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@@ -685,5 +709,7 @@ int main(int argc, char *argv[])
if (l_key_is_supported(L_KEY_FEATURE_CRYPTO))
l_test_add("key crypto", test_key_crypto, NULL);
+ l_test_add("key search", test_key_search, NULL);
+
return l_test_run();
}
--
2.34.3
next prev parent reply other threads:[~2022-11-18 21:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 21:16 [RFC 0/8] Crypto operations by key ID James Prestwood
2022-11-18 21:16 ` [RFC 1/8] key: add l_key_search James Prestwood
2022-11-22 16:43 ` Denis Kenzior
2022-11-22 17:16 ` James Prestwood
2022-11-22 17:09 ` Denis Kenzior
2022-11-22 18:34 ` James Prestwood
2022-11-18 21:16 ` James Prestwood [this message]
2022-11-18 21:16 ` [RFC 3/8] checksum: commonize checksum creation James Prestwood
2022-11-22 16:46 ` Denis Kenzior
2022-11-18 21:16 ` [RFC 4/8] checksum: add l_checksum_new_hmac_from_key_id James Prestwood
2022-11-22 16:53 ` Denis Kenzior
2022-11-18 21:16 ` [RFC 5/8] cert-crypto: refactor l_cert_pkcs5_pbkdf2 James Prestwood
2022-11-22 17:00 ` Denis Kenzior
2022-11-18 21:16 ` [RFC 6/8] cert: add l_cert_pkcs5_pbkdf2_from_key_id James Prestwood
2022-11-22 17:03 ` Denis Kenzior
2022-11-18 21:16 ` [RFC 7/8] cert: add explicit length to l_cert_pkcs5_pbkdf2 James Prestwood
2022-11-18 21:16 ` [RFC 8/8] unit: update test-pbkdf2 with API change James Prestwood
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=20221118211624.19298-3-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=ell@lists.linux.dev \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).