Table of Contents

How to get rid of LuCI HTTPS certificate warnings

Do you like the security of using LuCI-SSL (or Luci-SSL-OpenSSL), but sick of the security warnings your browser gives you because of an invalid certificate?

You can fix this by installing a certificate in LuCI that will be trusted automatically by most modern browsers (such as a (wildcard) certificate issued by Let's Encrypt) or by installing a self-signed certificate and manually telling your devices to trust this certificate.

Option A: Automatic free HTTPS certificate from LetsEncrypt

This may only work if your router is accessible from the public internet. For detailed instructions, refer to Get a free HTTPS certificate from LetsEncrypt for OpenWrt with ACME.sh.

Option B: Installing any publicly trusted certificate

These instructions are tested with a (wildcard) certificate issued by Let's Encrypt, but should work for any certificate signed by an official certificate authority. Pre-requisites for this option are:

Given these pre-requisites, there are three simple steps to start using your publicly trusted certificate. First we convert the certificate to a format LuCI/uhttpd likes. Next we put the converted certificate on the correct location. Lastly we restart uhttpd to start using the certificate.

Place the PEM files at the right location

PEM files can be either individual or “inline” as a single file including cert, key, and CA (NGINX format.) Should you use an inline, simply make two copies of it and name them according to the information that follows. these PEM certificate files must be placed at /etc/uhttpd.key and /etc/uhttpd.crt on the OpenWRT installation respectively. Before doing this, you may want to back up whatever is currently stored at that location (e.g. cp /etc/uhttpd.key /etc/uhttpd.key.bak and cp /etc/uhttpd.crt /etc/uhttpd.crt.bakon the OpenWRT machine). Alternatively, configure uhttpd to look at another location by setting the key and cert paths (see uhttpd) Then, if you have rsync activated on OpenWRT, you can use:

rsync /tmp/uhttpd.key openwrt:/etc/uhttpd.key
rsync /tmp/uhttpd.crt openwrt:/etc/uhttpd.crt

where openwrt is recognised from your ssh config. If you do not want to use rsync you can use scp instead, or do a simple cp if you issued the openssl commands already on the OpenWRT machine. The main goal is to put the DER-formatted certificate files to wherever the key and cert parameters of /etc/config/uhttpd are pointing.

Activate the certificate

Lastly, issue the following command to restart uhttpd and thereby start using the new certificate:

ssh openwrt "/etc/init.d/uhttpd restart"

Now, when navigating to openwrt.example.com the connection should be automatically trusted. Note that, since all the above commands can be issued on an external machine with ssh access to the OpenWRT install, you can create a script to automatically update the certificate without having to touch OpenWRT yourself.

Option C: Creating, installing & trusting a self-signed certificate

With these instructions, you can generate your own self-signed certificate, which your browser will accept as valid.

One new headache was that, browsers usually only look at one key part of a self-signed certificate, the CN (common name). However, starting with Chrome version 58, it not only looks at the CN (common name) in the certificate, but also at the SAN (subject alt name or DNS name), which makes generating a certificate more complicated than before. You might have even had a certificate you made yourself, that worked until recently, stop working when Chrome 58 was released and most likely automatically updated and installed.

So, to get rid of the annoying “Warning, this is an insecure site, do you want to proceed?” warning messages, and other similar messages from other browsers, proceed with the following.

I know it looks long, but it's easy and goes fast. Should take about 10 minutes tops.

Create & Install

  1. Connect via SSH
  2. Install the openssl-util and LuCI uhttpd packages. This is required to generate a new certificate in the way you want it to be, and to be able to easily tell LuCI how to use it.
    opkg update && opkg install openssl-util luci-app-uhttpd
  3. Create /etc/ssl/myconfig.conf with the following content:
    myconfig.conf
    [req]
    distinguished_name  = req_distinguished_name
    x509_extensions     = v3_req
    prompt              = no
    string_mask         = utf8only
     
    [req_distinguished_name]
    C                   = US
    ST                  = VA
    L                   = SomeCity
    O                   = OpenWrt
    OU                  = Home Router
    CN                  = luci.openwrt
     
    [v3_req]
    keyUsage            = nonRepudiation, digitalSignature, keyEncipherment
    extendedKeyUsage    = serverAuth
    subjectAltName      = @alt_names
     
    [alt_names]
    DNS.1               = luci.openwrt
    IP.1                = 192.168.1.1
  4. You can edit the values for C (country), ST (state), L (location), O (organization), OU (organization unit) to whatever you want.
    1. It's extremely important the values for CN and DNS.1 match, and also that IP.1 has the correct private IP address for the device.
      • Some of you might have a different IP, or you might access it via a hostname; the hostname should go in both CN and DNS.1 fields. The correct private IP address should go into IP.1.
  5. Save the file and then navigate to /etc/ssl with the following command:
    cd /etc/ssl
  6. Then issue the following command:
    openssl req -x509 -nodes -days 397 -newkey rsa:2048 -keyout mycert.key -out mycert.crt -config myconfig.conf

    This will create two files, mycert.key and mycert.crt
    Alternatively you can create ECDSA certificate (to speedup key exchange phase) with the following command:

    openssl req -x509 -nodes -days 397 -newkey ec:<(openssl ecparam -name prime256v1) -keyout mycert.key -out mycert.crt -config myconfig.conf
  7. Note that in the commands above, the validity of the certificate was set to 13 months (397 days, the “-days” option), so the process would need to be repeated when the period lapses. Some (all) browsers do not accept longer validity: https://github.com/cabforum/servercert/blob/90a98dc7c1131eaab01af411968aa7330d315b9b/docs/BR.md?plain=1#L175
  8. In LuCI, go to Services → uHTTPd
    • In the field for HTTPS Certificate, select the file /etc/ssl/mycert.crt, or select “Upload file” to transfer it from your PC (mycert.crt)
    • In the field for HTTPS Private Key, select the file /etc/ssl/mycert.key, or select “Upload file” to transfer it from your PC (mycert.key)
    • Hit save and apply.
  9. Restart uhttpd
    /etc/init.d/uhttpd restart
  10. Now to make it so that those 2 files are saved when you make a backup, in LuCI, go to System → Backup/Flash Firmware, Click Configuration tab, then add /etc/ssl/mycert.crt & /etc/ssl/mycert.key
    • When you make and restore a backup, your cert and key will automatically be backed up and restored. The changes you made in LuCI → Services → uHTTPd will automatically be backed up because /etc/config/uhttpd is automatically backed up.
  11. Hit Submit ( Or Save and Apply, depending on the LuCI Theme you're using )

Chain of trust

Windows (older versions of Chrome only)

Windows (script)

GNU/Linux

Enjoy!!

All the credit for the creation of (part C of) this walk-through goes to @StarCMS who originally posted this in @Davidc502's thread. Minor changes and wiki formatting by @mariano.silva ( mariano.silva@gmail.com )

Option D: Let OpenWRT generate a new self-signed certificate

This was tested with OpenWrt 23.05 and not sure whether it will work with older versions. Also certificate may not be ideal if created with version before this pull request was merged https://github.com/openwrt/openwrt/pull/1536

OpenWrt will generate on boot a new self-signed certificate in case existing one is removed. To remove the existing certificate, open an ssh terminal to your router and run rm -i /etc/uhttpd.* and confirm deleting uhttpd.crt and uhttpd.key. Then issue the service uhttpd restart command.

You can use the luci-app-uhttpd extension to get more control over the generated new certificate. Otherwise you will still not set proper subjectAltName and will need to add a new security exception in your browser to open LuCI. If you set proper subjectAltName, you can follow instructions in option C to install the certificate on your machine.