mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
dfbc2e81e3
quic-go now vendors all of its dependencies, so we don't need to vendor them here. Created by running: gvt delete github.com/lucas-clemente/quic-go gvt delete github.com/bifurcation/mint gvt delete github.com/lucas-clemente/aes12 gvt delete github.com/lucas-clemente/fnv128a gvt delete github.com/lucas-clemente/quic-go-certificates gvt delete github.com/aead/chacha20 gvt delete github.com/hashicorp/golang-lru gvt fetch -tag v0.10.0-no-integrationtests github.com/lucas-clemente/quic-go
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package handshake
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/lucas-clemente/quic-go/internal/crypto"
|
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
|
)
|
|
|
|
var (
|
|
kexLifetime = protocol.EphermalKeyLifetime
|
|
kexCurrent crypto.KeyExchange
|
|
kexCurrentTime time.Time
|
|
kexMutex sync.RWMutex
|
|
)
|
|
|
|
// getEphermalKEX returns the currently active KEX, which changes every protocol.EphermalKeyLifetime
|
|
// See the explanation from the QUIC crypto doc:
|
|
//
|
|
// A single connection is the usual scope for forward security, but the security
|
|
// difference between an ephemeral key used for a single connection, and one
|
|
// used for all connections for 60 seconds is negligible. Thus we can amortise
|
|
// the Diffie-Hellman key generation at the server over all the connections in a
|
|
// small time span.
|
|
func getEphermalKEX() (crypto.KeyExchange, error) {
|
|
kexMutex.RLock()
|
|
res := kexCurrent
|
|
t := kexCurrentTime
|
|
kexMutex.RUnlock()
|
|
if res != nil && time.Since(t) < kexLifetime {
|
|
return res, nil
|
|
}
|
|
|
|
kexMutex.Lock()
|
|
defer kexMutex.Unlock()
|
|
// Check if still unfulfilled
|
|
if kexCurrent == nil || time.Since(kexCurrentTime) >= kexLifetime {
|
|
kex, err := crypto.NewCurve25519KEX()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
kexCurrent = kex
|
|
kexCurrentTime = time.Now()
|
|
return kexCurrent, nil
|
|
}
|
|
return kexCurrent, nil
|
|
}
|