namecoin-torbutton.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. diff --git a/chrome/content/tor-circuit-display.js b/chrome/content/tor-circuit-display.js
  2. index 119f6fca..477b0302 100644
  3. --- a/chrome/content/tor-circuit-display.js
  4. +++ b/chrome/content/tor-circuit-display.js
  5. @@ -48,7 +48,11 @@ let credentialsToNodeDataMap = new Map(),
  6. knownCircuitIDs = new Map(),
  7. // A mutable map that records the SOCKS credentials for the
  8. // latest channels for each browser + domain.
  9. - browserToCredentialsMap = new Map();
  10. + browserToCredentialsMap = new Map(),
  11. + // A mutable map from stream id to .bit[.onion] domains
  12. + bitTargets = {},
  13. + // A mutable map from .bit[.onion] domains to .onion domains.
  14. + bitToOnionMap = {};
  15. // __trimQuotes(s)__.
  16. // Removes quotation marks around a quoted string.
  17. @@ -132,6 +136,28 @@ let getCircuitStatusByID = async function (aController, circuitID) {
  18. return null;
  19. };
  20. +// __collectBitTargets(aContoller)__.
  21. +// Watches for STREAM NEW events. When a NEW event occurs, we will see
  22. +// the stream's target domain. If that target is a .bit domain, then
  23. +// we want to be sure to record this so we can later record if it is
  24. +// remapped to a .onion domain.
  25. +let collectBitTargets = function (aController) {
  26. + return aController.watchEvent(
  27. + "STREAM",
  28. + streamEvent => streamEvent.StreamStatus === "NEW",
  29. + async (streamEvent) => {
  30. + logger.eclog(3, "new streamEvent:" + JSON.stringify(streamEvent));
  31. + if (streamEvent && streamEvent.StreamID && streamEvent.Target) {
  32. + let targetDomain = streamEvent.Target.split(":")[0];
  33. + if (targetDomain.endsWith(".bit") ||
  34. + targetDomain.endsWith(".bit.onion")) {
  35. + bitTargets[streamEvent.StreamID] = Services.eTLD.getBaseDomainFromHost(targetDomain);
  36. + logger.eclog(3, "stream on .bit domain: " + targetDomain);
  37. + }
  38. + }
  39. + });
  40. +};
  41. +
  42. // __collectIsolationData(aController, updateUI)__.
  43. // Watches for STREAM SENTCONNECT events. When a SENTCONNECT event occurs, then
  44. // we assume isolation settings (SOCKS username+password) are now fixed for the
  45. @@ -145,6 +171,15 @@ let collectIsolationData = function (aController, updateUI) {
  46. "STREAM",
  47. streamEvent => streamEvent.StreamStatus === "SENTCONNECT",
  48. async (streamEvent) => {
  49. + logger.eclog(3, "sentconnect streamEvent:" + JSON.stringify(streamEvent));
  50. + // Collect any stream target that might be an onion.
  51. + if (streamEvent && streamEvent.StreamID && streamEvent.Target) {
  52. + let targetDomain = streamEvent.Target.split(":")[0];
  53. + if (targetDomain.endsWith(".onion")) {
  54. + bitToOnionMap[bitTargets[streamEvent.StreamID]] = targetDomain;
  55. + logger.eclog(3, "mapped " + bitTargets[streamEvent.StreamID] + " to " + targetDomain);
  56. + }
  57. + }
  58. if (!knownCircuitIDs.get(streamEvent.CircuitID)) {
  59. logger.eclog(3, "streamEvent.CircuitID: " + streamEvent.CircuitID);
  60. knownCircuitIDs.set(streamEvent.CircuitID, true);
  61. @@ -312,7 +347,9 @@ let updateCircuitDisplay = function () {
  62. }
  63. let domainParts = [];
  64. - if (domain.endsWith(".onion")) {
  65. + logger.eclog(3, "bit to onion map:" + JSON.stringify(bitToOnionMap) + ", domain: " + domain);
  66. + let mappedOnion = bitToOnionMap[domain];
  67. + if (domain.endsWith(".onion") || mappedOnion) {
  68. for (let i = 0; i < 3; ++i) {
  69. li(uiString("relay"));
  70. }
  71. @@ -325,24 +362,28 @@ let updateCircuitDisplay = function () {
  72. domainParts.push(domain);
  73. }
  74. - // We use a XUL html:span element so that the tooltiptext is displayed.
  75. - li([
  76. - "html:span",
  77. - {
  78. - class: "circuit-onion",
  79. - onclick: `
  80. - this.classList.add("circuit-onion-copied");
  81. - Cc[
  82. - "@mozilla.org/widget/clipboardhelper;1"
  83. - ].getService(Ci.nsIClipboardHelper).copyString(this.getAttribute("data-onion"))
  84. - `,
  85. - "data-onion": domain,
  86. - "data-text-clicktocopy": torbutton_get_property_string("torbutton.circuit_display.click_to_copy"),
  87. - "data-text-copied": torbutton_get_property_string("torbutton.circuit_display.copied"),
  88. - tooltiptext: domain,
  89. - },
  90. - ...domainParts,
  91. - ]);
  92. + if (mappedOnion) {
  93. + li(domain, " ", ["span", { class: "circuit-ip-address" }, mappedOnion]);
  94. + } else {
  95. + // We use a XUL html:span element so that the tooltiptext is displayed.
  96. + li([
  97. + "html:span",
  98. + {
  99. + class: "circuit-onion",
  100. + onclick: `
  101. + this.classList.add("circuit-onion-copied");
  102. + Cc[
  103. + "@mozilla.org/widget/clipboardhelper;1"
  104. + ].getService(Ci.nsIClipboardHelper).copyString(this.getAttribute("data-onion"))
  105. + `,
  106. + "data-onion": domain,
  107. + "data-text-clicktocopy": torbutton_get_property_string("torbutton.circuit_display.click_to_copy"),
  108. + "data-text-copied": torbutton_get_property_string("torbutton.circuit_display.copied"),
  109. + tooltiptext: domain,
  110. + },
  111. + ...domainParts,
  112. + ]);
  113. + }
  114. // Hide the note about guards if we are using a bridge.
  115. document.getElementById("circuit-guard-note-container").style.display =
  116. @@ -450,6 +491,7 @@ let setupDisplay = function (enablePrefName) {
  117. stopCollectingIsolationData = null,
  118. stopCollectingBrowserCredentials = null,
  119. stopEnsuringCorrectPopupDimensions = null,
  120. + stopCollectingBitTargets = null,
  121. stop = function() {
  122. syncDisplayWithSelectedTab(false);
  123. if (myController) {
  124. @@ -462,6 +504,9 @@ let setupDisplay = function (enablePrefName) {
  125. if (stopEnsuringCorrectPopupDimensions) {
  126. stopEnsuringCorrectPopupDimensions();
  127. }
  128. + if (stopCollectingBitTargets) {
  129. + stopCollectingBitTargets();
  130. + }
  131. myController = null;
  132. }
  133. },
  134. @@ -475,6 +520,7 @@ let setupDisplay = function (enablePrefName) {
  135. stop();
  136. });
  137. syncDisplayWithSelectedTab(true);
  138. + stopCollectingBitTargets = collectBitTargets(myController);
  139. stopCollectingIsolationData = collectIsolationData(myController, updateCircuitDisplay);
  140. stopCollectingBrowserCredentials = collectBrowserCredentials();
  141. stopEnsuringCorrectPopupDimensions = ensureCorrectPopupDimensions();