Skip to content

zpcprovider for sign/verify (ecdsa/eddsa)#41

Open
holger-dengler wants to merge 33 commits into
opencryptoki:mainfrom
holger-dengler:provider-sign
Open

zpcprovider for sign/verify (ecdsa/eddsa)#41
holger-dengler wants to merge 33 commits into
opencryptoki:mainfrom
holger-dengler:provider-sign

Conversation

@holger-dengler
Copy link
Copy Markdown
Contributor

This PR requires PR #40.

This PR adds OpenSSL provider support for libzpc. This first version covers the main functionality for store, keymgmt, sign/verify and decoder support.

As the series add a lot of new code, it is split into many commits to make the review (hopefully) a bit easier.

ToDo:

  • public key support for store/decoder
  • alloc/free needs some debugging

Restriction:

  • the tests uses hard-coded public keys, so running tests on other machines require code changes in tprovider.c.
  • the provider only supports uv origins, so testing is limited to SEL environments.

@ifranzki
Copy link
Copy Markdown
Contributor

Are you looking at the Travis build failures? You might need to build OpenSSL from source to have a 3.5.0 version to build against.

@holger-dengler
Copy link
Copy Markdown
Contributor Author

Yes, a fix for the travis is in progress. It looks like travis only provides 3.0 out of the box. So I'll build my own. At least 3.5, better 4.0.

Comment thread src/uri.c Outdated
Comment thread src/provider.c Outdated
Comment thread src/object.h Outdated
Comment thread src/signature.c Outdated
Comment thread src/signature.c
@holger-dengler holger-dengler force-pushed the provider-sign branch 2 times, most recently from 7c72889 to 1659e06 Compare May 2, 2026 15:53
@holger-dengler
Copy link
Copy Markdown
Contributor Author

holger-dengler commented May 2, 2026

The update contains:

  • re-order of the commits (move test to the end of the series)
  • rework of signature/eddsa
  • pick review comments
  • minor fixes

@holger-dengler
Copy link
Copy Markdown
Contributor Author

Another update (force push) to remove the merge conflicts and add a fix for travis.

@ifranzki
Copy link
Copy Markdown
Contributor

ifranzki commented May 4, 2026

I would suggest to also add tests that utilize the openssl application to use protected key origins. For example, creating/signing a certificate with a protected key origin specified via URI or PEM using openssl x509 -in cert.csr -out cert.pem -req -signkey <protected key origin> -days 1001.

Comment thread CMakeLists.txt Outdated
@holger-dengler
Copy link
Copy Markdown
Contributor Author

I would suggest to also add tests that utilize the openssl application to use protected key origins. For example, creating/signing a certificate with a protected key origin specified via URI or PEM using openssl x509 -in cert.csr -out cert.pem -req -signkey <protected key origin> -days 1001.

I plan to rework the test. tprovider will be renamed (t_provider) and changed to do only the lookup for the provider components. All key-related functional test will be moved to a new t_openssl test script, which uses openssl to create keys and call the functions. such a split is required to run the tests in a CI.

Comment thread src/provider.c Outdated
Comment thread src/provider.c Outdated
Comment thread src/provider.c Outdated
Comment thread src/provider.c Outdated
Comment thread src/keymgmt.c
Comment thread src/keymgmt.c
Comment thread src/keymgmt.c
@ifranzki
Copy link
Copy Markdown
Contributor

ifranzki commented May 5, 2026

I would move the provider sources into a subdirectory, e.g. src/provider/. Maybe even move the library sources into a subdirectory e.g. src/lib/.

@holger-dengler
Copy link
Copy Markdown
Contributor Author

I would postpone the source code restructuring until the provider transition is done (symmetric cipher, secure-key origins etc). There will be eventually also some removal of no longer used code.

Comment thread openssl.conf.in
@holger-dengler
Copy link
Copy Markdown
Contributor Author

I'll check the asan-build option.

Introduce the build option BUILD_ASAN to enable the address sanitizer
in the compile options. Executable or shared library targets has to
enable the address sanitizer in the link options as well.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
The provider is the base to plug-in further implementation like
key-management, ciphers and so on. It has no functionality itself.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Add a module build target for the zpcprovider. Other than shared
objects, the provider module has no so-name and also no API
versioning.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
The provider-specific key object structure is shared between the
provider components and references to the internal zpc-key
structure(s).

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
A hbkzpc-URI references a hardware-backed key origin. The parser
destructs the URI into key-value pairs.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Add internal object build target for uri. The internal object can be
shared between targets.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
The mapping helpers provide mappings between e.g. algorithm strings
and algorithm-related values.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Introduce a store-loader for hbkzpc-URI based keys. The store-loader
creates a provider-specific key object and adds relevant information
from the URI.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Introduce a asymmetric key management to map the provider-specific key
object to a intern zpc-key.

Not supported:
- key generation
- key import

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Add helpers to generate DER-encoded algorithm-ids based on key and
digest information.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Add signature algorithms for sign/verify with ECDSA and EDDSA keys.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Add the supported TLS properties for the zpcprovider.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
The ASN.1 module provides DER en-/decoding for hbkzpc-URIs. These
functions are required for the decoder/encoder support.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Add internal object build target for ASN.1 module. The internal object
can be shared between targets.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Add decoders for PEM and DER to support hbkzpc-URI files.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
To use the zpc functionality via the OpenSSL API, the zpcprovider has
to be defined in the OpenSSL configuration.

The build configures the template and creates a `openssl.cnf` file,
which can be used for test purposes. The configuration file will be
created in the build output folder.

The build also configures a second template and creates a
configuration drop-in file `zpcprovider.cnf`. This file can be
included in existing OpenSSL configuration files.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
The scripts set breakpoints for to all zpcprovider functions, which
are called by the OpenSSL provider API (dispatch functions). Each
zpcprovider component has its own gdb-script. Sourcing multiple
scripts is possible.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
@holger-dengler
Copy link
Copy Markdown
Contributor Author

New PR version with

  • integrated feedback
  • ASAN build option

@ifranzki
Copy link
Copy Markdown
Contributor

Build failures in Travis:

/home/travis/build/opencryptoki/libzpc/src/signature.c:430:38: warning: implicit declaration of function ‘EVP_MD_CTX_dup’; did you mean ‘EVP_MAC_CTX_dup’? [-Wimplicit-function-declaration]
  430 |             !(sctx_dst->fwd_md_ctx = EVP_MD_CTX_dup(sctx_src->fwd_md_ctx)))
      |                                      ^~~~~~~~~~~~~~
      |                                      EVP_MAC_CTX_dup
/home/travis/build/opencryptoki/libzpc/src/signature.c:430:36: warning: assignment to ‘EVP_MD_CTX *’ {aka ‘struct evp_md_ctx_st *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  430 |             !(sctx_dst->fwd_md_ctx = EVP_MD_CTX_dup(sctx_src->fwd_md_ctx)))
      |                                    ^
In file included from /usr/include/openssl/ec.h:103,
                 from /usr/include/openssl/ecdsa.h:10,
                 from /home/travis/build/opencryptoki/libzpc/src/signature.c:6:
/home/travis/build/opencryptoki/libzpc/src/signature.c: In function ‘eddsa_gettable_ctx_params’:
/home/travis/build/opencryptoki/libzpc/src/signature.c:685:40: error: ‘OSSL_SIGNATURE_PARAM_INSTANCE’ undeclared (first use in this function); did you mean ‘OSSL_SIGNATURE_PARAM_KAT’?
  685 |                 OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_INSTANCE, NULL, 0),
      |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/opencryptoki/libzpc/src/signature.c:685:40: note: each undeclared identifier is reported only once for each function it appears in
/home/travis/build/opencryptoki/libzpc/src/signature.c:686:41: error: ‘OSSL_SIGNATURE_PARAM_CONTEXT_STRING’ undeclared (first use in this function); did you mean ‘OSSL_SIGNATURE_PARAM_DIGEST_SIZE’?
  686 |                 OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_CONTEXT_STRING, NULL, 0),
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/opencryptoki/libzpc/src/signature.c: In function ‘eddsa_get_ctx_params’:
/home/travis/build/opencryptoki/libzpc/src/signature.c:706:39: error: ‘OSSL_SIGNATURE_PARAM_INSTANCE’ undeclared (first use in this function); did you mean ‘OSSL_SIGNATURE_PARAM_KAT’?
  706 |         p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_INSTANCE);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                       OSSL_SIGNATURE_PARAM_KAT
/home/travis/build/opencryptoki/libzpc/src/signature.c:712:39: error: ‘OSSL_SIGNATURE_PARAM_CONTEXT_STRING’ undeclared (first use in this function); did you mean ‘OSSL_SIGNATURE_PARAM_DIGEST_SIZE’?
  712 |         p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_CONTEXT_STRING);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                       OSSL_SIGNATURE_PARAM_DIGEST_SIZE
/home/travis/build/opencryptoki/libzpc/src/signature.c: In function ‘eddsa_settable_ctx_params’:
/home/travis/build/opencryptoki/libzpc/src/signature.c:725:40: error: ‘OSSL_SIGNATURE_PARAM_INSTANCE’ undeclared (first use in this function); did you mean ‘OSSL_SIGNATURE_PARAM_KAT’?
  725 |                 OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_INSTANCE, NULL, 0),
      |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/opencryptoki/libzpc/src/signature.c:726:41: error: ‘OSSL_SIGNATURE_PARAM_CONTEXT_STRING’ undeclared (first use in this function); did you mean ‘OSSL_SIGNATURE_PARAM_DIGEST_SIZE’?
  726 |                 OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_CONTEXT_STRING, NULL, 0),
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/opencryptoki/libzpc/src/signature.c: In function ‘eddsa_set_ctx_params’:
/home/travis/build/opencryptoki/libzpc/src/signature.c:740:45: error: ‘OSSL_SIGNATURE_PARAM_INSTANCE’ undeclared (first use in this function); did you mean ‘OSSL_SIGNATURE_PARAM_KAT’?
  740 |         p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_INSTANCE);
      |                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                             OSSL_SIGNATURE_PARAM_KAT
/home/travis/build/opencryptoki/libzpc/src/signature.c:749:45: error: ‘OSSL_SIGNATURE_PARAM_CONTEXT_STRING’ undeclared (first use in this function); did you mean ‘OSSL_SIGNATURE_PARAM_DIGEST_SIZE’?
  749 |         p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_CONTEXT_STRING);
      |                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                             OSSL_SIGNATURE_PARAM_DIGEST_SIZE
gmake[2]: *** [CMakeFiles/zpcprovider.dir/build.make:160: CMakeFiles/zpcprovider.dir/src/signature.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:198: CMakeFiles/zpcprovider.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

@ifranzki
Copy link
Copy Markdown
Contributor

/home/travis/build/opencryptoki/libzpc/src/signature.c:430:38: warning: implicit declaration of function ‘EVP_MD_CTX_dup’; did you mean ‘EVP_MAC_CTX_dup’? [-Wimplicit-function-declaration]
  430 |             !(sctx_dst->fwd_md_ctx = EVP_MD_CTX_dup(sctx_src->fwd_md_ctx)))

The EVP_MD_CTX_dup() function was added in OpenSSL 3.1.

But you can do something like

EVP_MD_CTX *EVP_MD_CTX_dup(const EVP_MD_CTX *in)
{
    EVP_MD_CTX *out = EVP_MD_CTX_new();

    if (out != NULL && !EVP_MD_CTX_copy_ex(out, in)) {
        EVP_MD_CTX_free(out);
        out = NULL;
    }
    return out;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants