mkchain
mkchain
Open source tool to help you build a valid SSL certificate chain.
<p>
</a>
</p>
<p>
<a rel="nofollow noopener" target="_blank" href="#description">Description</a><br /> • <a rel="nofollow noopener" target="_blank" href="#how-to-use">How To Use</a><br /> • <a rel="nofollow noopener" target="_blank" href="#parameters">Parameters</a><br /> • <a rel="nofollow noopener" target="_blank" href="#how-it-works">How it works</a><br /> • <a rel="nofollow noopener" target="_blank" href="#requirements">Requirements</a><br /> • <a rel="nofollow noopener" target="_blank" href="#other">Other</a><br /> • <a rel="nofollow noopener" target="_blank" href="#license">License</a>
</p>
<p>
Created by<br /> <a rel="nofollow noopener" target="_blank" href="https://twitter.com/trimstray">trimstray</a> and<br /> contributors
</p>
<h2 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-description" class="anchor" aria-hidden="true" href="#description"></a>Description
</h2>
<p>
Is an open source tool to help you build a valid SSL certificate chain. Also can help you fix the incomplete chain and download all missing CA certificates. You can also download all certificates from remote server and <a rel="nofollow noopener" target="_blank" href="https://medium.com/@superseb/get-your-certificate-chain-right-4b117a9c0fce">get your certificate chain right</a>.
</p>
<h2 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-how-to-use" class="anchor" aria-hidden="true" href="#how-to-use"></a>How To Use
</h2>
<p>
It’s simple:
</p>
<pre># Clone this repository
git clone https://github.com/trimstray/mkchain
Go into the repository #
cd mkchain
Install #
./setup.sh install
Run the app #
mkchain -i /data/certs -o /data/chain.crt
<blockquote>
<ul dir="auto">
<li>
symlink to <code>bin/mkchain</code> is placed in <code>/usr/local/bin</code>
</li>
<li>
man page is placed in <code>/usr/local/man/man8</code>
</li>
</ul>
</blockquote>
<h2 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-parameters" class="anchor" aria-hidden="true" href="#parameters"></a>Parameters
</h2>
<p>
Provides the following options:
</p>
<pre> Usage:
mkchain <option|long-option>
Examples: mkchain –in Root.crt –in Intermediate1.crt –in Server.crt –out bundle_chain_certs.crt mkchain –in /tmp/certs –out bundle_chain_certs.crt –with-root mkchain -i Server.crt -o bundle_chain_certs.crt mkchain -i https://incomplete-chain.badssl.com/ –with-root
Options: –help show this message –debug displays information on the screen (debug mode) -i, –in add certificates to merge (file, multiple files, directory with ssl certificates or remote domain) -o, –out saves the result (chain) to a file –with-root add root certificate to certificates chain
<blockquote>
<p>
<code>-o|--out</code> – without this param <code>mkchain</code> save output chain to <code>mkchain/chains/</code> directory.
</p>
</blockquote>
<h2 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-how-it-works" class="anchor" aria-hidden="true" href="#how-it-works"></a>How It Works
</h2>
<blockquote>
<p>
Before read it, please see article about <strong><a rel="nofollow noopener" target="_blank" href="https://support.dnsimple.com/articles/what-is-ssl-certificate-chain/">SSL Certificate Chain</a></strong>.
</p>
</blockquote>
<p>
Let’s start with <strong>ssllabs</strong> certificate chain. They are delivered together with the <code>mkchain</code> and can be found in the <code>example/ssllabs.com</code> directory which additionally contains the <code>all</code> directory (containing all the certificates needed to assemble the chain) and the <code>server_certificate</code> directory (containing only the server certificate).<br /> The correct chain for the <strong>ssllabs.com</strong> domain (the result of the <code>openssl</code> command):
</p>
<pre>Certificate chain
0 s:/C=US/ST=California/L=Redwood City/O=Qualys, Inc./CN=ssllabs.com i:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2012 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1K 1 s:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2012 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1K i:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2009 Entrust, Inc. - for authorized use only/CN=Entrust Root Certification Authority - G2 2 s:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2009 Entrust, Inc. - for authorized use only/CN=Entrust Root Certification Authority - G2 i:/C=US/O=Entrust, Inc./OU=www.entrust.net/CPS is incorporated by reference/OU=(c) 2006 Entrust, Inc./CN=Entrust Root Certification Authority
<p>
The above code presents a full chain consisting of:
</p>
<ul dir="auto">
<li>
<strong>Identity Certificate</strong> (Server Certificate)<br /> issued for ssllabs.com by Entrust Certification Authority – L1K
</li>
<li>
<strong>Intermediate Certificate</strong><br /> issued for Entrust Certification Authority – L1K by Entrust Root Certification Authority – G2
</li>
<li>
<strong>Intermediate Certificate</strong><br /> issued for Entrust Root Certification Authority – G2 by Entrust Root Certification Authority
</li>
<li>
<strong>Root Certificate</strong> (Self-Signed Certificate)<br /> issued for Entrust Root Certification Authority by Entrust Root Certification Authority
</li>
</ul>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-scenario-1" class="anchor" aria-hidden="true" href="#scenario-1"></a>Scenario 1
</h4>
<p>
In this scenario, we will chain all delivered certificates. Example of running the tool:
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-scenario-2" class="anchor" aria-hidden="true" href="#scenario-2"></a>Scenario 2
</h4>
<p>
In this scenario, we only use the server certificate and use it to retrieve the remaining required certificates. Then, as above, we will combine all the provided certificates. Example of running the tool:
</p>
<h3 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-certificate-chain" class="anchor" aria-hidden="true" href="#certificate-chain"></a>Certificate Chain
</h3>
<p>
In order to create a valid chain, you must provide the tool with all the necessary certificates (if you set directory for <code>-i|--in</code> param). It will be:
</p>
<ul dir="auto">
<li>
<strong>Server Certificate</strong>
</li>
<li>
<strong>Intermediate CAs</strong> and <strong>Root CAs</strong>
</li>
</ul>
<p>
This is very important because without it you will not be able to determine the beginning and end of the chain.
</p>
<blockquote>
<p>
If you set only certificate file as a <code>-i|--in</code> value, <code>mkchain</code> automatically download all necessary certificates.
</p>
</blockquote>
<p>
However, if you look inside the generated chain after generating with <code>mkchain</code>, you will not find the root certificate there.<br /> Why? Because self-signed root certificates need not/should not be included in web server configuration. They serve no purpose (clients will always ignore them) and they incur a slight performance (latency) penalty because they increase the size of the SSL handshake.<br /> If you want to add a root certificate to the certificate chain, call the utility with the <code>--with-root</code> parameter.
</p>
<h3 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-certification-paths" class="anchor" aria-hidden="true" href="#certification-paths"></a>Certification Paths
</h3>
<p>
<code>mkchain</code> allows use of two <strong>certification paths</strong>:
</p>
<h3 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-output-comments" class="anchor" aria-hidden="true" href="#output-comments"></a>Output comments
</h3>
<p>
When generating the chain of certificates, <code>mkchain</code> displays comments with information about certificates, including any errors.<br /> Here is a list of all possibilities:
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-not-found-identity-end-user-server-certificate" class="anchor" aria-hidden="true" href="#not-found-identity-end-user-server-certificate"></a>not found identity (end-user, server) certificate
</h4>
<p>
The message is displayed in the absence of a server certificate that is the beginning of the chain. This is a unique case because in this situation the <code>mkchain</code> ends its operation displaying only this information. The server certificate is the only certificate required to correctly create a chain. Without this certificate, the correct chain will not be created.
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-found-correct-identity-end-user-server-certificate" class="anchor" aria-hidden="true" href="#found-correct-identity-end-user-server-certificate"></a>found correct identity (end-user, server) certificate
</h4>
<p>
The reverse situation here – message displayed when a valid server certificate is found.
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-not-found-first-intermediate-certificate" class="anchor" aria-hidden="true" href="#not-found-first-intermediate-certificate"></a>not found first intermediate certificate
</h4>
<p>
This message appears when the first of the two intermediate certificates is not found. This information does not explicitly specify the absence of a second intermediate certificate and on the other hand it allows to determine whether the intermediate certificate to which the server certificate was signed exists. Additionally, it can be displayed if the second intermediate certificate has been delivered.
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-not-found-second-intermediate-certificate" class="anchor" aria-hidden="true" href="#not-found-second-intermediate-certificate"></a>not found second intermediate certificate
</h4>
<p>
Similar to the above, however, it concerns the second intermediate certificate. However, it is possible to create the chain correctly using the second certification path, e.g. using the first intermediate certificate and replacing the second with the main certificate.
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-one-or-more-intermediate-certificate-not-found" class="anchor" aria-hidden="true" href="#one-or-more-intermediate-certificate-not-found"></a>one or more intermediate certificate not found
</h4>
<p>
This message means that one or all of the required intermediate certificates are missing and displayed in the absence of the root certificate.
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-found-n-correct-intermediate-certificates" class="anchor" aria-hidden="true" href="#found-n-correct-intermediate-certificates"></a>found ‘n’ correct intermediate certificate(s)
</h4>
<p>
This message indicates the number of valid intermediate certificates.
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-not-found-correct-root-certificate" class="anchor" aria-hidden="true" href="#not-found-correct-root-certificate"></a>not found correct root certificate
</h4>
<p>
The lack of the root certificate is treated as a warning. Of course, when configuring certificates on the server side, it is not recommended to attach a root certificate, but if you create it with the <code>mkchain</code>, it treats the chain as incomplete displaying information about the incorrect creation of the chain.
</p>
<h4 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-an-empty-cn-field-was-found-in-one-of-the-certificates" class="anchor" aria-hidden="true" href="#an-empty-cn-field-was-found-in-one-of-the-certificates"></a>an empty CN field was found in one of the certificates
</h4>
<p>
This message does not inform about the error and about the lack of the CN field what can happen with some certificates (look at <code>example/google.com</code>). Common Name field identifies the host name associated with the certificate. There is no requirement in <strong>RFC3280</strong> for an Issuer DN to have a CN. Most CAs do include a CN in the Issuer DN, but some don’t, such as this Equifax CA.
</p>
<h2 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-requirements" class="anchor" aria-hidden="true" href="#requirements"></a>Requirements
</h2>
<p>
<code>mkchain</code> uses external utilities to be installed before running:
</p>
<ul dir="auto">
<li>
<strong><a rel="nofollow noopener" target="_blank" href="https://www.openssl.org/">OpenSSL</a></strong> (testing on 1.1.0g/h)
</li>
</ul>
<p>
This tool working with:
</p>
<ul dir="auto">
<li>
<strong>GNU/Linux</strong> (testing on Debian and CentOS)
</li>
<li>
<strong><a rel="nofollow noopener" target="_blank" href="https://www.gnu.org/software/bash/">Bash</a></strong> (testing on 4.4.19)
</li>
</ul>
<p>
<strong>MacOS/FreeBSD</strong>:
</p>
<ul dir="auto">
<li>
replace for getopt(1) that supports GNU-style long options (<code>pkg install getopt</code>)
</li>
<li>
also work on MacOS with <code>greadlink</code> from <strong>coreutils</strong> (installed via homebrew)
</li>
</ul>
<h2 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-other" class="anchor" aria-hidden="true" href="#other"></a>Other
</h2>
<h3 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-contributing" class="anchor" aria-hidden="true" href="#contributing"></a>Contributing
</h3>
<p>
See <strong>this</strong>.
</p>
<h3 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-project-architecture" class="anchor" aria-hidden="true" href="#project-architecture"></a>Project architecture
</h3>
<p>
See <strong>this</strong>.
</p>
<h2 dir="auto">
<a rel="nofollow noopener" target="_blank" id="user-content-license" class="anchor" aria-hidden="true" href="#license"></a>License
</h2>
<p>
GPLv3 :…
</p>