Free SSL Cert with Azure AppService

To write a small blog for a friend and with nonprofit then it can be expensive to pay a site, a domain and even and SSL Cert. Then I found a way to create an SSL Cert free and install it in an AppService in Azure. I would like you share that with you and feedbacks are welcome.

Remember that Azure allow external Cert only in Plans B or higher. F and D are not working with SSL. Even if D allow you to create or add a Custom Domain it does not allow you to have a Cert. You need B or higher.

Important! The commando letscrypt has been replaced but certbot that practly do the same thing. I updated the codes.

Tools I used:

  • Visual Studio. C# (You can use your favorite tool and lang. I used C# and vs)
  • VirtualBox or AzureVM (We need a Ubuntu server version 18 or further)
  • Ubuntu App for Windows (from Microsoft Store)
  • Let’s Encrypt It seems to be an organization of developers working Open Source and taking donations. Something common in Unix wrold and more and more in OpenSource. I think it seems trustfully so far.

From the beginning I followed this instructions from Jarod Ferguson How to get free SSL... but later I adapted it to the current version of Azure and others impidements I got on the way.

My steps:

  1. Create a VM with Ubuntu' (either in AzureVM or VirtualBox). Think about to use Username and Password instead of SSH to make it easy. If you create a VM in Azure use an own ResourceGroup then you can remove everything at once after you are done.

  2. Use/Open Ubuntu App for Windows or Windows Terminal Ubuntu and login to the VM using the path in SSH info:

    ssh < your username >@< IP-address to the server >

    ssh wille@23.100.3.158
    
  3. Install packages

    sudo apt-get install git
    git clone https://github.com/certbot/certbot
     cd certbot
    sudo certbot certonly --manual 
    
  4. Give your email address when it asks for it.

  5. Read the license and Agree

  6. Type in the Domain you want to Cert

  7. Give an OK to share the address in public lists

  8. Now save the encrypt code and the URL address and DO NOT CLOSE THE TERMINAL and goto Visual Studio. Create a Controller in your application returning this encrypt code as a string and typing this URL path. Something like that:

    using Microsoft.AspNetCore.Mvc;
    namespace MySite.Controller 
    {
    	[Route("*.well-known/acme-challenge/Bp_2131dd_kn7qQj4V1ek-GM5asaASdIyJa0_T-Ww_Dg")]
    	[ApiController]
    	public class LetsEncryptController : ControllerBase
    	{
    		[HttpGet]
    		public string Verify()
    		{
    			return "Bp_2131dd_kn7qQj4V1ek-GM5asaASdIyJa0_T-Ww_Dg.w7Pssadf24564BHDEEHhmd-HZow-Lp64564eMg";
    		}
    	}
    }
    

    Think about that the encrypt codes in this sample are fake. Use the one you got in the terminal by letsencrypt.

  9. Now publish to your site and then ensure the URL path is working.

  10. Return to the Ubuntu terminal and Press < Enter >

  11. If you get error be sure your site is returning the text for encrypted code and try again.

  12. When it is working, continue in the Ubuntu Terminal. To be sure you have write-access we type following codes: ('wille' is my user.)

    sudo -s
    sudo chown wille -R /etc/letsencrypt
    cd /etc/letsencrypt/
    sudo chown $USER:$USER live
    cd /etc/letsencrypt/live/<yourdomain.com>/
    sudo chown $USER:$USER privkey.pem
    chmod 644 privkey.pem
    openssl pkcs12 -export -out cert.pfx -inkey privkey.pem -in cert.pem
    cp cert.pfx /home/wille
    
  13. To download the cert file to your PC I have 3 differents ways of shareing files with Ubuntu.

    A. In case you are using Multipass Ubutnu you should mount a drive from your computer to the server in Multipass by typing in ps:

    multipass mount c:\users\wille\myubuntufolder primary:/home/ubuntu/mypc
    

    B. Using WSL you can access your files in the server by typing: \\wsl$ in your FileExplorer.

    C. If you are using a VM in Azure or connecting by remote to a server by ssh use pspc.exe

    pscp.exe wille@23.100.2.138:/home/wille/cert.pfx c:\myPC\cert.pfx
    
  14. Now when we have the cert.pfx we go into Azure Portal and to your AppService.

  15. There, we open "Custom Domain"

  16. We go to the one is "Not Secure" and press in "Add Binding".

  17. There, you can upload the cert file.

Good luck! Tell me if I miss something.