mirror of
https://github.com/refraction-networking/utls.git
synced 2025-04-03 20:17:36 +03:00
crypto/tls,regexp: remove always-nil error results
These were harmless, but added unnecessary verbosity to the code. This can happen as a result of refactors: for example, the method sessionState used to return errors in some cases. Change-Id: I4e6dacc01ae6a49b528c672979f95cbb86795a85 Reviewed-on: https://go-review.googlesource.com/c/go/+/528995 Reviewed-by: Leo Isla <islaleo93@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Olivier Mengué <olivier.mengue@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
This commit is contained in:
parent
0cb1694084
commit
8d53a491d1
5 changed files with 9 additions and 21 deletions
|
@ -915,10 +915,7 @@ func (hs *clientHandshakeState) saveSessionTicket() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
session, err := c.sessionState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
session := c.sessionState()
|
||||
session.secret = hs.masterSecret
|
||||
|
||||
cs := &ClientSessionState{ticket: hs.ticket, session: session}
|
||||
|
|
|
@ -753,11 +753,7 @@ func (c *Conn) handleNewSessionTicket(msg *newSessionTicketMsgTLS13) error {
|
|||
psk := cipherSuite.expandLabel(c.resumptionSecret, "resumption",
|
||||
msg.nonce, cipherSuite.hash.Size())
|
||||
|
||||
session, err := c.sessionState()
|
||||
if err != nil {
|
||||
c.sendAlert(alertInternalError)
|
||||
return err
|
||||
}
|
||||
session := c.sessionState()
|
||||
session.secret = psk
|
||||
session.useBy = uint64(c.config.time().Add(lifetime).Unix())
|
||||
session.ageAdd = msg.ageAdd
|
||||
|
|
|
@ -810,10 +810,7 @@ func (hs *serverHandshakeState) sendSessionTicket() error {
|
|||
c := hs.c
|
||||
m := new(newSessionTicketMsg)
|
||||
|
||||
state, err := c.sessionState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state := c.sessionState()
|
||||
state.secret = hs.masterSecret
|
||||
if hs.sessionState != nil {
|
||||
// If this is re-wrapping an old key, then keep
|
||||
|
@ -821,6 +818,7 @@ func (hs *serverHandshakeState) sendSessionTicket() error {
|
|||
state.createdAt = hs.sessionState.createdAt
|
||||
}
|
||||
if c.config.WrapSession != nil {
|
||||
var err error
|
||||
m.ticket, err = c.config.WrapSession(c.connectionStateLocked(), state)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -837,13 +837,11 @@ func (c *Conn) sendSessionTicket(earlyData bool) error {
|
|||
|
||||
m := new(newSessionTicketMsgTLS13)
|
||||
|
||||
state, err := c.sessionState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state := c.sessionState()
|
||||
state.secret = psk
|
||||
state.EarlyData = earlyData
|
||||
if c.config.WrapSession != nil {
|
||||
var err error
|
||||
m.label, err = c.config.WrapSession(c.connectionStateLocked(), state)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -865,8 +863,7 @@ func (c *Conn) sendSessionTicket(earlyData bool) error {
|
|||
// The value is not stored anywhere; we never need to check the ticket age
|
||||
// because 0-RTT is not supported.
|
||||
ageAdd := make([]byte, 4)
|
||||
_, err = c.config.rand().Read(ageAdd)
|
||||
if err != nil {
|
||||
if _, err := c.config.rand().Read(ageAdd); err != nil {
|
||||
return err
|
||||
}
|
||||
m.ageAdd = binary.LittleEndian.Uint32(ageAdd)
|
||||
|
|
|
@ -289,7 +289,7 @@ func ParseSessionState(data []byte) (*SessionState, error) {
|
|||
|
||||
// sessionState returns a partially filled-out [SessionState] with information
|
||||
// from the current connection.
|
||||
func (c *Conn) sessionState() (*SessionState, error) {
|
||||
func (c *Conn) sessionState() *SessionState {
|
||||
return &SessionState{
|
||||
version: c.vers,
|
||||
cipherSuite: c.cipherSuite,
|
||||
|
@ -302,7 +302,7 @@ func (c *Conn) sessionState() (*SessionState, error) {
|
|||
isClient: c.isClient,
|
||||
extMasterSecret: c.extMasterSecret,
|
||||
verifiedChains: c.verifiedChains,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// EncryptTicket encrypts a ticket with the [Config]'s configured (or default)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue