Przeglądaj źródła

Add support for UNFRONTED-MEEK-HTTPS

Rod Hynes 10 lat temu
rodzic
commit
2cbac80013
3 zmienionych plików z 37 dodań i 23 usunięć
  1. 23 18
      psiphon/meekConn.go
  2. 6 4
      psiphon/serverEntry.go
  3. 8 1
      psiphon/tunnel.go

+ 23 - 18
psiphon/meekConn.go

@@ -103,9 +103,11 @@ type transporter interface {
 // is spawned which will eventually start HTTP polling.
 // is spawned which will eventually start HTTP polling.
 // When frontingAddress is not "", fronting is used. This option assumes caller has
 // When frontingAddress is not "", fronting is used. This option assumes caller has
 // already checked server entry capabilities.
 // already checked server entry capabilities.
+// Fronting always uses HTTPS. Otherwise, HTTPS is optional.
 func DialMeek(
 func DialMeek(
 	serverEntry *ServerEntry, sessionId string,
 	serverEntry *ServerEntry, sessionId string,
-	frontingAddress string, config *DialConfig) (meek *MeekConn, err error) {
+	useHttps bool, frontingAddress string,
+	config *DialConfig) (meek *MeekConn, err error) {
 
 
 	// Configure transport
 	// Configure transport
 	// Note: MeekConn has its own PendingConns to manage the underlying HTTP transport connections,
 	// Note: MeekConn has its own PendingConns to manage the underlying HTTP transport connections,
@@ -119,14 +121,12 @@ func DialMeek(
 	*meekConfig = *config
 	*meekConfig = *config
 	meekConfig.PendingConns = pendingConns
 	meekConfig.PendingConns = pendingConns
 
 
-	var host string
+	// host is both what is dialed and what ends up in the HTTP Host header
+	host := fmt.Sprintf("%s:%d", serverEntry.IpAddress, serverEntry.MeekServerPort)
 	var dialer Dialer
 	var dialer Dialer
 	var proxyUrl func(*http.Request) (*url.URL, error)
 	var proxyUrl func(*http.Request) (*url.URL, error)
 
 
-	if frontingAddress != "" {
-		// In this case, host is not what is dialed but is what ends up in the HTTP Host header
-		host = serverEntry.MeekFrontingHost
-
+	if useHttps || frontingAddress != "" {
 		// Custom TLS dialer:
 		// Custom TLS dialer:
 		//
 		//
 		//  1. ignores the HTTP request address and uses the fronting domain
 		//  1. ignores the HTTP request address and uses the fronting domain
@@ -160,19 +160,24 @@ func DialMeek(
 		// exclusively connect to non-MiM CDNs); then the adversary kills the underlying TCP connection after
 		// exclusively connect to non-MiM CDNs); then the adversary kills the underlying TCP connection after
 		// some short period. This is mitigated by the "impaired" protocol classification mechanism.
 		// some short period. This is mitigated by the "impaired" protocol classification mechanism.
 
 
-		dialer = NewCustomTLSDialer(
-			&CustomTLSConfig{
-				Dial:                          NewTCPDialer(meekConfig),
-				Timeout:                       meekConfig.ConnectTimeout,
-				FrontingAddr:                  fmt.Sprintf("%s:%d", frontingAddress, 443),
-				SendServerName:                false,
-				SkipVerify:                    true,
-				UseIndistinguishableTLS:       config.UseIndistinguishableTLS,
-				TrustedCACertificatesFilename: config.TrustedCACertificatesFilename,
-			})
+		customTLSConfig := &CustomTLSConfig{
+			Dial:                          NewTCPDialer(meekConfig),
+			Timeout:                       meekConfig.ConnectTimeout,
+			SendServerName:                false,
+			SkipVerify:                    true,
+			UseIndistinguishableTLS:       config.UseIndistinguishableTLS,
+			TrustedCACertificatesFilename: config.TrustedCACertificatesFilename,
+		}
+
+		if frontingAddress != "" {
+			// In this case, host is not what is dialed but is what ends up in the HTTP Host header
+			host = serverEntry.MeekFrontingHost
+			customTLSConfig.FrontingAddr = fmt.Sprintf("%s:%d", frontingAddress, 443)
+		}
+
+		dialer = NewCustomTLSDialer(customTLSConfig)
+
 	} else {
 	} else {
-		// In the unfronted case, host is both what is dialed and what ends up in the HTTP Host header
-		host = fmt.Sprintf("%s:%d", serverEntry.IpAddress, serverEntry.MeekServerPort)
 
 
 		if strings.HasPrefix(meekConfig.UpstreamProxyUrl, "http://") {
 		if strings.HasPrefix(meekConfig.UpstreamProxyUrl, "http://") {
 			// For unfronted meek, we let the http.Transport handle proxying, as the
 			// For unfronted meek, we let the http.Transport handle proxying, as the

+ 6 - 4
psiphon/serverEntry.go

@@ -30,15 +30,17 @@ import (
 )
 )
 
 
 const (
 const (
-	TUNNEL_PROTOCOL_SSH            = "SSH"
-	TUNNEL_PROTOCOL_OBFUSCATED_SSH = "OSSH"
-	TUNNEL_PROTOCOL_UNFRONTED_MEEK = "UNFRONTED-MEEK-OSSH"
-	TUNNEL_PROTOCOL_FRONTED_MEEK   = "FRONTED-MEEK-OSSH"
+	TUNNEL_PROTOCOL_SSH                  = "SSH"
+	TUNNEL_PROTOCOL_OBFUSCATED_SSH       = "OSSH"
+	TUNNEL_PROTOCOL_UNFRONTED_MEEK       = "UNFRONTED-MEEK-OSSH"
+	TUNNEL_PROTOCOL_UNFRONTED_MEEK_HTTPS = "UNFRONTED-MEEK-HTTPS-OSSH"
+	TUNNEL_PROTOCOL_FRONTED_MEEK         = "FRONTED-MEEK-OSSH"
 )
 )
 
 
 var SupportedTunnelProtocols = []string{
 var SupportedTunnelProtocols = []string{
 	TUNNEL_PROTOCOL_FRONTED_MEEK,
 	TUNNEL_PROTOCOL_FRONTED_MEEK,
 	TUNNEL_PROTOCOL_UNFRONTED_MEEK,
 	TUNNEL_PROTOCOL_UNFRONTED_MEEK,
+	TUNNEL_PROTOCOL_UNFRONTED_MEEK_HTTPS,
 	TUNNEL_PROTOCOL_OBFUSCATED_SSH,
 	TUNNEL_PROTOCOL_OBFUSCATED_SSH,
 	TUNNEL_PROTOCOL_SSH,
 	TUNNEL_PROTOCOL_SSH,
 }
 }

+ 8 - 1
psiphon/tunnel.go

@@ -343,17 +343,24 @@ func dialSsh(
 	// So depending on which protocol is used, multiple layers are initialized.
 	// So depending on which protocol is used, multiple layers are initialized.
 	port := 0
 	port := 0
 	useMeek := false
 	useMeek := false
+	useMeekHttps := false
 	useFronting := false
 	useFronting := false
 	useObfuscatedSsh := false
 	useObfuscatedSsh := false
 	switch selectedProtocol {
 	switch selectedProtocol {
 	case TUNNEL_PROTOCOL_FRONTED_MEEK:
 	case TUNNEL_PROTOCOL_FRONTED_MEEK:
 		useMeek = true
 		useMeek = true
+		useMeekHttps = true
 		useFronting = true
 		useFronting = true
 		useObfuscatedSsh = true
 		useObfuscatedSsh = true
 	case TUNNEL_PROTOCOL_UNFRONTED_MEEK:
 	case TUNNEL_PROTOCOL_UNFRONTED_MEEK:
 		useMeek = true
 		useMeek = true
 		useObfuscatedSsh = true
 		useObfuscatedSsh = true
 		port = serverEntry.SshObfuscatedPort
 		port = serverEntry.SshObfuscatedPort
+	case TUNNEL_PROTOCOL_UNFRONTED_MEEK_HTTPS:
+		useMeek = true
+		useMeekHttps = true
+		useObfuscatedSsh = true
+		port = serverEntry.SshObfuscatedPort
 	case TUNNEL_PROTOCOL_OBFUSCATED_SSH:
 	case TUNNEL_PROTOCOL_OBFUSCATED_SSH:
 		useObfuscatedSsh = true
 		useObfuscatedSsh = true
 		port = serverEntry.SshObfuscatedPort
 		port = serverEntry.SshObfuscatedPort
@@ -403,7 +410,7 @@ func dialSsh(
 		TrustedCACertificatesFilename: config.TrustedCACertificatesFilename,
 		TrustedCACertificatesFilename: config.TrustedCACertificatesFilename,
 	}
 	}
 	if useMeek {
 	if useMeek {
-		conn, err = DialMeek(serverEntry, sessionId, frontingAddress, dialConfig)
+		conn, err = DialMeek(serverEntry, sessionId, useMeekHttps, frontingAddress, dialConfig)
 		if err != nil {
 		if err != nil {
 			return nil, nil, ContextError(err)
 			return nil, nil, ContextError(err)
 		}
 		}