How to generate certificate if private key is in HSM?

demonguy

I often use openssl to generate RSA key and certificate. But now i encounter a problem. openssl x509 -req require private key as input. But now we're using HSM to protect private key and I'll never be able to touch the private key. In this way how do i suppose to generate a x509 certificate?

dave_thompson_085

I've seen some HSMs come with their own support programs ready to use for a variety of things including key generation and cert or CSR creation, or make them available (for example on the vendor website); did you check for that? Assuming that isn't a (good) option:

You don't identify your HSM; there are thousands of models with at least hundreds of interfaces, although a significant fraction (not nearly all) use the "standard" (mostly) PKCS#11 interface.

OpenSSL has a fairly open-ended ENGINE API that redirects some subsets of cryptographic functions -- such as privatekey generation, signing and decryption -- to an implementation other than OpenSSL's normal one -- such as an HSM. OpenSSL comes with a few engines builtin -- at least by default; a particular build (such as the package for a Linux distribution) may omit the builtin engines, in which case you may need to do your own build. Other people can also write engine modules, including but not limited to a maker or supplier of a particular HSM model or line and including you.

  1. If your HSM is one of those with a builtin engine, configure that engine as needed according to its documentation, and use the appropriate -engine id or -*engine id options to your openssl (sub)commands.

Note that req -new generates a certificate only with -x509, usually plus some related arguments, and a cert generated this way is selfsigned; otherwise req -new generates a Certificate Signing Request (CSR) that you then get a CA to "convert" into a CA-signed "real" certificate (the PKCS#10 CSR itself is always selfsigned). req can also generate a new privatekey instead of using an existing one, and this generation can be "in" the engine thus on the HSM.

  1. If your HSM does not have a builtin engine but does have an engine from some other party, install it to your system. This is the case for PKCS#11. This may require changing your version of OpenSSL to one supported by the engine. Then proceed as in 1: configure the engine and use it.

  2. If your HSM does not have any engine but its API provides the operations OpenSSL wants in an engine, you can write (and debug!) an engine module for it. Then proceed as in 1 using your engine. Also consider offering your engine module to the world, the community using this type of HSM, and/or the OpenSSL project.

  3. If your HSM's capabilities don't fit into the engine API, or no engine module exists and you don't want to create one, you can instead write your own program, using some (perhaps much) of the code from openssl/apps/req.c, to generate a privatekey and/or use an existing one on your HSM, build the data structures for a certificate (or CSR) within OpenSSL in more or less the existing way, but then give X509_[REQ_]sign_ctx an EVP_PKEY (the polymorphic-in-C data structure used in OpenSSL for various types of asymmetric keys) that you have set up with custom methods that use your HSM's API (and some identification of the key on the HSM) to do the signing. Make sure any licensing on your program is compatible with the OpenSSL license (which is essentially BSD-advertising style).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Generate Private Key for Existing SSL Certificate

From Dev

Thales Payshield HSM RSA Private Key

From Dev

php openssl: how to match the private key with the certificate

From Dev

How do I convert a certificate to a private key?

From Dev

How to verify if the private key matches with the certificate..?

From Dev

How to locate the private key of a certificate in Windows

From Dev

How to generate a string that is valid PEM private key?

From Dev

How to generate a public/private key (UNIX)

From Dev

openssl : How to create .pem file with private key, associated public certificate, and certificate chain all the way to the root certificate?

From Dev

Generate private key with OpenSSL

From Dev

How to load PEM certificate together with private key in libcurl using mbedtls

From Dev

How to access the OpenShift wildcard SSL certificate and private key

From Dev

JAVA : How to make SSL connection with public certificate and private key

From Dev

How to export Certificate and private key as a single file using java code?

From Dev

PKCS11Interop : How to extract certificate with private key?

From Dev

How CSP find the private key of certificate to perform cryptographic operations?

From Java

Distribution certificate / private key not installed

From Dev

certificate and private key for push notification

From Dev

Getting "No certificate matches private key"

From Dev

Missing PFX or certificate + private key

From Dev

certificate and private key for push notification

From Dev

Azure KeyVault: How to tell if a key is HSM protected

From Dev

How to generate a public key certificate and a .jks file using keytool?

From Dev

Not sure how to generate an ECDSA signature, given a private key and a message

From Dev

How to generate fixed length exponent of a given RSA private key in Java?

From Dev

How to generate ECDSA private and public key for DNSSEC using OpenSSL?

From Dev

Generate private key that cannot be exported

From Dev

Certificate generated by Openssl Contains "PRIVATE KEY" instead of "RSA PRIVATE KEY"

From Dev

In Java, how do I decrypt using the private key from an X509 certificate (public/private key pair) inside a JKS keystore?

Related Related

  1. 1

    Generate Private Key for Existing SSL Certificate

  2. 2

    Thales Payshield HSM RSA Private Key

  3. 3

    php openssl: how to match the private key with the certificate

  4. 4

    How do I convert a certificate to a private key?

  5. 5

    How to verify if the private key matches with the certificate..?

  6. 6

    How to locate the private key of a certificate in Windows

  7. 7

    How to generate a string that is valid PEM private key?

  8. 8

    How to generate a public/private key (UNIX)

  9. 9

    openssl : How to create .pem file with private key, associated public certificate, and certificate chain all the way to the root certificate?

  10. 10

    Generate private key with OpenSSL

  11. 11

    How to load PEM certificate together with private key in libcurl using mbedtls

  12. 12

    How to access the OpenShift wildcard SSL certificate and private key

  13. 13

    JAVA : How to make SSL connection with public certificate and private key

  14. 14

    How to export Certificate and private key as a single file using java code?

  15. 15

    PKCS11Interop : How to extract certificate with private key?

  16. 16

    How CSP find the private key of certificate to perform cryptographic operations?

  17. 17

    Distribution certificate / private key not installed

  18. 18

    certificate and private key for push notification

  19. 19

    Getting "No certificate matches private key"

  20. 20

    Missing PFX or certificate + private key

  21. 21

    certificate and private key for push notification

  22. 22

    Azure KeyVault: How to tell if a key is HSM protected

  23. 23

    How to generate a public key certificate and a .jks file using keytool?

  24. 24

    Not sure how to generate an ECDSA signature, given a private key and a message

  25. 25

    How to generate fixed length exponent of a given RSA private key in Java?

  26. 26

    How to generate ECDSA private and public key for DNSSEC using OpenSSL?

  27. 27

    Generate private key that cannot be exported

  28. 28

    Certificate generated by Openssl Contains "PRIVATE KEY" instead of "RSA PRIVATE KEY"

  29. 29

    In Java, how do I decrypt using the private key from an X509 certificate (public/private key pair) inside a JKS keystore?

HotTag

Archive