[tor-commits] [meek/master] Try deleting the registry key before exiting.

dcf at torproject.org dcf at torproject.org
Wed Aug 28 05:59:18 UTC 2019


commit f7ca0eaf83c6abb6cac41e20f7daf011a79b3fd1
Author: David Fifield <david at bamsoftware.com>
Date:   Thu Mar 7 15:46:54 2019 -0700

    Try deleting the registry key before exiting.
---
 meek-client-torbrowser/linux.go                  |  6 ++++++
 meek-client-torbrowser/mac.go                    |  6 ++++++
 meek-client-torbrowser/meek-client-torbrowser.go | 13 +++++++++++++
 meek-client-torbrowser/windows.go                | 20 +++++++++++++-------
 4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/meek-client-torbrowser/linux.go b/meek-client-torbrowser/linux.go
index f728f1d..69ee7b7 100644
--- a/meek-client-torbrowser/linux.go
+++ b/meek-client-torbrowser/linux.go
@@ -29,3 +29,9 @@ func osSpecificCommandSetup(cmd *exec.Cmd) {
 func installHelperNativeManifest() error {
 	return writeNativeManifestToFile(helperNativeManifestDir, helperNativeExecutablePath)
 }
+
+func uninstallHelperNativeManifest() error {
+	// Nothing to do here: the host manifest file is written inside the
+	// browser directory, so we assume we don't have to clean it up.
+	return nil
+}
diff --git a/meek-client-torbrowser/mac.go b/meek-client-torbrowser/mac.go
index 995aca5..918a62e 100644
--- a/meek-client-torbrowser/mac.go
+++ b/meek-client-torbrowser/mac.go
@@ -42,3 +42,9 @@ func installHelperNativeManifest() error {
 	// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#Mac_OS_X
 	return writeNativeManifestToFile(filepath.Join(homeDir, "Mozilla", "NativeMessagingHosts"), helperNativeExecutablePath)
 }
+
+func uninstallHelperNativeManifest() error {
+	// Nothing to do here: the host manifest file is written inside the
+	// browser directory, so we assume we don't have to clean it up.
+	return nil
+}
diff --git a/meek-client-torbrowser/meek-client-torbrowser.go b/meek-client-torbrowser/meek-client-torbrowser.go
index 0284280..b512b10 100644
--- a/meek-client-torbrowser/meek-client-torbrowser.go
+++ b/meek-client-torbrowser/meek-client-torbrowser.go
@@ -15,6 +15,11 @@
 // executed as given, except that a --helper option is added that points to the
 // port number read from firefox.
 //
+// On Windows, this program assumes that it has exclusive control over the
+// HKEY_CURRENT_USER\SOFTWARE\Mozilla\NativeMessagingHosts\meek.http.helper
+// registry key. It creates the key when run and tries to delete it when
+// exiting.
+//
 // This program proxies stdin and stdout to and from meek-client, so it is
 // actually meek-client that drives the pluggable transport negotiation with
 // tor.
@@ -422,6 +427,14 @@ func main() {
 		log.Print(err)
 	}
 
+	// Make a best-effort attempt to remove the registry key that points to
+	// the meek.http.helper.json file on Windows, because the registry is
+	// persistent global state.
+	err = uninstallHelperNativeManifest()
+	if err != nil {
+		log.Printf("uninstalling native host manifest: %v", err)
+	}
+
 	var wg sync.WaitGroup
 	if firefoxCmd != nil {
 		wg.Add(1)
diff --git a/meek-client-torbrowser/windows.go b/meek-client-torbrowser/windows.go
index 907d1dc..d96a02d 100644
--- a/meek-client-torbrowser/windows.go
+++ b/meek-client-torbrowser/windows.go
@@ -22,6 +22,7 @@ const (
 	// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#Windows
 	helperNativeManifestDir    = "TorBrowser/Data/Browser/.mozilla/native-messaging-hosts"
 	helperNativeExecutablePath = "TorBrowser/Tor/PluggableTransports/meek-http-helper.exe"
+	registryKey                = `SOFTWARE\Mozilla\NativeMessagingHosts\` + nativeAppName
 )
 
 func osSpecificCommandSetup(cmd *exec.Cmd) {
@@ -39,16 +40,21 @@ func installHelperNativeManifest() error {
 		return err
 	}
 
-	// TODO: Find a way to do this without having to write to the registry.
-	// https://bugs.torproject.org/29347#comment:9
+	// On Windows we must set a registry key pointing to the host manifest.
+	// We'll attempt to delete the key in uninstallHelperNativeManifest.
 	// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#Windows
-	k, _, err := registry.CreateKey(
-		registry.CURRENT_USER,
-		`SOFTWARE\Mozilla\NativeMessagingHosts\`+nativeAppName,
-		registry.WRITE,
-	)
+	k, _, err := registry.CreateKey(registry.CURRENT_USER, registryKey, registry.WRITE)
 	if err != nil {
 		return err
 	}
 	return k.SetStringValue("", absManifestPath)
 }
+
+func uninstallHelperNativeManifest() error {
+	// Delete the registry key pointing to the host manifest. We don't
+	// delete any higher up the tree; e.g. an empty
+	// HKEY_CURRENT_USER\SOFTWARE\Mozilla\NativeMessagingHosts will remain
+	// even if it was not present before installHelperNativeManifest was
+	// called.
+	return registry.DeleteKey(registry.CURRENT_USER, registryKey)
+}





More information about the tor-commits mailing list