config.go 936 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. )
  13. type Config interface {
  14. ServerName() string
  15. SetServerName(serverName string)
  16. NextProtos() []string
  17. SetNextProtos(nextProto []string)
  18. Config() (*STDConfig, error)
  19. Client(conn net.Conn) Conn
  20. Clone() Config
  21. }
  22. type ServerConfig interface {
  23. Config
  24. adapter.Service
  25. Server(conn net.Conn) Conn
  26. }
  27. type Conn interface {
  28. net.Conn
  29. HandshakeContext(ctx context.Context) error
  30. ConnectionState() tls.ConnectionState
  31. }
  32. func ParseTLSVersion(version string) (uint16, error) {
  33. switch version {
  34. case "1.0":
  35. return tls.VersionTLS10, nil
  36. case "1.1":
  37. return tls.VersionTLS11, nil
  38. case "1.2":
  39. return tls.VersionTLS12, nil
  40. case "1.3":
  41. return tls.VersionTLS13, nil
  42. default:
  43. return 0, E.New("unknown tls version:", version)
  44. }
  45. }