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