Skip to content

Commit 01665a5

Browse files
cjpattonbwesterb
authored andcommitted
crypto/tls: add CFControl parameter to Config
Add CFControl parameter to Config. This value will be used to propagate Cloudflare-internal logic from the TLS configuration to HTTP requests.
1 parent 858979d commit 01665a5

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/crypto/tls/common.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ type ConnectionState struct {
279279
// RFC 7627, and https://mitls.org/pages/attacks/3SHAKE#channelbindings.
280280
TLSUnique []byte
281281

282+
// CFControl is used to pass additional TLS configuration information to
283+
// HTTP requests.
284+
//
285+
// NOTE: This feature is used to implement Cloudflare-internal features.
286+
// This feature is unstable and applications MUST NOT depend on it.
287+
CFControl interface{}
288+
282289
// ekm is a closure exposed via ExportKeyingMaterial.
283290
ekm func(label string, context []byte, length int) ([]byte, error)
284291
}
@@ -739,6 +746,13 @@ type Config struct {
739746
// used for debugging.
740747
KeyLogWriter io.Writer
741748

749+
// CFControl is used to pass additional TLS configuration information to
750+
// HTTP requests via ConnectionState.
751+
//
752+
// NOTE: This feature is used to implement Cloudflare-internal features.
753+
// This feature is unstable and applications MUST NOT depend on it.
754+
CFControl interface{}
755+
742756
// mutex protects sessionTicketKeys and autoSessionTicketKeys.
743757
mutex sync.RWMutex
744758
// sessionTicketKeys contains zero or more ticket keys. If set, it means
@@ -829,6 +843,7 @@ func (c *Config) Clone() *Config {
829843
DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled,
830844
Renegotiation: c.Renegotiation,
831845
KeyLogWriter: c.KeyLogWriter,
846+
CFControl: c.CFControl,
832847
sessionTicketKeys: c.sessionTicketKeys,
833848
autoSessionTicketKeys: c.autoSessionTicketKeys,
834849
}

src/crypto/tls/conn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,7 @@ func (c *Conn) connectionStateLocked() ConnectionState {
15271527
state.VerifiedChains = c.verifiedChains
15281528
state.SignedCertificateTimestamps = c.scts
15291529
state.OCSPResponse = c.ocspResponse
1530+
state.CFControl = c.config.CFControl
15301531
if !c.didResume && c.vers != VersionTLS13 {
15311532
if c.clientFinishedIsFirst {
15321533
state.TLSUnique = c.clientFinished[:]

src/crypto/tls/tls_cf_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package tls
2+
3+
import (
4+
"testing"
5+
)
6+
7+
type testCFControl struct {
8+
flags uint64
9+
}
10+
11+
// Check that CFControl is correctly propagated from Config to ConnectionState.
12+
func TestPropagateCFControl(t *testing.T) {
13+
want := uint64(23)
14+
s := Server(nil, &Config{CFControl: &testCFControl{want}})
15+
got := s.ConnectionState().CFControl.(*testCFControl).flags
16+
if got != want {
17+
t.Errorf("failed to propagate CFControl: got %v; want %v", got, want)
18+
}
19+
}

src/crypto/tls/tls_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,8 @@ func TestCloneNonFuncFields(t *testing.T) {
829829
f.Set(reflect.ValueOf(RenegotiateOnceAsClient))
830830
case "mutex", "autoSessionTicketKeys", "sessionTicketKeys":
831831
continue // these are unexported fields that are handled separately
832+
case "CFControl":
833+
f.Set(reflect.ValueOf(&testCFControl{23}))
832834
default:
833835
t.Errorf("all fields must be accounted for, but saw unknown field %q", fn)
834836
}

0 commit comments

Comments
 (0)