@@ -124,9 +124,7 @@ func (m *natTestMetrics) AddUDPCipherSearch(accessKeyFound bool, timeToCipher ti
124
124
125
125
// Takes a validation policy, and returns the metrics it
126
126
// generates when localhost access is attempted
127
- func sendToDiscard (payloads [][]byte , validator onet.TargetIPValidator , useValidCipher bool ) * natTestMetrics {
128
- ciphers , _ := MakeTestCiphers ([]string {"asdf" })
129
- cipher := ciphers .SnapshotForClientIP (netip.Addr {})[0 ].Value .(* CipherEntry ).CryptoKey
127
+ func sendToDiscard (ciphers CipherList , payloads [][]byte , cipher * shadowsocks.EncryptionKey , validator onet.TargetIPValidator ) * natTestMetrics {
130
128
clientConn := makePacketConn ()
131
129
metrics := & natTestMetrics {}
132
130
handler := NewPacketHandler (timeout , ciphers , metrics )
@@ -141,12 +139,7 @@ func sendToDiscard(payloads [][]byte, validator onet.TargetIPValidator, useValid
141
139
targetAddr := socks .ParseAddr ("127.0.0.1:9" )
142
140
for _ , payload := range payloads {
143
141
plaintext := append (targetAddr , payload ... )
144
- var ciphertext []byte
145
- if useValidCipher {
146
- ciphertext = make ([]byte , cipher .SaltSize ()+ len (plaintext )+ cipher .TagSize ())
147
- } else {
148
- ciphertext = []byte ("invalid cipher" )
149
- }
142
+ ciphertext := make ([]byte , cipher .SaltSize ()+ len (plaintext )+ cipher .TagSize ())
150
143
shadowsocks .Pack (ciphertext , plaintext , cipher )
151
144
clientConn .recv <- packet {
152
145
addr : & net.UDPAddr {
@@ -163,11 +156,15 @@ func sendToDiscard(payloads [][]byte, validator onet.TargetIPValidator, useValid
163
156
}
164
157
165
158
func sendToDiscardWithValidCipher (payloads [][]byte , validator onet.TargetIPValidator ) * natTestMetrics {
166
- return sendToDiscard (payloads , validator , true )
159
+ ciphers , _ := MakeTestCiphers ([]string {"asdf" })
160
+ cipher := ciphers .SnapshotForClientIP (netip.Addr {})[0 ].Value .(* CipherEntry ).CryptoKey
161
+ return sendToDiscard (ciphers , payloads , cipher , validator )
167
162
}
168
163
169
164
func sendToDiscardWithInValidCipher (payloads [][]byte , validator onet.TargetIPValidator ) * natTestMetrics {
170
- return sendToDiscard (payloads , validator , false )
165
+ ciphers , _ := MakeTestCiphers ([]string {"asdf" })
166
+ cipher , _ := shadowsocks .NewEncryptionKey (shadowsocks .CHACHA20IETFPOLY1305 , "invalid cipher" )
167
+ return sendToDiscard (ciphers , payloads , cipher , validator )
171
168
}
172
169
173
170
func TestIPFilter (t * testing.T ) {
0 commit comments