Skip to content

Commit 6801c27

Browse files
FiloSottilegopherbot
authored andcommitted
crypto/tls: make SessionState.Extra a slice of byte slices
Fixes #60539 Updates #60105 Change-Id: I7b567cc1d0901891ed97d29591db935cd487cc71 Reviewed-on: https://go-review.googlesource.com/c/go/+/501675 Auto-Submit: Filippo Valsorda <[email protected]> Run-TryBot: Filippo Valsorda <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 1f11ea6 commit 6801c27

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

api/go1.21.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pkg crypto/tls, type QUICEvent struct, Level QUICEncryptionLevel #44886
8080
pkg crypto/tls, type QUICEvent struct, Suite uint16 #44886
8181
pkg crypto/tls, type SessionState struct #60105
8282
pkg crypto/tls, type SessionState struct, EarlyData bool #60107
83-
pkg crypto/tls, type SessionState struct, Extra []uint8 #60105
83+
pkg crypto/tls, type SessionState struct, Extra [][]uint8 #60539
8484
pkg crypto/x509, type RevocationListEntry struct #53573
8585
pkg crypto/x509, type RevocationListEntry struct, Extensions []pkix.Extension #53573
8686
pkg crypto/x509, type RevocationListEntry struct, ExtraExtensions []pkix.Extension #53573

src/crypto/tls/handshake_messages_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ func (*SessionState) Generate(rand *rand.Rand, size int) reflect.Value {
355355
s.cipherSuite = uint16(rand.Intn(math.MaxUint16))
356356
s.createdAt = uint64(rand.Int63())
357357
s.secret = randomBytes(rand.Intn(100)+1, rand)
358-
s.Extra = randomBytes(rand.Intn(100), rand)
358+
for n, i := rand.Intn(3), 0; i < n; i++ {
359+
s.Extra = append(s.Extra, randomBytes(rand.Intn(100), rand))
360+
}
359361
if rand.Intn(10) > 5 {
360362
s.EarlyData = true
361363
}

src/crypto/tls/ticket.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ type SessionState struct {
2727
//
2828
// Certificate CertificateChain<0..2^24-1>;
2929
//
30+
// opaque Extra<0..2^24-1>;
31+
//
3032
// struct {
3133
// uint16 version;
3234
// SessionStateType type;
3335
// uint16 cipher_suite;
3436
// uint64 created_at;
3537
// opaque secret<1..2^8-1>;
36-
// opaque extra<0..2^24-1>;
38+
// Extra extra<0..2^24-1>;
3739
// uint8 ext_master_secret = { 0, 1 };
3840
// uint8 early_data = { 0, 1 };
3941
// CertificateEntry certificate_list<0..2^24-1>;
@@ -62,12 +64,13 @@ type SessionState struct {
6264
//
6365
// This allows [Config.UnwrapSession]/[Config.WrapSession] and
6466
// [ClientSessionCache] implementations to store and retrieve additional
65-
// data.
67+
// data alongside this session.
6668
//
67-
// If Extra is already set, the implementation must preserve the previous
68-
// value across a round-trip, for example by appending and stripping a
69-
// fixed-length suffix.
70-
Extra []byte
69+
// To allow different layers in a protocol stack to share this field,
70+
// applications must only append to it, not replace it, and must use entries
71+
// that can be recognized even if out of order (for example, by starting
72+
// with a id and version prefix).
73+
Extra [][]byte
7174

7275
// EarlyData indicates whether the ticket can be used for 0-RTT in a QUIC
7376
// connection. The application may set this to false if it is true to
@@ -115,7 +118,11 @@ func (s *SessionState) Bytes() ([]byte, error) {
115118
b.AddBytes(s.secret)
116119
})
117120
b.AddUint24LengthPrefixed(func(b *cryptobyte.Builder) {
118-
b.AddBytes(s.Extra)
121+
for _, extra := range s.Extra {
122+
b.AddUint24LengthPrefixed(func(b *cryptobyte.Builder) {
123+
b.AddBytes(extra)
124+
})
125+
}
119126
})
120127
if s.extMasterSecret {
121128
b.AddUint8(1)
@@ -176,19 +183,27 @@ func ParseSessionState(data []byte) (*SessionState, error) {
176183
s := cryptobyte.String(data)
177184
var typ, extMasterSecret, earlyData uint8
178185
var cert Certificate
186+
var extra cryptobyte.String
179187
if !s.ReadUint16(&ss.version) ||
180188
!s.ReadUint8(&typ) ||
181189
(typ != 1 && typ != 2) ||
182190
!s.ReadUint16(&ss.cipherSuite) ||
183191
!readUint64(&s, &ss.createdAt) ||
184192
!readUint8LengthPrefixed(&s, &ss.secret) ||
185-
!readUint24LengthPrefixed(&s, &ss.Extra) ||
193+
!s.ReadUint24LengthPrefixed(&extra) ||
186194
!s.ReadUint8(&extMasterSecret) ||
187195
!s.ReadUint8(&earlyData) ||
188196
len(ss.secret) == 0 ||
189197
!unmarshalCertificate(&s, &cert) {
190198
return nil, errors.New("tls: invalid session encoding")
191199
}
200+
for !extra.Empty() {
201+
var e []byte
202+
if !readUint24LengthPrefixed(&extra, &e) {
203+
return nil, errors.New("tls: invalid session encoding")
204+
}
205+
ss.Extra = append(ss.Extra, e)
206+
}
192207
switch extMasterSecret {
193208
case 0:
194209
ss.extMasterSecret = false

0 commit comments

Comments
 (0)