@@ -200,25 +200,41 @@ var tls12ForbiddenCipherSuites = map[uint16]struct{}{
200
200
201
201
// NewTLS uses c to construct a TransportCredentials based on TLS.
202
202
func NewTLS (c * tls.Config ) TransportCredentials {
203
- tc := & tlsCreds {credinternal .CloneTLSConfig (c )}
204
- tc .config .NextProtos = credinternal .AppendH2ToNextProtos (tc .config .NextProtos )
203
+ cfg := applyDefaults (c )
204
+ if cfg .GetConfigForClient != nil {
205
+ oldFn := cfg .GetConfigForClient
206
+ cfg .GetConfigForClient = func (hello * tls.ClientHelloInfo ) (* tls.Config , error ) {
207
+ cfgForClient , err := oldFn (hello )
208
+ if err != nil || cfgForClient == nil {
209
+ return cfgForClient , err
210
+ }
211
+ return applyDefaults (cfgForClient ), nil
212
+ }
213
+ }
214
+ tc := & tlsCreds {config : cfg }
215
+ return tc
216
+ }
217
+
218
+ func applyDefaults (c * tls.Config ) * tls.Config {
219
+ config := credinternal .CloneTLSConfig (c )
220
+ config .NextProtos = credinternal .AppendH2ToNextProtos (config .NextProtos )
205
221
// If the user did not configure a MinVersion and did not configure a
206
222
// MaxVersion < 1.2, use MinVersion=1.2, which is required by
207
223
// https://datatracker.ietf.org/doc/html/rfc7540#section-9.2
208
- if tc . config .MinVersion == 0 && (tc . config .MaxVersion == 0 || tc . config .MaxVersion >= tls .VersionTLS12 ) {
209
- tc . config .MinVersion = tls .VersionTLS12
224
+ if config .MinVersion == 0 && (config .MaxVersion == 0 || config .MaxVersion >= tls .VersionTLS12 ) {
225
+ config .MinVersion = tls .VersionTLS12
210
226
}
211
227
// If the user did not configure CipherSuites, use all "secure" cipher
212
228
// suites reported by the TLS package, but remove some explicitly forbidden
213
229
// by https://datatracker.ietf.org/doc/html/rfc7540#appendix-A
214
- if tc . config .CipherSuites == nil {
230
+ if config .CipherSuites == nil {
215
231
for _ , cs := range tls .CipherSuites () {
216
232
if _ , ok := tls12ForbiddenCipherSuites [cs .ID ]; ! ok {
217
- tc . config .CipherSuites = append (tc . config .CipherSuites , cs .ID )
233
+ config .CipherSuites = append (config .CipherSuites , cs .ID )
218
234
}
219
235
}
220
236
}
221
- return tc
237
+ return config
222
238
}
223
239
224
240
// NewClientTLSFromCert constructs TLS credentials from the provided root
0 commit comments