openssl and external card reader support in TLS

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

openssl and external card reader support in TLS

Tobias.Wolf

I need to implement support for the external authentication of a card reader within a TLS handshake. We did this already with PKCS11 using the C_Sign function and it is working fine.

Now I need to implement the same functionality in another use case with openssl for TLS handshake.

My Question is there a callback I can use or do I need to implement my own ENGINE? I want to avoid implementing the ENGINE interface, because that is a lot of work and maybe over engineered for this scenario, right?

Reply | Threaded
Open this post in threaded view
|

RE: openssl and external card reader support in TLS

Michael Wojcik
> From: openssl-users [mailto:[hidden email]] On Behalf Of [hidden email]
> Sent: Tuesday, October 22, 2019 07:03

> I need to implement support for the external authentication of a card reader within a
> TLS handshake. We did this already with PKCS11 using the C_Sign function and it is
> working fine.

> Now I need to implement the same functionality in another use case with openssl for
> TLS handshake.

> My Question is there a callback I can use or do I need to implement my own ENGINE?

OpenSSL includes a PKCS#11 engine. I've used it in the past to interact with some HSMs for cryptographic operations such as code signing. While some research and additional software may be required to get all the PKCS#11 ducks in a row, it sounds like you've already successfully used PKCS#11 with your device, so I'd expect using it with OpenSSL will be fairly straightforward.

You can find examples of using the openssl command-line utility with the PKCS#11 engine online. That's a good way to get started; it will let you confirm what settings and commands you need.

--
Michael Wojcik
Distinguished Engineer, Micro Focus


Reply | Threaded
Open this post in threaded view
|

AW: openssl and external card reader support in TLS

Tobias.Wolf
Our PKCS11 module development will discontinue and therefore I can`t use it anymore, but the idea is great and very interesting.
To give more details we need a callback or similar mechanism to replace the signature created in Certificate TLS message with our signature coming from the card reader.

TLS handshake
......
S: Certificate Request
C: Certificate Verify --> here we want to hook in "Signature" and replace the value!
.....

We tried already with the client callback

int (*client_cert_cb)(SSL *ssl, X509 **x509,
                                                       EVP_PKEY **pkey));

But there it is mandatory to give in the private key which we don`t have, because that part is done by the card reader machine.
I think the caller of the callback is doing later on a rsa sign processing with the private key and there I want to hook in!

Tobias Wolf, T-Systems

-----Urspr√ľngliche Nachricht-----
Von: openssl-users <[hidden email]> Im Auftrag von Michael Wojcik
Gesendet: Dienstag, 22. Oktober 2019 17:00
An: [hidden email]
Betreff: RE: openssl and external card reader support in TLS

> From: openssl-users [mailto:[hidden email]] On
> Behalf Of [hidden email]
> Sent: Tuesday, October 22, 2019 07:03

> I need to implement support for the external authentication of a card
> reader within a TLS handshake. We did this already with PKCS11 using
> the C_Sign function and it is working fine.

> Now I need to implement the same functionality in another use case
> with openssl for TLS handshake.

> My Question is there a callback I can use or do I need to implement my own ENGINE?

OpenSSL includes a PKCS#11 engine. I've used it in the past to interact with some HSMs for cryptographic operations such as code signing. While some research and additional software may be required to get all the PKCS#11 ducks in a row, it sounds like you've already successfully used PKCS#11 with your device, so I'd expect using it with OpenSSL will be fairly straightforward.

You can find examples of using the openssl command-line utility with the PKCS#11 engine online. That's a good way to get started; it will let you confirm what settings and commands you need.

--
Michael Wojcik
Distinguished Engineer, Micro Focus


Reply | Threaded
Open this post in threaded view
|

RE: openssl and external card reader support in TLS

Michael Wojcik
> From: [hidden email] [mailto:[hidden email]]
> Sent: Wednesday, October 23, 2019 02:11
>
> Our PKCS11 module development will discontinue and therefore I can`t use it
> anymore, but the idea is great and very interesting.
> To give more details we need a callback or similar mechanism to replace the
> signature created in Certificate TLS message with our signature coming from
> the card reader.

For OpenSSL 1, the Engine mechanism is the way to do this. If you're discontinuing your PKCS#11 interface, then I think the only option is to write a custom engine.

For OpenSSL 3, I understand there's a new Provider mechanism for this purpose, but I haven't investigated it.

--
Michael Wojcik
Distinguished Engineer, Micro Focus



Reply | Threaded
Open this post in threaded view
|

Re: AW: openssl and external card reader support in TLS

Jan Just Keijser-2
In reply to this post by Tobias.Wolf
Hi Tobias,

On 23/10/19 10:11, [hidden email] wrote:

> Our PKCS11 module development will discontinue and therefore I can`t use it anymore, but the idea is great and very interesting.
> To give more details we need a callback or similar mechanism to replace the signature created in Certificate TLS message with our signature coming from the card reader.
>
> TLS handshake
> ......
> S: Certificate Request
> C: Certificate Verify --> here we want to hook in "Signature" and replace the value!
> .....
>
> We tried already with the client callback
>
> int (*client_cert_cb)(SSL *ssl, X509 **x509,
>                                                         EVP_PKEY **pkey));
>
> But there it is mandatory to give in the private key which we don`t have, because that part is done by the card reader machine.
> I think the caller of the callback is doing later on a rsa sign processing with the private key and there I want to hook in!
>

writing your own engine might be the easiest thing: the way it
currently(most likely) works, is
 ¬† openssl -> engine_pkcs11 -> libp11 -> pkcs11 driver

all you'd have to do is move your pkcs11 driver code into a fork of the
engine_pkcs11 code. That code is less than 2000 lines long, so it should
be fairly straightforward.

JM2CW,

JJK
Reply | Threaded
Open this post in threaded view
|

AW: openssl and external card reader support in TLS

Tobias.Wolf
In reply to this post by Michael Wojcik
We decided to implement the engine concept, but as far as I understood acts the engine on a globally level, right?
But in our application we have two different TLS communication ways, is it possible that our custom engine is only active for one transport way i.e. on ssl context level?