Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
don't use TLS 1.3 compatibility mode when using alternative record layer
Browse files Browse the repository at this point in the history
Compatibility mode consists of:
* clients sending a legacy_session_id in the ClientHello
* both endpoints sending change_cipher_spec record

change_cipher_spec records are already filtered out by
Conn.writeRecord(). This commit makes sure that the session_id is only
set when no alternative record layer is used.
  • Loading branch information
marten-seemann committed Mar 18, 2023
1 parent 9aac34b commit 73f8bcb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions handshake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, *ecdh.PrivateKey, error) {
vers: clientHelloVersion,
compressionMethods: []uint8{compressionNone},
random: make([]byte, 32),
sessionId: make([]byte, 32),
ocspStapling: true,
scts: true,
serverName: hostnameInSNI(config.ServerName),
Expand Down Expand Up @@ -126,8 +125,11 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, *ecdh.PrivateKey, error) {
// A random session ID is used to detect when the server accepted a ticket
// and is resuming a session (see RFC 5077). In TLS 1.3, it's always set as
// a compatibility measure (see RFC 8446, Section 4.1.2).
if _, err := io.ReadFull(config.rand(), hello.sessionId); err != nil {
return nil, nil, errors.New("tls: short read from Rand: " + err.Error())
if c.extraConfig == nil || c.extraConfig.AlternativeRecordLayer == nil {
hello.sessionId = make([]byte, 32)
if _, err := io.ReadFull(config.rand(), hello.sessionId); err != nil {
return nil, nil, errors.New("tls: short read from Rand: " + err.Error())
}
}

if hello.vers >= VersionTLS12 {
Expand Down

0 comments on commit 73f8bcb

Please sign in to comment.