# Create and Apply SSL Certificate to OpenWRT LuCI Web Interface

## Prerequisites

- A XCA PKI database https://youtu.be/ezzj3x207lQ

## Create Your SSL Certificate

1. Launch XCA
2. Open the PKI database if it is not already (File > Open DataBase), enter password
3. Click on the Certificates tab, right click on your Intermediate CA certificate
4. Select New
5. On the Source tab, make sure Use this Certificate for signing is selected
6. Verify your Intermediate CA certificate is selected from the drop down
7. Click the Subject tab
8. Complete the Distinguished Name section

   internalName: openwrt.i12bretro.local
   countryName: US
   stateOrProvinceName: Virginia
   localityName: Northern
   organizationName: i12bretro
   organizationUnitName: i12bretro Certificate Authority
   commonName: openwrt.i12bretro.local

9. Click the Generate a New Key button
10. Enter a name and set the key size to at least 2048
11. Click Create
12. Click on the Extensions tab
13. Select End Entity from the type list
14. Click Edit next to Subject Alternative Name
15. Add any DNS or IP addresses that the certificate will identify
16. Update the validity dates to fit your needs
17. Click the Key Usage tab
18. Under Key Usage select Digital Signature, Key Encipherment
19. Under Extended Key Usage select Web Server and Web Client Authentication
20. Click the Netscape tab
21. Select SSL Server
22. Click OK to create the certificate

## Exporting Required Files

1. In XCA, click on the Certificates tab
2. Right click the SSL certificate > Export > File
3. Set the file name to uhttpd.crt verify the export format is PEM (*.crt)
4. Click OK
5. Click the Private Keys tab
6. Right click the private key generated for the SSL certificate > Export > File
7. Set the file name to uhttpd.key and verify the export format is PEM private (*.pem)
8. Click OK

## Installing Prerequisites

1. Log into OpenWRT via SSH
2. Run the following commands to install prerequisites
   # update opkg packages
   opkg update
   # install prerequisite packages
   opkg install luci-lib-px5g px5g-standalone libustream-openssl
   # install/update luci
   opkg install luci
   # restart uhttpd service
   /etc/init.d/uhttpd restart
3. Download WinSCP Download
4. Extract WinSCP and run the executable
5. Connect to the OpenWRT IP address via WinSCP
6. Navigate to /etc
7. Rename uhttpd.crt and uhttpd.key to .old
8. Copy the created uhttpd.crt and uhttpd.key to /etc
9. Back in the terminal, run the following command to restart uhttpd
   /etc/init.d/uhttpd restart

## Applying SSL Certificates in Open-WRT

1. Open a web browser and navigate to https://OpenWRT_IP
2. Authenticate at the Open-WRT login
3. Select System > System from the top navigation
4. Set the hostname to match the hostname of the SSL certificate
5. Click the Save & Apply button

Source: https://fabianlee.org/2016/09/19/openwrt-enabling-https-for-the-luci-web-admin-interface/