Skip to contentSkip to conversation

unit: Add better check for pkcs8_key_parser availability

PATCH Superseded Bastien Nocera 2 participants 3 messages Feb 19

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 unit: Add better check for pkcs8_key_parser availability

Check whether the pkcs8_key_parser kernel module is available (whether built-in or as a module) before announcing that we support PKCS#8.
---
Changes since v1:
- Fix missing #include

 unit/test-eapol.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
unit/test-eapol.c +11 -0
index 58f3e054a5ae..2ffc3e700108 100644
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
+#include <sys/stat.h>
 #include <linux/if_ether.h>
 #include <ell/ell.h>
 
@@ -3923,6 +3924,16 @@ static bool aes_precheck(const void *data)
 
 static bool pkcs8_precheck(const void *data)
 {
+	struct stat s;
+
+	/* Despite the path, this directory exists whether the module
+	 * is external or built-in. */
+	if (stat ("/sys/module/pkcs8_key_parser", &s) != 0)
+		return false;
+
+	if (!S_ISDIR (s.st_mode))
+		return false;
+
 	return (IS_ENABLED(HAVE_PKCS8_SUPPORT) &&
 		l_cipher_is_supported(L_CIPHER_AES) &&
 		l_cipher_is_supported(L_CIPHER_AES_CBC) &&
Signature · 1 line
2.53.0
#1 lore raw

Hi Bastien,

Quoted 22 lines

Check whether the pkcs8_key_parser kernel module is available (whether built-in or as a module) before announcing that we support PKCS#8.
---
Changes since v1:
- Fix missing #include

unit/test-eapol.c | 11 +++++++++++

1 file changed, 11 insertions(+)
unit/test-eapol.c +1 -0
index 58f3e054a5ae..2ffc3e700108 100644
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
+#include <sys/stat.h>
 #include <linux/if_ether.h>
 #include <ell/ell.h>
 

unit/test-eapol.c static bool aes_precheck(const void *data) · line 3930

Quoted 7 lines
unit/test-eapol.c +4 -0
@@ -3923,6 +3924,16 @@ static bool aes_precheck(const void *data)
 
 static bool pkcs8_precheck(const void *data)
 {
+ struct stat s;
+
+ /* Despite the path, this directory exists whether the module
+ * is external or built-in. */

for some reason we stuck with this comments style (M2 in doc/coding-style.txt):

	/*
	 * foo
	 * bar
	 */

Regards

Marcel

#2 lore raw
Quoted 36 lines · Marcel Holtmann

Hi Bastien,

Quoted 23 lines

Check whether the pkcs8_key_parser kernel module is available (whether
built-in or as a module) before announcing that we support PKCS#8.
---
Changes since v1:
- Fix missing #include

unit/test-eapol.c | 11 +++++++++++

1 file changed, 11 insertions(+)
unit/test-eapol.c +1 -0
index 58f3e054a5ae..2ffc3e700108 100644
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
+#include <sys/stat.h>
 #include <linux/if_ether.h>
 #include <ell/ell.h>
 

unit/test-eapol.c static bool aes_precheck(const void *data) · line 3930

Quoted 7 lines
unit/test-eapol.c +4 -0
@@ -3923,6 +3924,16 @@ static bool aes_precheck(const void *data)
 
 static bool pkcs8_precheck(const void *data)
 {
+ struct stat s;
+
+ /* Despite the path, this directory exists whether the module
+ * is external or built-in. */

for some reason we stuck with this comments style (M2 in doc/coding- style.txt):

Quoted 4 lines
	/*
	 * foo
	 * bar
	 */

Sent a v3.