[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [goptlib/master] Parse SOCKS userid parameters as SocksRequest.Args.
commit a7d271a44bef29942d8a0c2489d61a5ddd2098a1
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Sat Dec 7 22:26:46 2013 -0800
Parse SOCKS userid parameters as SocksRequest.Args.
---
socks.go | 7 +++++++
socks_test.go | 28 ++++++++++++++++++----------
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/socks.go b/socks.go
index 2ae1c5e..a3c5ede 100644
--- a/socks.go
+++ b/socks.go
@@ -22,6 +22,8 @@ type SocksRequest struct {
Username string
// The endpoint requested by the client as a "host:port" string.
Target string
+ // The parsed contents of Username as a keyâ??value mapping.
+ Args Args
}
// SocksConn encapsulates a net.Conn and information associated with a SOCKS request.
@@ -145,6 +147,11 @@ func readSocks4aConnect(s io.Reader) (req SocksRequest, err error) {
}
req.Username = string(usernameBytes[:len(usernameBytes)-1])
+ req.Args, err = parseClientParameters(req.Username)
+ if err != nil {
+ return
+ }
+
var port int
var host string
diff --git a/socks_test.go b/socks_test.go
index 2fb8a8c..bcd4433 100644
--- a/socks_test.go
+++ b/socks_test.go
@@ -12,13 +12,15 @@ func TestReadSocks4aConnect(t *testing.T) {
// missing userid
[]byte("\x04\x01\x12\x34\x01\x02\x03\x04"),
// missing \x00 after userid
- []byte("\x04\x01\x12\x34\x01\x02\x03\x04userid"),
+ []byte("\x04\x01\x12\x34\x01\x02\x03\x04key=value"),
// missing hostname
- []byte("\x04\x01\x12\x34\x00\x00\x00\x01userid\x00"),
+ []byte("\x04\x01\x12\x34\x00\x00\x00\x01key=value\x00"),
// missing \x00 after hostname
- []byte("\x04\x01\x12\x34\x00\x00\x00\x01userid\x00hostname"),
+ []byte("\x04\x01\x12\x34\x00\x00\x00\x01key=value\x00hostname"),
+ // bad nameâ??value mapping
+ []byte("\x04\x01\x12\x34\x00\x00\x00\x01userid\x00hostname\x00"),
// BIND request
- []byte("\x04\x02\x12\x34\x01\x02\x03\x04userid\x00"),
+ []byte("\x04\x02\x12\x34\x01\x02\x03\x04\x00"),
// SOCKS5
[]byte("\x05\x01\x00"),
}
@@ -28,8 +30,8 @@ func TestReadSocks4aConnect(t *testing.T) {
addr net.TCPAddr
}{
{
- []byte("\x04\x01\x12\x34\x01\x02\x03\x04userid\x00"),
- "userid", net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 0x1234},
+ []byte("\x04\x01\x12\x34\x01\x02\x03\x04key=value\x00"),
+ "key=value", net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 0x1234},
},
{
[]byte("\x04\x01\x12\x34\x01\x02\x03\x04\x00"),
@@ -42,16 +44,16 @@ func TestReadSocks4aConnect(t *testing.T) {
target string
}{
{
- []byte("\x04\x01\x12\x34\x00\x00\x00\x01userid\x00hostname\x00"),
- "userid", "hostname:4660",
+ []byte("\x04\x01\x12\x34\x00\x00\x00\x01key=value\x00hostname\x00"),
+ "key=value", "hostname:4660",
},
{
[]byte("\x04\x01\x12\x34\x00\x00\x00\x01\x00hostname\x00"),
"", "hostname:4660",
},
{
- []byte("\x04\x01\x12\x34\x00\x00\x00\x01userid\x00\x00"),
- "userid", ":4660",
+ []byte("\x04\x01\x12\x34\x00\x00\x00\x01key=value\x00\x00"),
+ "key=value", ":4660",
},
{
[]byte("\x04\x01\x12\x34\x00\x00\x00\x01\x00\x00"),
@@ -88,6 +90,9 @@ func TestReadSocks4aConnect(t *testing.T) {
t.Errorf("%q â?? address %s (expected %s)", test.input,
req.Target, test.addr.String())
}
+ if req.Args == nil {
+ t.Errorf("%q â?? unexpected nil Args from username %q", test.input, req.Username)
+ }
}
for _, test := range hostnameTests {
@@ -105,6 +110,9 @@ func TestReadSocks4aConnect(t *testing.T) {
t.Errorf("%q â?? target %q (expected %q)", test.input,
req.Target, test.target)
}
+ if req.Args == nil {
+ t.Errorf("%q â?? unexpected nil Args from username %q", test.input, req.Username)
+ }
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits