In this article I will explain how we can use that service to get a free SSL certificate and add that to WSO2 API Cloud. So that you can have your own API store like;
In order to do that you need to have following things in hand.
- Domain name.
- Rights to add/delete/modify DNS A records and CNAMEs.
- Publicly accessible webserver with root access or a home router with port forwarding capabilities.
If you have a publicly accessible webserver you can skip this step.If you don't have a publicly accessible webserver you can make your home PC/Laptop a temporary webserver if you can do port forwarding/NATing in you home router. I will show how I did that with my ADSL router. You can get help on port forwarding information by referring to this website http://portforward.com.
a. Add a port forwarding rule in your home router.
Get your local (laptop) IP (by running ifconfig/ip addr) and put that as the backend server in your router for. Set the WAN port as 80 and LAN port as 80.
After adding the rule it will be like this.
b. Start a webserver in your laptop. We can use the simple Python server for this. Make sure to check the IPTable rules/Firewall rules.
mkdir /tmp/www cd /tmp/www/ echo 'This is my home PC :)' > index.html sudo python3 -m http.server 80
c. Get the public IP of your router. Go to this link : http://checkip.dyndns.org it will give the public IP address. This IP is changing time-to-time so no worries.
d. Try to access that IP from a browser.
If it is giving the expected output you have a publicly accessible webserver.
Now we need to update a DNS entry. My expectation is to have a single SSL certificate for both domains 'store.thilina.piyasundara.org' and 'api.thilina.piyasundara.org'.
a. Go to your DNS provides console and add an A record for both domain names to point to the public IP of your webserver (or the IP that we got from the previous step).
b. Try to access both via a browser and if its giving the expected out put you can proceed to the next step.
I'm follow the instruction in the 'let's encrypt' guide. As I'm using the python server I need to use the 'certonly' option when running the command to generate the certs.
a. Get the git clone of the letsencrypt project.
git clone https://github.com/letsencrypt/letsencrypt cd letsencrypt
b. Run cert generation command. (this requires root/sudo access)
./letsencrypt-auto certonly --webroot -w /tmp/www/ -d store.thilina.piyasundara.org -d api.thilina.piyasundara.org
If this succeed you can find the SSL keys and certs in '/etc/letsencrypt/live/store.thilina.piyasundara.org' location.
Check the content of the certs. (Be root before you try to 'ls' that directory)
openssl x509 -in cert.pem -text -noout
Create an API in WSO2 API Cloud if you don't have one. Else start on adding a custom domain to your tenant.
a. Remove both A records and add CNAME records to those two domains. Both should point to the domain 'customdns.api.cloud.wso2.com'.
b. Now click on the 'Configure' option in the top options bar and select the 'Custom URL' option.
c. Make ready you SSL certs. Copy 'cert.pem', 'chain.pem' and 'privkey.pem' to you home directory.
d. Modify API store domain. Click on the modify button, add the domain name click on verify. It will take few seconds. If that succeed you have correctly configured the CNAME to point to WSO2 cloud.
e. Add cert files to the API Cloud. The order should be the certificate (cert.pem), private key (privatekey.pem) and the CAs chain file (chain.pem). Again it will take sometime to verify uploaded details.
f. Update the gateway domain same as the previous.
Now if you go the API Store it will show something like this.
g. Same way you can use the gateway domain when you need to invoke APIs.
curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer
Now you don't need '-k' option. If not make sure you operating system (CA list) is up to date.
Make sure to remove port forwarding in you home router if you use that and any changes that you make while obtaining the SSL certificates.