<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I don’t suggest it as a final solution – although for me it works great and we have customers exchanging 2-4 million XML documents per day with no performance issues – BUT no matter what it is a good debugging tool. Inetd gets all the initial connections and closes them when done. It might or might or might not be involved with the HSM at all.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>You might also look at the process table (some form of ps) and grep for stunnel and relatives and see if they are hanging around. In theory, if a process dies, it “should” close it’s connections. If it is floating in space it will not.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Inetd will kill the process – at least on Centos and AIX and SCO – for sure and for certain.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>E<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> stunnel-users [mailto:stunnel-users-bounces@stunnel.org] <b>On Behalf Of </b>Brent Kimberley<br><b>Sent:</b> Friday, September 27, 2019 7:29 AM<br><b>To:</b> stunnel-users@stunnel.org; andrew.lynch@atos.net<br><b>Subject:</b> Re: [stunnel-users] stunnel-users Digest, Vol 182, Issue 14<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal><span style='font-family:"Helvetica",sans-serif'>>> <span style='color:#26282A'>Over time, after numerous reloads of stunnel (kill -HUP) the HSM reports that its connection table is full. </span><o:p></o:p></span></p></div><div><div><div><p class=MsoNormal><span style='font-family:"Helvetica",sans-serif;color:#26282A'>>> Logging from the engine shows that stunnel is never freeing the keys and therefore the engine is not closing the associated sessions with the HSM. Each stunnel reload opens 70 new sessions until eventually the HSM's configured limit is exceeded.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div></div><div><p class=MsoNormal><span style='font-family:"Helvetica",sans-serif;color:#26282A'>Where does the signal dispatcher free keys on SIG_HUP?<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span style='font-family:"Helvetica",sans-serif'><a href="https://github.com/mtrojnar/stunnel/blob/master/src/stunnel.c" target="_blank">https://github.com/mtrojnar/stunnel/blob/master/src/stunnel.c</a><o:p></o:p></span></p></div><div><div><p class=MsoNormal><span style='font-family:"Helvetica",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Helvetica",sans-serif'><o:p> </o:p></span></p></div></div></div><div id="ydpaf216824yahoo_quoted_0356605184"><div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Date: Fri, 27 Sep 2019 07:23:29 +0000<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>From: "Lynch, Andrew" <<a href="mailto:andrew.lynch@atos.net" target="_blank">andrew.lynch@atos.net</a>><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>To: Eric Eberhard <<a href="mailto:flash@vicsmba.com" target="_blank">flash@vicsmba.com</a>><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Cc: "<a href="mailto:stunnel-users@stunnel.org" target="_blank">stunnel-users@stunnel.org</a>" <<a href="mailto:stunnel-users@stunnel.org" target="_blank">stunnel-users@stunnel.org</a>><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Subject: Re: [stunnel-users] stunnel with OpenSSL engine: reload leaks HSM connections<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Hi Eric,<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Thank you for your suggestion. It is certainly worth looking into, although I suspect it may be impractical in our environment.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Now we have a single stunnel.conf with 70 services which would translate into 70 additional entries in inetd.conf. Each of those entries then needs to have its own reduced stunnel.conf so that it will only load the cert and key for its endpoint.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>The stunnel HOWTO recommends daemon mode over inetd mode due to the overhead for forking and SSL initialization. We would have additional overhead for engine init and HSM connection.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Regards,<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Andrew.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>-----Original Message-----<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>From: Eric Eberhard [mailto:<a href="mailto:flash@vicsmba.com" target="_blank">flash@vicsmba.com</a>] <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Sent: Thursday, September 26, 2019 7:20 PM<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>To: Lynch, Andrew; <a href="mailto:stunnel-users@stunnel.org" target="_blank">stunnel-users@stunnel.org</a><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Subject: RE: [stunnel-users] stunnel with OpenSSL engine: reload leaks HSM connections?<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Try running in inetd mode -- even if you don't like this you will learn something. Inetd will close connections as needed. E<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>-----Original Message-----<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>From: stunnel-users [mailto:<a href="mailto:stunnel-users-bounces@stunnel.org" target="_blank">stunnel-users-bounces@stunnel.org</a>] On Behalf Of Lynch, Andrew<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Sent: Thursday, September 26, 2019 5:56 AM<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>To: <a href="mailto:stunnel-users@stunnel.org" target="_blank">stunnel-users@stunnel.org</a><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Subject: [stunnel-users] stunnel with OpenSSL engine: reload leaks HSM connections?<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Hi,<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>We are using stunnel as a server to terminate incoming TLS connections. The config has around 70 services with certificates whose EC private keys are stored in an HSM and accessed using an OpenSSL engine.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Over time, after numerous reloads of stunnel (kill -HUP) the HSM reports that its connection table is full. Logging from the engine shows that stunnel is never freeing the keys and therefore the engine is not closing the associated sessions with the HSM. Each stunnel reload opens 70 new sessions until eventually the HSM's configured limit is exceeded.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>This behaviour has been observed on Suse Enterprise Linux 12.3 with the system-provided stunnel-5.00-4.3.4, but I can reproduce it with my own build of the current version 5.55.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Is this a known issue? It appears that other (ephemeral) keys are being freed, just not those associated with the service certificates.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Currently our workaround is to perform a full restart instead of a reload.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>This closes all HSM sessions when the process terminates, but of course it also kills any open client connections so it can only be done during the scheduled maintenance windows.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Regards,<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Andrew.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>_______________________________________________<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>stunnel-users mailing list<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><a href="mailto:stunnel-users@stunnel.org" target="_blank">stunnel-users@stunnel.org</a><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><a href="https://www.stunnel.org/cgi-bin/mailman/listinfo/stunnel-users" target="_blank">https://www.stunnel.org/cgi-bin/mailman/listinfo/stunnel-users</a><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>------------------------------<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>Subject: Digest Footer<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>_______________________________________________<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>stunnel-users mailing list<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><a href="mailto:stunnel-users@stunnel.org" target="_blank">stunnel-users@stunnel.org</a><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><a href="https://www.stunnel.org/cgi-bin/mailman/listinfo/stunnel-users" target="_blank">https://www.stunnel.org/cgi-bin/mailman/listinfo/stunnel-users</a><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>------------------------------<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>End of stunnel-users Digest, Vol 182, Issue 14<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Helvetica",sans-serif;color:#26282A'>**********************************************<o:p></o:p></span></p></div></div></div></div></div></body></html>