Create SSL Certificate Authority for HTTPS on local

Tram Ho

There are also many articles on how to create a self-signed SSL for localhost so that you can test HTTPS. But there are disadvantages: when you visit the site, there will be a NET :: ERR_CERT_AUTHORITY_INVALID warning because no one has validated our SSL. And we can’t test new technologies like PWA or HTTP2 on localhost. Today I would like to introduce a way to create SSL “green” for localhost so that we can try technologies like PWA or HTTP2 or simply look at it. Let’s start working together.

Create a Certificate Authority

First, we must become a certificate provider (like existing certificate providers such as GlobalSign, Comodo, DigiCert, etc.) and notify the browser that the certificates are generated by the Certificate Authority. Our offer is valid.

Create the root Certificate Authority (CA) by first creating a private key:

After entering this command, we perform a pass phase entry to create. The result has the form:

After we have a private key, we create a root certificate:

When executing this command, it will ask for the pass phase of the rootCA.key file that we just entered earlier, please enter it correctly and fill in some of the required information, the result should look like this (data demo data entered by me):

Once done, you will get two files, rootCA.key and rootCA.pem . From now on, you have become a Certificate Authority (of course it is only local, not like the current famous providers). And from now on, we can create SSL for ourselves from the above two files. But this step is not necessarily a green SSL because the browsers do not have information about our root certificate. We will go to the next step, it is extremely important for our SSL to become green.

Install Root Certificate for browsers

With this article, I will guide people how to install root certitficate for Chrome and FireFox.

Google Chrome

First, open Google Chrome and go to the following link: chrome://settings/certificates . Then, select the Authorities tab and click on IMPORT then select the rootCA.pem file we just created earlier. After selecting that file, we will have the following screen:

Select all and click OK .

Mozilla Firefox

First, open Mozilla Firefox and access the following link: about:preferences#privacy . Then, scroll down to the bottom of the page, at the Certificates section, click View Certificates … , in this popup, select the Authorities tab and then click Import … and select the rootCA.pem file we just created earlier. After selecting the file, we will have the following screen:

Mozilla releases Firefox 59.0.2 to fix CPU, memory and audio problems on BSD

Select all and click OK .

So now, with these two browsers (on our machines), we have been sitting with the big CAs in the world!

Now try to create HTTPS for a local website to see the results.

Create HTTPS for the local site

First, we create a private key for domain local (I will choose the domain test-ssl.local ):

Then create CSR (Certificate Signing Request):

We will be asked the same information as before to create the CA root:

You can customize the information you want. Part A challegen password and An optional company name you can leave blank.

Next step, we create a config file to define the Subject Alternative Name (SAN) for this SSL. We make file creation:

And enter the content below:

You can add more DNS.x = <Domain bạn muốn> . But here I only use for this domain only. Now we will create the domain certificate:

This time we will be asked to pass the phase of rootCA.pem , you enter the pass phase you used when creating rootCA.key . That’s it, now we will have the following files:

  • test-ssl.local.key : Private key
  • test-ssl.local.csr : Certificate Signing Request
  • test-ssl.local.crt : Signed certificate

It is done. Now we can add HTTPS to our local domain with private key file and certificate file. I will always do demo with NginX (by default, you have installed NginX already).

Install HTTPS with NginX

First, create a directory to contain the code:

Then create the index.html file with simple content to display:

Content of index.html file:

Next, we create a virtual host for NginX:

Content of virtual host file:

Then, create a symlink to the /etc/nginx/site-enabled to enable virtual host (in fact, you can create files directly into this directory without having to create site-available , but I encourage You should not do it directly so that when I want to disable virtual host, just delete the symlink and it will not affect the original virtual host file):

Use goaccess to visualize access log nginx / apache

Restart NginX:

Next, we will point our domain to localhost by adding the following content to the /etc/hosts :

Add the following line:

That’s it, now try accessing https: //test-ssl.local to see the results. We will get a perfect HTTPS page without any warning screen and no red slash in the address bar.

Yes, do you see the green color in Firefox? Look ha ha? As for Chrome, from version 69 onwards, it has deleted the secure indicator for HTTPS pages, so we don’t see that nice green!

Epilogue

From now on, you can manually create more HTTPS for the local site with the root CA we created (you only need to do it from the Create HTTPS step for the local site onwards). And you can freely try new technologies like PWA or HTTP2 without the need for master SSL. My post here is the end. Hope it will be useful for you in the near future!

Securing the Web with HTTPS makes loading pages slower
Is HTTPS really secure?
Share the news now

Source : viblo .u8ea41a4e1770a7a29714056fbfe48bf1 { padding:0px; margin: 0; padding-top:1em!important; padding-bottom:1em!important; width:100%; display: block; font-weight:bold; background-color:#eaeaea; border:0!important; border-left:4px solid #34495E!important; text-decoration:none; } .u8ea41a4e1770a7a29714056fbfe48bf1:active, .u8ea41a4e1770a7a29714056fbfe48bf1:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; text-decoration:none; } .u8ea41a4e1770a7a29714056fbfe48bf1 { transition: background-color 250ms; webkit-transition: background-color 250ms; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; } .u8ea41a4e1770a7a29714056fbfe48bf1 .ctaText { font-weight:bold; color:inherit; text-decoration:none; font-size: 16px; } .u8ea41a4e1770a7a29714056fbfe48bf1 .postTitle { color:#000000; text-decoration: underline!important; font-size: 16px; } .u8ea41a4e1770a7a29714056fbfe48bf1:hover .postTitle { text-decoration: underline!important; } Bảo mật Web bằng HTTPS khiến việc load trang trở nên chậm hơn .u20ece84bb5a6aebb6489427959f5735f { padding:0px; margin: 0; padding-top:1em!important; padding-bottom:1em!important; width:100%; display: block; font-weight:bold; background-color:#eaeaea; border:0!important; border-left:4px solid #34495E!important; text-decoration:none; } .u20ece84bb5a6aebb6489427959f5735f:active, .u20ece84bb5a6aebb6489427959f5735f:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; text-decoration:none; } .u20ece84bb5a6aebb6489427959f5735f { transition: background-color 250ms; webkit-transition: background-color 250ms; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; } .u20ece84bb5a6aebb6489427959f5735f .ctaText { font-weight:bold; color:inherit; text-decoration:none; font-size: 16px; } .u20ece84bb5a6aebb6489427959f5735f .postTitle { color:#000000; text-decoration: underline!important; font-size: 16px; } .u20ece84bb5a6aebb6489427959f5735f:hover .postTitle { text-decoration: underline!important; } HTTPS có thực sự bảo mật?