@@ -37,6 +37,9 @@ func (h listenerConnectionHandler) close(conn *Conn) {
37
37
// cookie calculates a cookie for the net.Addr passed. It is calculated as a
38
38
// hash of the random cookie salt and the address.
39
39
func (h listenerConnectionHandler ) cookie (addr net.Addr ) uint32 {
40
+ if h .l .conf .DisableCookies {
41
+ return 0
42
+ }
40
43
udp , _ := addr .(* net.UDPAddr )
41
44
b := make ([]byte , 6 , 22 )
42
45
binary .LittleEndian .PutUint32 (b , h .cookieSalt )
@@ -93,15 +96,15 @@ func (h listenerConnectionHandler) handleOpenConnectionRequest1(b []byte, addr n
93
96
return fmt .Errorf ("handle OPEN_CONNECTION_REQUEST_1: incompatible protocol version %v (listener protocol = %v)" , pk .ClientProtocol , protocolVersion )
94
97
}
95
98
96
- data , _ := (& message.OpenConnectionReply1 {ServerGUID : h .l .id , Cookie : h .cookie (addr ), ServerHasSecurity : true , MTU : mtuSize }).MarshalBinary ()
99
+ data , _ := (& message.OpenConnectionReply1 {ServerGUID : h .l .id , Cookie : h .cookie (addr ), ServerHasSecurity : ! h . l . conf . DisableCookies , MTU : mtuSize }).MarshalBinary ()
97
100
_ , err := h .l .conn .WriteTo (data , addr )
98
101
return err
99
102
}
100
103
101
104
// handleOpenConnectionRequest2 handles an open connection request 2 packet
102
105
// stored in buffer b, coming from an address.
103
106
func (h listenerConnectionHandler ) handleOpenConnectionRequest2 (b []byte , addr net.Addr ) error {
104
- pk := & message.OpenConnectionRequest2 {ServerHasSecurity : true }
107
+ pk := & message.OpenConnectionRequest2 {ServerHasSecurity : ! h . l . conf . DisableCookies }
105
108
if err := pk .UnmarshalBinary (b ); err != nil {
106
109
return fmt .Errorf ("read OPEN_CONNECTION_REQUEST_2: %w" , err )
107
110
}
0 commit comments