|
@@ -22,6 +22,7 @@ package psiphon
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
"crypto/md5"
|
|
"crypto/md5"
|
|
|
|
|
+ "encoding/base64"
|
|
|
"encoding/hex"
|
|
"encoding/hex"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"io"
|
|
"io"
|
|
@@ -182,38 +183,55 @@ func TestObfuscatedRemoteServerLists(t *testing.T) {
|
|
|
// run mock remote server list host
|
|
// run mock remote server list host
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
- remoteServerListHostAddress := net.JoinHostPort(serverIPaddress, "8081")
|
|
|
|
|
|
|
+ // Exercise using multiple download URLs
|
|
|
|
|
+ remoteServerListHostAddresses := []string{
|
|
|
|
|
+ net.JoinHostPort(serverIPaddress, "8081"),
|
|
|
|
|
+ net.JoinHostPort(serverIPaddress, "8082"),
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// The common remote server list fetches will 404
|
|
// The common remote server list fetches will 404
|
|
|
- remoteServerListURL := fmt.Sprintf("http://%s/server_list_compressed", remoteServerListHostAddress)
|
|
|
|
|
|
|
+ remoteServerListURL := fmt.Sprintf("http://%s/server_list_compressed", remoteServerListHostAddresses[0])
|
|
|
remoteServerListDownloadFilename := filepath.Join(testDataDirName, "server_list_compressed")
|
|
remoteServerListDownloadFilename := filepath.Join(testDataDirName, "server_list_compressed")
|
|
|
|
|
|
|
|
- obfuscatedServerListRootURL := fmt.Sprintf("http://%s/", remoteServerListHostAddress)
|
|
|
|
|
- obfuscatedServerListDownloadDirectory := testDataDirName
|
|
|
|
|
|
|
+ obfuscatedServerListRootURLsJSONConfig := "["
|
|
|
|
|
+ obfuscatedServerListRootURLs := make([]string, len(remoteServerListHostAddresses))
|
|
|
|
|
+ for i := 0; i < len(remoteServerListHostAddresses); i++ {
|
|
|
|
|
|
|
|
- go func() {
|
|
|
|
|
- startTime := time.Now()
|
|
|
|
|
- serveMux := http.NewServeMux()
|
|
|
|
|
- for _, paveFile := range paveFiles {
|
|
|
|
|
- file := paveFile
|
|
|
|
|
- serveMux.HandleFunc("/"+file.Name, func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
- md5sum := md5.Sum(file.Contents)
|
|
|
|
|
- w.Header().Add("Content-Type", "application/octet-stream")
|
|
|
|
|
- w.Header().Add("ETag", hex.EncodeToString(md5sum[:]))
|
|
|
|
|
- http.ServeContent(w, req, file.Name, startTime, bytes.NewReader(file.Contents))
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- httpServer := &http.Server{
|
|
|
|
|
- Addr: remoteServerListHostAddress,
|
|
|
|
|
- Handler: serveMux,
|
|
|
|
|
- }
|
|
|
|
|
- err := httpServer.ListenAndServe()
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- // TODO: wrong goroutine for t.FatalNow()
|
|
|
|
|
- t.Fatalf("error running remote server list host: %s", err)
|
|
|
|
|
|
|
+ obfuscatedServerListRootURLs[i] = fmt.Sprintf("http://%s/", remoteServerListHostAddresses[i])
|
|
|
|
|
|
|
|
|
|
+ obfuscatedServerListRootURLsJSONConfig += fmt.Sprintf(
|
|
|
|
|
+ "{\"URL\" : \"%s\"}", base64.StdEncoding.EncodeToString([]byte(obfuscatedServerListRootURLs[i])))
|
|
|
|
|
+ if i == len(remoteServerListHostAddresses)-1 {
|
|
|
|
|
+ obfuscatedServerListRootURLsJSONConfig += "]"
|
|
|
|
|
+ } else {
|
|
|
|
|
+ obfuscatedServerListRootURLsJSONConfig += ","
|
|
|
}
|
|
}
|
|
|
- }()
|
|
|
|
|
|
|
+
|
|
|
|
|
+ go func(remoteServerListHostAddress string) {
|
|
|
|
|
+ startTime := time.Now()
|
|
|
|
|
+ serveMux := http.NewServeMux()
|
|
|
|
|
+ for _, paveFile := range paveFiles {
|
|
|
|
|
+ file := paveFile
|
|
|
|
|
+ serveMux.HandleFunc("/"+file.Name, func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
+ md5sum := md5.Sum(file.Contents)
|
|
|
|
|
+ w.Header().Add("Content-Type", "application/octet-stream")
|
|
|
|
|
+ w.Header().Add("ETag", hex.EncodeToString(md5sum[:]))
|
|
|
|
|
+ http.ServeContent(w, req, file.Name, startTime, bytes.NewReader(file.Contents))
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ httpServer := &http.Server{
|
|
|
|
|
+ Addr: remoteServerListHostAddress,
|
|
|
|
|
+ Handler: serveMux,
|
|
|
|
|
+ }
|
|
|
|
|
+ err := httpServer.ListenAndServe()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ // TODO: wrong goroutine for t.FatalNow()
|
|
|
|
|
+ t.Fatalf("error running remote server list host: %s", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ }(remoteServerListHostAddresses[i])
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ obfuscatedServerListDownloadDirectory := testDataDirName
|
|
|
|
|
|
|
|
//
|
|
//
|
|
|
// run Psiphon server
|
|
// run Psiphon server
|
|
@@ -264,7 +282,7 @@ func TestObfuscatedRemoteServerLists(t *testing.T) {
|
|
|
defer waitGroup.Done()
|
|
defer waitGroup.Done()
|
|
|
io.Copy(remoteConn, localConn)
|
|
io.Copy(remoteConn, localConn)
|
|
|
}()
|
|
}()
|
|
|
- if localConn.Req.Target == remoteServerListHostAddress {
|
|
|
|
|
|
|
+ if common.Contains(remoteServerListHostAddresses, localConn.Req.Target) {
|
|
|
io.CopyN(localConn, remoteConn, 500)
|
|
io.CopyN(localConn, remoteConn, 500)
|
|
|
} else {
|
|
} else {
|
|
|
io.Copy(localConn, remoteConn)
|
|
io.Copy(localConn, remoteConn)
|
|
@@ -295,7 +313,7 @@ func TestObfuscatedRemoteServerLists(t *testing.T) {
|
|
|
"RemoteServerListSignaturePublicKey" : "%s",
|
|
"RemoteServerListSignaturePublicKey" : "%s",
|
|
|
"RemoteServerListUrl" : "%s",
|
|
"RemoteServerListUrl" : "%s",
|
|
|
"RemoteServerListDownloadFilename" : "%s",
|
|
"RemoteServerListDownloadFilename" : "%s",
|
|
|
- "ObfuscatedServerListRootURL" : "%s",
|
|
|
|
|
|
|
+ "ObfuscatedServerListRootURLs" : %s,
|
|
|
"ObfuscatedServerListDownloadDirectory" : "%s",
|
|
"ObfuscatedServerListDownloadDirectory" : "%s",
|
|
|
"UpstreamProxyUrl" : "%s"
|
|
"UpstreamProxyUrl" : "%s"
|
|
|
}`
|
|
}`
|
|
@@ -305,7 +323,7 @@ func TestObfuscatedRemoteServerLists(t *testing.T) {
|
|
|
signingPublicKey,
|
|
signingPublicKey,
|
|
|
remoteServerListURL,
|
|
remoteServerListURL,
|
|
|
remoteServerListDownloadFilename,
|
|
remoteServerListDownloadFilename,
|
|
|
- obfuscatedServerListRootURL,
|
|
|
|
|
|
|
+ obfuscatedServerListRootURLsJSONConfig,
|
|
|
obfuscatedServerListDownloadDirectory,
|
|
obfuscatedServerListDownloadDirectory,
|
|
|
disruptorProxyURL)
|
|
disruptorProxyURL)
|
|
|
|
|
|
|
@@ -360,7 +378,7 @@ func TestObfuscatedRemoteServerLists(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for _, paveFile := range paveFiles {
|
|
for _, paveFile := range paveFiles {
|
|
|
- u, _ := url.Parse(obfuscatedServerListRootURL)
|
|
|
|
|
|
|
+ u, _ := url.Parse(obfuscatedServerListRootURLs[0])
|
|
|
u.Path = path.Join(u.Path, paveFile.Name)
|
|
u.Path = path.Join(u.Path, paveFile.Name)
|
|
|
etag, _ := GetUrlETag(u.String())
|
|
etag, _ := GetUrlETag(u.String())
|
|
|
md5sum := md5.Sum(paveFile.Contents)
|
|
md5sum := md5.Sum(paveFile.Contents)
|