namecoin.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. From eb837a4888ab4e0fa91931f49a927e7af0254367 Mon Sep 17 00:00:00 2001
  2. From: Jeremy Rand <jeremyrand@airmail.cc>
  3. Date: Tue, 4 Aug 2020 02:42:00 +0000
  4. Subject: [PATCH 1/2] Launch Namecoin on Linux
  5. ---
  6. src/components/tl-process.js | 60 ++++++++++++++++++++++++++++++++++--
  7. src/modules/tl-util.jsm | 8 +++++
  8. 2 files changed, 66 insertions(+), 2 deletions(-)
  9. diff --git a/src/components/tl-process.js b/src/components/tl-process.js
  10. index e9d7cde..510cbaf 100644
  11. --- a/src/components/tl-process.js
  12. +++ b/src/components/tl-process.js
  13. @@ -393,11 +393,30 @@ TorProcessService.prototype =
  14. var torrcFile = TorLauncherUtil.getTorFile("torrc", true);
  15. var torrcDefaultsFile =
  16. TorLauncherUtil.getTorFile("torrc-defaults", false);
  17. + var electrumNMCFile = null;
  18. + var stemNSFile = null;
  19. var hashedPassword = this.mProtocolSvc.TorGetPassword(true);
  20. var controlIPCFile = this.mProtocolSvc.TorGetControlIPCFile();
  21. var controlPort = this.mProtocolSvc.TorGetControlPort();
  22. var socksPortInfo = this.mProtocolSvc.TorGetSOCKSPortInfo();
  23. + let env = Cc["@mozilla.org/process/environment;1"]
  24. + .getService(Ci.nsIEnvironment);
  25. +
  26. + var enableNamecoin = false;
  27. + if (env.exists("TOR_ENABLE_NAMECOIN"))
  28. + enableNamecoin = env.get("TOR_ENABLE_NAMECOIN") == "1";
  29. +
  30. + var verboseNamecoin = false;
  31. + if (enableNamecoin)
  32. + {
  33. + if (env.exists("TOR_VERBOSE_NAMECOIN"))
  34. + verboseNamecoin = env.get("TOR_VERBOSE_NAMECOIN") == "1";
  35. +
  36. + electrumNMCFile = TorLauncherUtil.getTorFile("electrum-nmc", false);
  37. + stemNSFile = TorLauncherUtil.getTorFile("stemns", false);
  38. + }
  39. +
  40. var detailsKey;
  41. if (!exeFile)
  42. detailsKey = "tor_missing";
  43. @@ -407,11 +426,16 @@ TorProcessService.prototype =
  44. detailsKey = "datadir_missing";
  45. else if (!onionAuthDir)
  46. detailsKey = "onionauthdir_missing";
  47. + else if (!electrumNMCFile && enableNamecoin)
  48. + detailsKey = "electrum_nmc_missing";
  49. + else if (!stemNSFile && enableNamecoin)
  50. + detailsKey = "stemns_missing";
  51. else if (!hashedPassword)
  52. detailsKey = "password_hash_missing";
  53. if (detailsKey)
  54. {
  55. + // TODO: add strings for Electrum-NMC and StemNS
  56. var details = TorLauncherUtil.getLocalizedString(detailsKey);
  57. var key = "unable_to_start_tor";
  58. var err = TorLauncherUtil.getFormattedLocalizedString(key,
  59. @@ -517,11 +541,15 @@ TorProcessService.prototype =
  60. args.push("1");
  61. }
  62. + if (enableNamecoin)
  63. + {
  64. + args.push("__LeaveStreamsUnattached");
  65. + args.push("1");
  66. + }
  67. +
  68. // Set an environment variable that points to the Tor data directory.
  69. // This is used by meek-client-torbrowser to find the location for
  70. // the meek browser profile.
  71. - let env = Cc["@mozilla.org/process/environment;1"]
  72. - .getService(Ci.nsIEnvironment);
  73. env.set("TOR_BROWSER_TOR_DATA_DIR", dataDir.path);
  74. // On Windows, prepend the Tor program directory to PATH. This is
  75. @@ -547,6 +575,34 @@ TorProcessService.prototype =
  76. p.runwAsync(args, args.length, this, false);
  77. this.mTorProcess = p;
  78. this.mTorProcessStartTime = Date.now();
  79. +
  80. + if (enableNamecoin)
  81. + {
  82. + args = [];
  83. + args.push("daemon");
  84. + if (verboseNamecoin)
  85. + args.push("-v");
  86. + args.push("--dir");
  87. + args.push("TorBrowser/Data/Electrum-NMC/");
  88. +
  89. + p = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
  90. + p.init(electrumNMCFile);
  91. +
  92. + TorLauncherLogger.log(2, "Starting " + electrumNMCFile.path);
  93. + for (var i = 0; i < args.length; ++i)
  94. + TorLauncherLogger.log(2, " " + args[i]);
  95. +
  96. + p.runwAsync(args, args.length, this, false);
  97. +
  98. + args = [];
  99. +
  100. + p = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
  101. + p.init(stemNSFile);
  102. +
  103. + TorLauncherLogger.log(2, "Starting " + stemNSFile.path);
  104. +
  105. + p.runwAsync(args, args.length, this, false);
  106. + }
  107. }
  108. catch (e)
  109. {
  110. diff --git a/src/modules/tl-util.jsm b/src/modules/tl-util.jsm
  111. index b721372..ad56752 100644
  112. --- a/src/modules/tl-util.jsm
  113. +++ b/src/modules/tl-util.jsm
  114. @@ -613,6 +613,10 @@ let TorLauncherUtil = // Public
  115. path = "Tor/PluggableTransports";
  116. else if (isIPC)
  117. path = "Tor/" + ipcFileName;
  118. + else if ("electrum-nmc" == aTorFileType)
  119. + path = "TorBrowser/Electrum-NMC/run_electrum_nmc";
  120. + else if ("stemns" == aTorFileType)
  121. + path = "TorBrowser/StemNS/poc.py";
  122. }
  123. }
  124. else if (this.isWindows)
  125. @@ -652,6 +656,10 @@ let TorLauncherUtil = // Public
  126. path = "Data/Browser";
  127. else if (isIPC)
  128. path = "Data/Tor/" + ipcFileName;
  129. + else if ("electrum-nmc" == aTorFileType)
  130. + path = "Electrum-NMC/run_electrum_nmc";
  131. + else if ("stemns" == aTorFileType)
  132. + path = "StemNS/poc.py";
  133. }
  134. if (!path && !useAppDir)
  135. --
  136. 2.20.1
  137. From b65d5e8b5256d2f6ae41f248dc95048d43336c43 Mon Sep 17 00:00:00 2001
  138. From: Jeremy Rand <jeremyrand@airmail.cc>
  139. Date: Wed, 19 Aug 2020 05:19:19 +0000
  140. Subject: [PATCH 2/2] Launch Namecoin on Windows
  141. ---
  142. src/components/tl-process.js | 17 +++++++++++
  143. src/modules/tl-util.jsm | 56 ++++++++++++++++++++++++++++++++++++
  144. 2 files changed, 73 insertions(+)
  145. diff --git a/src/components/tl-process.js b/src/components/tl-process.js
  146. index 510cbaf..75d8b4e 100644
  147. --- a/src/components/tl-process.js
  148. +++ b/src/components/tl-process.js
  149. @@ -395,6 +395,7 @@ TorProcessService.prototype =
  150. TorLauncherUtil.getTorFile("torrc-defaults", false);
  151. var electrumNMCFile = null;
  152. var stemNSFile = null;
  153. + var pythonFile = null;
  154. var hashedPassword = this.mProtocolSvc.TorGetPassword(true);
  155. var controlIPCFile = this.mProtocolSvc.TorGetControlIPCFile();
  156. var controlPort = this.mProtocolSvc.TorGetControlPort();
  157. @@ -415,6 +416,8 @@ TorProcessService.prototype =
  158. electrumNMCFile = TorLauncherUtil.getTorFile("electrum-nmc", false);
  159. stemNSFile = TorLauncherUtil.getTorFile("stemns", false);
  160. + if (TorLauncherUtil.isWindows)
  161. + pythonFile = TorLauncherUtil.getTorFile("python", false);
  162. }
  163. var detailsKey;
  164. @@ -430,6 +433,8 @@ TorProcessService.prototype =
  165. detailsKey = "electrum_nmc_missing";
  166. else if (!stemNSFile && enableNamecoin)
  167. detailsKey = "stemns_missing";
  168. + else if (!pythonFile && enableNamecoin && TorLauncherUtil.isWindows)
  169. + detailsKey = "python_missing";
  170. else if (!hashedPassword)
  171. detailsKey = "password_hash_missing";
  172. @@ -579,6 +584,11 @@ TorProcessService.prototype =
  173. if (enableNamecoin)
  174. {
  175. args = [];
  176. + if (TorLauncherUtil.isWindows)
  177. + {
  178. + args.push(electrumNMCFile.path);
  179. + electrumNMCFile = pythonFile;
  180. + }
  181. args.push("daemon");
  182. if (verboseNamecoin)
  183. args.push("-v");
  184. @@ -595,11 +605,18 @@ TorProcessService.prototype =
  185. p.runwAsync(args, args.length, this, false);
  186. args = [];
  187. + if (TorLauncherUtil.isWindows)
  188. + {
  189. + args.push(stemNSFile.path);
  190. + stemNSFile = pythonFile;
  191. + }
  192. p = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
  193. p.init(stemNSFile);
  194. TorLauncherLogger.log(2, "Starting " + stemNSFile.path);
  195. + for (var i = 0; i < args.length; ++i)
  196. + TorLauncherLogger.log(2, " " + args[i]);
  197. p.runwAsync(args, args.length, this, false);
  198. }
  199. diff --git a/src/modules/tl-util.jsm b/src/modules/tl-util.jsm
  200. index ad56752..f2971e8 100644
  201. --- a/src/modules/tl-util.jsm
  202. +++ b/src/modules/tl-util.jsm
  203. @@ -554,6 +554,12 @@ let TorLauncherUtil = // Public
  204. if (!path && !torFile)
  205. {
  206. + let env = Cc["@mozilla.org/process/environment;1"]
  207. + .getService(Ci.nsIEnvironment);
  208. + var verboseNamecoin = false;
  209. + if (env.exists("TOR_VERBOSE_NAMECOIN"))
  210. + verboseNamecoin = env.get("TOR_VERBOSE_NAMECOIN") == "1";
  211. +
  212. // No preference and no pre-determined IPC path: use a default path.
  213. isRelativePath = true;
  214. if (TLUtilInternal._isUserDataOutsideOfAppDir)
  215. @@ -575,6 +581,14 @@ let TorLauncherUtil = // Public
  216. path = "Tor\\onion-auth";
  217. else if ("pt-profiles-dir" == aTorFileType)
  218. path = "Tor\\PluggableTransports";
  219. + else if ("electrum-nmc" == aTorFileType)
  220. + path = "TorBrowser\\Electrum-NMC\\run_electrum_nmc";
  221. + else if ("stemns" == aTorFileType)
  222. + path = "TorBrowser\\StemNS\\poc.py";
  223. + else if ("python" == aTorFileType && verboseNamecoin)
  224. + path = "python.exe";
  225. + else if ("python" == aTorFileType)
  226. + path = "pythonw.exe";
  227. }
  228. else if (this.isMac)
  229. {
  230. @@ -636,6 +650,14 @@ let TorLauncherUtil = // Public
  231. path = "Data\\Tor\\onion-auth";
  232. else if ("pt-profiles-dir" == aTorFileType)
  233. path = "Data\\Browser";
  234. + else if ("electrum-nmc" == aTorFileType)
  235. + path = "Electrum-NMC\\run_electrum_nmc";
  236. + else if ("stemns" == aTorFileType)
  237. + path = "StemNS\\poc.py";
  238. + else if ("python" == aTorFileType && verboseNamecoin)
  239. + path = "python.exe";
  240. + else if ("python" == aTorFileType)
  241. + path = "pythonw.exe";
  242. }
  243. else // Linux, Mac OS and others.
  244. {
  245. @@ -668,6 +690,40 @@ let TorLauncherUtil = // Public
  246. try
  247. {
  248. + // Python searching is only a thing on Windows
  249. + if ("python" == aTorFileType)
  250. + {
  251. + const kEnvPath = "PATH";
  252. + var env = Cc["@mozilla.org/process/environment;1"]
  253. + .getService(Ci.nsIEnvironment);
  254. +
  255. + if (!env.exists(kEnvPath))
  256. + return null;
  257. + var searchPaths = env.get(kEnvPath).split(";");
  258. +
  259. + for (var i = 0; i < searchPaths.length; ++i)
  260. + {
  261. + torFile = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsIFile);
  262. + try {
  263. + torFile.initWithPath(searchPaths[i]);
  264. + }
  265. + catch (e)
  266. + {
  267. + // Passing the empty string to initWithPath causes an error.
  268. + // searchPaths will end with an empty string if the PATH contains a
  269. + // trailing semicolon. Other invalid/weird paths (if present in
  270. + // PATH) might also cause an error, so we catch them all here in an
  271. + // attempt to be tolerant.
  272. + continue;
  273. + }
  274. + torFile.append(path);
  275. + if (torFile.exists())
  276. + return torFile;
  277. + }
  278. +
  279. + return null;
  280. + }
  281. +
  282. if (useAppDir)
  283. {
  284. torFile = TLUtilInternal._appDir.clone();
  285. --
  286. 2.20.1