Git Product home page Git Product logo

nethsm-pkcs11's Introduction

PKCS#11 Module for the Nitrokey NetHSM

codecov.io

This module allows to use a Nitrokey NetHSM as a backend for PKCS#11 operations.

See the list of supported features for more details.

Download

Download the latest binary from the release page.

Documentation

Follow the documentation for usage instructions.

Debug Options

Set the RUST_LOG env variable to trace, debug, info, warn or err to change the logging level.

Docker Examples

For testing and development purposes there are two examples using the PKCS11 driver with Nginx and Apache.

They require each a certificate built with the container/<server>/generate.sh.

They can be built with:

# Building the images 
docker build -t nginx-testing -f container/nginx/Dockerfile .
docker build -t apache-testing -f container/apache/Dockerfile .

Assuming that a NetHSM is runnig on localhost:8443, they can then be run with :

docker run --net=host nginx-testing:latest
docker run --net=host apache-testing:latest

The NetHSM is expected to have be provisionned with the following configuration:

nitropy nethsm --host localhost:8443 --no-verify-tls provision -u 0123456789 -a Administrator
nitropy nethsm --host localhost:8443 --no-verify-tls add-user -n Operator -u operator -p opPassphrase -r Operator

Building

Required are gcc and a working Rust toolchain of at least version (MSRV) 1.70.

cargo build --release

The dynamic library will be in ${CARGO_TARGET_DIR:-target}/release/libnethsm_pkcs11.so.

Alpine Linux

You need to install musl-dev and gcc:

apk add musl-dev gcc

To build on Alpine Linux you will need to add the C argument target-feature=-crt-static:

RUSTFLAGS="-C target-feature=-crt-static" cargo build --release

nethsm-pkcs11's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nethsm-pkcs11's Issues

Clustering support

The use case would be when multiple NetHSMs would have the same keys stored.

Right now this can be achieved by configuring multiple slots in the configuration, but the application will see all the servers as different slots, so the load balancing needs to be done by the application.

The idea would be to list multiple servers with different addresses and credentials and try to balance the usage between each of them.

Problem with recent versions of openssl / libp11

With the packages in debian buster it works :
libp11 : 0.4.11-1
OpenSSL : OpenSSL 1.1.1n 15 Mar 2022

Dosen't work with arch packages :
libp11 : 0.4.12-2
OpenSSL : OpenSSL 3.1.1 30 May 2023 (Library: OpenSSL 3.1.1 30 May 2023)

The error is :

Unable to enumerate private keys
The private key was not found at: pkcs11:object=nginx;type=public
PKCS11_get_private_key returned NULL
Could not read key from org.openssl.engine:pkcs11:pkcs11:object=nginx;type=public
40B7CBBAF97F0000:error:40000065:pkcs11 engine:ERR_ENG_error:object not found:eng_back.c:887:
40B7CBBAF97F0000:error:13000080:engine routines:ENGINE_load_private_key:failed loading private key:crypto/engine/eng_pkey.c:79:

When using libp11 from commit 74497e0fa5b69b15790d6697e1ebce13af842d4c the error is different :

409711B3017F0000:error:068000DE:asn1 encoding routines:asn1_template_ex_i2d:illegal zero content:crypto/asn1/tasn_enc.c:374:
409711B3017F0000:error:020C0100:rsa routines:rsa_priv_encode:malloc failure:crypto/rsa/rsa_ameth.c:154:
409711B3017F0000:error:03000092:digital envelope routines:EVP_PKEY2PKCS8:private key encode error:crypto/evp/evp_pkey.c:161:
409711B3017F0000:error:04800073:PEM routines:do_pk8pkey:error converting private key:crypto/pem/pem_pk8.c:133:

Investigate ssh not accepting eddsa keys

nitropy nethsm --no-verify-tls --host localhost:8443 generate-key --type Curve25519 --length 255 --mechanism "EdDSA_Signature"  --key-id FirstEdDSAKey 

This command should output the key in ssh form :

ssh-keygen -D ~/git/nethsm-pkcs11/target/debug/libnethsm_pkcs11.so -e

Work on a custom openapi generator for the api

The current rust generator doesn't fit with our usage of the api, meaning we currently have to apply patches on top of the generated code in order to use the api.

The objective is to have a custom openapi generator where we won't need patches on top of the generated code.

Future plans

This issue is here to discuss the next features and functionalities to be implemented.

  1. OpenDNSSEC compatibility : #57 It seems unlikely that the OpenDNSSEC implementation will change in the next month, so if we want to support it this year, we will need to adapt to it.
  2. WIP : Openapi generation : Currently I applied a bunch of patches on top of the generated crate, I would need to either create a repeatable patch or customise the openapi code generator.
  3. Concurrency : currently everything is blocking, but there's a concurrency option in the PKCS11 specification and not supporting it may cause problems ?
  4. Key listing is slow : currently we fetch one key at a time because of the blocking architecture and the NetHSM api that list keys only returns the names. One solution would be to do concurrent api calls.
  5. State management : C_GetOperationState and C_SetOperationState are functions that can be used to pause and resume cryptographic operations. This could be implemented but would require some design on how we store all this information (serialisation).
  6. Notify : the PKCS11 spec as a field where you can pass a function to be called back when certain events happen. This would require polling the NetHSM regularly to check for events.
  7. C_WaitForSlotEvent : same as 6.
  8. Certificates : Currently I'm trying for every key to get the certificate and adding it to the list of keys when it works. Should I look for certificates only when a request for certificate objects is made ? This may break some programs.
  9. Need to figure out how to do unit testing of the functions.
  10. Proper handling of the CKF_LIBRARY_CANT_CREATE_OS_THREADS, currently we can't support this flag so CKR_NEED_TO_CREATE_THREADS should be returned. We could become compatible by using ureq.

unit tests

Write unit tests for the different parts of the module.

feat: list certificates

Currently only private keys, public keys and secret keys are listed.

The module should try to get the certificate associated to a key from the server and if available store the der-encoded certificate in the CKA_VALUE field and list the certificate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.