@@ -41,20 +41,20 @@ internal async Task OnTlsClientHelloAsync(ConnectionContext connection)
4141 // no data is consumed, it will be processed by the follow-up middlewares
4242 input . AdvanceTo ( buffer . Start ) ;
4343
44- switch ( parseState )
44+ if ( parseState == ClientHelloParseState . NotEnoughData )
4545 {
46- case ClientHelloParseState . NotEnoughData :
47- continue ;
48-
49- case ClientHelloParseState . NotTlsClientHello :
50- await _next ( connection ) ;
51- return ;
46+ continue ;
47+ }
5248
53- case ClientHelloParseState . ValidTlsClientHello :
54- _tlsClientHelloBytesCallback ( connection , clientHelloBytes ) ;
55- await _next ( connection ) ;
56- return ;
49+ if ( parseState == ClientHelloParseState . ValidTlsClientHello )
50+ {
51+ _tlsClientHelloBytesCallback ( connection , clientHelloBytes ) ;
5752 }
53+
54+ // Here either it's a valid TLS client hello or definitely not a TLS client hello.
55+ // Anyway we can continue with the middleware pipeline
56+ await _next ( connection ) ;
57+ break ;
5858 }
5959
6060 await _next ( connection ) ;
@@ -78,7 +78,7 @@ private static ClientHelloParseState TryParseClientHello(ReadOnlySequence<byte>
7878 }
7979
8080 // Protocol version
81- if ( ! reader . TryReadBigEndian ( out short version ) || IsValidProtocolVersion ( version ) == false )
81+ if ( ! reader . TryReadBigEndian ( out short version ) || ! IsValidProtocolVersion ( version ) )
8282 {
8383 return ClientHelloParseState . NotTlsClientHello ;
8484 }
@@ -109,14 +109,14 @@ private static ClientHelloParseState TryParseClientHello(ReadOnlySequence<byte>
109109 }
110110
111111 private static bool IsValidProtocolVersion ( short version )
112- => version == 0x0002 // SSL 2.0 (0x0002)
113- || version == 0x0300 // SSL 3.0 (0x0300)
114- || version == 0x0301 // TLS 1.0 (0x0301)
115- || version == 0x0302 // TLS 1.1 (0x0302)
116- || version == 0x0303 // TLS 1.2 (0x0303)
117- || version == 0x0304 ; // TLS 1.3 (0x0304)
118-
119- private enum ClientHelloParseState
112+ => version is 0x0002 // SSL 2.0 (0x0002)
113+ or 0x0300 // SSL 3.0 (0x0300)
114+ or 0x0301 // TLS 1.0 (0x0301)
115+ or 0x0302 // TLS 1.1 (0x0302)
116+ or 0x0303 // TLS 1.2 (0x0303)
117+ or 0x0304 ; // TLS 1.3 (0x0304)
118+
119+ private enum ClientHelloParseState : byte
120120 {
121121 NotEnoughData ,
122122 NotTlsClientHello ,
0 commit comments