<div dir="ltr"><div>Hi Rob,</div><div><br></div><div>Thanks for the information and the patch. I will post to the NSS lists and also give the patch a try if I have time.</div><div><br></div><div>Best regards!<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 21, 2020 at 6:41 PM Rob Crittenden <<a href="mailto:rcritten@redhat.com">rcritten@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">George wrote:<br>
> We have been troubleshooting SSL issues using Apache with mod_nss and<br>
> Safenet HSMs for quite a while, so hopefully you can provide some insight.<br>
> <br>
> Red Hat Enterprise Linux Server release 7.6 (Maipo)<br>
> httpd.x86_64                      2.4.6-90.el7              <br>
> @rhel-7-server-rpms<br>
> mod_nss.x86_64                    1.0.14-12.el7            <br>
>  @rhel-7-server-rpms<br>
> nss.x86_64                        3.36.0-7.1.el7_6          <br>
> @rhel-7-server-rpms<br>
> <br>
> Apache is configured with mod_nss and Safenet libcryptoki, using<br>
> TLSv1.2. We see that in a seemingly random fashion, the Apache worker<br>
> suddenly can't talk to the HSM anymore, and can't recover from that. All<br>
> subsequent requests handled by this worker fail with the same error<br>
> message. Only way to recover is to kill the worker (or restart whole<br>
> Apache):<br>
> <br>
> [Tue Sep 24 20:21:19.375686 2019] [:error] [pid 2646] SSL Library Error:<br>
> -8152 The key does not support the requested operation<br>
> <br>
> Packet captures show that the incoming TLS Client Hello that triggers<br>
> the error is identical to a successful one. We have noticed,<br>
> nevertheless, that there *might* be some correspondence with TLS session<br>
> reuse. There have been several instances in which a worker fails with<br>
> this error soon after handling a resumed TLS session (so the worker<br>
> receives a Client Hello with a session-id, successfully handles the<br>
> request without renegotiation but fails soon after on a subsequent<br>
> request). Anyway, I couldn't find any way to effectively disable TLS<br>
> session reuse in mod_nss (can that be done??)<br>
> <br>
> We have also sniffed the PKCS11 conversation between NSS and the HSM and<br>
> can we see where the problem occurs. It looks that the Apache worker is<br>
> trying to perform operations on an invalid object handle (pay attention<br>
> to hObject=0x00001A60). PID 2646 is the Apache worker that failed in the<br>
> example before:<br>
> <br>
> pid(2646) tid(140580153710720) time(24/09/2019,20:21:19.313)     ><br>
> C_GetAttributeValue hSession=0x00020001 hObject=0x00001A60<br>
> pTemplate=0x0x7ffe7173b7c0 count=1<br>
> pid(2646) tid(140580153710720) time(24/09/2019,20:21:19.348)     <<<br>
> C_GetAttributeValue rv=0x00000082{object handle invalid}<br>
> pTemplate=0x0x7ffe7173b7c0<br>
> <br>
> pid(2646) tid(140580153710720) time(24/09/2019,20:21:19.357)     ><br>
> C_SignInit hSession=0x0002005B<br>
> pMechanism=0x0x7ffe7173b760{type=0x1{RSA_PKCS} pParam=0x(nil)<br>
> paramLen=0} hObject=0x00001A60<br>
> pid(2646) tid(140580153710720) time(24/09/2019,20:21:19.374)     <<<br>
> C_SignInit rv=0x00000060{key handle invalid}<br>
> <br>
> <br>
> That object handler 0x00001A60 seems to have been explicitly destroyed<br>
> by the same process more than 2 hours before in this example:<br>
> <br>
> pid(2646) tid(140580153710720) time(24/09/2019,18:00:09.521)     ><br>
> C_DestroyObject hSession=0x00020001 hObject=0x00001A60<br>
> pid(2646) tid(140580153710720) time(24/09/2019,18:00:09.523)     <<br>
> C_DestroyObject rv=0x00000000{success}<br>
> <br>
> <br>
> Any further information or ideas are welcome.<br>
<br>
I can't really speak to the PKCS#11 errors since NSS hides all that. I'm<br>
not sure what in NSS would trigger the C_DestroyObject call in your<br>
PKCS#11 driver.<br>
<br>
There is not currently a way to disable session caching in mod_nss. It<br>
would only be a couple of lines of code if you wanted to experiment with<br>
it. This patch would do it I think. A cache would still be setup but by<br>
setting SSL_NO_CACHE it would be ignored. I don't know what sort of<br>
performance hit this will add.<br>
<br>
diff --git a/nss_engine_init.c b/nss_engine_init.c<br>
index 61e2f499..85756e63 100644<br>
--- a/nss_engine_init.c<br>
+++ b/nss_engine_init.c<br>
@@ -729,14 +729,14 @@ static void nss_init_ctx_socket(server_rec *s,<br>
         nss_log_nss_error(APLOG_MARK, APLOG_ERR, s);<br>
         nss_die();<br>
     }<br>
-    if (!mctx->as_server) {<br>
+//    if (!mctx->as_server) {<br>
         if ((SSL_OptionSet(mctx->model, SSL_NO_CACHE, PR_TRUE)) !=<br>
SECSuccess)<br>
{<br>
             ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,<br>
                     "Unable to disable SSL client caching");<br>
             nss_log_nss_error(APLOG_MARK, APLOG_ERR, s);<br>
             nss_die();<br>
         }<br>
-    }<br>
+//    }<br>
 #ifdef SSL_ENABLE_RENEGOTIATION<br>
     if (SSL_OptionSet(mctx->model, SSL_ENABLE_RENEGOTIATION,<br>
             mctx->enablerenegotiation ?<br>
<br>
<br>
rob<br>
<br>
</blockquote></div></div>