Browse Source

Additional changes based on feedback

Miro 1 year ago
parent
commit
47d0ac1e71
2 changed files with 41 additions and 0 deletions
  1. 5 0
      psiphon/server/shadowsocks.go
  2. 36 0
      psiphon/server/shadowsocks_test.go

+ 5 - 0
psiphon/server/shadowsocks.go

@@ -131,6 +131,11 @@ func NewShadowsocksConn(conn net.Conn) *ShadowsocksConn {
 }
 
 func (conn *ShadowsocksConn) Read(b []byte) (int, error) {
+	// TODO: invoke the irregular tunnel logger if Read fails due to an invalid
+	// message from the client. I.e., client does not know the shadowsocks key.
+	// Requires enumerating the Read errors that correspond to an invalid
+	// message because no exported error types, or values, are returned on
+	// such an error.
 	return conn.Conn.Read(b)
 }
 

+ 36 - 0
psiphon/server/shadowsocks_test.go

@@ -21,6 +21,7 @@ package server
 
 import (
 	"bytes"
+	"crypto/rand"
 	"io"
 	"net"
 	"testing"
@@ -204,6 +205,41 @@ func TestShadowsocksServer(t *testing.T) {
 	if numIrregularTunnels != 2 {
 		t.Fatal("expected 2 irregular tunnels")
 	}
+
+	// Mimic random bytes
+
+	go runListener(listener, recv)
+
+	conn, err = net.Dial("tcp", listener.Addr().String())
+	if err != nil {
+		t.Fatalf("net.Dial failed %v", err)
+	}
+	defer conn.Close()
+
+	randomBytes := make([]byte, clientToServerRecorder.Len())
+
+	_, err = rand.Read(randomBytes)
+	if err != nil {
+		t.Fatalf("rand.Read failed %v", err)
+	}
+
+	_, err = conn.Write(randomBytes)
+	if err != nil {
+		t.Fatalf("conn.Read failed %v", err)
+	}
+
+	r = <-recv
+
+	if r.err == nil {
+		t.Fatalf("expected error")
+	}
+
+	// Note: currently an invalid message from the client is not logged as an
+	// irregular tunnel due to the limitations described in
+	// ShadowsocksConn.Read so do not expect another irregular tunnel.
+	if numIrregularTunnels != 2 {
+		t.Fatal("expected 2 irregular tunnels")
+	}
 }
 
 type writeRecorder struct {