defaults.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright 2024 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package tls
  5. import (
  6. // [Psiphon]
  7. // "internal/godebug"
  8. "slices"
  9. _ "unsafe" // for linkname
  10. )
  11. // Defaults are collected in this file to allow distributions to more easily patch
  12. // them to apply local policies.
  13. // [Psiphon]
  14. // var tlskyber = godebug.New("tlskyber")
  15. func defaultCurvePreferences() []CurveID {
  16. // [Psiphon]
  17. // if tlskyber.Value() == "0" {
  18. // return []CurveID{X25519, CurveP256, CurveP384, CurveP521}
  19. // }
  20. // For now, x25519Kyber768Draft00 must always be followed by X25519.
  21. return []CurveID{x25519Kyber768Draft00, X25519, CurveP256, CurveP384, CurveP521}
  22. }
  23. // defaultSupportedSignatureAlgorithms contains the signature and hash algorithms that
  24. // the code advertises as supported in a TLS 1.2+ ClientHello and in a TLS 1.2+
  25. // CertificateRequest. The two fields are merged to match with TLS 1.3.
  26. // Note that in TLS 1.2, the ECDSA algorithms are not constrained to P-256, etc.
  27. var defaultSupportedSignatureAlgorithms = []SignatureScheme{
  28. PSSWithSHA256,
  29. ECDSAWithP256AndSHA256,
  30. Ed25519,
  31. PSSWithSHA384,
  32. PSSWithSHA512,
  33. PKCS1WithSHA256,
  34. PKCS1WithSHA384,
  35. PKCS1WithSHA512,
  36. ECDSAWithP384AndSHA384,
  37. ECDSAWithP521AndSHA512,
  38. PKCS1WithSHA1,
  39. ECDSAWithSHA1,
  40. }
  41. // [Psiphon]
  42. // var tlsrsakex = godebug.New("tlsrsakex")
  43. // var tls3des = godebug.New("tls3des")
  44. func defaultCipherSuites() []uint16 {
  45. suites := slices.Clone(cipherSuitesPreferenceOrder)
  46. return slices.DeleteFunc(suites, func(c uint16) bool {
  47. // [Psiphon] BEGIN
  48. // return disabledCipherSuites[c] ||
  49. // tlsrsakex.Value() != "1" && rsaKexCiphers[c] ||
  50. // tls3des.Value() != "1" && tdesCiphers[c]
  51. return disabledCipherSuites[c] || rsaKexCiphers[c] || tdesCiphers[c]
  52. // [Psiphon] END
  53. })
  54. }
  55. // defaultCipherSuitesTLS13 is also the preference order, since there are no
  56. // disabled by default TLS 1.3 cipher suites. The same AES vs ChaCha20 logic as
  57. // cipherSuitesPreferenceOrder applies.
  58. //
  59. // defaultCipherSuitesTLS13 should be an internal detail,
  60. // but widely used packages access it using linkname.
  61. // Notable members of the hall of shame include:
  62. // - github.com/quic-go/quic-go
  63. // - github.com/sagernet/quic-go
  64. //
  65. // Do not remove or change the type signature.
  66. // See go.dev/issue/67401.
  67. //
  68. //go:linkname defaultCipherSuitesTLS13
  69. var defaultCipherSuitesTLS13 = []uint16{
  70. TLS_AES_128_GCM_SHA256,
  71. TLS_AES_256_GCM_SHA384,
  72. TLS_CHACHA20_POLY1305_SHA256,
  73. }
  74. // defaultCipherSuitesTLS13NoAES should be an internal detail,
  75. // but widely used packages access it using linkname.
  76. // Notable members of the hall of shame include:
  77. // - github.com/quic-go/quic-go
  78. // - github.com/sagernet/quic-go
  79. //
  80. // Do not remove or change the type signature.
  81. // See go.dev/issue/67401.
  82. //
  83. //go:linkname defaultCipherSuitesTLS13NoAES
  84. var defaultCipherSuitesTLS13NoAES = []uint16{
  85. TLS_CHACHA20_POLY1305_SHA256,
  86. TLS_AES_128_GCM_SHA256,
  87. TLS_AES_256_GCM_SHA384,
  88. }
  89. var defaultSupportedVersionsFIPS = []uint16{
  90. VersionTLS12,
  91. }
  92. // defaultCurvePreferencesFIPS are the FIPS-allowed curves,
  93. // in preference order (most preferable first).
  94. var defaultCurvePreferencesFIPS = []CurveID{CurveP256, CurveP384, CurveP521}
  95. // defaultSupportedSignatureAlgorithmsFIPS currently are a subset of
  96. // defaultSupportedSignatureAlgorithms without Ed25519 and SHA-1.
  97. var defaultSupportedSignatureAlgorithmsFIPS = []SignatureScheme{
  98. PSSWithSHA256,
  99. PSSWithSHA384,
  100. PSSWithSHA512,
  101. PKCS1WithSHA256,
  102. ECDSAWithP256AndSHA256,
  103. PKCS1WithSHA384,
  104. ECDSAWithP384AndSHA384,
  105. PKCS1WithSHA512,
  106. ECDSAWithP521AndSHA512,
  107. }
  108. // defaultCipherSuitesFIPS are the FIPS-allowed cipher suites.
  109. var defaultCipherSuitesFIPS = []uint16{
  110. TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
  111. TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
  112. TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
  113. TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
  114. TLS_RSA_WITH_AES_128_GCM_SHA256,
  115. TLS_RSA_WITH_AES_256_GCM_SHA384,
  116. }
  117. // defaultCipherSuitesTLS13FIPS are the FIPS-allowed cipher suites for TLS 1.3.
  118. var defaultCipherSuitesTLS13FIPS = []uint16{
  119. TLS_AES_128_GCM_SHA256,
  120. TLS_AES_256_GCM_SHA384,
  121. }