<html 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=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@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;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.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>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Sorry I realized I didn’t include the OpenSSL version I was using.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This is with OpenSSL 1.1.1d  10 Sep 2019.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-Dan<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">openssl-users <openssl-users-bounces@openssl.org><br>
<b>Date: </b>Wednesday, November 11, 2020 at 10:29 AM<br>
<b>To: </b>openssl-users@openssl.org <openssl-users@openssl.org><br>
<b>Subject: </b>Deleted client certificate trust expectations<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="line-height:12.0pt"><b><span style="font-size:10.0pt;color:black">External Mail.</span></b><span style="font-size:10.0pt;color:black"> Careful of links / attachments. Submit Helpdesk if unsure.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">I have a question/issue about how OpenSSL should handle a deleted client certificate. It appears that once a trusted certificate is read from the filesystem, it remains trusted throughout the lifespan of the server process.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">I wrote a small SSL web service that reproduces the issue I’m having with my application.
<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Pardon the Perl syntax – I’ve not rewritten this in C but I think the intent is clear.  This code reproduces the scenario:<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">use Socket;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">use Net::SSLeay qw(die_now die_if_ssl_error);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">Net::SSLeay::load_error_strings();<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">Net::SSLeay::SSLeay_add_ssl_algorithms();<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">Net::SSLeay::randomize();<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$our_ip = "\0\0\0\0";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$port = 1235;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$sockaddr_template = 'S n a4 x8';<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$our_serv_params = pack ($sockaddr_template, &AF_INET, $port, $our_ip);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">socket (S, &AF_INET, &SOCK_STREAM, 0)  or die "socket: $!";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">bind (S, $our_serv_params)             or die "bind:   $!";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">listen (S, 5);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$ctx = Net::SSLeay::CTX_new ();<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$key = "client.key";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$cert = "client.crt";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$trust_dir = "/client_trusted_certificates";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">Net::SSLeay::CTX_use_RSAPrivateKey_file($ctx, $key, Net::SSLeay::FILETYPE_PEM());<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">Net::SSLeay::CTX_use_certificate_file($ctx, $cert, Net::SSLeay::FILETYPE_PEM());<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">Net::SSLeay::CTX_set_session_id_context($ctx,'sessiontest',length('sessiontest'));<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">Net::SSLeay::CTX_load_verify_locations($ctx,"",$trust_dir);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">Net::SSLeay::CTX_set_verify($ctx,&Net::SSLeay::VERIFY_PEER, \&verify_client_cert);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">while (1)<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">{<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   $addr = accept (NS, S);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   select (NS);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   $| = 1;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   select (STDOUT);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   $ssl = Net::SSLeay::new($ctx);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   Net::SSLeay::set_fd($ssl, fileno(NS));<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   $err = Net::SSLeay::accept($ssl);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   $got = Net::SSLeay::read($ssl);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   print $got."\n";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   Net::SSLeay::write ($ssl, uc ($got));<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   Net::SSLeay::free ($ssl);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">   close NS;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">}<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> <o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">sub verify_client_cert<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">{<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">    my ($pre_verify,$x509_store) = @_;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> <o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">    print "Pre-verify: $pre_verify\n";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">    print "ctx error: ".Net::SSLeay::X509_STORE_CTX_get_error($x509_store)."\n";<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">    return $pre_verify;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">}<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> <o:p></o:p></p>
<p class="MsoNormal">This all works as it should, and verify_client_cert() is called appropriately when the client cert is provided.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">The issue I’m having is how the verify process works when a certificate is removed from the trusted directory while this service is running.  If a client connects with a client cert and the service verifies that certificate, then the trusted
 client cert is removed from /trusted_clients, then the client connects again – the client cert will still verify.  The client cert will continue to  verify until I restart the server. 
<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">An strace of the process confirms that it only opens the trusted directory once, subsequent connections using this client cert do not re-open or look for the file in the trust directory.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">My understanding of how this should work was that it should read the contents of that directory at the time the verify takes place, not when CTX_set_verify() is called, but that doesn’t seem to be what is happening. 
<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Another interesting bit is that the inverse is not true.  If I add a cert to the trusted directory, it immediately uses it without having to restart the process.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">I assume that if I used a certificate revocation list and revoked the client cert this wouldn’t be an issue, but why are the directory contents cached? Is this for performance reasons?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Thanks <o:p></o:p></p>
<p class="MsoNormal">Dan Freed<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</body>
</html>