<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi,<br>
<br>
On 08/01/21 22:35, George wrote:<br>
</div>
<blockquote type="cite"
cite="mid:95f017bb-6946-f37d-e585-05367f0e2da7@gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="moz-cite-prefix">Hi,<br>
<br>
I have been trying to setup mutual authentication using a
smart card but I can't seem to get the OpenSSL Engine to send a
response back to the server containing client's certificate from
the smart card. <br>
<br>
I'm using the following to configure the certificate and private
key:<br>
<br>
ENGINE_ctrl_cmd(engine, "LOAD_CERT_CTRL", 0, &cert_info,
NULL, 0);<br>
SSL_CTX_use_certificate(sslContext, cert_info.cert);<br>
<br>
EVP_PKEY* privateKey = ENGINE_load_private_key(engine,
"2b2586c684d69b670c0a805edf514e720f2b757d8e2faa0b3a7ff23d1ccfc7ba",
transfer_pin, &cb_data);<br>
SSL_CTX_use_PrivateKey(sslContext, privateKey);<br>
<br>
(I have been using the code in <a class="moz-txt-link-freetext"
href="https://github.com/jjkeijser/ppp/blob/eap-tls/pppd/eap-tls.c"
moz-do-not-send="true">https://github.com/jjkeijser/ppp/blob/eap-tls/pppd/eap-tls.c</a>
as a guide.)<br>
<br>
This seems be successful. However, when I start the mutual
authentication with <br>
SSL_connect(ssl)<br>
, the mutual authentications handshake fails. I can see the
server requesting the certificate from the client and the client
sends back an ACK for this message. However, the client does not
send the certificate to the server.<br>
<br>
I was looking through the OpenSSL code
openssl-1.0.2u\ssl\ssl_rsa.c and noticed something interesting.
The comment indicates that the flag <b>RSA_METHOD_FLAG_NO_CHECK</b>
should be set for smart cards:<br>
<br>
static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey)<br>
{<br>
. . .<br>
#ifndef OPENSSL_NO_RSA<br>
<b> /*</b><b><br>
</b><b> * Don't check the public/private key, this is
mostly for smart</b><b><br>
</b><b> * cards.</b><b><br>
</b><b> */</b><br>
if ((pkey->type == EVP_PKEY_RSA) &&<br>
(RSA_flags(pkey->pkey.rsa) &
RSA_METHOD_FLAG_NO_CHECK)) ;<br>
else<br>
#endif<br>
. . .<br>
}<br>
<br>
However, it is not actually set when I use a debugger to inspect
the flag. Does it need to be set? If so, how is this done? I
could not find anything related to this in <br>
<a class="moz-txt-link-freetext"
href="https://github.com/jjkeijser/ppp/blob/eap-tls/pppd/eap-tls.c"
moz-do-not-send="true">https://github.com/jjkeijser/ppp/blob/eap-tls/pppd/eap-tls.c</a><br>
</div>
</blockquote>
<br>
<br>
if you read through the code blob that Michael pointed you to, you
will find that this flag needs to be set *under certain
circumstances* when using smartcards. It has to do mostly with the
situation where<br>
- private key is on the smart card<br>
- the public key/certificate is NOT on the smart card<br>
- you ask OpenSSL to verify the private key without explicitly
providing a public key.<br>
<br>
I've never run into this issue, but then again, I have not tested
very often the case where the certificate was not present on the
HSM/smart card but the private key is. YMMV.<br>
<br>
As for using pksc11helper versus using libp11: that is just a matter
of taste. I used the engine_pkcs11 + libp11 route for the eap-tls
code , mostly because it was the first "working" set of tools I
found at the time.<br>
<br>
You can also take the "pkcs11helper" route, which is what OpenVPN
does (see <a class="moz-txt-link-freetext" href="https://github.com/openvpn">https://github.com/openvpn</a>). Both methods have pro's and
con's. <br>
<br>
Do you run into problems if you DO not set the
RSA_METHOD_FLAG_NO_CHECK flag? All that flag does is to stop
OpenSSL from verifying that a public key/cert and private key
match/belong together for RSA keys only; if your smartcard supports
EC keys then this flag will do you no good.<br>
<br>
HTH,<br>
<br>
JJK<br>
<br>
</body>
</html>