Skip to contentSkip to conversation

ima-evm-utils: Add support for signing with pkcs11 URIs

PATCH Superseded Stefan Berger 4 participants 21 messages Aug 10, 2021 – Sep 4, 2021 Keys-trusted

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ima-evm-utils: Add support for signing with pkcs11 URIs

From: Stefan Berger <[email protected]>

This series of patches adds support for signing with pkcs11 URIs and the keyid explicitly provided via a command line option.
A test program is provided setting up softhsm for test cases to use. Tests are passing on gitub actions with some distros not enabled (Debian, Ubuntu) where I could not reproduce the github actions failure on the same type of container locally (debian:stable).

Stefan

v2:
- Use global imaevm_params.eng field for the ENGINE
- Fix bug on engine initialization in existing code

Stefan Berger (8):
evmctl: Implement support for EVMCTL_KEY_PASSWORD environment variable
evmctl: Handle engine initialization properly
evmctl: Move code setting up engine to own funtion
evmctl: Extend libimaevm_params with ENGINE field and use it
evmctl: Setup the pkcs11 engine if key has pkcs11: prefix
libimaevm: Add support for pkcs11 private keys for signing a v2 hash
tests: Extend sign_verify test with pkcs11-specific test
tests: Get the packages for pkcs11 testing on the CI/CD system

 README                 |   5 +
 ci/alt.sh              |   3 +
 ci/fedora.sh           |   8 ++
 ci/tumbleweed.sh       |   3 +
 src/evmctl.c           |  54 +++++---
 src/imaevm.h           |   2 +
 src/libimaevm.c        |  47 +++++--
 tests/functions.sh     |  26 ++++
 tests/sign_verify.test |  50 +++++--
 tests/softhsm_setup    | 290 +++++++++++++++++++++++++++++++++++++++++
 10 files changed, 448 insertions(+), 40 deletions(-)
 create mode 100755 tests/softhsm_setup
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/8 evmctl: Implement support for EVMCTL_KEY_PASSWORD environment variable

From: Stefan Berger <[email protected]>

If the user did not use the --pass option to provide a key password, get the key password from the EVMCTL_KEY_PASSWORD environment variable.

---
 README       | 4 ++++
 src/evmctl.c | 6 ++++++
 2 files changed, 10 insertions(+)
README +4 -0
index 87cd3b5..1cc027f 100644
@@ -70,6 +70,10 @@ OPTIONS
   -v                 increase verbosity level
   -h, --help         display this help and exit
 
+Environment variables:
+
+EVMCTL_KEY_PASSWORD  : Private key password to use; do not use --pass option
+
 
 INTRODUCTION
 ------------
src/evmctl.c +6 -0
index a8065bb..58f8e66 100644
@@ -2530,6 +2530,9 @@ static void usage(void)
 		"      --ignore-violations ignore ToMToU measurement violations\n"
 		"  -v                 increase verbosity level\n"
 		"  -h, --help         display this help and exit\n"
+		"\n"
+		"Environment variables:\n\n"
+		"EVMCTL_KEY_PASSWORD  : Private key password to use; do not use --pass option\n"
 		"\n");
 }
 
@@ -2813,6 +2816,9 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	if (!imaevm_params.keypass)
+		imaevm_params.keypass = getenv("EVMCTL_KEY_PASSWORD");
+
 	if (argv[optind] == NULL)
 		usage();
 	else
Signature · 1 line
2.31.1
maintainer
#2 lore raw

Re: [PATCH v2 1/8] evmctl: Implement support for EVMCTL_KEY_PASSWORD environment variable

[Cc: Vitaly]

Quoted 6 lines · Stefan Berger

From: Stefan Berger <[email protected]>

If the user did not use the --pass option to provide a key password, get the key password from the EVMCTL_KEY_PASSWORD environment variable.

Thanks, Stefan.

Vitaly, I'm not sure that there's any benefit of using secure heap for a password stored as an environment variable, but it needs to at least be documented.

thanks,

Mimi

#3 lore raw

Re: [PATCH v2 1/8] evmctl: Implement support for EVMCTL_KEY_PASSWORD environment variable

Mimi, Stefan,

Quoted 8 lines · Mimi Zohar

[Cc: Vitaly]

Quoted 5 lines · Stefan Berger

From: Stefan Berger <[email protected]>

If the user did not use the --pass option to provide a key password, get the key password from the EVMCTL_KEY_PASSWORD environment variable.

Quoted 7 lines
Quoted 1 line

Thanks, Stefan.

Vitaly, I'm not sure that there's any benefit of using secure heap for a password stored as an environment variable, but it needs to at least be documented.

I did not receive this patch nor it's in the git.

Thanks,

Quoted 4 lines

thanks,

Mimi

#4 lore raw

PATCH v2 2/8 evmctl: Handle engine initialization properly

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

Fix the following issue when passing a not available engine:

$ ./src/evmctl --engine foo
engine foo isn't available
140322992015168:error:25066067:DSO support routines:dlfcn_load:could not load the shared library:crypto/dso/dso_dlfcn.c:118:filename(/usr/lib64/engines-1.1/foo.so): /usr/lib64/engines-1.1/foo.so: cannot open shared object file: No such file or directory
140322992015168:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto/dso/dso_lib.c:162:
140322992015168:error:260B6084:engine routines:dynamic_load:dso not found:crypto/engine/eng_dyn.c:414:
140322992015168:error:2606A074:engine routines:ENGINE_by_id:no such engine:crypto/engine/eng_list.c:334:id=foo
Segmentation fault (core dumped)

Also, jump to the exit when the setup of the engine failed.

---
 src/evmctl.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
src/evmctl.c +5 -1
index 58f8e66..ed0ece3 100644
@@ -2765,7 +2765,10 @@ int main(int argc, char *argv[])
 				ENGINE_free(eng);
 				eng = NULL;
 			}
-			ENGINE_set_default(eng, ENGINE_METHOD_ALL);
+			if (eng)
+				ENGINE_set_default(eng, ENGINE_METHOD_ALL);
+			else
+				goto error;
 			break;
 		case 140: /* --xattr-user */
 			xattr_ima = "user.ima";
@@ -2839,6 +2842,7 @@ int main(int argc, char *argv[])
 			err = 125;
 	}
 
+error:
 	if (eng) {
 		ENGINE_finish(eng);
 		ENGINE_free(eng);
Signature · 1 line
2.31.1
maintainer
#5 lore raw

Re: [PATCH v2 2/8] evmctl: Handle engine initialization properly

Quoted 3 lines · Stefan Berger

From: Stefan Berger <[email protected]>

Fix the following issue when passing a not available engine:

First describe the problem and then include details and/or an example. For example, "Handle failure to initialize the openssl engine. For example, "

Quoted 10 lines
$ ./src/evmctl --engine foo
engine foo isn't available
140322992015168:error:25066067:DSO support routines:dlfcn_load:could not load the shared library:crypto/dso/dso_dlfcn.c:118:filename(/usr/lib64/engines-1.1/foo.so): /usr/lib64/engines-1.1/foo.so: cannot open shared object file: No such file or directory
140322992015168:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto/dso/dso_lib.c:162:
140322992015168:error:260B6084:engine routines:dynamic_load:dso not found:crypto/engine/eng_dyn.c:414:
140322992015168:error:2606A074:engine routines:ENGINE_by_id:no such engine:crypto/engine/eng_list.c:334:id=foo
Segmentation fault (core dumped)

Also, jump to the exit when the setup of the engine failed.

Patch descriptions should not be explaining the details of the code, but providing the motivation for the patch. Please remove this line.

Quoted 2 lines

Thanks,

Mimi

Quoted 28 lines
---
 src/evmctl.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
src/evmctl.c +5 -1
index 58f8e66..ed0ece3 100644
@@ -2765,7 +2765,10 @@ int main(int argc, char *argv[])
 				ENGINE_free(eng);
 				eng = NULL;
 			}
-			ENGINE_set_default(eng, ENGINE_METHOD_ALL);
+			if (eng)
+				ENGINE_set_default(eng, ENGINE_METHOD_ALL);
+			else
+				goto error;
 			break;
 		case 140: /* --xattr-user */
 			xattr_ima = "user.ima";
@@ -2839,6 +2842,7 @@ int main(int argc, char *argv[])
 			err = 125;
 	}
 
+error:
 	if (eng) {
 		ENGINE_finish(eng);
 		ENGINE_free(eng);
#6 lore raw

PATCH v2 3/8 evmctl: Move code setting up engine to own funtion

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

---
 src/evmctl.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
src/evmctl.c +19 -13
index ed0ece3..4b6f3fb 100644
@@ -2631,6 +2631,23 @@ static char *get_password(void)
 	return pwd;
 }
 
+static ENGINE *setup_engine(const char *engine_id)
+{
+	ENGINE *eng = ENGINE_by_id(engine_id);
+	if (!eng) {
+		log_err("engine %s isn't available\n", optarg);
+		ERR_print_errors_fp(stderr);
+	} else if (!ENGINE_init(eng)) {
+		log_err("engine %s init failed\n", optarg);
+		ERR_print_errors_fp(stderr);
+		ENGINE_free(eng);
+		eng = NULL;
+	}
+	if (eng)
+		ENGINE_set_default(eng, ENGINE_METHOD_ALL);
+	return eng;
+}
+
 int main(int argc, char *argv[])
 {
 	int err = 0, c, lind;
@@ -2755,19 +2772,8 @@ int main(int argc, char *argv[])
 			verify_list_sig = 1;
 			break;
 		case 139: /* --engine e */
-			eng = ENGINE_by_id(optarg);
-			if (!eng) {
-				log_err("engine %s isn't available\n", optarg);
-				ERR_print_errors_fp(stderr);
-			} else if (!ENGINE_init(eng)) {
-				log_err("engine %s init failed\n", optarg);
-				ERR_print_errors_fp(stderr);
-				ENGINE_free(eng);
-				eng = NULL;
-			}
-			if (eng)
-				ENGINE_set_default(eng, ENGINE_METHOD_ALL);
-			else
+			eng = setup_engine(optarg);
+			if (!eng)
 				goto error;
 			break;
 		case 140: /* --xattr-user */
Signature · 1 line
2.31.1
maintainer
#7 lore raw

Re: [PATCH v2 3/8] evmctl: Move code setting up engine to own funtion

Quoted 1 line · Stefan Berger

From: Stefan Berger <[email protected]>

Missing patch description.

For example, the subject line could be "evmctl: define a function to setup the openssl engine". Provide the motivation before saying, "move the existing code setting up engine to own function."

thanks,

Mimi

#8 lore raw

PATCH v2 4/8 evmctl: Extend libimaevm_params with ENGINE field and use it

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

Extend the global libimaevm_params structure with an ENGINE field 'eng' and use it in place of the local ENGINE variable in main().

---
 src/evmctl.c | 11 +++++------
 src/imaevm.h |  2 ++
 2 files changed, 7 insertions(+), 6 deletions(-)
src/evmctl.c +5 -6
index 4b6f3fb..625a511 100644
@@ -2651,7 +2651,6 @@ static ENGINE *setup_engine(const char *engine_id)
 int main(int argc, char *argv[])
 {
 	int err = 0, c, lind;
-	ENGINE *eng = NULL;
 	unsigned long keyid;
 	char *eptr;
 
@@ -2772,8 +2771,8 @@ int main(int argc, char *argv[])
 			verify_list_sig = 1;
 			break;
 		case 139: /* --engine e */
-			eng = setup_engine(optarg);
-			if (!eng)
+			imaevm_params.eng = setup_engine(optarg);
+			if (!imaevm_params.eng)
 				goto error;
 			break;
 		case 140: /* --xattr-user */
@@ -2849,9 +2848,9 @@ int main(int argc, char *argv[])
 	}
 
 error:
-	if (eng) {
-		ENGINE_finish(eng);
-		ENGINE_free(eng);
+	if (imaevm_params.eng) {
+		ENGINE_finish(imaevm_params.eng);
+		ENGINE_free(imaevm_params.eng);
 #if OPENSSL_API_COMPAT < 0x10100000L
 		ENGINE_cleanup();
 #endif
src/imaevm.h +2 -0
index 491f136..8792aa2 100644
@@ -48,6 +48,7 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <openssl/rsa.h>
+#include <openssl/engine.h>
 
 #ifdef USE_FPRINTF
 #define do_log(level, fmt, args...)	\
@@ -197,6 +198,7 @@ struct libimaevm_params {
 	const char *keyfile;
 	const char *keypass;
 	uint32_t keyid;		/* keyid overriding value, unless 0. (Host order.) */
+	ENGINE *eng;
 };
 
 struct RSA_ASN1_template {
Signature · 1 line
2.31.1
maintainer
#9 lore raw

Re: [PATCH v2 4/8] evmctl: Extend libimaevm_params with ENGINE field and use it

Perhaps update the subject line like, "Define and use an ENGINE field in libimaevm_params".

Quoted 6 lines · Stefan Berger

From: Stefan Berger <[email protected]>

Extend the global libimaevm_params structure with an ENGINE field 'eng' and use it in place of the local ENGINE variable in main().

thanks,

Mimi

#10 lore raw

PATCH v2 5/8 evmctl: Setup the pkcs11 engine if key has pkcs11: prefix

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

If the key has the pkcs11: URI prefix then setup the pkcs11 engine if the user hasn't chosen a specific engine already.

---
 src/evmctl.c | 8 ++++++++
 1 file changed, 8 insertions(+)
src/evmctl.c +8 -0
index 625a511..5178643 100644
@@ -2827,6 +2827,14 @@ int main(int argc, char *argv[])
 	if (!imaevm_params.keypass)
 		imaevm_params.keypass = getenv("EVMCTL_KEY_PASSWORD");
 
+	if (imaevm_params.keyfile != NULL &&
+	    imaevm_params.eng == NULL &&
+	    !strncmp(imaevm_params.keyfile, "pkcs11:", 7)) {
+		imaevm_params.eng = setup_engine("pkcs11");
+		if (!imaevm_params.eng)
+			goto error;
+	}
+
 	if (argv[optind] == NULL)
 		usage();
 	else
Signature · 1 line
2.31.1
maintainer
#11 lore raw

Re: [PATCH v2 5/8] evmctl: Setup the pkcs11 engine if key has pkcs11: prefix

Hi Stefan,

Simplify the subject line. Perhaps something like, "evmctl: use the pkcs11 engine for pkcs11 prefixed URIs"?

Quoted 6 lines · Stefan Berger

From: Stefan Berger <[email protected]>

If the key has the pkcs11: URI prefix then setup the pkcs11 engine if the user hasn't chosen a specific engine already.

thanks

Mimi

#12 lore raw

PATCH v2 6/8 libimaevm: Add support for pkcs11 private keys for signing a v2 hash

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

Add support for pkcs11 private keys for signing a v2 hash.

---
 README          |  1 +
 src/evmctl.c    |  1 +
 src/libimaevm.c | 47 ++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 38 insertions(+), 11 deletions(-)
README +1 -0
index 1cc027f..2bb363c 100644
@@ -48,6 +48,7 @@ OPTIONS
       --xattr-user   store xattrs in user namespace (for testing purposes)
       --rsa          use RSA key type and signing scheme v1
   -k, --key          path to signing key (default: /etc/keys/{privkey,pubkey}_evm.pem)
+                     or a pkcs11 URI
       --keyid n      overwrite signature keyid with a 32-bit value in hex (for signing)
       --keyid-from-cert file
                      read keyid value from SKID of a x509 cert file
src/evmctl.c +1 -0
index 5178643..0a54ac3 100644
@@ -2503,6 +2503,7 @@ static void usage(void)
 		"      --xattr-user   store xattrs in user namespace (for testing purposes)\n"
 		"      --rsa          use RSA key type and signing scheme v1\n"
 		"  -k, --key          path to signing key (default: /etc/keys/{privkey,pubkey}_evm.pem)\n"
+		"                     or a pkcs11 URI\n"
 		"      --keyid n      overwrite signature keyid with a 32-bit value in hex (for signing)\n"
 		"      --keyid-from-cert file\n"
 		"                     read keyid value from SKID of a x509 cert file\n"
src/libimaevm.c +36 -11

62 lines not on this page · raw message

Signature · 1 line
2.31.1
maintainer
#13 lore raw

Re: [PATCH v2 6/8] libimaevm: Add support for pkcs11 private keys for signing a v2 hash

Hi Stefan,

Perhaps reword the subject line as, "libimaevm: add pkcs11 private key support for signing a v2 hash".

Quoted 5 lines · Stefan Berger

From: Stefan Berger <[email protected]>

Add support for pkcs11 private keys for signing a v2 hash.

thanks,

Mimi

#14 lore raw

PATCH v2 7/8 tests: Extend sign_verify test with pkcs11-specific test

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

Extend the sign_verify test with a pkcs11-specific test. Import softhsm_setup script from my swtpm project and contribute it to this porject under dual license BSD 3-clause and GLP 2.0.

---
 tests/functions.sh     |  26 ++++
 tests/sign_verify.test |  50 +++++--
 tests/softhsm_setup    | 290 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 352 insertions(+), 14 deletions(-)
 create mode 100755 tests/softhsm_setup
tests/functions.sh +26 -0
index 91cd5d9..cbb7ea4 100755
@@ -272,3 +272,29 @@ _report_exit() {
   fi
 }
 
+_at_exit() {
+  _report_exit
+  if [ -n "${WORKDIR}" ]; then
+    rm -f "${WORKDIR}"
+  fi
+}
+
+_softhsm_setup() {
+  local workdir="$1"
+
+  local msg
+
+  export SOFTHSM_SETUP_CONFIGDIR="${workdir}"
+  export SOFTHSM2_CONF="${workdir}/softhsm2.conf"
+
+  msg=$(./softhsm_setup setup 2>&1)
+  if [ $? -eq 0 ]; then
+    echo "softhsm_setup setup succeeded: $msg"
+    PKCS11_KEYURI=$(echo $msg | sed -n 's|^keyuri: \(.*\)|\1|p')
+
+    export OPENSSL_ENGINE="-engine pkcs11"
+    export OPENSSL_KEYFORM="-keyform engine"
+  else
+    echo "softhsm_setup setup failed: ${msg}"
+  fi
+}
tests/sign_verify.test +36 -14

104 lines not on this page · raw message

tests/softhsm_setup new file +290 -0

290 lines not on this page · raw message

Signature · 1 line
2.31.1
maintainer
#15 lore raw

Re: [PATCH v2 7/8] tests: Extend sign_verify test with pkcs11-specific test

Hi Stefan,

Quoted 7 lines · Stefan Berger

From: Stefan Berger <[email protected]>

Extend the sign_verify test with a pkcs11-specific test. Import softhsm_setup script from my swtpm project and contribute it to this porject under dual license BSD 3-clause and GLP 2.0.

Up to here, the patches were nicely split up. Just from reading the patch description, this patch needs to be split up.

Quoted 12 lines
---
 tests/functions.sh     |  26 ++++
 tests/sign_verify.test |  50 +++++--
 tests/softhsm_setup    | 290 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 352 insertions(+), 14 deletions(-)
 create mode 100755 tests/softhsm_setup
tests/functions.sh +0 -0
index 91cd5d9..cbb7ea4 100755

tests/functions.sh _report_exit() { · line 281

Quoted 10 lines
tests/functions.sh +7 -0
@@ -272,3 +272,29 @@ _report_exit() {
   fi
 }
 
+_at_exit() {
+  _report_exit
+  if [ -n "${WORKDIR}" ]; then
+    rm -f "${WORKDIR}"
+  fi
+}
+

It would be nice to have a function comment here.

tests/functions.sh _report_exit() { · line 284

Quoted 3 lines
tests/functions.sh +3 -0
+_softhsm_setup() {
+  local workdir="$1"
+

${WORKDIR} is being passed as a parameter. Why is a local environment variable needed?

Quoted 5 lines
tests/functions.sh +5 -0
+  local msg
+
+  export SOFTHSM_SETUP_CONFIGDIR="${workdir}"
+  export SOFTHSM2_CONF="${workdir}/softhsm2.conf"
+

tests/functions.sh _report_exit() { · line 299

Quoted 10 lines
tests/functions.sh +10 -0
+  msg=$(./softhsm_setup setup 2>&1)
+  if [ $? -eq 0 ]; then
+    echo "softhsm_setup setup succeeded: $msg"
+    PKCS11_KEYURI=$(echo $msg | sed -n 's|^keyuri: \(.*\)|\1|p')
+
+    export OPENSSL_ENGINE="-engine pkcs11"
+    export OPENSSL_KEYFORM="-keyform engine"
+  else
+    echo "softhsm_setup setup failed: ${msg}"
+  fi

Should there be a test checking that softhsm_setup is installed before
using it? If it's not installed, then the test is "skipped".

Quoted 16 lines
tests/functions.sh +1 -0
+}
tests/sign_verify.test +2 -1
index 3b42eec..369765e 100755
@@ -28,7 +28,8 @@ fi
 
 ./gen-keys.sh >/dev/null 2>&1
 
-trap _report_exit EXIT
+trap _at_exit EXIT
+WORKDIR=$(mktemp -d)
 set -f # disable globbing
 
 # Determine keyid from a cert

tests/sign_verify.test check_sign() { · line 136

Quoted 5 lines
tests/sign_verify.test +1 -1
@@ -132,11 +133,16 @@ check_sign() {
   # OPTS (additional options for evmctl),
   # FILE (working file to sign).
   local "$@"
-  local KEY=${KEY%.*}.key
+  local key verifykey

Agreed, don't modify the global variable, use a local one. Making this a separate patch, would simplify review.

thanks,

Mimi

#16 lore raw

Re: [PATCH v2 7/8] tests: Extend sign_verify test with pkcs11-specific test

Quoted 5 lines · Mimi Zohar

Hi Stefan,

Quoted 2 lines · Stefan Berger

From: Stefan Berger <[email protected]>

Quoted 7 lines
Quoted 5 lines

Extend the sign_verify test with a pkcs11-specific test. Import softhsm_setup script from my swtpm project and contribute it to this porject under dual license BSD 3-clause and GLP 2.0.

Up to here, the patches were nicely split up. Just from reading the patch description, this patch needs to be split up.

Ok, softhsm_setup will be a separate patch then before function.sh and sign_verify.test are being patched.

Quoted 16 lines
Quoted 16 lines
---
  tests/functions.sh     |  26 ++++
  tests/sign_verify.test |  50 +++++--
  tests/softhsm_setup    | 290 +++++++++++++++++++++++++++++++++++++++++
  3 files changed, 352 insertions(+), 14 deletions(-)

create mode 100755 tests/softhsm_setup

tests/functions.sh +0 -0
index 91cd5d9..cbb7ea4 100755
@@ -272,3 +272,29 @@ _report_exit() {
    fi
  }
 
Quoted 8 lines

tests/functions.sh _report_exit() { · line 281

Quoted 7 lines
tests/functions.sh +7 -0
+_at_exit() {
+  _report_exit
+  if [ -n "${WORKDIR}" ]; then
+    rm -f "${WORKDIR}"
+  fi
+}
+

It would be nice to have a function comment here.

I can add this.

Quoted 6 lines

tests/functions.sh _report_exit() { · line 284

Quoted 4 lines
tests/functions.sh +3 -0
+_softhsm_setup() {
+  local workdir="$1"
+

${WORKDIR} is being passed as a parameter. Why is a local environment variable needed?

I prefer to avoid accessing them when they can be passed to functions as parameters. I rather only use global variables at the 'top level' and then pass them down as parameters to all the lower level functions.

Quoted 10 lines
Quoted 10 lines
tests/functions.sh +9 -0
+  local msg
+
+  export SOFTHSM_SETUP_CONFIGDIR="${workdir}"
+  export SOFTHSM2_CONF="${workdir}/softhsm2.conf"
+
+  msg=$(./softhsm_setup setup 2>&1)
+  if [ $? -eq 0 ]; then
+    echo "softhsm_setup setup succeeded: $msg"
+    PKCS11_KEYURI=$(echo $msg | sed -n 's|^keyuri: \(.*\)|\1|p')
Quoted 8 lines

tests/functions.sh _report_exit() { · line 299

Quoted 6 lines
tests/functions.sh +6 -0
+
+    export OPENSSL_ENGINE="-engine pkcs11"
+    export OPENSSL_KEYFORM="-keyform engine"
+  else
+    echo "softhsm_setup setup failed: ${msg}"
+  fi

Should there be a test checking that softhsm_setup is installed before
using it? If it's not installed, then the test is "skipped".

softhsm_setup is being contributed to this project via the code above, so it should be available.

Quoted 28 lines
Quoted 17 lines
tests/functions.sh +1 -0
+}
tests/sign_verify.test +2 -1
index 3b42eec..369765e 100755
@@ -28,7 +28,8 @@ fi
 
  ./gen-keys.sh >/dev/null 2>&1
 
-trap _report_exit EXIT
+trap _at_exit EXIT
+WORKDIR=$(mktemp -d)
  set -f # disable globbing
 
  # Determine keyid from a cert

tests/sign_verify.test check_sign() { · line 136

Quoted 5 lines
tests/sign_verify.test +1 -1
@@ -132,11 +133,16 @@ check_sign() {
    # OPTS (additional options for evmctl),
    # FILE (working file to sign).
    local "$@"
-  local KEY=${KEY%.*}.key
+  local key verifykey

Agreed, don't modify the global variable, use a local one. Making this a separate patch, would simplify review.
thanks,

Mimi

#17 lore raw

PATCH v2 8/8 tests: Get the packages for pkcs11 testing on the CI/CD system

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

Get the packages for pkcs11 testing on the CI/CD system.

This is the status on various distros:

- Alpine: could not find package with pkcs11 engine
- Alt Linux: works
- Debian: debian:stable: evmctl is not able to find the pkcs11 module but

          preceeding openssl command line tests with the pkcs11 URI succeeded;
          cannot recreate the issue locally in the debian:stable container
          --> disabled on Ubuntu and Debian

- CentOS7: tests with pkcs11 URI fail on openssl command line level
- CentOS: works
- Fedora: works
- OpenSuSE Leap: package not available in main repo
- OpenSuSE Tumbleweed: works

---
 ci/alt.sh        | 3 +++
 ci/fedora.sh     | 8 ++++++++
 ci/tumbleweed.sh | 3 +++
 3 files changed, 14 insertions(+)
ci/alt.sh +3 -0
index 884c995..65389be 100755
@@ -12,12 +12,15 @@ apt-get install -y \
 		asciidoc \
 		attr \
 		docbook-style-xsl \
+		gnutls-utils \
 		libattr-devel \
 		libkeyutils-devel \
+		libp11 \
 		libssl-devel \
 		openssl \
 		openssl-gost-engine \
 		rpm-build \
+		softhsm \
 		wget \
 		xsltproc \
 		xxd \
ci/fedora.sh +8 -0
index 2d80915..0993607 100755
@@ -25,6 +25,7 @@ yum -y install \
 	automake \
 	diffutils \
 	docbook-xsl \
+	gnutls-utils \
 	gzip \
 	keyutils-libs-devel \
 	libattr-devel \
@@ -33,6 +34,7 @@ yum -y install \
 	make \
 	openssl \
 	openssl-devel \
+	openssl-pkcs11 \
 	pkg-config \
 	procps \
 	sudo \
@@ -42,3 +44,9 @@ yum -y install \
 
 yum -y install docbook5-style-xsl || true
 yum -y install swtpm || true
+
+# SoftHSM is available via EPEL on CentOS
+if [ -f /etc/centos-release ]; then
+	yum -y install epel-release
+fi
+yum -y install softhsm || true
\ No newline at end of file
ci/tumbleweed.sh +3 -0
index dfc478b..4e3da0c 100755
@@ -42,6 +42,9 @@ zypper --non-interactive install --force-resolution --no-recommends \
 	which \
 	xsltproc
 
+zypper --non-interactive install --force-resolution --no-recommends \
+	gnutls openssl-engine-libp11 softhsm || true
+
 if [ -f /usr/lib/ibmtss/tpm_server -a ! -e /usr/local/bin/tpm_server ]; then
 	ln -s /usr/lib/ibmtss/tpm_server /usr/local/bin
 fi
Signature · 1 line
2.31.1
maintainer
#18 lore raw

Re: [PATCH v2 8/8] tests: Get the packages for pkcs11 testing on the CI/CD system

Quoted 9 lines · Stefan Berger

From: Stefan Berger <[email protected]>

Get the packages for pkcs11 testing on the CI/CD system.

This is the status on various distros:

- Alpine: could not find package with pkcs11 engine
- Alt Linux: works
- Debian: debian:stable: evmctl is not able to find the pkcs11 module but

Quoted 8 lines
          preceeding openssl command line tests with the pkcs11 URI succeeded;
          cannot recreate the issue locally in the debian:stable container
          --> disabled on Ubuntu and Debian

- CentOS7: tests with pkcs11 URI fail on openssl command line level
- CentOS: works
- Fedora: works
- OpenSuSE Leap: package not available in main repo
- OpenSuSE Tumbleweed: works

In patch 7/8 there's a comment of requiring a certain release. Should there be a test for a specific version? Then only run the pkcs11 tests if that version or later is installed.

thanks,

Mimi

#19 lore raw

Re: [PATCH v2 8/8] tests: Get the packages for pkcs11 testing on the CI/CD system

Quoted 18 lines · Mimi Zohar
Quoted 9 lines · Stefan Berger

From: Stefan Berger <[email protected]>

Get the packages for pkcs11 testing on the CI/CD system.

This is the status on various distros:

- Alpine: could not find package with pkcs11 engine
- Alt Linux: works
- Debian: debian:stable: evmctl is not able to find the pkcs11 module but

Quoted 8 lines
           preceeding openssl command line tests with the pkcs11 URI succeeded;
           cannot recreate the issue locally in the debian:stable container
           --> disabled on Ubuntu and Debian

- CentOS7: tests with pkcs11 URI fail on openssl command line level
- CentOS: works
- Fedora: works
- OpenSuSE Leap: package not available in main repo
- OpenSuSE Tumbleweed: works

Quoted 3 lines

In patch 7/8 there's a comment of requiring a certain release. Should there be a test for a specific version? Then only run the pkcs11 tests if that version or later is installed.

I'll add a test into softhsm_setup checking that the version identifier is at least 2.2.0.

  Stefan

Quoted 4 lines

thanks,

Mimi

maintainer
#20 lore raw
In reply to Stefan Berger

Hi Stefan,

Quoted 4 lines · Stefan Berger

From: Stefan Berger <[email protected]>

This series of patches adds support for signing with pkcs11 URIs and the keyid explicitly provided via a command line option.

Before explaining "what" , please provide the motivation for adding pkcs11 support.

Other than updating the cover letter and the patch descriptions, patches 1 - 6 look good. (Still looking at 7/8 and 8/8.)

thanks,

Mimi