From 43ae82ec0ea003ef3a04367d7d838ea1b0b2098b Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Wed, 8 Apr 2020 15:58:46 +0100 Subject: [PATCH] Fix test, improve err message and fix nil interface casting --- internal/multiplex/obfs.go | 6 ++++-- internal/multiplex/switchboard.go | 6 ++++-- internal/server/activeuser_test.go | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/multiplex/obfs.go b/internal/multiplex/obfs.go index edaf381..640e15a 100644 --- a/internal/multiplex/obfs.go +++ b/internal/multiplex/obfs.go @@ -103,9 +103,11 @@ func MakeDeobfs(salsaKey [32]byte, payloadCipher cipher.AEAD, hasRecordLayer boo if hasRecordLayer { rlLen = 5 } + // record layer length + stream header length + minimum data size (i.e. nonce size of salsa20) + minInputLen := rlLen + HEADER_LEN + 8 deobfs := func(in []byte) (*Frame, error) { - if len(in) < rlLen+HEADER_LEN+8 { - return nil, fmt.Errorf("Input cannot be shorter than %v bytes", rlLen+HEADER_LEN+8) + if len(in) < minInputLen { + return nil, fmt.Errorf("input size %v, but it cannot be shorter than %v bytes", len(in), minInputLen) } peeled := make([]byte, len(in)-rlLen) diff --git a/internal/multiplex/switchboard.go b/internal/multiplex/switchboard.go index 00d67ce..802c58d 100644 --- a/internal/multiplex/switchboard.go +++ b/internal/multiplex/switchboard.go @@ -87,8 +87,8 @@ func (sb *switchboard) send(data []byte, connId *uint32) (n int, err error) { return writeAndRegUsage(conn, data) case FIXED_CONN_MAPPING: connI, ok := sb.conns.Load(*connId) - conn := connI.(net.Conn) if ok { + conn := connI.(net.Conn) return writeAndRegUsage(conn, data) } else { newConnId, conn, err := sb.pickRandConn() @@ -161,7 +161,9 @@ func (sb *switchboard) deplex(connId uint32, conn net.Conn) { sb.valve.AddRx(int64(n)) if err != nil { log.Debugf("a connection for session %v has closed: %v", sb.session.id, err) - sb.close("a connection has dropped unexpectedly") + //sb.close("a connection has dropped unexpectedly") + //return + sb.conns.Delete(connId) return } diff --git a/internal/server/activeuser_test.go b/internal/server/activeuser_test.go index 7968981..0a4a7a4 100644 --- a/internal/server/activeuser_test.go +++ b/internal/server/activeuser_test.go @@ -10,12 +10,12 @@ import ( "testing" ) -func getSeshConfig(unordered bool) *mux.SessionConfig { +func getSeshConfig(unordered bool) mux.SessionConfig { var sessionKey [32]byte rand.Read(sessionKey[:]) obfuscator, _ := mux.MakeObfuscator(0x00, sessionKey, true) - seshConfig := &mux.SessionConfig{ + seshConfig := mux.SessionConfig{ Obfuscator: obfuscator, Valve: nil, UnitRead: util.ReadTLS, @@ -49,7 +49,7 @@ func TestActiveUser_Bypass(t *testing.T) { } // get first session again - seshx, existing, err := user.GetSession(0, &mux.SessionConfig{}) + seshx, existing, err := user.GetSession(0, mux.SessionConfig{}) if err != nil { t.Fatal(err) }