Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active November 2, 2023 10:01
Show Gist options
  • Select an option

  • Save unitycoder/ec217d20eecc2dfaf8d316acd8c3c5c5 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/ec217d20eecc2dfaf8d316acd8c3c5c5 to your computer and use it in GitHub Desktop.
Using HTTPListener with HTTPS for local IP Address (Windows)

Using HTTPListener with HTTPS

  • VS: c# httplistener project, add listener.Prefixes.Add($"https://192.168.1.xxx:4443/"); *or some other ip/port
  • Browser: Test connecting into it, error: "Secure Connection Failed : Error code: PR_CONNECT_RESET_ERROR"
  • PowerShell (as administrator) to get certhash using snippet below:
$certs = Get-ChildItem -Path Cert:\LocalMachine\My
foreach ($cert in $certs) {
    $thumbprint = $cert.Thumbprint
    $appid = [System.Guid]::NewGuid()
    Write-Host "Certificate certhash: $thumbprint"
    #Write-Host "Application ID (appid): $appid"
}
  • Pick one of those (2nd one is usually the correct?)
  • "appid" is from your vs studio *.sln solution file, SolutionGuid =
  • CommandPrompt (as administrator): netsh http add sslcert ipport=0.0.0.0:4443 certhash=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx appid={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
  • Browser test reload: https://192.168.1.xxx:4443
  • Browser: Warning about insecure cert (ERR_CERT_AUTHORITY_INVALID), press advanced, Accept and Continue
  • Done!

OPTIONAL

  • Open firewall port for incoming TCP 4443 (if you want other computers from LAN to connect into your webserver)

UNINSTALLING

  • CommandPrompt (as administrator): netsh http delete sslcert ipport=0.0.0.0:4443

TROUBLESHOOTING

"SSL Certificate add failed, Error: 1312 A specified logon session does not exist. It may already have been terminated."

Wrong certhash with netsh command. Try other ones from the returned list.

"The parameter is incorrect."

Dont use ticks or quotes for appid='{...}' in netsh command

"Secure Connection Failed: Error code: Certificate type not approved for application., SEC_ERROR_INADEQUATE_CERT_TYPE"

Used wrong appid taken from powershell list, use another one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment