mirror of https://github.com/cbeuw/Cloak
Fix test, improve err message and fix nil interface casting
This commit is contained in:
parent
3bc59ff4b6
commit
43ae82ec0e
|
|
@ -103,9 +103,11 @@ func MakeDeobfs(salsaKey [32]byte, payloadCipher cipher.AEAD, hasRecordLayer boo
|
||||||
if hasRecordLayer {
|
if hasRecordLayer {
|
||||||
rlLen = 5
|
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) {
|
deobfs := func(in []byte) (*Frame, error) {
|
||||||
if len(in) < rlLen+HEADER_LEN+8 {
|
if len(in) < minInputLen {
|
||||||
return nil, fmt.Errorf("Input cannot be shorter than %v bytes", rlLen+HEADER_LEN+8)
|
return nil, fmt.Errorf("input size %v, but it cannot be shorter than %v bytes", len(in), minInputLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
peeled := make([]byte, len(in)-rlLen)
|
peeled := make([]byte, len(in)-rlLen)
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,8 @@ func (sb *switchboard) send(data []byte, connId *uint32) (n int, err error) {
|
||||||
return writeAndRegUsage(conn, data)
|
return writeAndRegUsage(conn, data)
|
||||||
case FIXED_CONN_MAPPING:
|
case FIXED_CONN_MAPPING:
|
||||||
connI, ok := sb.conns.Load(*connId)
|
connI, ok := sb.conns.Load(*connId)
|
||||||
conn := connI.(net.Conn)
|
|
||||||
if ok {
|
if ok {
|
||||||
|
conn := connI.(net.Conn)
|
||||||
return writeAndRegUsage(conn, data)
|
return writeAndRegUsage(conn, data)
|
||||||
} else {
|
} else {
|
||||||
newConnId, conn, err := sb.pickRandConn()
|
newConnId, conn, err := sb.pickRandConn()
|
||||||
|
|
@ -161,7 +161,9 @@ func (sb *switchboard) deplex(connId uint32, conn net.Conn) {
|
||||||
sb.valve.AddRx(int64(n))
|
sb.valve.AddRx(int64(n))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("a connection for session %v has closed: %v", sb.session.id, err)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getSeshConfig(unordered bool) *mux.SessionConfig {
|
func getSeshConfig(unordered bool) mux.SessionConfig {
|
||||||
var sessionKey [32]byte
|
var sessionKey [32]byte
|
||||||
rand.Read(sessionKey[:])
|
rand.Read(sessionKey[:])
|
||||||
obfuscator, _ := mux.MakeObfuscator(0x00, sessionKey, true)
|
obfuscator, _ := mux.MakeObfuscator(0x00, sessionKey, true)
|
||||||
|
|
||||||
seshConfig := &mux.SessionConfig{
|
seshConfig := mux.SessionConfig{
|
||||||
Obfuscator: obfuscator,
|
Obfuscator: obfuscator,
|
||||||
Valve: nil,
|
Valve: nil,
|
||||||
UnitRead: util.ReadTLS,
|
UnitRead: util.ReadTLS,
|
||||||
|
|
@ -49,7 +49,7 @@ func TestActiveUser_Bypass(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get first session again
|
// get first session again
|
||||||
seshx, existing, err := user.GetSession(0, &mux.SessionConfig{})
|
seshx, existing, err := user.GetSession(0, mux.SessionConfig{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue