<?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 Sufiyan Ghori on Medium]]></title>
        <description><![CDATA[Stories by Sufiyan Ghori on Medium]]></description>
        <link>https://medium.com/@sufiyanghori?source=rss-3c731e06a741------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bZ1M1JBJu2Wc9xMOuLhWoA.png</url>
            <title>Stories by Sufiyan Ghori on Medium</title>
            <link>https://medium.com/@sufiyanghori?source=rss-3c731e06a741------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 17:57:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sufiyanghori/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[[Guide] using Hashicorp Vault to manage PKI and issue certificates]]></title>
            <link>https://medium.com/@sufiyanghori/guide-using-hashicorp-vault-to-manage-pki-and-issue-certificates-e1981e7574e?source=rss-3c731e06a741------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1981e7574e</guid>
            <category><![CDATA[pki]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[hashicorp]]></category>
            <category><![CDATA[hashicorp-vault]]></category>
            <dc:creator><![CDATA[Sufiyan Ghori]]></dc:creator>
            <pubDate>Sun, 05 Aug 2018 05:18:24 GMT</pubDate>
            <atom:updated>2018-08-07T08:38:30.705Z</atom:updated>
            <content:encoded><![CDATA[<p>Vault is an encrypted key-value store, which is designed to solve many challenges that are faced by organisations these days, be it a small startup or an enterprise, they all face some basic issues, one of which is “secret sprawl”, which means that 100s of credentials just ramble around, generated by dozens of different people. This is due to a lack of centralisation of credentials; organisations don’t have a single source where all these credentials originated from.</p><p>Another such challenge is “Limited Visibility”; organisations don’t know what certain credentials are being used for? Should it be revoked? Will it break something if revoked? You see, there is very limited visibility on how these credentials are being utilised.</p><p>In comes Hashicorp Vault, a centralised key-value store which provides restrictive access to credentials using policies and ACLs. It also acts as a pass-through-encryption, which essentially means that instead of just storing data within Vault, it can return encrypted data to a user, thus providing Encryption as a Service (EaaS) model. Some of Vault’s distinct features that separates it from any other tool in the market are,</p><ul><li>Dynamic credentials generation using secret backends.</li><li>Authentication and auditing of each request and response.</li><li>Credentials having a lease associated with them.</li></ul><p>But that’s not all, Vault allows you to manage an entire Public Key Infrastructure (PKI) to ensure secure communication among different services. This allows companies to easily setup their own certificate authority (CA), revoke or issue new certificates using simple API calls, thus dumping the painful process of constantly generating self-signed certificates.</p><p>In this guide, I am going to briefly explain how Vault works, how it can be configured, and finally how you can use it to create your own Root CA, issue certificates dynamically thus leveraging Vault’s auth method.</p><p>Things covered in this guide:</p><ul><li>Installing and configuring Vault</li><li>How vault initialisation works</li><li>How vault secures itself</li><li>Creating a Root CA</li><li>Creating Intermediate CA</li><li>Issuing a certificate to a Web server</li></ul><p><strong>Downloading Vault</strong></p><p>Vault pre-compiled binaries can be downloaded from <a href="https://www.vaultproject.io/downloads.html">https://www.vaultproject.io/downloads.html</a> The vault binary inside the zip file is all that is necessary to run Vault. Once downloaded, unzip the file,</p><pre>unzip vault_0.10.4_linux_amd64.zip -d /etc/vault/</pre><p>Add vault into <strong>PATH</strong>,</p><pre>$ echo &#39;export PATH=$PATH:/etc/vault/&#39; &gt;&gt; ~/.profile</pre><pre>$ . ~/.profile</pre><p><strong>Verify installation,</strong></p><pre>vault -h</pre><p>Vault ships with a pre-configured <em>dev</em> mode which doesn’t require any further configuration, and allows room for experimentation. In this mode, Vault runs entirely in-memory and starts unsealed (more on it later) with a single unseal key (It is recommended not to run <em>dev</em> mode in production as it is highly insecure).</p><p>To fully utilise Vault’s capabilities, I’ll setup a real vault server which requires a configuration file unlike <em>dev </em>mode. Vault accepts <strong>HCL </strong>and <strong>JSON </strong>as its configuration, and must be provided with -config flag. Vault accepts various parameters among which <em>storage</em> and <em>listener</em> are required. <em>storage</em> configures the storage backend where Vault data should be stored, while the latter allows to configure <em>host </em>and a <em>port </em>where Vault listens for API requests. You can explore further optional parameters on <a href="https://www.vaultproject.io/docs/configuration/index.html">Vault configuration</a> page.</p><p>So, let’s create a config file with required parameters,</p><pre>backend &quot;file&quot; {<br>path = &quot;/home/suf/secrets&quot;<br>}</pre><pre>listener &quot;tcp&quot; {<br>address = &quot;127.0.0.1:8200&quot;<br>tls_disable = 1<br>}</pre><p>Save above content in config.hcl file, and start vault server,</p><pre>vault server -config config.hcl</pre><p>While the server is running, open another terminal, and initialise vault for use:</p><pre>export VAULT_ADDR=&#39;http://127.0.0.1:8200&#39;</pre><pre>vault operator init</pre><p>As soon as the server is initialised, you will see some useful information on your screen, including Unseal Keys, Initial Root Token, etc, as shown below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*OAvQ1b-Y-X40k1e-ACKQ6A.png" /></figure><p>Copy this information in a separate file as we are going to use it soon. Now, let’s talk about why this information is extremely important, and why your Vault storage becomes useless if you lose it.</p><p>Let me give you a little bit of background. When you first run a Vault server, it starts in a <strong>“sealed”</strong> state, which essentially means that even though Vault is aware of the location of encrypted storage, and how to access it, it has no knowledge of how to decrypt the data at rest. <br>It’s kind of a chicken and egg situation, and the question is how Vault should access its own encrypted data? There must be a key that decrypts vault’s entire storage.<br>So where does Vault store this decryption key? The answer is, nowhere. In fact, vault uses <em>Shamir’s Secret Sharing</em> algorithm which is a form of secret sharing, where an actual key is split into <strong>N</strong> parts,<strong> T</strong> of which are required to re-create the original key. These N parts in vault are called <strong>“Unseal Keys”</strong>, and they are generated when the vault server is initialised.</p><p>So, what happened when you initialized a Vault server?</p><p>When you first initialised the server using vault operator init command, Vault generated a master key, and immediately split it into 5 key parts, i.e. <em>“Unseal Key 1…5”</em>. That master key was never stored anywhere, and the only way to retrieve that key is to have a quorum of unseal keys re-generate it, as depicted below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*EuVME-xsPdrASPkP_xSf7g.jpeg" /><figcaption>Vault uses Shamir Secret sharing algorithm to create Master key</figcaption></figure><p>This master key is used to decrypt the underlying encryption key.</p><p>This is an actual message that displays when vault server is first initialised,</p><blockquote>Vault initialised with 5 key shares and a key threshold of 3. Please securely distribute the key shares printed above. When the Vault is re-sealed, restarted, or stopped, you must supply at least 3 of these keys to unseal it before it can start servicing requests.</blockquote><blockquote>Vault does not store the generated master key. Without at least 3 keys to reconstruct the master key, Vault will remain permanently sealed!</blockquote><p>As you can see, 3 Unseal keys are required to unseal Vault before we can access it. If you try to access Vault before unsealing it, you will get Vault is sealed error. Let’s go ahead and unseal the vault using any 3 of 5 unseal keys,</p><pre>vault operator unseal 5E+rusg+bMYNjLyI/QltN/WBB/uK8IhwjA9lKicLJPiP<br>vault operator unseal 06w4FpfzNbq4Vid060m4HRNZ4pW/7ijLOuY4aXTRBdCv<br>vault operator unseal jP2ugbUMy1l2l+kNZQX8yfLtqGS25FVIRnRu4DD+z3PZ</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JnG9a9R1mIX7xzF1mZ4Nrg.png" /><figcaption>Unsealing Vault</figcaption></figure><p>Once unsealed successfully, Login to Vault using the root token you saved earlier. (You can learn more about Root Token <a href="https://www.vaultproject.io/docs/concepts/tokens.html#root-tokens">here</a>)</p><pre>vault login</pre><p>You should receive the following message,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APfH_Y8AI39C8GdGooqRaw.jpeg" /><figcaption>Logging in to vault</figcaption></figure><p>Before going any further, we need to learn some basics about vault backends, since this is what we will be using to create a PKI.</p><h3><strong>Vault Backends</strong></h3><p>Vault has a concept of backends, you can think of them like plugins that have some specific features. For instance, in our config file, we have used Storage backend called <em>file</em>. Vault has other storage backends available as well, such as; <em>in-mem, consul, mysql, postgresql etc</em>.</p><p>Just like storage backends, Vault has <strong>“secret backends”</strong> which are responsible for managing secrets. Some secret backends simply act like encrypted key-value store, while others dynamically generate secrets when queried. PKI is one such backend, and can manage an entire CA. It is important to note that unlike storage backend, of which you can only have one, multiple PKI backends can be created, and can be isolated from each other using paths. This is necessary in our situation, since we would be creating two PKI backends, one for the Root CA, and the other for Intermediate CA.</p><p>We are now equipped to start creating our chain of trust!</p><h3><strong>Creating Root CA</strong></h3><p>Before creating a Root CA, we need to enable PKI backend, and mount it at a path,</p><pre>vault secrets enable -path=rootca_store -description=”PKI backend for Root CA” -max-lease-ttl=87600h pki</pre><pre><strong><em>Success! Enabled the pki secrets engine at: rootca_store/</em></strong></pre><p>verify by listing all secret engines,</p><pre>vault secrets list</pre><p>-path option mount PKI secret backend at a new path, rootca_store in this case. Each secret engine in vault defines its own path and properties. To the user, secrets engines behave similar to a virtual filesystem, supporting operations like read, write, and delete depending on the permission assigned to them using roles.</p><p>Now let’s create our CA Certificate and Key.</p><p>/pki/root/generate/:type endpoint is used for generating Root CA. :type in this endpoint specifies the type of the root to create. It can either be exported, in which case the root private key will be returned in the response; or internal, where the private key will not be returned and cannot be retrieved later.</p><pre>vault write rootca_store/root/generate/internal \<br>common_name=”suf.com” \<br>ttl=87600h \<br>key_bits=4096</pre><p>To learn about the other options I used, checkout <a href="https://www.vaultproject.io/api/secret/pki/index.html">Vault’s PKI docs</a>.</p><p>Verify that the Certificate has been generated:</p><pre>curl -s <a href="http://127.0.0.1:8200/v1/rootca_store/ca/pem">http://127.0.0.1:8200/v1/rootca_store/ca/pem</a></pre><p>Great! You have just created a Root CA.</p><p>But wait! We haven’t configured certificate revocation, i.e. CRL or OSCP yet. This must be configured using config/urls endpoint.</p><p>Let’s go ahead and configure CRL then:</p><pre>vault write rootca_store/config/urls issuing_certificates=&quot;<a href="http://127.0.0.1:8200/v1/rootca_store/ca">http://127.0.0.1:8200/v1/rootca_store/ca</a>&quot; \<br>crl_distribution_points=&quot;<a href="http://127.0.0.1:8200/v1/rootca_store/crl">http://127.0.0.1:8200/v1/rootca_store/crl</a>&quot;</pre><p>Observe that I have also configured issuing_certificates url, which specifies the value for the <em>Issuing Certificate</em> field. Both issuing_certificates and crl_distribution_points can be an array or a comma-separated string list.</p><h3>Creating an Intermediate CA</h3><p>Following steps must be followed in order to generate an intermediate CA:</p><ul><li>Mount PKI to a new path</li><li>Generate intermediate certificate signing request (CSR)</li><li>Sign Intermediate CSR using Root CA and generate Certificate</li><li>Import Root signed certificate into Intermediate CA</li><li>Verify signing was successful</li><li>Configure certificate revocation</li></ul><p>Let’s get started!</p><ul><li><strong>Mount PKI to a new path</strong></li></ul><pre>vault secrets enable -path=interca -description=&quot;PKI backend for Intermediate CA&quot; \<br>-max-lease-ttl=87600h pki<br><strong><em>Success! Enabled the pki secrets engine at: interca/</em></strong></pre><ul><li><strong>Generate intermediate CSR</strong></li></ul><p>Generate certificate signing request, and save it into a file, let’s name it <em>signing_request.csr</em>,</p><pre>vault write interca/intermediate/generate/internal ttl=26280h key_bits=4096 | grep -zo — &quot;-*BEGIN.*END.*-*$&quot; &gt; signing_request.csr</pre><p>We need to take that signing request from the intermediate authority and sign it using root CA generated earlier.</p><ul><li><strong>Sign Intermediate CSR using Root CA and generate a certificate</strong></li></ul><pre>vault write rootca_store/root/sign-intermediate \<br>csr=@signing_request.csr \<br>ttl=8760h \ format=pem_bundle</pre><p>Save both certificate and issuing_ca in a single file, let’s say <em>mycertreq.crt</em>,</p><pre> -----BEGIN CERTIFICATE-----<br>MIIFhzCCA2+gAwIBAgIUH83a+PyxwgzsZERZHzRR1kwwSc4wDQYJKoZIhvcNAQEL<br>BQAwEjEQMA4GA1UEAxMHc3VmLmNvbTAeFw0xODA4MDUwMjEyMTJaFw0xOTA4MDUw<br>MjEyNDJaMAAwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw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6/NykYYG6ON6t65TMLOQnBqEAEkWxbczmq2LMd8D7ufYBMJg1hChM8KpcD6Sq<br>5uoD5PaGkeYsdX6Gdd8RtWVDG0bi5hUqvCkxpvXakbOmo4DMc+ww/mc0LL5mlecd<br>9HX1cs9ZBjJEQ5ADul6GGOpeqxsWdE543OnNsy6HjnXYJhHPbu342c+jlXccCpnA<br>KfmpZdFU58KYzaHAKudV9PWlyloUk0X3gIqSqHX7bX7/8E3MtTivJKxl9zIaI/YP<br>EgYHLwZQ10ODi2tlSs1zJ6KYYFyrtVSqdysnTAg2WtH3uFtWOf181VMs3BpgdyUk<br>6EPbdyluZ27nzA2/OFVECAUwfjVPIx98Y6g1CYa3cTjOMJcmoiNDL6ciptfDDsVt<br>iePV5Ybos0fUD7/IyUHGSNnvyXDiCrFfTCFdveqiU6vkKj6oPQI2WPIKrZPsymnC<br>DbUog0VYDpC/M10Dix9s51lfdKyvar7uDuJ6ONw=<br>-----END CERTIFICATE-----</pre><ul><li><strong>Import Root signed certificate into the Intermediate CA</strong></li></ul><p>Now that we have a Root CA signed certificate, we need to import it into our Intermediate CA backend.</p><pre>vault write interca/intermediate/set-signed \<br>certificate=<a href="http://twitter.com/mycertreq">@mycertreq</a>.crt</pre><pre><strong><em>Success! Data written to: interca/intermediate/set-signed</em></strong></pre><ul><li><strong>Verify signing was successful</strong></li></ul><pre>curl -s <a href="http://127.0.0.1:8200/v1/interca/ca/pem">http://127.0.0.1:8200/v1/interca/ca/pem</a> | openssl x509 -text</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*Ix1HaBx95jnLowF4VX2Kng.png" /></figure><ul><li><strong>Configure certificate revocation</strong></li></ul><p>The last thing we need to do is to set the CA &amp; CRL’s URL just like we did for the Root CA.</p><pre>vault write interca/config/urls issuing_certificates=&quot;<a href="http://127.0.0.1:8200/v1/interca/ca">http://127.0.0.1:8200/v1/interca/ca</a>&quot; \ crl_distribution_points=&quot;<a href="http://127.0.0.1:8200/v1/interca/crl">http://127.0.0.1:8200/v1/interca/crl</a>&quot;</pre><p>Our intermediate CA is now configured and ready to issue certificates.</p><ul><li><strong>Requesting a Certificate for a Web Server</strong></li></ul><p>Now that our CA’s are configured, we’d want to issue certificates. Doing so requires two steps:</p><ul><li>We need to configure a <em>role</em>. A <em>role </em>is a logical name that maps to a <em>policy </em>used to generate those credentials. Our role will define constraints around certificates we generate, such as: key type, strength, types of certificates allowed, etc.</li><li>We need to request a certificate using the role we created.</li></ul><p>roles/:name endpoint allows us to create or update the role definition. Let’s use it to create a <em>role </em>name test_server .</p><pre>vault write interca/roles/test_server \<br>key_bits=2048 \<br>max_ttl=4380h \<br>allow_any_name=true</pre><p>Head to <a href="https://www.vaultproject.io/api/secret/pki/index.html#create-update-role">Vault’s role documentation</a> to know what other options are available.</p><p>Now, we can use this role to issue a certificate,</p><pre>vault write interca/issue/test_server \<br>common_name=”your_server_hostname” \<br>ttl=720h \<br>format=pem</pre><p>It will generate a new <em>certificate</em>, and output <em>issuing_ca</em>, and a <em>private key</em> that needs to be used by the relying party (our test_server).</p><p><strong>Congratulations, you have just issued your first certificate!</strong></p><p><strong>What’s next?</strong></p><p>We need to deploy this certificate on a web server, and test it using a local browser.</p><p>I will be deploying it on nginx server I created for this guide.</p><p>Here is what we are going to do:</p><ul><li>Save certificate and issuing_ca from the generated certificate in a single file.</li><li>Save private_key in a separate file</li><li>Move <em>certificate </em>and <em>private_key </em>to nginx server in /etc/nginx/cert/</li><li>Configure nginx to use this certificate.</li></ul><p>private key generated by certificate saved in /etc/nginx/cert/key :</p><pre>-----BEGIN RSA PRIVATE KEY-----<br>MIIEpAIBAAKCAQEAxOQ+LLtHQI3/8FJDQOjb1K5fEFER8rJjBEGgFeHYYrXN9kKh<br>ZfiRVybYgLUXqedn3NJkTANiwlyrRIjW5Dk1qwgA34SlXXEpRubk86Dxpj1s5Mv5<br>qUA9G1P2PgvBmP02/pBX1blfSLCwUaqx9HHhvimDiNVWWImN5Z7PW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z8e<br>HTTpwGpZAu19j+swHqVUiAkCgYBSeEyOhzkLrI+ZtXNL0uusnNyVLRPqZtwDARAJ<br>TKd8Y4iZkur+8++1X6eh6dP1vkzmNuQBzkLuDYiAGvIB50ETPPZxZP6UXOEdDSr3<br>ZMXVJPFehJY/j+x93mxaX9XU4hP4l3p3Yy0aZfsUw2bx8c3a8VGMMNbocYZoomG1<br>7yn0fQKBgQC9BFfo0UdODFyRjALG0OlSThikXAGtXPxfBXI20wZRcOTouXwRy2sm<br>M4HZVmoIkeuLKewXgbO5MFR5jhlVCz2CZAcY1tPMyjHi0jWnPW/8IVTQfifp7n/s<br>bsH08+Nh4zmp4VsdXyuyB8Col/FkFc2B5fNRkSP9mExEvaoibOx7ig==<br>-----END RSA PRIVATE KEY-----</pre><p>certificate followed by issuing_ca certificate saved in/etc/nginx/cert/ssl_cert :</p><pre>-----BEGIN CERTIFICATE-----<br>MIIEbDCCAlSgAwIBAgIUZdZvZtcKcIBMaESNdZnBbDLFA3AwDQYJKoZIhvcNAQEL<br>BQAwADAeFw0xODA4MDUwMzMyNTBaFw0xODA5MDQwMzMzMjBaMBExDzANBgNVBAMT<br>BnVidW50dTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMTkPiy7R0CN<br>//BSQ0Do29SuXxBREfKyYwRBoBXh2GK1zfZCoWX4kVcm2IC1F6nnZ9zSZEwDYsJc<br>q0SI1uQ5NasIAN+EpV1xKUbm5POg8aY9bOTL+alAPRtT9j4LwZj9Nv6QV9W5X0iw<br>sFGqsfRx4b4pg4jVVliJjeWez1jar6suaIzZhmpC40wgFanp6SxFjneynQmObtdu<br>4unoTLGs844mB9WGFdIJ5T+eeQMv4llxe5yVySH+NqDvM9KJbptp4/mFxOtOBw6+<br>N7ClcoQda9u36jLw+RojB7d0WSFpprLcGjjv5vGmZNhPy1+vcdu0hNtUs5IeiW2B<br>4GyHePC75TkCAwEAAaOBzDCByTAOBgNVHQ8BAf8EBAMCA6gwHQYDVR0l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0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9yb290<br>Y2Ffc3RvcmUvY2EwOgYDVR0fBDMwMTAvoC2gK4YpaHR0cDovLzEyNy4wLjAuMTo4<br>MjAwL3YxL3Jvb3RjYV9zdG9yZS9jcmwwDQYJKoZIhvcNAQELBQADggIBAFnUFAi6<br>lqkJHPJWXof259nZ/unXjqB39ZApEZY6uy7lrhIo3M/HbWAygZjElNAdk+Ula/79<br>rWTRSoQu2yl91KnQmIB6ZuaPtgAMpMbm3acAtmrnD7ibZKxSSA3WXb1cQi0b9eFf<br>wR6uUfZuB7cGgtvT+9p44LpxLHHHzYy1c2AMifArJtR0HmhUZbZy30uHf+kxcSsk<br>NFsVp3xJLjtL6giZv5hv5TubGo+i4BYFoQ/fOLmI2zo4dFJwHtSRwyxomYl92egH<br>ZgmRyKjtqNqlmbFfSl3K++M3oAmbTIys9Rel1sSqStUPxmlY0xJi02iN/ClyIdSa<br>b+Q3ccBQrE9COAhEeV+zgUq4okvE7AOkP8SsJ9a3VhLijjNeb/Migm6Z+Wl6pPbP<br>uYPOMLfTOTo9NBdFTT9yR9HRSHwdtWhpEX0kuZ5B4eDk586WXkIZWzEw1cEeRAzb<br>kM9lSuHKo016bwRUNGlVFlDTi+zGUbxfIKD9/tqI8Vw5OkUQI8FTXqLbe5C4XMT3<br>JTSo3XKneXxuF6fpXe+eUTkU02hwhIJOM1w33riZmf5QoCwTcttDaY3W/5aN8pIs<br>+r5lPwtKjz5mQWVJT4xDuRs5bfUNjRq+MREVUdORwdtRfEUfb8uMIEuMRX8Wr2kB<br>Xn8kPbKGYxJhp2A5WVy5/E6DW5DFG6by6syT<br>-----END CERTIFICATE-----</pre><p>This is what my nginx.conf looks like,</p><pre>http {<br> include /etc/nginx/mime.types;<br> default_type application/octet-stream;<br> server {<br> listen 443 ssl default_server;<br> server_name test_server;<br> ssl on;<br> ssl_session_timeout 5m;<br> ssl_certificate /etc/nginx/cert/ssl_cert;<br> ssl_certificate_key /etc/nginx/cert/key;<br> ssl_protocols TLSv1 TLSv1.1 TLSv1.2;<br> ssl_ciphers HIGH:!aNULL:!MD5;</pre><pre>location / {<br> root /usr/share/nginx/html;<br> index index.html index.htm;<br> }<br> }<br> access_log /var/log/nginx/access.log;<br> error_log /var/log/nginx/error.log;</pre><pre>include /etc/nginx/conf.d/*.conf;<br> include /etc/nginx/sites-enabled/*;<br>}</pre><p>Web-server is now using a certificate issued by our own root CA!</p><h3>Testing</h3><p>Your Root CA certificate must be available in your local browser to perform authentication.</p><p>From vault server, visit and save Root certificate in a file, let’s say root.crt,</p><pre>curl -s <a href="http://127.0.0.1:8200/v1/rootca_store/ca/pem">http://127.0.0.1:8200/v1/rootca_store/ca/pem</a></pre><p>Then in your local browser (I am using Google Chrome), go to Settings -&gt; click on Advanced at the very bottom of the page, then select Manage certificates ,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZGhQmAkQjpwZsCahkRNvg.jpeg" /></figure><p>Next, click on Import and select the root certificate file you saved earlier, click Next and Finish. You should get the following message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*Bwkocb2pKVspNqtDaWihjQ.jpeg" /></figure><p>Now visit your web-server, and you should see that your connection is secure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zlo5sBO60UTxCOu3zsndGQ.jpeg" /></figure><p>Your server is using a certificate issued by your very own Root CA.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1981e7574e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>