Browse Source

Merge branch 'master' into session-ticket-protocol

Rod Hynes 9 years ago
parent
commit
e5104883c0

+ 56 - 29
MobileLibrary/iOS/build-psiphon-framework.sh

@@ -1,6 +1,12 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 
 
-set -x
+# -x echos commands. -u exits if an unintialized variable is used.
+# -e exits if a command returns an error.
+set -x -u -e
+
+# Reset the PATH to macOS default. This is mainly so we don't execute the wrong
+# gomobile executable.
+PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
 
 
 BASE_DIR=$(cd "$(dirname "$0")" ; pwd -P)
 BASE_DIR=$(cd "$(dirname "$0")" ; pwd -P)
 cd ${BASE_DIR}
 cd ${BASE_DIR}
@@ -10,7 +16,7 @@ BUILD_DIR="${BASE_DIR}/build"
 
 
 # Ensure go is installed
 # Ensure go is installed
 which go 2>&1 > /dev/null
 which go 2>&1 > /dev/null
-if [ $? -ne 0 ]; then
+if [[ $? != 0 ]]; then
   echo "Go is not installed in the path, aborting"
   echo "Go is not installed in the path, aborting"
   exit 1
   exit 1
 fi
 fi
@@ -31,16 +37,20 @@ TRUSTED_ROOT_CA_FILE=${BASE_DIR}/PsiphonTunnel/PsiphonTunnel/rootCAs.txt
 # Download trustedroot CAs off curl website, see https://curl.haxx.se/docs/caextract.html for details
 # Download trustedroot CAs off curl website, see https://curl.haxx.se/docs/caextract.html for details
 curl -o $TRUSTED_ROOT_CA_FILE https://curl.haxx.se/ca/cacert.pem
 curl -o $TRUSTED_ROOT_CA_FILE https://curl.haxx.se/ca/cacert.pem
 
 
-rc=$?; if [[ $rc != 0 ]]; then
+if [[ $? != 0 ]]; then
   echo "FAILURE: curl -o $TRUSTED_ROOT_CA_FILE https://curl.haxx.se/ca/cacert.pem"
   echo "FAILURE: curl -o $TRUSTED_ROOT_CA_FILE https://curl.haxx.se/ca/cacert.pem"
-  exit $rc
+  exit 1
 fi
 fi
 
 
-# Not exporting this breaks go commands later if run via jenkins
+# Exporting these seems necessary for subcommands to pick them up.
 export GOPATH=${PWD}/go-ios-build
 export GOPATH=${PWD}/go-ios-build
+export PATH=${GOPATH}/bin:${PATH}
+
+# The GOPATH we're using is temporary, so make sure there isn't one from a previous run.
+rm -rf ${GOPATH}
 
 
 # When updating the pinned rev, you will have to manually delete go-ios-build
 # When updating the pinned rev, you will have to manually delete go-ios-build
-GOMOBILE_PINNED_REV=aa9922ad4c79ee8a56cd45bf433f2aa943712b09
+GOMOBILE_PINNED_REV=72eef9d09307f0b437153fd152229f56edc0ab20
 GOMOBILE_PATH=${GOPATH}/src/golang.org/x/mobile/cmd/gomobile
 GOMOBILE_PATH=${GOPATH}/src/golang.org/x/mobile/cmd/gomobile
 
 
 IOS_SRC_DIR=${GOPATH}/src/github.com/Psiphon-Labs/psiphon-ios
 IOS_SRC_DIR=${GOPATH}/src/github.com/Psiphon-Labs/psiphon-ios
@@ -50,22 +60,35 @@ OPENSSL_SRC_DIR=${GOPATH}/src/github.com/Psiphon-Inc/openssl
 PATH=${PATH}:${GOPATH}/bin
 PATH=${PATH}:${GOPATH}/bin
 
 
 mkdir -p ${GOPATH}
 mkdir -p ${GOPATH}
-rc=$?; if [[ $rc != 0 ]]; then
+if [[ $? != 0 ]]; then
   echo "FAILURE: mkdir -p ${GOPATH}"
   echo "FAILURE: mkdir -p ${GOPATH}"
-  exit $rc
+  exit 1
+fi
+
+# Symlink the current source directory into GOPATH, so that we're building the
+# code in this local repo, rather than pulling from Github and building that.
+mkdir -p ${GOPATH}/src/github.com/Psiphon-Labs
+if [[ $? != 0 ]]; then
+  echo "mkdir -p ${GOPATH}/src/github.com/Psiphon-Labs"
+  exit 1
+fi
+ln -s "${BASE_DIR}/../.." "${GOPATH}/src/github.com/Psiphon-Labs/psiphon-tunnel-core"
+if [[ $? != 0 ]]; then
+  echo "ln -s ../.. ${GOPATH}/src/github.com/Psiphon-Labs/psiphon-tunnel-core"
+  exit 1
 fi
 fi
 
 
 mkdir -p ${INTERMEDIATE_OUPUT_DIR}
 mkdir -p ${INTERMEDIATE_OUPUT_DIR}
-rc=$?; if [[ $rc != 0 ]]; then
+if [[ $? != 0 ]]; then
   echo "FAILURE: mkdir -p ${INTERMEDIATE_OUPUT_DIR}"
   echo "FAILURE: mkdir -p ${INTERMEDIATE_OUPUT_DIR}"
-  exit $rc
+  exit 1
 fi
 fi
 
 
 if [ ! -e ${IOS_SRC_DIR} ]; then
 if [ ! -e ${IOS_SRC_DIR} ]; then
   echo "iOS source directory (${IOS_SRC_DIR}) not found, creating link"
   echo "iOS source directory (${IOS_SRC_DIR}) not found, creating link"
   mkdir -p $(dirname ${IOS_SRC_DIR})
   mkdir -p $(dirname ${IOS_SRC_DIR})
   ln -s $(pwd -P) $IOS_SRC_DIR
   ln -s $(pwd -P) $IOS_SRC_DIR
-  if [ $? -ne 0 ]; then
+  if [[ $? != 0 ]]; then
     echo "..Could not create symlink, aborting"
     echo "..Could not create symlink, aborting"
     exit 1
     exit 1
   fi
   fi
@@ -79,9 +102,9 @@ function strip_architectures() {
     if ! [[ "${valid_archs}" == *"$ARCH"* ]]; then
     if ! [[ "${valid_archs}" == *"$ARCH"* ]]; then
       echo "Stripping ARCH ${ARCH} from $1"
       echo "Stripping ARCH ${ARCH} from $1"
       lipo -remove "$ARCH" -output "$1" "$1"
       lipo -remove "$ARCH" -output "$1" "$1"
-      rc=$?; if [[ $rc != 0 ]]; then
+      if [[ $? != 0 ]]; then
         echo "FAILURE: lipo $1"
         echo "FAILURE: lipo $1"
-        exit $rc
+        exit 1
       fi
       fi
     fi
     fi
   done
   done
@@ -94,15 +117,16 @@ strip_architectures "${LIBSSL}"
 strip_architectures "${LIBCRYPTO}"
 strip_architectures "${LIBCRYPTO}"
 
 
 go get -d -u -v github.com/Psiphon-Inc/openssl
 go get -d -u -v github.com/Psiphon-Inc/openssl
-rc=$?; if [[ $rc != 0 ]]; then
+if [[ $? != 0 ]]; then
   echo "FAILURE: go get -d -u -v github.com/Psiphon-Inc/openssl"
   echo "FAILURE: go get -d -u -v github.com/Psiphon-Inc/openssl"
-  exit $rc
+  exit 1
 fi
 fi
 
 
-go get -d -u -v github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
-rc=$?; if [[ $rc != 0 ]]; then
-  echo "FAILURE: go get -d -u -v github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi"
-  exit $rc
+# Don't use -u, because this path points to our local repo, and we don't want it overridden.
+go get -d -v github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
+if [[ $? != 0 ]]; then
+  echo "FAILURE: go get -d -v github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi"
+  exit 1
 fi
 fi
 
 
 function check_pinned_version() {
 function check_pinned_version() {
@@ -124,17 +148,23 @@ function check_pinned_version() {
   fi
   fi
 }
 }
 
 
+set +e
 check_pinned_version
 check_pinned_version
-if [ $? -ne 0 ]; then
+rc=$?
+set -e
+if [[ rc != 0 ]]; then
     go get -u golang.org/x/mobile/cmd/gomobile
     go get -u golang.org/x/mobile/cmd/gomobile
     cd ${GOPATH}/src/golang.org/x/mobile/cmd/gomobile
     cd ${GOPATH}/src/golang.org/x/mobile/cmd/gomobile
     git checkout master
     git checkout master
-    git branch -d pinned
     git checkout -b pinned ${GOMOBILE_PINNED_REV}
     git checkout -b pinned ${GOMOBILE_PINNED_REV}
     go install
     go install
-    gomobile init -v
+    ${GOPATH}/bin/gomobile init -v
+    if [[ $? != 0 ]]; then
+      echo "FAILURE: ${GOPATH}/bin/gomobile init -v"
+      exit 1
+    fi
     check_pinned_version
     check_pinned_version
-    if [ $? -ne 0 ]; then
+    if [[ $? != 0 ]]; then
       echo "gomobile not found, aborting"
       echo "gomobile not found, aborting"
       exit 1
       exit 1
     fi
     fi
@@ -144,7 +174,7 @@ BUILDDATE=$(date +%Y-%m-%dT%H:%M:%S%z)
 BUILDREPO=$(git config --get remote.origin.url)
 BUILDREPO=$(git config --get remote.origin.url)
 BUILDREV=$(git rev-parse --short HEAD)
 BUILDREV=$(git rev-parse --short HEAD)
 GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
 GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
-GOMOBILEVERSION=$(gomobile version | perl -ne '/gomobile version (.*?) / && print $1')
+GOMOBILEVERSION=$(${GOPATH}/bin/gomobile version | perl -ne '/gomobile version (.*?) / && print $1')
 
 
 LDFLAGS="\
 LDFLAGS="\
 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildDate=${BUILDDATE} \
 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildDate=${BUILDDATE} \
@@ -164,18 +194,15 @@ echo " Gomobile version: ${GOMOBILEVERSION}"
 echo ""
 echo ""
 
 
 # Patch source files to build on Darwin
 # Patch source files to build on Darwin
-LC_ALL=C sed -i -- 's/+build android windows$/+build android windows darwin/' "${TUNNEL_CORE_SRC_DIR}/psiphon/opensslConn.go"
-LC_ALL=C sed -i -- 's/+build !android,!windows$/+build !android,!windows,!darwin/' "${TUNNEL_CORE_SRC_DIR}/psiphon/opensslConn_unsupported.go"
-
 IOS_CGO_BUILD_FLAGS='// #cgo darwin CFLAGS: -I'"${OPENSSL_INCLUDE}"'\
 IOS_CGO_BUILD_FLAGS='// #cgo darwin CFLAGS: -I'"${OPENSSL_INCLUDE}"'\
 // #cgo darwin LDFLAGS:'"${LIBSSL}"'\
 // #cgo darwin LDFLAGS:'"${LIBSSL}"'\
 // #cgo darwin LDFLAGS:'"${LIBCRYPTO}"''
 // #cgo darwin LDFLAGS:'"${LIBCRYPTO}"''
 
 
 LC_ALL=C sed -i -- "s|// #cgo pkg-config: libssl|${IOS_CGO_BUILD_FLAGS}|" "${OPENSSL_SRC_DIR}/build.go"
 LC_ALL=C sed -i -- "s|// #cgo pkg-config: libssl|${IOS_CGO_BUILD_FLAGS}|" "${OPENSSL_SRC_DIR}/build.go"
 
 
-gomobile bind -target ios -ldflags="${LDFLAGS}" -o "${INTERMEDIATE_OUPUT_DIR}/${INTERMEDIATE_OUPUT_FILE}" github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
+${GOPATH}/bin/gomobile bind -target ios -ldflags="${LDFLAGS}" -o "${INTERMEDIATE_OUPUT_DIR}/${INTERMEDIATE_OUPUT_FILE}" github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
 rc=$?; if [[ $rc != 0 ]]; then
 rc=$?; if [[ $rc != 0 ]]; then
-  echo "FAILURE: gomobile bind"
+  echo "FAILURE: ${GOPATH}/bin/gomobile bind -target ios -ldflags="${LDFLAGS}" -o "${INTERMEDIATE_OUPUT_DIR}/${INTERMEDIATE_OUPUT_FILE}" github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi"
   exit $rc
   exit $rc
 fi
 fi
 
 

+ 25 - 3
README.md

@@ -18,7 +18,7 @@ This project is in production and used as the tunneling engine in our Windows an
 Client Setup
 Client Setup
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------
 
 
-#### Build
+### Build
 
 
 * Go 1.5 (or higher) is required.
 * Go 1.5 (or higher) is required.
 * This project builds and runs on recent versions of Windows, Linux, and Mac OS X.
 * This project builds and runs on recent versions of Windows, Linux, and Mac OS X.
@@ -42,7 +42,29 @@ Client Setup
     "
     "
     ```
     ```
 
 
-#### Configure
+#### Platform-specific instructions
+
+##### macOS
+
+1. You must have [Homebrew](http://brew.sh/) installed.
+
+2. `brew install openssl pkg-config`
+
+3. Find out where Homebrew put the `pkgconfig` files for OpenSSL -- the location depends on your Homebrew installation. Run this command:
+
+   ```
+   $ brew info openssl
+   ```
+   
+   Make note of the "build variable" path for `PKG_CONFIG_PATH`.
+   
+4. Set `PKG_CONFIG_PATH=<path discovered above>` when building. This can be easily done on the build command line like so:
+
+   ```
+   $ PKG_CONFIG_PATH=<path discovered above> go build
+   ```
+
+### Configure
 
 
  * Configuration files are standard text files containing a valid JSON object. Example:
  * Configuration files are standard text files containing a valid JSON object. Example:
 
 
@@ -64,7 +86,7 @@ Client Setup
 * Replace each `<placeholder>` with a value from your Psiphon server. The Psiphon server-side stack is open source and can be found in our [Psiphon 3 repository](https://bitbucket.org/psiphon/psiphon-circumvention-system).
 * Replace each `<placeholder>` with a value from your Psiphon server. The Psiphon server-side stack is open source and can be found in our [Psiphon 3 repository](https://bitbucket.org/psiphon/psiphon-circumvention-system).
 
 
 
 
-#### Run
+### Run
 
 
 * Run `./ConsoleClient --config psiphon.config` where `psiphon.config` is created as described in the [Configure](#configure) section above
 * Run `./ConsoleClient --config psiphon.config` where `psiphon.config` is created as described in the [Configure](#configure) section above
 
 

+ 1 - 1
psiphon/opensslConn.go

@@ -1,4 +1,4 @@
-// +build android windows
+// +build android windows darwin
 
 
 /*
 /*
  * Copyright (c) 2015, Psiphon Inc.
  * Copyright (c) 2015, Psiphon Inc.

+ 1 - 1
psiphon/opensslConn_unsupported.go

@@ -1,4 +1,4 @@
-// +build !android,!windows
+// +build !android,!windows,!darwin
 
 
 /*
 /*
  * Copyright (c) 2015, Psiphon Inc.
  * Copyright (c) 2015, Psiphon Inc.