config.go 983 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package tls
  2. import (
  3. "context"
  4. "crypto/tls"
  5. "net"
  6. "github.com/sagernet/sing-box/adapter"
  7. E "github.com/sagernet/sing/common/exceptions"
  8. )
  9. type (
  10. STDConfig = tls.Config
  11. STDConn = tls.Conn
  12. ConnectionState = tls.ConnectionState
  13. )
  14. type Config interface {
  15. ServerName() string
  16. SetServerName(serverName string)
  17. NextProtos() []string
  18. SetNextProtos(nextProto []string)
  19. Config() (*STDConfig, error)
  20. Client(conn net.Conn) Conn
  21. Clone() Config
  22. }
  23. type ServerConfig interface {
  24. Config
  25. adapter.Service
  26. Server(conn net.Conn) Conn
  27. }
  28. type Conn interface {
  29. net.Conn
  30. HandshakeContext(ctx context.Context) error
  31. ConnectionState() ConnectionState
  32. }
  33. func ParseTLSVersion(version string) (uint16, error) {
  34. switch version {
  35. case "1.0":
  36. return tls.VersionTLS10, nil
  37. case "1.1":
  38. return tls.VersionTLS11, nil
  39. case "1.2":
  40. return tls.VersionTLS12, nil
  41. case "1.3":
  42. return tls.VersionTLS13, nil
  43. default:
  44. return 0, E.New("unknown tls version:", version)
  45. }
  46. }