Skip to content

Commit

Permalink
Merge branch 'master' into staging-client
Browse files Browse the repository at this point in the history
  • Loading branch information
rod-hynes committed May 7, 2018
2 parents af55278 + 75ee037 commit a7a8983
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
5 changes: 3 additions & 2 deletions psiphon/common/tactics/tactics.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const (
SPEED_TEST_PADDING_MIN_SIZE = 0
SPEED_TEST_PADDING_MAX_SIZE = 256
TACTICS_PADDING_MAX_SIZE = 256
TACTICS_OBFUSCATED_KEY_SIZE = 32
SPEED_TEST_SAMPLES_PARAMETER_NAME = "speed_test_samples"
APPLIED_TACTICS_TAG_PARAMETER_NAME = "applied_tactics_tag"
STORED_TACTICS_TAG_PARAMETER_NAME = "stored_tactics_tag"
Expand Down Expand Up @@ -398,7 +399,7 @@ func GenerateKeys() (encodedRequestPublicKey, encodedRequestPrivateKey, encodedO
return "", "", "", common.ContextError(err)
}

obfuscatedKey, err := common.MakeSecureRandomBytes(common.OBFUSCATE_KEY_LENGTH)
obfuscatedKey, err := common.MakeSecureRandomBytes(TACTICS_OBFUSCATED_KEY_SIZE)
if err != nil {
return "", "", "", common.ContextError(err)
}
Expand Down Expand Up @@ -475,7 +476,7 @@ func (server *Server) Validate() error {
} else {
if len(server.RequestPublicKey) != 32 ||
len(server.RequestPrivateKey) != 32 ||
len(server.RequestObfuscatedKey) != common.OBFUSCATE_KEY_LENGTH {
len(server.RequestObfuscatedKey) != TACTICS_OBFUSCATED_KEY_SIZE {
return common.ContextError(errors.New("invalid request key"))
}
}
Expand Down
1 change: 0 additions & 1 deletion psiphon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,6 @@ func (controller *Controller) getTactics(done chan struct{}) {
case <-controller.establishCtx.Done():
return
case <-tacticsRetryDelay.C:
default:
}

tacticsRetryDelay.Stop()
Expand Down
35 changes: 19 additions & 16 deletions psiphon/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,22 @@ func controllerRun(t *testing.T, runConfig *controllerRunConfig) {
modifyConfig["DataStoreDirectory"] = testDataDirName
modifyConfig["RemoteServerListDownloadFilename"] = filepath.Join(testDataDirName, "server_list_compressed")
modifyConfig["UpgradeDownloadFilename"] = filepath.Join(testDataDirName, "upgrade")

if runConfig.protocol != "" {
modifyConfig["TunnelProtocols"] = protocol.TunnelProtocols{runConfig.protocol}
}

// Override client retry throttle values to speed up automated
// tests and ensure tests complete within fixed deadlines.
modifyConfig["FetchRemoteServerListRetryPeriodMilliseconds"] = 250
modifyConfig["FetchUpgradeRetryPeriodMilliseconds"] = 250
modifyConfig["EstablishTunnelPausePeriodSeconds"] = 1

if runConfig.disableUntunneledUpgrade {
// Disable untunneled upgrade downloader to ensure tunneled case is tested
modifyConfig["UpgradeDownloadClientVersionHeader"] = "invalid-value"
}

configJSON, _ = json.Marshal(modifyConfig)

config, err := LoadConfig(configJSON)
Expand Down Expand Up @@ -492,31 +508,17 @@ func controllerRun(t *testing.T, runConfig *controllerRunConfig) {
// that the tactics request succeeds.
config.NetworkIDGetter = &testNetworkGetter{}

// The following config values must be applied through client parameters
// (setting the fields in Config directly will have no effect since the
// client parameters have been populated by LoadConfig).
// The following values can only be applied through client parameters.
// TODO: a successful tactics request can reset these parameters.

applyParameters := make(map[string]interface{})

if runConfig.disableUntunneledUpgrade {
// Disable untunneled upgrade downloader to ensure tunneled case is tested
applyParameters[parameters.UpgradeDownloadClientVersionHeader] = ""
}

if runConfig.transformHostNames {
applyParameters[parameters.TransformHostNameProbability] = 1.0
} else {
applyParameters[parameters.TransformHostNameProbability] = 0.0
}

// Override client retry throttle values to speed up automated
// tests and ensure tests complete within fixed deadlines.
applyParameters[parameters.FetchRemoteServerListRetryPeriod] = "250ms"
applyParameters[parameters.FetchUpgradeRetryPeriod] = "250ms"
applyParameters[parameters.EstablishTunnelPausePeriod] = "250ms"

applyParameters[parameters.LimitTunnelProtocols] = protocol.TunnelProtocols{runConfig.protocol}

err = config.SetClientParameters("", true, applyParameters)
if err != nil {
t.Fatalf("SetClientParameters failed: %s", err)
Expand Down Expand Up @@ -580,6 +582,7 @@ func controllerRun(t *testing.T, runConfig *controllerRunConfig) {
case "ConnectingServer":

serverProtocol := payload["protocol"].(string)

if runConfig.protocol != "" && serverProtocol != runConfig.protocol {
// TODO: wrong goroutine for t.FatalNow()
t.Fatalf("wrong protocol selected: %s", serverProtocol)
Expand Down
2 changes: 1 addition & 1 deletion psiphon/httpProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package psiphon
import (
"bytes"
"compress/gzip"
"crypto/tls"
"errors"
"fmt"
"io"
Expand All @@ -38,7 +39,6 @@ import (

"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/parameters"
"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/tls"
"github.com/grafov/m3u8"
)

Expand Down
32 changes: 13 additions & 19 deletions psiphon/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,18 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
localHTTPProxyPort := 8081

// Note: calling LoadConfig ensures the Config is fully initialized
clientConfigJSON := `
clientConfigJSON := fmt.Sprintf(`
{
"ClientPlatform" : "Windows",
"ClientVersion" : "0",
"SponsorId" : "0",
"PropagationChannelId" : "0",
"DisableRemoteServerListFetcher" : true,
"UseIndistinguishableTLS" : true
}`
"UseIndistinguishableTLS" : true,
"EstablishTunnelPausePeriodSeconds" : 1,
"ConnectionWorkerPoolSize" : %d,
"TunnelProtocols" : ["%s"]
}`, numTunnels, runConfig.tunnelProtocol)
clientConfig, _ := psiphon.LoadConfig([]byte(clientConfigJSON))

clientConfig.DataStoreDirectory = testDataDirName
Expand Down Expand Up @@ -582,27 +585,18 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
clientConfig.NetworkIDGetter = &testNetworkGetter{}
}

// The following config values must be applied through client parameters
// (setting the fields in Config directly will have no effect since the
// client parameters have been populated by LoadConfig).

applyParameters := make(map[string]interface{})

applyParameters[parameters.ConnectionWorkerPoolSize] = numTunnels

applyParameters[parameters.EstablishTunnelPausePeriod] = "250ms"

applyParameters[parameters.LimitTunnelProtocols] = protocol.TunnelProtocols{runConfig.tunnelProtocol}

if doTactics {
// Configure nonfunctional values that must be overridden by tactics.

applyParameters := make(map[string]interface{})

applyParameters[parameters.TunnelConnectTimeout] = "1s"
applyParameters[parameters.TunnelRateLimits] = common.RateLimits{WriteBytesPerSecond: 1}
}

err = clientConfig.SetClientParameters("", true, applyParameters)
if err != nil {
t.Fatalf("SetClientParameters failed: %s", err)
err = clientConfig.SetClientParameters("", true, applyParameters)
if err != nil {
t.Fatalf("SetClientParameters failed: %s", err)
}
}

controller, err := psiphon.NewController(clientConfig)
Expand Down

0 comments on commit a7a8983

Please sign in to comment.