Browse Source

Merge branch 'master' of https://github.com/Psiphon-Labs/psiphon-tunnel-core

Rod Hynes 11 years ago
parent
commit
d7b34d297f
1 changed files with 13 additions and 3 deletions
  1. 13 3
      psiphon/meekConn.go

+ 13 - 3
psiphon/meekConn.go

@@ -43,7 +43,7 @@ import (
 // https://bitbucket.org/psiphon/psiphon-circumvention-system/src/default/go/meek-client/meek-client.go
 
 const (
-	MEEK_PROTOCOL_VERSION      = 1
+	MEEK_PROTOCOL_VERSION      = 2
 	MEEK_COOKIE_MAX_PADDING    = 32
 	MAX_SEND_PAYLOAD_LENGTH    = 65536
 	FULL_RECEIVE_BUFFER_LENGTH = 4194304
@@ -434,6 +434,14 @@ func (meek *MeekConn) roundTrip(sendPayload []byte) (receivedPayload io.ReadClos
 	if response.StatusCode != http.StatusOK {
 		return nil, ContextError(fmt.Errorf("http request failed %d", response.StatusCode))
 	}
+        // observe response cookies for meek session key token.
+        // Once found it must be used for all consecutive requests made to the server
+        for _, c := range response.Cookies() {
+            if meek.cookie.Name == c.Name {
+                meek.cookie.Value = c.Value
+                break
+            }
+        }
 	return response.Body, nil
 }
 
@@ -443,14 +451,16 @@ type meekCookieData struct {
 	MeekProtocolVersion int    `json:"v"`
 }
 
-// makeCookie creates the cookie to be sent with all meek HTTP requests.
+// makeCookie creates the cookie to be sent with initial meek HTTP request.
 // The purpose of the cookie is to send the following to the server:
 //   ServerAddress -- the Psiphon Server address the meek server should relay to
 //   SessionID -- the Psiphon session ID (used by meek server to relay geolocation
 //     information obtained from the CDN through to the Psiphon Server)
 //   MeekProtocolVersion -- tells the meek server that this client understands
 //     the latest protocol.
-// The entire cookie also acts as an meek/HTTP session ID.
+// The server will create a session using these values and send the session ID
+// back to the client via Set-Cookie header. Client must use that value with
+// all consequent HTTP requests
 // In unfronted meek mode, the cookie is visible over the adversary network, so the
 // cookie is encrypted and obfuscated.
 func makeCookie(serverEntry *ServerEntry, sessionId string) (cookie *http.Cookie, err error) {