tls.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package option
  2. import (
  3. "crypto/tls"
  4. E "github.com/sagernet/sing/common/exceptions"
  5. )
  6. type InboundTLSOptions struct {
  7. Enabled bool `json:"enabled,omitempty"`
  8. ServerName string `json:"server_name,omitempty"`
  9. ALPN []string `json:"alpn,omitempty"`
  10. MinVersion string `json:"min_version,omitempty"`
  11. MaxVersion string `json:"max_version,omitempty"`
  12. CipherSuites []string `json:"cipher_suites,omitempty"`
  13. Certificate string `json:"certificate,omitempty"`
  14. CertificatePath string `json:"certificate_path,omitempty"`
  15. Key string `json:"key,omitempty"`
  16. KeyPath string `json:"key_path,omitempty"`
  17. }
  18. type OutboundTLSOptions struct {
  19. Enabled bool `json:"enabled,omitempty"`
  20. DisableSNI bool `json:"disable_sni,omitempty"`
  21. ServerName string `json:"server_name,omitempty"`
  22. Insecure bool `json:"insecure,omitempty"`
  23. ALPN []string `json:"alpn,omitempty"`
  24. MinVersion string `json:"min_version,omitempty"`
  25. MaxVersion string `json:"max_version,omitempty"`
  26. CipherSuites []string `json:"cipher_suites,omitempty"`
  27. Certificate string `json:"certificate,omitempty"`
  28. CertificatePath string `json:"certificate_path,omitempty"`
  29. }
  30. func ParseTLSVersion(version string) (uint16, error) {
  31. switch version {
  32. case "1.0":
  33. return tls.VersionTLS10, nil
  34. case "1.1":
  35. return tls.VersionTLS11, nil
  36. case "1.2":
  37. return tls.VersionTLS12, nil
  38. case "1.3":
  39. return tls.VersionTLS13, nil
  40. default:
  41. return 0, E.New("unknown tls version:", version)
  42. }
  43. }