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 Aug 15, 2017
2 parents 12bec9b + 97ff95e commit 8e42913
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
17 changes: 13 additions & 4 deletions psiphon/common/authPackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,21 @@ func WriteAuthenticatedDataPackage(
// ReadAuthenticatedDataPackage extracts and verifies authenticated
// data from an AuthenticatedDataPackage. The package must have been
// signed with the given key.
//
// Set isCompressed to false to read packages that are not compressed.
func ReadAuthenticatedDataPackage(
compressedPackage []byte, signingPublicKey string) (string, error) {
dataPackage []byte, isCompressed bool, signingPublicKey string) (string, error) {

packageJSON, err := Decompress(compressedPackage)
if err != nil {
return "", ContextError(err)
var packageJSON []byte
var err error

if isCompressed {
packageJSON, err = Decompress(dataPackage)
if err != nil {
return "", ContextError(err)
}
} else {
packageJSON = dataPackage
}

var authenticatedDataPackage *AuthenticatedDataPackage
Expand Down
8 changes: 4 additions & 4 deletions psiphon/common/authPackage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestAuthenticatedPackage(t *testing.T) {

t.Run("read package: success", func(t *testing.T) {
content, err := ReadAuthenticatedDataPackage(
packagePayload, signingPublicKey)
packagePayload, true, signingPublicKey)
if err != nil {
t.Fatalf("ReadAuthenticatedDataPackage failed: %s", err)
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestAuthenticatedPackage(t *testing.T) {

t.Run("read package: wrong signing key", func(t *testing.T) {
_, err = ReadAuthenticatedDataPackage(
packagePayload, wrongSigningPublicKey)
packagePayload, true, wrongSigningPublicKey)
if err == nil {
t.Fatalf("ReadAuthenticatedDataPackage unexpectedly succeeded")
}
Expand All @@ -130,7 +130,7 @@ func TestAuthenticatedPackage(t *testing.T) {

t.Run("read package: tampered data", func(t *testing.T) {
_, err = ReadAuthenticatedDataPackage(
tamperedPackagePayload, signingPublicKey)
tamperedPackagePayload, true, signingPublicKey)
if err == nil {
t.Fatalf("ReadAuthenticatedDataPackage unexpectedly succeeded")
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func BenchmarkAuthenticatedPackage(b *testing.B) {
b.Run("read package", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := ReadAuthenticatedDataPackage(
packagePayload, signingPublicKey)
packagePayload, true, signingPublicKey)
if err != nil {
b.Fatalf("ReadAuthenticatedDataPackage failed: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions psiphon/common/osl/osl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ func UnpackRegistry(
registryPackage []byte, signingPublicKey string) (*Registry, []byte, error) {

encodedRegistry, err := common.ReadAuthenticatedDataPackage(
registryPackage, signingPublicKey)
registryPackage, true, signingPublicKey)
if err != nil {
return nil, nil, common.ContextError(err)
}
Expand Down Expand Up @@ -1278,7 +1278,7 @@ func (registry *Registry) UnpackOSL(
}

oslPayload, err := common.ReadAuthenticatedDataPackage(
dataPackage, signingPublicKey)
dataPackage, true, signingPublicKey)
if err != nil {
return "", common.ContextError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion psiphon/splitTunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (classifier *SplitTunnelClassifier) getRoutes(tunnel *Tunnel) (routesData [
var encodedRoutesData string
if !useCachedRoutes {
encodedRoutesData, err = common.ReadAuthenticatedDataPackage(
routesDataPackage, classifier.routesSignaturePublicKey)
routesDataPackage, false, classifier.routesSignaturePublicKey)
if err != nil {
NoticeAlert("failed to read split tunnel routes package: %s", common.ContextError(err))
useCachedRoutes = true
Expand Down

0 comments on commit 8e42913

Please sign in to comment.