Ticket #18904: 0001-Bug-18904-Mac-OS-meek-http-helper-profile-not-update.patch

File 0001-Bug-18904-Mac-OS-meek-http-helper-profile-not-update.patch, 4.6 KB (added by mcs, 3 years ago)

meek patch

  • meek-client-torbrowser/mac.go

    From 9f224abcc68834d8d72346c7446d2b8af9cd5b63 Mon Sep 17 00:00:00 2001
    From: Kathy Brade <brade@pearlcrescent.com>
    Date: Thu, 12 May 2016 11:31:40 -0400
    Subject: [PATCH] Bug 18904: Mac OS meek-http-helper profile not updated
    
    To ensure that the meek-http-helper profile is up-to-date with respect
    to the template (e.g., after Tor Browser has been updated), the
    contents of the file meek-template-sha256sum.txt within the profile
    are compared with the corresponding template file; if they differ, the
    profile is deleted and recreated.
    ---
     meek-client-torbrowser/mac.go                    |  2 +-
     meek-client-torbrowser/meek-client-torbrowser.go | 50 ++++++++++++++++++++----
     2 files changed, 44 insertions(+), 8 deletions(-)
    
    diff --git a/meek-client-torbrowser/mac.go b/meek-client-torbrowser/mac.go
    index a2be44c..de946be 100644
    a b package main 
    77
    88const (
    99        // During startup of meek-client-torbrowser, the browser profile is
    10         // created under firefoxProfilePath if it does not exist by making a
     10        // created and maintained under firefoxProfilePath by making a
    1111        // recursive copy of everything under profileTemplatePath.
    1212        firefoxPath         = "../firefox"
    1313        firefoxProfilePath  = "../../../../TorBrowser-Data/Tor/PluggableTransports/profile.meek-http-helper"
  • meek-client-torbrowser/meek-client-torbrowser.go

    diff --git a/meek-client-torbrowser/meek-client-torbrowser.go b/meek-client-torbrowser/meek-client-torbrowser.go
    index 8647d5d..a98fcb5 100644
    a b package main 
    2222
    2323import (
    2424        "bufio"
     25        "bytes"
    2526        "flag"
    2627        "fmt"
    2728        "io"
    func copyFile(srcPath string, mode os.FileMode, destPath string) error { 
    9192        return err
    9293}
    9394
    94 // Make sure that the browser profile exists. If it does not exist and if
    95 // profileTemplatePath is not empty, create it by making a recursive copy of
     95// Make sure that the browser profile exists. If profileTemplatePath is not
     96// empty, the profile is created and maintained by making a recursive copy of
    9697// all the files and directories under profileTemplatePath. A safe copy is
    9798// done by first copying the profile files into a temporary directory and
    9899// then doing an atomic rename of the temporary directory as the last step.
    99 func ensureProfileExists(profilePath string) error {
     100// To ensure that the profile is up-to-date with respect to the template
     101// (e.g., after Tor Browser has been updated), the contents of the file
     102// meek-template-sha256sum.txt within the profile are compared with the
     103// corresponding template file; if they differ, the profile is deleted and
     104// recreated.
     105func prepareBrowserProfile(profilePath string) error {
    100106        _, err := os.Stat(profilePath)
    101         if err == nil || os.IsExist(err) {
    102                 return nil      // The profile has already been created.
    103         }
     107        profileExists := err == nil || os.IsExist(err)
    104108
    105109        // If profileTemplatePath is not set, we are running on a platform that
    106110        // expects the profile to already exist.
    107111        if profileTemplatePath == "" {
     112                if profileExists {
     113                        return nil
     114                }
    108115                return err
    109116        }
    110117
     118        if profileExists {
     119                if isBrowserProfileUpToDate(profileTemplatePath, profilePath) {
     120                        return nil
     121                }
     122
     123                // Remove outdated meek helper profile.
     124                log.Printf("removing outdated profile at %s\n", profilePath)
     125                err = os.RemoveAll(profilePath)
     126                if err != nil {
     127                        return err
     128                }
     129        }
     130
    111131        log.Printf("creating profile by copying files from %s to %s\n", profileTemplatePath, profilePath)
    112132        profileParentPath := filepath.Dir(profilePath)
    113133        err = os.MkdirAll(profileParentPath, os.ModePerm)
    func ensureProfileExists(profilePath string) error { 
    160180        return os.Rename(tmpPath, profilePath)
    161181}
    162182
     183// Return true if the profile is up-to-date with the template.
     184func isBrowserProfileUpToDate(templatePath string, profilePath string) bool {
     185        checksumFileName := "meek-template-sha256sum.txt"
     186        templateChecksumPath := filepath.Join(templatePath, checksumFileName)
     187        templateData, err := ioutil.ReadFile(templateChecksumPath)
     188        if (err != nil) {
     189                return false
     190        }
     191        profileChecksumPath := filepath.Join(profilePath, checksumFileName)
     192        profileData, err := ioutil.ReadFile(profileChecksumPath)
     193        if (err != nil) {
     194                return false
     195        }
     196
     197        return bytes.Equal(templateData, profileData)
     198}
    163199
    164200// Run firefox and return its exec.Cmd and stdout pipe.
    165201func runFirefox() (cmd *exec.Cmd, stdout io.Reader, err error) {
    func runFirefox() (cmd *exec.Cmd, stdout io.Reader, err error) { 
    174210        if err != nil {
    175211                return
    176212        }
    177         err = ensureProfileExists(profilePath)
     213        err = prepareBrowserProfile(profilePath)
    178214        if err != nil {
    179215                return
    180216        }