Move digest_sign_verify out of test_cryptoapi.c
PATCH 1/3 Move digest_sign_verify out of test_cryptoapi.c
From: Selva Nair <[email protected]...>
- This function will be reused for testing pkcs11
--- tests/unit_tests/openvpn/Makefile.am | 1 + tests/unit_tests/openvpn/pkey_test_utils.c | 141 +++++++++++++++++++++ tests/unit_tests/openvpn/test_cryptoapi.c | 98 +------------- 3 files changed, 143 insertions(+), 97 deletions(-) create mode 100644 tests/unit_tests/openvpn/pkey_test_utils.c
tests/unit_tests/openvpn/Makefile.am +1 -0
@@ -156,6 +156,7 @@ cryptoapi_testdriver_CFLAGS = @TEST_CFLAGS@ \ cryptoapi_testdriver_LDFLAGS = @TEST_LDFLAGS@ \ $(OPTIONAL_CRYPTO_LIBS) -lcrypt32 -lncrypt cryptoapi_testdriver_SOURCES = test_cryptoapi.c mock_msg.c \ + pkey_test_utils.c \ $(top_srcdir)/src/openvpn/xkey_helper.c \ $(top_srcdir)/src/openvpn/xkey_provider.c \ $(top_srcdir)/src/openvpn/buffer.c \
tests/unit_tests/openvpn/pkey_test_utils.c new file +141 -0
141 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +1 -97
110 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 2/3 Unit tests: Test for PKCS#11 using a softhsm2 token
From: Selva Nair <[email protected]...>
- Load some test certificate/key pairs into a temporary softhsm2 token and enumerate available objects through pkcs11-helper interface
- For each object, load it into SSL_CTX and test sign (if using OpenSSL 3) or check the certificate and public-key match (if using OpenSSl 1.1.1.). The pkcs11-id for each object is specified directly or through a mocked management callback to test pkcs11-id-management
Limitations:
Depends on libsofthsm2.so and p11tool (install softhsm2 and gnutls-bin packages). Mbed-TLS/pkcs11-helper combination is not tested.
If locations of these binaries are not auto-detected or need to be overridden, use -DSOFTHSM2_UTIL=<path> -DP11TOOL=<path> to configure. Location of SOFTHSM2_MODULE is not auto-detected and defaults to /usr/lib/softhsm/libsofthsm2.so. It may be changed by passing -DSOFTHSM2_MODULE=/some-path/libsofthsm2.so to configure. Also see "configure --help".
The test is enabled only if --enable-pkcs11 is in use, and SOFTHSM2_UTIL & P11TOOL are found in path or manually defined during configuring.
Changes relative to github PR
- Explicitly disable building the test on Windows: need to port mkstemp, mkdtemp, setenv etc., before enabling this on Windows.
--- configure.ac | 16 + tests/unit_tests/openvpn/Makefile.am | 29 ++ tests/unit_tests/openvpn/mock_msg.c | 6 + tests/unit_tests/openvpn/test_pkcs11.c | 453 +++++++++++++++++++++++++ 4 files changed, 504 insertions(+) create mode 100644 tests/unit_tests/openvpn/test_pkcs11.c
configure.ac +16 -0
@@ -1345,6 +1345,7 @@ if test "${enable_comp_stub}" = "yes"; then AC_DEFINE([ENABLE_COMP_STUB], [1], [Enable compression stub capability]) fi +AM_CONDITIONAL([HAVE_SOFTHSM2], [false]) if test "${enable_pkcs11}" = "yes"; then test "${have_pkcs11_helper}" != "yes" && AC_MSG_ERROR([PKCS11 enabled but libpkcs11-helper is missing]) OPTIONAL_PKCS11_HELPER_CFLAGS="${PKCS11_HELPER_CFLAGS}"
@@ -1357,6 +1358,21 @@ if test "${enable_pkcs11}" = "yes"; then AC_DEFINE_UNQUOTED([DEFAULT_PKCS11_MODULE], "${proxy_module}", [p11-kit proxy])], [] ) + # + # softhsm2 for pkcs11 tests + # + AC_ARG_VAR([P11TOOL], [full path to p11tool]) + AC_PATH_PROGS([P11TOOL], [p11tool],, [$PATH:/usr/local/bin:/usr/bin:/bin]) + AC_DEFINE_UNQUOTED([P11TOOL_PATH], ["$P11TOOL"], [Path to p11tool]) + AC_ARG_VAR([SOFTHSM2_UTIL], [full path to softhsm2-util]) + AC_ARG_VAR([SOFTHSM2_MODULE], [full path to softhsm2 module @<:@default=/usr/lib/softhsm/libsofthsm2.so@:>@]) + AC_PATH_PROGS([SOFTHSM2_UTIL], [softhsm2-util],, [$PATH:/usr/local/bin:/usr/bin:/bin]) + test -z "$SOFTHSM2_MODULE" && SOFTHSM2_MODULE=/usr/lib/softhsm/libsofthsm2.so + AC_DEFINE_UNQUOTED([SOFTHSM2_UTIL_PATH], ["$SOFTHSM2_UTIL"], [Path to softhsm2-util]) + AC_DEFINE_UNQUOTED([SOFTHSM2_MODULE_PATH], ["$SOFTHSM2_MODULE"], [Path to softhsm2 module]) + if test "${with_crypto_library}" = "openssl"; then + AM_CONDITIONAL([HAVE_SOFTHSM2], [test "${P11TOOL}" -a "${SOFTHSM2_UTIL}" -a "${SOFTHSM2_MODULE}"]) + fi fi # When testing a compiler option, we add -Werror to force
tests/unit_tests/openvpn/Makefile.am +29 -0
@@ -21,6 +21,12 @@ test_binaries += cryptoapi_testdriver LDADD = -lws2_32 endif +if HAVE_SOFTHSM2 +if !WIN32 +test_binaries += pkcs11_testdriver +endif +endif + if !CROSS_COMPILING TESTS = $(test_binaries) endif
@@ -166,6 +172,29 @@ cryptoapi_testdriver_SOURCES = test_cryptoapi.c mock_msg.c \ $(top_srcdir)/src/openvpn/win32-util.c endif +if HAVE_SOFTHSM2 +if !WIN32 +pkcs11_testdriver_CFLAGS = @TEST_CFLAGS@ \ + -I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn \ + $(OPTIONAL_CRYPTO_CFLAGS) +pkcs11_testdriver_LDFLAGS = @TEST_LDFLAGS@ \ + $(OPTIONAL_CRYPTO_LIBS) +pkcs11_testdriver_SOURCES = test_pkcs11.c mock_msg.c \ + pkey_test_utils.c mock_get_random.c \ + $(top_srcdir)/src/openvpn/xkey_helper.c \ + $(top_srcdir)/src/openvpn/xkey_provider.c \ + $(top_srcdir)/src/openvpn/argv.c \ + $(top_srcdir)/src/openvpn/env_set.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/otime.c \ + $(top_srcdir)/src/openvpn/run_command.c \ + $(top_srcdir)/src/openvpn/base64.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/pkcs11.c \ + $(top_srcdir)/src/openvpn/pkcs11_openssl.c +endif +endif + auth_token_testdriver_CFLAGS = @TEST_CFLAGS@ \ -I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn \ $(OPTIONAL_CRYPTO_CFLAGS)
tests/unit_tests/openvpn/mock_msg.c +6 -0
@@ -48,6 +48,12 @@ mock_set_debug_level(int level) x_debug_level = level; } +int +get_debug_level (void ) +{ +return x_debug_level; +} +void x_msg_va (const unsigned int flags,const char *format,va_list arglist)
tests/unit_tests/openvpn/test_pkcs11.c new file +453 -0
453 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [Openvpn-devel] [PATCH 2/3] Unit tests: Test for PKCS#11 using a softhsm2 token
Quoted 21 lines · On Wed, Mar 22, 2023 at 06:14:55PM -0400, [email protected]... wrote:
From: Selva Nair <[email protected]...>
- Load some test certificate/key pairs into a temporary softhsm2 token and enumerate available objects through pkcs11-helper interface
- For each object, load it into
SSL_CTXand test sign (if using OpenSSL 3) or check the certificate and public-key match (if using OpenSSl 1.1.1.). The pkcs11-id for each object is specified directly or through a mocked management callback to test pkcs11-id-managementLimitations:
Depends on libsofthsm2.so and p11tool (install softhsm2 and gnutls-bin packages). Mbed-TLS/pkcs11-helper combination is not tested.If locations of these binaries are not auto-detected or need to be overridden, use -DSOFTHSM2_UTIL=<path> -DP11TOOL=<path> to configure. Location of
SOFTHSM2_MODULEis not auto-detected and defaults to/usr/lib/softhsm/libsofthsm2.so. It may be changed by passing -DSOFTHSM2_MODULE=/some-path/libsofthsm2.so to configure. Also see "configure --help".
Quoted 8 lines
The test is enabled only if --enable-pkcs11 is in use, and
SOFTHSM2_UTIL& P11TOOL are found in path or manually defined during configuring.Changes relative to github PR
- Explicitly disable building the test on Windows: need to port mkstemp, mkdtemp, setenv etc., before enabling this on Windows.Signed-off-by Selva Nair <[email protected]...>
I reviewed this on Github, with a focus on the configuration part.
Approved it there, so
Signature · 1 line
Frank Lichtenheld
[Openvpn-devel] [PATCH applied] Re: Unit tests: Test for PKCS#11 using a softhsm2 token
In reply to [email protected]...Having pkcs#11 tests available is most welcome. This said, I have not really looked into "how can I make this do things for my test beds?", but will do...
With the #if HAVE_SOFTHSM2, this does not actually do anything for most build environments yet, but patch 3/3 will enable it for GHA Ubuntu 20/22 builds.
Your patch has been applied to the master branch.
commit 3013fde1c8290830d424b9f4ea84ee7c7dbfb75e
Author: Selva Nair Date: Wed Mar 22 18:14:55 2023 -0400
Unit tests: Test for PKCS#11 using a softhsm2 token
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg26483.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 3/3 Enable pkcs11 an dtest_pkcs11 in github actions
In reply to [email protected]...From: Selva Nair <[email protected]...>
- Enabled for the Ubuntu 22.04 build (OpenSSL 3) and one of the Ubuntu 20.04 builds (OpenSSL 1.1.1).
--- .github/workflows/build.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
.github/workflows/build.yaml +6 -2
@@ -297,11 +297,14 @@ jobs: sslpkg: "libssl-dev" libname: OpenSSL 3.0.2 ssllib: openssl + pkcs11pkg: "libpkcs11-helper1-dev softhsm2 gnutls-bin" + extraconf: --enable-pkcs11 - os: ubuntu-20.04 sslpkg: "libssl-dev" libname: OpenSSL 1.1.1 ssllib: openssl - extraconf: "--enable-iproute2" + pkcs11pkg: "libpkcs11-helper1-dev softhsm2 gnutls-bin" + extraconf: "--enable-iproute2 --enable-pkcs11" - os: ubuntu-20.04 sslpkg: "libssl-dev" libname: OpenSSL 1.1.1
@@ -326,11 +329,12 @@ jobs: name: "gcc - ${{matrix.os}} - ${{matrix.libname}} ${{matrix.extraconf}}" env: SSLPKG: "${{matrix.sslpkg}}" + PKCS11PKG: "${{matrix.pkcs11pkg}}" runs-on: ${{matrix.os}} steps: - name: Install dependencies - run: sudo apt update && sudo apt install -y liblzo2-dev libpam0g-dev liblz4-dev libcap-ng-dev libnl-genl-3-dev linux-libc-dev man2html libcmocka-dev python3-docutils libtool automake autoconf ${SSLPKG} + run: sudo apt update && sudo apt install -y liblzo2-dev libpam0g-dev liblz4-dev libcap-ng-dev libnl-genl-3-dev linux-libc-dev man2html libcmocka-dev python3-docutils libtool automake autoconf ${SSLPKG} ${PKCS11PKG} - name: Checkout OpenVPN uses: actions/[email protected]... - name: autoconf
Signature · 1 line
2.34.1
Re: [Openvpn-devel] [PATCH 3/3] Enable pkcs11 an dtest_pkcs11 in github actions
Quoted 9 lines · On Wed, Mar 22, 2023 at 06:14:56PM -0400, [email protected]... wrote:
From: Selva Nair <[email protected]...>
- Enabled for the Ubuntu 22.04 build (OpenSSL 3) and one of the Ubuntu 20.04 builds (OpenSSL 1.1.1).
Signed-off-by Selva Nair <[email protected]...>--- .github/workflows/build.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Worked in the PR, so
Signature · 1 line
Frank Lichtenheld
[Openvpn-devel] [PATCH applied] Re: Enable pkcs11 an dtest_pkcs11 in github actions
In reply to [email protected]...Ran this through GHA, it claims success, and claims having tested this...
[==========] Running 3 test(s).
Slot 0 has a free/uninitialized token.
The token has been initialized and is reassigned to slot 347291425
[ RUN ] test_pkcs11_ids
[ OK ] test_pkcs11_ids
[ RUN ] test_tls_ctx_use_pkcs11
[ OK ] test_tls_ctx_use_pkcs11
[ RUN ] test_tls_ctx_use_pkcs11__management
[ OK ] test_tls_ctx_use_pkcs11__management
Found token (b36c3fa5-a027-3fc0-2be4-05ee94b33f21) with matching token label. The token (softhsm2_tokens_53u42S/b36c3fa5-a027-3fc0-2be4-05ee94b33f21) has been deleted. [ PASSED ] 3 test(s).
[==========] 3 test(s) run.
PASS: pkcs11_testdriver
.. very nice!
Your patch has been applied to the master branch.
commit 9283c3980ff543e20f76fdfb4f4e59d5a9162d62
Author: Selva Nair Date: Wed Mar 22 18:14:56 2023 -0400
Enable pkcs11 an dtest_pkcs11 in github actions
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg26485.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Quoted 5 lines · On Wed, Mar 22, 2023 at 06:14:54PM -0400, [email protected]... wrote:
From: Selva Nair <[email protected]...>
- This function will be reused for testing pkcs11
Signed-off-by Selva Nair <[email protected]...>
This just moves code around.
Signature · 1 line
Frank Lichtenheld
"git show --color-moved=zebra" agrees with "this is just moving stuff around". I have tested that "make dist" picks up the new file (this is something we tend to get wrong), and ran this by GHA (pass).
At this point in the 2.6 life cycle, I think we can go back to the "everything goes to master, only bugfixes go to release/2.6" way of doing things - so this patchset (and subsequent new features for cryptoapi that benefit from the unit test) would only be "in master".
I am bringing this up at the community meeting today (and here in the mail) so you all have a chance to yell at me and convince me otherwise.
Your patch has been applied to the master branch.
commit 3bc071a8e3e21250f9be9c29273de0d96288056e (master)
Author: Selva Nair Date: Wed Mar 22 18:14:54 2023 -0400
Move digest_sign_verify out of test_cryptoapi.c
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg26484.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering