I couldn't find any of these answers that did everything from start to finish, so here are the steps for windows (I'm using win 11) with IIS installed, using openSSL (I used chocolatey to install openssl, not covered here) and using only vanilla PowerShell script language (no bash), without changing any browser settings at all (like allow-insecure-localhost), and no need to bypass security errors (e.g. thisisunsafe, badidea, danger).
This process here is only for creating local testing SSL certificates for faked domains and their subdomains that you've inserted into the C:\Windows\System32\drivers\etc\hosts file. (e.g. 127.0.0.1 example.com). You will need a separate line entry in the hosts file for each and every subdomain as well (e.g. 127.0.0.1 sub.example.com) because there doesn't seem to be a *.example.com way to do this. Be sure to leave an empty line at the end of the hosts file or you will go on a murderous rampage.
Some of this content was borrowed and updated from https://github.com/BenMorel/dev-certificates.
The below powershell script creates the 10-year CA certificate and key. You only need to create and install these files once, but you'll have to do it again if you lose these files because you can't generate the SSL certificates without them.
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -subj "/C=US/O=_Development CA/CN=Development certificates" -key ca.key -sha256 -days 3650 -out ca.crt
The resultant ca.crt file has to be imported using the "manage computer certificate" interface (search for this app in your windows start popup), entered into the "trusted root certification authorities/Certificates" leaf. Right-click on said Certificates leaf and choose All Tasks/import, then select the file.
The below powershell script is for generating individual domain SSL certificates. You first need to global replace example.com with the desired domain, then execute it in powershell.
# replace anywhere you see example.com text with your domain
openssl genrsa -out "example.com.key" 2048
openssl req -new -subj "/C=US/O=Local Development/CN=example.com" -key "example.com.key" -out "example.com.csr"
"authorityKeyIdentifier=keyid,issuer" | Out-File -encoding utf8 -FilePath "example.com.ext"
"basicConstraints=CA:FALSE" | Out-File -encoding utf8 -FilePath "example.com.ext" -Append
"keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment" | Out-File -encoding utf8 -FilePath "example.com.ext" -Append
"extendedKeyUsage = serverAuth, clientAuth" | Out-File -encoding utf8 -FilePath "example.com.ext" -Append
"subjectAltName = @alt_names" | Out-File -encoding utf8 -FilePath "example.com.ext" -Append
"[alt_names]" | Out-File -encoding utf8 -FilePath "example.com.ext" -Append
"DNS.1 = example.com" | Out-File -encoding utf8 -FilePath "example.com.ext" -Append
"DNS.2 = *.example.com" | Out-File -encoding utf8 -FilePath "example.com.ext" -Append
openssl x509 -req -in "example.com.csr" -extfile "example.com.ext" -CA ca.crt -CAkey ca.key -CAcreateserial -out "example.com.crt" -days 3650 -sha256
rm "example.com.csr"
rm "example.com.ext"
certutil -p password,password -mergepfx example.com.crt example.com.pfx
Next go into IIS manager, select the top node (server), and select Server Certificates. Import (top right), and select the pfx file that was created earlier (password is 'password' unless you changed it above), and 'personal' certificate store. Next, select your site, select bindings (right side), and add (or edit) an https type, set the host name to your domain (e.g. example.com), select Require Server Name Indication, and then choose the SSL certificate you just installed. Repeat, adding a second https binding, but this time with a host starting with *. (e.g. *.example.com, * is important to include subdomains). If it won't accept the *, then you'll need a separate entry for each subdomain. Should work with all browsers, at least all Chromium browsers. Test. Celebrate.
net::ERR_CERT_WEAK_SIGNATURE_ALGORITHM
. – Epicardiumthisisunsafe
in chrome. This has been changed – Azeotrope