<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — Verifying SSL Client Certificates?]]></title>
		<link>https://www.wolfssl.com/forums/topic673-verifying-ssl-client-certificates.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic673.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Verifying SSL Client Certificates?.]]></description>
		<lastBuildDate>Tue, 21 Jul 2015 17:46:28 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Verifying SSL Client Certificates?]]></title>
			<link>https://www.wolfssl.com/forums/post2100.html#p2100</link>
			<description><![CDATA[<p>Added, thanks!</p><p><a href="http://www.wolfssl.com/wolfSSL/Community.html">http://www.wolfssl.com/wolfSSL/Community.html</a></p><p>Best Regards,<br />Chris</p>]]></description>
			<author><![CDATA[null@example.com (chrisc)]]></author>
			<pubDate>Tue, 21 Jul 2015 17:46:28 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2100.html#p2100</guid>
		</item>
		<item>
			<title><![CDATA[Re: Verifying SSL Client Certificates?]]></title>
			<link>https://www.wolfssl.com/forums/post2070.html#p2070</link>
			<description><![CDATA[<p>No I don&#039;t mind, in fact I would like that very much.</p><p>Btw. this is my first experience using an SSL library and I really like wolfSSL. While OpenSSL is confusing the daylight out of me, wolfSSL is a little easier to understand and use.</p>]]></description>
			<author><![CDATA[null@example.com (alex_b)]]></author>
			<pubDate>Tue, 14 Jul 2015 21:16:03 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2070.html#p2070</guid>
		</item>
		<item>
			<title><![CDATA[Re: Verifying SSL Client Certificates?]]></title>
			<link>https://www.wolfssl.com/forums/post2067.html#p2067</link>
			<description><![CDATA[<p>Hi Alex,</p><p>Glad to see you got things figured out!&nbsp; Do you mind if we list your project on our Community page (<a href="http://wolfssl.com/wolfSSL/Community.html">http://wolfssl.com/wolfSSL/Community.html</a>)?</p><p>Thanks,<br />Chris</p>]]></description>
			<author><![CDATA[null@example.com (chrisc)]]></author>
			<pubDate>Tue, 14 Jul 2015 19:20:37 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2067.html#p2067</guid>
		</item>
		<item>
			<title><![CDATA[Re: Verifying SSL Client Certificates?]]></title>
			<link>https://www.wolfssl.com/forums/post2063.html#p2063</link>
			<description><![CDATA[<p>I have managed to solve the issue&nbsp; <img src="https://www.wolfssl.com/forums/img/smilies/smile.png" width="15" height="15" alt="smile" /> <br />The working code can be sampled here: <a href="http://sourceforge.net/projects/galaxy4linux/">http://sourceforge.net/projects/galaxy4linux/</a></p>]]></description>
			<author><![CDATA[null@example.com (alex_b)]]></author>
			<pubDate>Sun, 12 Jul 2015 20:16:18 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2063.html#p2063</guid>
		</item>
		<item>
			<title><![CDATA[Verifying SSL Client Certificates?]]></title>
			<link>https://www.wolfssl.com/forums/post2062.html#p2062</link>
			<description><![CDATA[<p>I am writing an application that uses libwebsockets with CyaSSL/wolfSSL as SSL provider.<br />My application uses a selfsigned CA certificate and server certificate, both created with OpenSSL.<br />So far, so good. I even get a green lock in the navigation bar when I import the CA certificate into chrome and connect to the websocket.</p><p>But now I would like users connecting to the websocket to have to present a client certificate to be able to connect. Initially I thought that the code I was using works. Even blocking revoked client certificates.</p><p>Recently, I have discovered that any client certificate signed by an &#039;old&#039; version of the CA certificate authenticates as valid when it should fail authentication, so the code only seems to work!<br />I&#039;ve been staring myself blind on any documentation I can find on this subject, but so far I still haven&#039;t figured it out.</p><p>Can you SSL guru&#039;s please help me, or point me in the right direction?</p><p>The initialisation of the SSL library is done by libwebsockets, any &#039;extra&#039; autentication like loading a certificate revocation list is done through a callback function. This is the relevant code for the libwebsockets initialization and the callback function for the html-protocol:<br /></p><div class="codebox"><pre><code>#include &lt;wolfssl/openssl/ssl.h&gt;

static struct libwebsocket_context * websocket_context;

static char *fn_ca_cert;      // complete path to CA certificate
static char *fn_srv_cert;     // complete path to Server certificate
static char *fn_srv_key;      // complete path to Server private key
static char *fn_crl_cert;     // complete path to CRL certificate
static char *path_crl_cert;   // complete path to CRL directory (ie. fn_crl_cert without the filename)

bool init_libwebsockets( void )
{
  struct lws_context_creation_info context_info;

  memset( &amp;context_info, 0, sizeof context_info );
  ...
  ...
  context_info.ssl_cert_filepath = fn_srv_cert;
  context_info.ssl_private_key_filepath = fn_srv_key;
  context_info.options = LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT;
  ...
  websocket_context = libwebsocket_create_context( &amp;context_info );
  if( websocket_context == NULL ){
    SYSLOG( LOG_ERR, &quot;websocket: init failed\n&quot; );
    return false;
  }
  
  return true;
}


static int websocket_callback_http( struct libwebsocket_context *context, struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len ){
{
  int n;
  switch( reason ){

    ...
    ...

    // This callback loads the CRL
    // user = SSL_CTX*
    //
    case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS:
#if ! HAVE_NO_SSL
      {
        char errbuf[160];
        SSL_CTX *ctx = (SSL_CTX*) user;

        // Load the CA cert
        n = SSL_CTX_load_verify_locations( ctx, fn_ca_cert, NULL );
        if( n != 1 ){
          n = ERR_get_error();
          SYSLOG( LOG_ERR, &quot;Encryption: problem loading CA certificate: %s&quot;, ERR_error_string( n, errbuf ) );
          return 1;
        }

        // Make sure our CRL exists
        FILE *fp = fopen( fn_crl_cert, &quot;rt&quot; );
        if( fp ){
          fclose( fp );

          // Load the CRL and activate CRL checking
          n = wolfSSL_CTX_LoadCRL( ctx, path_crl_cert, SSL_FILETYPE_PEM, 0 );
          if( n != 1 ){
            SYSLOG( LOG_ERR, &quot;Encryption: problem loading CRL directory: %s&quot;, wolfSSL_ERR_error_string( n, errbuf ) );
            return 1;
          }

          n = wolfSSL_CTX_EnableCRL( ctx, 0 );
          if( n != 1 ){
            SYSLOG( LOG_ERR, &quot;Encryption: problem enabling CRL: %s&quot;, wolfSSL_ERR_error_string( n, errbuf ) );
            return 1;
          }
        }
        else {
          SYSLOG( LOG_ERR, &quot;Encryption: problem loading CRL: %s&quot;, fn_crl_cert );
          return 1;
        }
      }
#endif
      break;


    // This callback decides whether or not to allow a client to connect (for all
    // protocols) and is called as:
    // int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx);
    //
    // in   = SSL* 
    // user = X509_STORE_CTX*
    // len  = preverify_ok
    //
    // Libwebsocket return conventions apply as usual, ie. return nonzero to block
    // the connection.
    //
    case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION:
      {
        n = 0;
#if ! HAVE_NO_SSL
        int err = 0;
        char errbuf[256];

        if( !len ){
          // The client certificate failed to be verified,
          // log the error message and refuse the connection by returning nonzero.
          //
          err = X509_STORE_CTX_get_error( (X509_STORE_CTX*)user );
          int depth = X509_STORE_CTX_get_error_depth( (X509_STORE_CTX*)user );
          wolfSSL_ERR_error_string_n( err, errbuf, sizeof( errbuf ) );
          SYSLOG( LOG_ERR, &quot;Encryption: Error: %s (%d), depth: %d&quot;, errbuf, err, depth );
          n = 1;
        }
#endif
      }
      return n;

    ...
    ...

    default:
      break;
  }
  return 0;
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (alex_b)]]></author>
			<pubDate>Thu, 09 Jul 2015 18:09:50 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2062.html#p2062</guid>
		</item>
	</channel>
</rss>
