mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-22 17:46:48 +08:00
Fix reading ticket hello
https://github.com/XTLS/Xray-core/pull/4952#issuecomment-3183283514 https://github.com/XTLS/Xray-core/pull/4952#issuecomment-3183324745
This commit is contained in:
@@ -212,19 +212,19 @@ func (c *ClientConn) Read(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t != 0 {
|
if t != 0 {
|
||||||
return 0, errors.New("unexpected type ", t, ", expect server random")
|
return 0, errors.New("unexpected type ", t, ", expect random hello")
|
||||||
}
|
}
|
||||||
peerRandom := make([]byte, 32)
|
peerRandomHello := make([]byte, 32)
|
||||||
if l != len(peerRandom) {
|
if l != len(peerRandomHello) {
|
||||||
return 0, errors.New("unexpected length ", l, " for server random")
|
return 0, errors.New("unexpected length ", l, " for random hello")
|
||||||
}
|
}
|
||||||
if _, err := io.ReadFull(c.Conn, peerRandom); err != nil {
|
if _, err := io.ReadFull(c.Conn, peerRandomHello); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if c.random == nil {
|
if c.random == nil {
|
||||||
return 0, errors.New("empty c.random")
|
return 0, errors.New("empty c.random")
|
||||||
}
|
}
|
||||||
c.peerAead = NewAead(ClientCipher, c.baseKey, peerRandom, c.random)
|
c.peerAead = NewAead(ClientCipher, c.baseKey, peerRandomHello, c.random)
|
||||||
c.peerNonce = make([]byte, 12)
|
c.peerNonce = make([]byte, 12)
|
||||||
}
|
}
|
||||||
if len(c.peerCache) != 0 {
|
if len(c.peerCache) != 0 {
|
||||||
|
@@ -203,20 +203,17 @@ func (c *ServerConn) Read(b []byte) (int, error) {
|
|||||||
if t != 0 {
|
if t != 0 {
|
||||||
return 0, errors.New("unexpected type ", t, ", expect ticket hello")
|
return 0, errors.New("unexpected type ", t, ", expect ticket hello")
|
||||||
}
|
}
|
||||||
peerTicket := make([]byte, 21)
|
peerTicketHello := make([]byte, 21+32)
|
||||||
if l != len(peerTicket) {
|
if l != len(peerTicketHello) {
|
||||||
return 0, errors.New("unexpected length ", l, " for ticket hello")
|
return 0, errors.New("unexpected length ", l, " for ticket hello")
|
||||||
}
|
}
|
||||||
if _, err := io.ReadFull(c.Conn, peerTicket); err != nil {
|
if _, err := io.ReadFull(c.Conn, peerTicketHello); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if !bytes.Equal(peerTicket, c.ticket) {
|
if !bytes.Equal(peerTicketHello[:21], c.ticket) {
|
||||||
return 0, errors.New("naughty boy")
|
return 0, errors.New("naughty boy")
|
||||||
}
|
}
|
||||||
c.peerRandom = make([]byte, 32)
|
c.peerRandom = peerTicketHello[21:]
|
||||||
if _, err := io.ReadFull(c.Conn, c.peerRandom); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
c.peerAead = NewAead(c.cipher, c.baseKey, c.peerRandom, c.ticket)
|
c.peerAead = NewAead(c.cipher, c.baseKey, c.peerRandom, c.ticket)
|
||||||
c.peerNonce = make([]byte, 12)
|
c.peerNonce = make([]byte, 12)
|
||||||
|
Reference in New Issue
Block a user