Browse Source

fixed bug: obfuscatedSshConn.Write was incorrectly overwriting input buffer

Rod Hynes 11 years ago
parent
commit
cd650c6cb2
2 changed files with 9 additions and 1 deletions
  1. 1 0
      README.md
  2. 8 1
      psiphon/obfuscatedSshConn.go

+ 1 - 0
README.md

@@ -14,6 +14,7 @@ Status
 This project is currently at the proof-of-concept stage. Current production Psiphon client code is available at our [main repository](https://bitbucket.org/psiphon/psiphon-circumvention-system).
 This project is currently at the proof-of-concept stage. Current production Psiphon client code is available at our [main repository](https://bitbucket.org/psiphon/psiphon-circumvention-system).
 
 
 ### TODO
 ### TODO
+* SSH variable length random padding in KEX phase
 * more test cases
 * more test cases
 * integrate meek-client
 * integrate meek-client
 * add config options
 * add config options

+ 8 - 1
psiphon/obfuscatedSshConn.go

@@ -24,6 +24,7 @@ import (
 	"encoding/binary"
 	"encoding/binary"
 	"errors"
 	"errors"
 	"io"
 	"io"
+	"log"
 	"net"
 	"net"
 )
 )
 
 
@@ -93,7 +94,11 @@ func (conn *ObfuscatedSshConn) Write(buffer []byte) (n int, err error) {
 		if err != nil {
 		if err != nil {
 			return
 			return
 		}
 		}
-		conn.obfuscator.ObfuscateClientToServer(buffer)
+		// Don't overwrite original buffer
+		obfuscatedBuffer := make([]byte, len(buffer))
+		copy(obfuscatedBuffer, buffer)
+		conn.obfuscator.ObfuscateClientToServer(obfuscatedBuffer)
+		return conn.Conn.Write(obfuscatedBuffer)
 	}
 	}
 	return conn.Conn.Write(buffer)
 	return conn.Conn.Write(buffer)
 }
 }
@@ -145,6 +150,7 @@ func (conn *ObfuscatedSshConn) readServerIdentification(buffer []byte) (n int, e
 				return 0, errors.New("invalid server identity line")
 				return 0, errors.New("invalid server identity line")
 			}
 			}
 			if bytes.HasPrefix(conn.serverIdentificationBuffer, []byte("SSH-")) {
 			if bytes.HasPrefix(conn.serverIdentificationBuffer, []byte("SSH-")) {
+				log.Printf("DEBUG server version string %s", string(conn.serverIdentificationBuffer))
 				break
 				break
 			}
 			}
 		}
 		}
@@ -215,6 +221,7 @@ func (conn *ObfuscatedSshConn) updateState(buffer []byte) (err error) {
 			}
 			}
 			if payloadLength > 1 {
 			if payloadLength > 1 {
 				packetType := uint32(conn.clientMessageBuffer[PREFIX_LENGTH])
 				packetType := uint32(conn.clientMessageBuffer[PREFIX_LENGTH])
+				log.Printf("DEBUG packetType %d", packetType)
 				if packetType == SSH_MSG_NEWKEYS {
 				if packetType == SSH_MSG_NEWKEYS {
 					conn.state = OBFUSCATION_STATE_FINISHED
 					conn.state = OBFUSCATION_STATE_FINISHED
 					conn.clientMessageBuffer = nil
 					conn.clientMessageBuffer = nil