Sfoglia il codice sorgente

implement ss2022 client timestamp check as per spec

Shelikhoo 2 anni fa
parent
commit
8a1777ce62

+ 9 - 0
proxy/shadowsocks2022/client_session.go

@@ -73,6 +73,15 @@ func (c *ClientUDPSession) KeepReading() {
 				newError("unable to decode udp response").Base(err).WriteToLog()
 				continue
 			}
+
+			{
+				timeDifference := int64(udpResp.TimeStamp) - time.Now().Unix()
+				if timeDifference < -30 || timeDifference > 30 {
+					newError("udp packet timestamp difference too large, packet discarded").WriteToLog()
+					continue
+				}
+			}
+
 			c.locker.Lock()
 			session, ok := c.sessionMap[string(udpResp.ClientSessionID[:])]
 			if ok {

+ 1 - 1
proxy/shadowsocks2022/encoding.go

@@ -203,7 +203,7 @@ func (t *TCPRequest) DecodeTCPResponseHeader(effectivePsk []byte, In io.Reader)
 		return newError("unexpected TCP header type")
 	}
 	timeDifference := int64(fixedLengthHeader.Timestamp) - time.Now().Unix()
-	if timeDifference < -60 || timeDifference > 60 {
+	if timeDifference < -30 || timeDifference > 30 {
 		return newError("timestamp is too far away")
 	}