Badgerati / Pode

Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
https://badgerati.github.io/Pode
MIT License
866 stars 92 forks source link

HTTPS error with self-signed cert #1411

Closed DanGough closed 3 weeks ago

DanGough commented 1 month ago

Describe the Bug

I am getting this error on every page load when using HTTPS with a self-signed cert:

[Error] AuthenticationException: Authentication failed, see inner exception.
   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken)
   at Pode.PodeRequest.UpgradeToSSL(CancellationToken cancellationToken) in C:\Projects\pode-builds\2.11.0\src\Listener\PodeRequest.cs:line 109
[Error] Win32Exception: An unknown error occurred while processing the certificate.

Steps To Reproduce

Run this and load the page:

#Requires -Modules @{ModuleName='Pode'; ModuleVersion='2.11.0'}
#Requires -Modules @{ModuleName='Pode.Web'; ModuleVersion='0.8.3'; MaximumVersion='0.8.3'}

Start-PodeServer {
    New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging -Levels Error, Warning, Informational #, Verbose
    Add-PodeEndpoint -Hostname 'localhost' -Protocol 'HTTPS' -Port 443 -SelfSigned       
    Use-PodeWebTemplates -Title 'Test'
    Add-PodeWebPage -Name 'Test' -ScriptBlock {
        New-PodeWebContainer -Content @(
            New-PodeWebQuote -Value 'Pode is awesome!' -Source 'Badgerati'
        )
    }
}

Expected Behavior

Page should load without error, as it does with Pode 2.10.0.

Platform

Badgerati commented 3 weeks ago

I've been able to reproduce the issue, and it's actually an "OK" error - caused by browsers not initially trusting localhost self-signed certs - but is now being displayed because of logging changes made in 2.11.0.

I've done some work to refactor how the logging and exceptions get thrown, and this "error" is now kept silent - unless Debug logging is enabled.