tls.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 Listable[string] `json:"alpn,omitempty"`
  10. MinVersion string `json:"min_version,omitempty"`
  11. MaxVersion string `json:"max_version,omitempty"`
  12. CipherSuites Listable[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. ACME *InboundACMEOptions `json:"acme,omitempty"`
  18. }
  19. type OutboundTLSOptions struct {
  20. Enabled bool `json:"enabled,omitempty"`
  21. DisableSNI bool `json:"disable_sni,omitempty"`
  22. ServerName string `json:"server_name,omitempty"`
  23. Insecure bool `json:"insecure,omitempty"`
  24. ALPN Listable[string] `json:"alpn,omitempty"`
  25. MinVersion string `json:"min_version,omitempty"`
  26. MaxVersion string `json:"max_version,omitempty"`
  27. CipherSuites Listable[string] `json:"cipher_suites,omitempty"`
  28. Certificate string `json:"certificate,omitempty"`
  29. CertificatePath string `json:"certificate_path,omitempty"`
  30. }
  31. func ParseTLSVersion(version string) (uint16, error) {
  32. switch version {
  33. case "1.0":
  34. return tls.VersionTLS10, nil
  35. case "1.1":
  36. return tls.VersionTLS11, nil
  37. case "1.2":
  38. return tls.VersionTLS12, nil
  39. case "1.3":
  40. return tls.VersionTLS13, nil
  41. default:
  42. return 0, E.New("unknown tls version:", version)
  43. }
  44. }