mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 12:27:37 +03:00
Fix timestamp diff
This commit is contained in:
parent
b35c53ca8f
commit
6310348018
1 changed files with 27 additions and 4 deletions
|
@ -364,9 +364,10 @@ func (c *clientConn) readResponse() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if math.Abs(float64(time.Now().Unix()-int64(epoch))) > 30 {
|
diff := int(math.Abs(float64(time.Now().Unix() - int64(epoch))))
|
||||||
|
if diff > 30 {
|
||||||
if debug.Enabled {
|
if debug.Enabled {
|
||||||
logger.Trace("server timestamp ", time.Unix(int64(epoch), 0).String())
|
logger.Trace("server timestamp ", time.Unix(int64(epoch), 0).String(), " diff ", diff)
|
||||||
}
|
}
|
||||||
return ErrBadTimestamp
|
return ErrBadTimestamp
|
||||||
}
|
}
|
||||||
|
@ -565,6 +566,10 @@ func (c *clientPacketConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error) {
|
||||||
}
|
}
|
||||||
buffer.Truncate(n)
|
buffer.Truncate(n)
|
||||||
|
|
||||||
|
if debug.Enabled {
|
||||||
|
logger.Trace("begin server packet")
|
||||||
|
}
|
||||||
|
|
||||||
var packetHeader []byte
|
var packetHeader []byte
|
||||||
if c.method.udpCipher != nil {
|
if c.method.udpCipher != nil {
|
||||||
_, err = c.method.udpCipher.Open(buffer.Index(PacketNonceSize), buffer.To(PacketNonceSize), buffer.From(PacketNonceSize), nil)
|
_, err = c.method.udpCipher.Open(buffer.Index(PacketNonceSize), buffer.To(PacketNonceSize), buffer.From(PacketNonceSize), nil)
|
||||||
|
@ -587,6 +592,11 @@ func (c *clientPacketConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error) {
|
||||||
return M.Socksaddr{}, err
|
return M.Socksaddr{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if debug.Enabled {
|
||||||
|
logger.Trace("session id ", sessionId)
|
||||||
|
logger.Trace("packet id ", packetId)
|
||||||
|
}
|
||||||
|
|
||||||
var remoteCipher cipher.AEAD
|
var remoteCipher cipher.AEAD
|
||||||
if packetHeader != nil {
|
if packetHeader != nil {
|
||||||
if sessionId == c.session.remoteSessionId {
|
if sessionId == c.session.remoteSessionId {
|
||||||
|
@ -617,7 +627,12 @@ func (c *clientPacketConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return M.Socksaddr{}, err
|
return M.Socksaddr{}, err
|
||||||
}
|
}
|
||||||
if math.Abs(float64(uint64(time.Now().Unix())-epoch)) > 30 {
|
|
||||||
|
diff := int(math.Abs(float64(time.Now().Unix() - int64(epoch))))
|
||||||
|
if diff > 30 {
|
||||||
|
if debug.Enabled {
|
||||||
|
logger.Trace("server timestamp ", time.Unix(int64(epoch), 0).String(), " diff ", diff)
|
||||||
|
}
|
||||||
return M.Socksaddr{}, ErrBadTimestamp
|
return M.Socksaddr{}, ErrBadTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,7 +679,15 @@ func (c *clientPacketConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error) {
|
||||||
return M.Socksaddr{}, E.Cause(err, "read padding length")
|
return M.Socksaddr{}, E.Cause(err, "read padding length")
|
||||||
}
|
}
|
||||||
buffer.Advance(int(paddingLength))
|
buffer.Advance(int(paddingLength))
|
||||||
return socks5.AddressSerializer.ReadAddrPort(buffer)
|
|
||||||
|
destination, err := socks5.AddressSerializer.ReadAddrPort(buffer)
|
||||||
|
if err != nil {
|
||||||
|
return M.Socksaddr{}, err
|
||||||
|
}
|
||||||
|
if debug.Enabled {
|
||||||
|
logger.Trace("ended client packet")
|
||||||
|
}
|
||||||
|
return destination, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type udpSession struct {
|
type udpSession struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue