Add strict mode

This commit is contained in:
世界 2023-02-21 16:13:51 +08:00
parent 9cb3e9e0ed
commit 574313aaae
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -26,6 +26,7 @@ type ServiceConfig struct {
Users []User // for protocol version 3 Users []User // for protocol version 3
Handshake HandshakeConfig Handshake HandshakeConfig
HandshakeForServerName map[string]HandshakeConfig // for protocol version 2/3 HandshakeForServerName map[string]HandshakeConfig // for protocol version 2/3
StrictMode bool // for protocol version 3
Handler Handler Handler Handler
Logger logger.ContextLogger Logger logger.ContextLogger
} }
@ -51,6 +52,7 @@ type Service struct {
users []User users []User
handshake HandshakeConfig handshake HandshakeConfig
handshakeForServerName map[string]HandshakeConfig handshakeForServerName map[string]HandshakeConfig
strictMode bool
handler Handler handler Handler
logger logger.ContextLogger logger logger.ContextLogger
} }
@ -62,6 +64,7 @@ func NewService(config ServiceConfig) (*Service, error) {
users: config.Users, users: config.Users,
handshake: config.Handshake, handshake: config.Handshake,
handshakeForServerName: config.HandshakeForServerName, handshakeForServerName: config.HandshakeForServerName,
strictMode: config.StrictMode,
handler: config.Handler, handler: config.Handler,
logger: config.Logger, logger: config.Logger,
} }
@ -196,7 +199,7 @@ func (s *Service) NewConnection(ctx context.Context, conn net.Conn, metadata M.M
return bufio.CopyConn(ctx, conn, handshakeConn) return bufio.CopyConn(ctx, conn, handshakeConn)
} }
if !isServerHelloSupportTLS13(serverHelloFrame.Bytes()) { if s.strictMode && !isServerHelloSupportTLS13(serverHelloFrame.Bytes()) {
s.logger.WarnContext(ctx, "TLS 1.3 is not supported, will copy bidirectional") s.logger.WarnContext(ctx, "TLS 1.3 is not supported, will copy bidirectional")
return bufio.CopyConn(ctx, conn, handshakeConn) return bufio.CopyConn(ctx, conn, handshakeConn)
} }