<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bernard Banta on Medium]]></title>
        <description><![CDATA[Stories by Bernard Banta on Medium]]></description>
        <link>https://medium.com/@bantab?source=rss-e63630385eaf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6h-aj2HX5lTCLP8t153a2Q.png</url>
            <title>Stories by Bernard Banta on Medium</title>
            <link>https://medium.com/@bantab?source=rss-e63630385eaf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:29:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bantab/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Protect Your Web App Using Client Certificate-based Authentication With Nginx]]></title>
            <link>https://medium.com/@bantab/protect-your-web-app-using-client-side-certificate-authentication-with-nginx-a9517da1f255?source=rss-e63630385eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9517da1f255</guid>
            <category><![CDATA[client-side-certificate]]></category>
            <category><![CDATA[nginx-ssl-client-verify]]></category>
            <category><![CDATA[web-app-authentication]]></category>
            <category><![CDATA[self-signed-certificate]]></category>
            <category><![CDATA[create-your-own-ca]]></category>
            <dc:creator><![CDATA[Bernard Banta]]></dc:creator>
            <pubDate>Tue, 25 Jul 2023 07:56:50 GMT</pubDate>
            <atom:updated>2023-08-01T09:15:04.083Z</atom:updated>
            <content:encoded><![CDATA[<p>In our company, we have a number of web apps and services that are only being accesses internally by our software engineers and a small number of clients. All the apps are secured using HTTPS, email/username and password and, some of them are restricted to whitelisted IP addresses. Due to the sensitivity of the information in these apps, we were looking for an additional way of securing them further. After researching, we decided to use client certificate-based authentication.</p><p>They way it works is that the user installs the provided certificate, with the extension format of .p12 or .pfx, on their device or web browser. This certificate serves as a user identifier to the server. When the user accesses the app, the client certificate is provided to the server to verify the user’s device. If the certificate cannot be verified, the user is denied access.</p><p>In this article, I’ll guide you step-by-step from creating your own Certificate Authority (CA) to creating a client certificate that will be installed the clients’ devices.</p><h3>1. Create Root CA</h3><h4>Step 1: Create the private key</h4><pre>openssl genrsa -des3 -out CAPrivate.key 2048</pre><p>You’ll be prompted the following;</p><p>Enter pass phrase for CAPrivate.key: <em>Enter the password of your choice</em><br>Verifying — Enter pass phrase for CAPrivate.key: <em>Repeat the password above</em></p><h4>Step 2: Generate the root certificate</h4><pre>openssl req -x509 -new -nodes -key CAPrivate.key -sha256 -days 365 \<br>-out CAPrivate.pem</pre><p>You’ll be prompted the following;</p><p>Enter pass phrase for CAPrivate.key: <em>Enter the password you entered when creating the private key above.<br></em>Country Name (2 letter code) []: <em>Enter country code e.g. KE</em><br>State or Province Name (full name) []: <em>Enter your city name e.g. Nairobi</em><br>Locality Name (eg, city) []: <em>Enter your city name e.g. Nairobi</em><br>Organization Name (eg, company) []: <em>Enter your full company or organization name e.g. Finplus Group Holdings LTD</em><br>Organizational Unit Name (eg, section) []: <em>You can enter your department name e.g. IT Security</em><br>Common Name (eg, fully qualified host name) []: <em>You can enter something like COMPANY ROOT CA</em><br>Email Address []: Enter your email address e.g. certs@example.com</p><h3>2. Generate your server certificate</h3><p>In this section we’ll create a certificate that will work with our domain example.com and all it’s subdomains *.example.com. So, the names of the files will start with <strong>star_example_com</strong>. The type of certificate that will be generating is known as a wild certificate.</p><h4>Step 1: Generate a private key</h4><pre>openssl genrsa -out star_example_com.key 2048</pre><h4>Step 2: Create a Certificate Signing Request (CSR)</h4><p>In this case we’ll create a</p><pre>openssl req -new -key star_example_com.key -out star_example_com.csr</pre><p>You’ll be prompted the following;</p><p>Country Name (2 letter code) []: <em>Enter country code e.g. KE</em><br>State or Province Name (full name) []: <em>Enter your city name e.g. Nairobi</em><br>Locality Name (eg, city) []: <em>Enter your city name e.g. Nairobi</em><br>Organization Name (eg, company) []: Enter company name or organization e.g. Example Group Holdings Ltd<br>Organizational Unit Name (eg, section) []: <em>You can enter your department name e.g. IT Security</em><br>Common Name (eg, fully qualified host name) []:*.example.com<br>Email Address []: <a href="/service/mailto:certs@finplus.co">certs@e</a>xample.com<br>A challenge password []: <em>Enter a password to lock your CSR. The password should be less than 20 bytes long</em></p><h4>Step 3: Create a certificate</h4><p>Create a file named v2.ext with the following contents</p><pre>subjectAltName = DNS:*.example.com, DNS:example.com</pre><p>Create a certificate</p><pre>openssl x509 -req -in star_example_com.csr -CA CAPrivate.pem -CAkey \<br>CAPrivate.key -CAcreateserial -out star_example_com.crt -days 365 \<br>-sha256 -extfile v3.ext</pre><h3>3. Generate client certificate — PKCS #12 (PFX)</h3><p>The client certificate here is generated using <a href="https://en.wikipedia.org/wiki/PKCS_12">PKCS #12</a>, which is an archive format of storing the certificate, CA certificate and the private key in a bundle. The file extension format of .p12 or .pfxare supported. For more security, I recommend you lock the file with a password. This way, if someone gets access to the file they will not be able to install the certificate without the password and gain access to your web app or service. Run the following command below to generate the client sharable certificate.</p><pre>openssl pkcs12 -export -out logs_finplus_co_user.pfx -inkey star_example_com.key \<br>-in star_example_com.crt -certfile CAPrivate.pem</pre><p>You’ll get the following prompt;</p><p>Enter Export Password:</p><h3>4. Update Nginx configuration</h3><p>Add the following under http {}</p><pre># certificate<br>ssl_certificate /etc/nginx/client_certs/star_example_com.crt;<br>ssl_certificate_key /etc/nginx/client_certs/star_example_com.key;<br><br># client certificate<br>ssl_client_certificate /etc/nginx/client_certs/CAPrivate.pem;<br># make verification optional, so we can display a 403 message to those<br># who fail authentication<br>ssl_verify_client optional;</pre><p>Add the following under location / {}</p><pre># if the client-side certificate failed to authenticate, show a 403<br># message to the client<br>if ($ssl_client_verify != SUCCESS) {<br>    return 403;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9517da1f255" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>