4

Considering this thread:

Create certificate without private key with OpenSSL

I have a very similar situation. I have a USB eToken 5110 JC (Aladdin) which has an inaccessible private key, since it's the main objective. I can use pkcs11-tool --module /lib/libeToken.so.9 -l --pin -s -i and it works fine. The libeToken.so.9 is provided by the SAC 9.1 (Safenet Authentication Tool) driver. So far so good.

My problem is: I need to generate certificates and sign them with this eToken. I tried to use the pkcs11 engine with openssl with no success. Maybe due misconfiguration (I tried https://github.com/OpenSC/libp11 how to, but I've got many errors, and I've given up)

I tried to use gpg but I get errors while learning card.

Since I can easily export certificates and public keys from USB Token, the tip of Valentin Bossi sounds good, since I could run openssl x509 -force_pubkey. Is it correct so far?

What will be the problem of doing this? I know that signing is a process of generating a hash of some data and encrypt it with a private key. When some data is sent to someone with its signature, the recipient will check what was the hashing algorithm, then generate a hash of the data with the same algorithm, and compare to the decrypted hash data with the sender's public key, am I right?

So when generating a certificate, no matter if the data came from a CSR or stdin, the signature made via public key would not assure digital signing, since anyone could get this public key and generate certificates on behalf the eToken owner.

So, what now? What have I got wrong?

Encrypted data with a private key can be decrypted with its public key and vice versa. But I didn't know that it's possible to encrypt and decrypt by using the same key (since the keys are asymmetric).

schroeder
  • 123,438
  • 55
  • 284
  • 319
  • I forgot to say that the error of using openssl pkcs11engine is related to the prohibittion for reading RSA private key from token, which is reasonable, since A3 and A4 certificates are hardware protected keys. So, the eToken has no READ flag on RSA private key, so pkcs11 engine seems to not work. – Fellipe Theophilo Barata May 14 '18 at 18:01
  • So, since I can sign documents with pkcs11-tool, is it possible to the certificate process in steps, in which I can generate the x509 attributes with openssl or any tool like gpg, then sign it with pkcs11-tool (which will create a digest of these attributes and encrypt with rsa private key) and then finally construct a file certificate, which will be composes by three parts: x509 data(openssl or gpg or whatever) + encrypted digest with rsa privkey (pkcs11-tool) + public key (exported from etoken with pkcs11-tool) – Fellipe Theophilo Barata May 14 '18 at 18:04
  • Is it possible to do it? what tool have this feature of creating x509 data without signatures? I've created a python/django application using cryptography.io , but it's using on-disk assymetric keys. – Fellipe Theophilo Barata May 14 '18 at 18:07
  • instead of comments, you can edit your question to include these things – schroeder May 14 '18 at 18:36

1 Answers1

2

I think you are confusing things. In the question you refer to a different problem is addressed: not being able to sign the CSR with the proper private key but still creating a certificate based on this CSR. This is possible since the signature of the CSR is only used to verify that the creator of the CSR has actually access to the private key but the private key is not actually needed to create the certificate.

You are instead asking about signing the certificate - which is different from and serves a different purpose then signing a CSR. Since the signature on the certificate is essential to check the validity of the certificate you cannot skip it or fake it (using a different private key). Thus, there is no way to properly sign a certificate without having somehow access to the private key, i.e. by having the private key itself or by having a device containing the key which can be used for signing.

Steffen Ullrich
  • 184,332
  • 29
  • 363
  • 424
  • Hi Steffen! Thanks for reply and clarify. So, in this case, do you know if is it possible to build a certificate in a separately steps? As I said, I can sign data using the pkcs11-tool. So theoretically it could be possible to create x509 data attributes, then generate the signature of it, and then, build a certificate file appending the x509 part + signature + public key. What do you think? If so, do you know any tool, including any python lib to do it? – Fellipe Theophilo Barata May 15 '18 at 12:00
  • @FellipeTheophiloBarata: Your original question was answered. Please don't ask a new (albeit related) question in a comment. Apart from that I'm not aware of any software which can do what you want. – Steffen Ullrich May 15 '18 at 12:24