2121var certPublicKeySpecified = int . TryParse ( builder . Configuration [ "certPublicKeyLength" ] , out var certPublicKeyConfig ) ;
2222var certPublicKeyLength = certPublicKeySpecified ? certPublicKeyConfig : 2048 ;
2323var enableHostHeaderValidation = bool . TryParse ( builder . Configuration [ "enableHostHeaderValidation" ] , out var enableHostHeaderValidationConfig ) && enableHostHeaderValidationConfig ;
24+ var supportedTlsVersions = ParseSslProtocols ( builder . Configuration [ "tlsProtocols" ] ) ;
2425
2526// endpoints
2627var listeningEndpoints = builder . Configuration [ "urls" ] ?? "https://localhost:5000/" ;
27- var supportedTlsVersions = ParseSslProtocols ( builder . Configuration [ "tlsProtocols" ] ) ;
28+
29+ // determine if listening is expected only on HTTP scheme
30+ var httpOnly = true ;
31+ foreach ( var endpoint in listeningEndpoints . Split ( [ ';' ] , StringSplitOptions . RemoveEmptyEntries ) )
32+ {
33+ var urlPrefix = UrlPrefix . Create ( endpoint ) ;
34+ if ( urlPrefix . Scheme == "https" )
35+ {
36+ httpOnly = false ;
37+ }
38+ }
39+ if ( httpOnly )
40+ {
41+ Console . WriteLine ( "[Note] Server scheme is HTTP, not HTTPS." ) ;
42+ }
2843
2944// debug
3045var writeCertValidationEventsToConsole = bool . TryParse ( builder . Configuration [ "certValidationConsoleEnabled" ] , out var certValidationConsoleEnabled ) && certValidationConsoleEnabled ;
@@ -71,6 +86,22 @@ void ConfigureListen(KestrelServerOptions serverOptions, IConfigurationRoot conf
7186
7287 serverOptions . Listen ( endpoint , listenOptions =>
7388 {
89+ var protocol = config [ "protocol" ] ?? "" ;
90+ if ( protocol . Equals ( "h2" , StringComparison . OrdinalIgnoreCase ) )
91+ {
92+ listenOptions . Protocols = HttpProtocols . Http1AndHttp2 ;
93+ }
94+ else if ( protocol . Equals ( "h2c" , StringComparison . OrdinalIgnoreCase ) )
95+ {
96+ listenOptions . Protocols = HttpProtocols . Http2 ;
97+ }
98+
99+ if ( httpOnly )
100+ {
101+ // all TLS related settings should be below
102+ return ;
103+ }
104+
74105 var certificatePath = Path . Combine ( "certificates" , $ "testCert-{ certPublicKeyLength } .pfx") ;
75106 Console . WriteLine ( $ "Using certificate: { certificatePath } ") ;
76107
@@ -107,16 +138,6 @@ void ConfigureListen(KestrelServerOptions serverOptions, IConfigurationRoot conf
107138 options . ClientCertificateValidation = AllowAnyCertificateValidationWithLogging ;
108139 }
109140 } ) ;
110-
111- var protocol = config [ "protocol" ] ?? "" ;
112- if ( protocol . Equals ( "h2" , StringComparison . OrdinalIgnoreCase ) )
113- {
114- listenOptions . Protocols = HttpProtocols . Http1AndHttp2 ;
115- }
116- else if ( protocol . Equals ( "h2c" , StringComparison . OrdinalIgnoreCase ) )
117- {
118- listenOptions . Protocols = HttpProtocols . Http2 ;
119- }
120141 } ) ;
121142 }
122143} ) ;
@@ -204,7 +225,11 @@ bool AllowAnyCertificateValidationWithLogging(X509Certificate2 certificate, X509
204225await app . StartAsync ( ) ;
205226
206227Console . WriteLine ( "Application Info:" ) ;
207- LogOpenSSLVersion ( ) ;
228+ if ( ! httpOnly )
229+ {
230+ LogOpenSSLVersion ( ) ;
231+ Console . WriteLine ( $ "\t supported TLS versions: { supportedTlsVersions } ") ;
232+ }
208233if ( mTlsEnabled )
209234{
210235 Console . WriteLine ( $ "\t mTLS is enabled (client cert is required)") ;
@@ -221,7 +246,6 @@ bool AllowAnyCertificateValidationWithLogging(X509Certificate2 certificate, X509
221246{
222247 Console . WriteLine ( $ "\t enabled logging stats to console") ;
223248}
224- Console . WriteLine ( $ "\t supported TLS versions: { supportedTlsVersions } ") ;
225249Console . WriteLine ( $ "\t listening endpoints: { listeningEndpoints } ") ;
226250Console . WriteLine ( "--------------------------------" ) ;
227251
0 commit comments