forked from quic-go/quic-go
Merge pull request #1937 from lucas-clemente/fix-hrr-race
fix race condition in crypto setup when sending a HelloRetryRequest
This commit is contained in:
@@ -220,7 +220,7 @@ func newCryptoSetup(
|
|||||||
messageChan: make(chan []byte, 100),
|
messageChan: make(chan []byte, 100),
|
||||||
receivedReadKey: make(chan struct{}),
|
receivedReadKey: make(chan struct{}),
|
||||||
receivedWriteKey: make(chan struct{}),
|
receivedWriteKey: make(chan struct{}),
|
||||||
writeRecord: make(chan struct{}),
|
writeRecord: make(chan struct{}, 1),
|
||||||
closeChan: make(chan struct{}),
|
closeChan: make(chan struct{}),
|
||||||
}
|
}
|
||||||
qtlsConf := tlsConfigToQtlsConfig(tlsConf, cs, extHandler)
|
qtlsConf := tlsConfigToQtlsConfig(tlsConf, cs, extHandler)
|
||||||
@@ -510,13 +510,6 @@ func (h *cryptoSetup) SetWriteKey(suite *qtls.CipherSuite, trafficSecret []byte)
|
|||||||
|
|
||||||
// WriteRecord is called when TLS writes data
|
// WriteRecord is called when TLS writes data
|
||||||
func (h *cryptoSetup) WriteRecord(p []byte) (int, error) {
|
func (h *cryptoSetup) WriteRecord(p []byte) (int, error) {
|
||||||
defer func() {
|
|
||||||
select {
|
|
||||||
case h.writeRecord <- struct{}{}:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
h.mutex.Lock()
|
h.mutex.Lock()
|
||||||
defer h.mutex.Unlock()
|
defer h.mutex.Unlock()
|
||||||
|
|
||||||
@@ -527,6 +520,11 @@ func (h *cryptoSetup) WriteRecord(p []byte) (int, error) {
|
|||||||
if !h.clientHelloWritten && h.perspective == protocol.PerspectiveClient {
|
if !h.clientHelloWritten && h.perspective == protocol.PerspectiveClient {
|
||||||
h.clientHelloWritten = true
|
h.clientHelloWritten = true
|
||||||
close(h.clientHelloWrittenChan)
|
close(h.clientHelloWrittenChan)
|
||||||
|
} else {
|
||||||
|
// We need additional signaling to properly detect HelloRetryRequests.
|
||||||
|
// For servers: when the ServerHello is written.
|
||||||
|
// For clients: when a reply is sent in response to a ServerHello.
|
||||||
|
h.writeRecord <- struct{}{}
|
||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
case protocol.EncryptionHandshake:
|
case protocol.EncryptionHandshake:
|
||||||
|
|||||||
Reference in New Issue
Block a user