mirror of
https://github.com/refraction-networking/utls.git
synced 2025-04-03 20:17:36 +03:00
crypto/tls: add ClientSessionState.ResumptionState and NewResumptionState
For #60105 Fixes #25351 Change-Id: Iffd658f2663cfc47b48157824226ed6c0260a59e Reviewed-on: https://go-review.googlesource.com/c/go/+/496820 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Filippo Valsorda <filippo@golang.org> Reviewed-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
parent
e911b27e23
commit
170472af9d
2 changed files with 70 additions and 8 deletions
|
@ -1069,6 +1069,47 @@ func testResumption(t *testing.T, version uint16) {
|
|||
|
||||
clientConfig.ClientSessionCache = nil
|
||||
testResumeState("WithoutSessionCache", false)
|
||||
|
||||
clientConfig.ClientSessionCache = &serializingClientCache{t: t}
|
||||
testResumeState("BeforeSerializingCache", false)
|
||||
testResumeState("WithSerializingCache", true)
|
||||
}
|
||||
|
||||
type serializingClientCache struct {
|
||||
t *testing.T
|
||||
|
||||
ticket, state []byte
|
||||
}
|
||||
|
||||
func (c *serializingClientCache) Get(sessionKey string) (session *ClientSessionState, ok bool) {
|
||||
if c.ticket == nil {
|
||||
return nil, false
|
||||
}
|
||||
state, err := ParseSessionState(c.state)
|
||||
if err != nil {
|
||||
c.t.Error(err)
|
||||
return nil, false
|
||||
}
|
||||
cs, err := NewResumptionState(c.ticket, state)
|
||||
if err != nil {
|
||||
c.t.Error(err)
|
||||
return nil, false
|
||||
}
|
||||
return cs, true
|
||||
}
|
||||
|
||||
func (c *serializingClientCache) Put(sessionKey string, cs *ClientSessionState) {
|
||||
ticket, state, err := cs.ResumptionState()
|
||||
if err != nil {
|
||||
c.t.Error(err)
|
||||
return
|
||||
}
|
||||
stateBytes, err := state.Bytes()
|
||||
if err != nil {
|
||||
c.t.Error(err)
|
||||
return
|
||||
}
|
||||
c.ticket, c.state = ticket, stateBytes
|
||||
}
|
||||
|
||||
func TestLRUClientSessionCache(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue