summaryrefslogtreecommitdiff
path: root/projects/instantbird/0021-Bug-13855-Use-known-onions-for-XMPP-servers.patch
blob: 06d2af5f98fea4744924a7781bbb801e7958d418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
From b6e51b8b315b26ceb0e93c65b132e3479cc64ea0 Mon Sep 17 00:00:00 2001
From: Sukhbir Singh <sukhbir@torproject.org>
Date: Tue, 15 Aug 2017 16:40:33 -0400
Subject: [PATCH 21/22] Bug 13855: Use known onions for XMPP servers

---
 im/content/accountWizard.js                        | 42 +++++++++++++++++++++-
 im/content/accountWizard.xul                       |  6 ++--
 .../chrome/instantbird/accountWizard.properties    |  2 ++
 3 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/im/content/accountWizard.js b/im/content/accountWizard.js
index 2ca9ba3b0e..7efedd5ed5 100644
--- a/im/content/accountWizard.js
+++ b/im/content/accountWizard.js
@@ -7,6 +7,14 @@ Cu.import("resource:///modules/imServices.jsm");
 
 var PREF_EXTENSIONS_GETMOREPROTOCOLSURL = "extensions.getMoreProtocolsURL";
 
+// Borrowed and inspired by xmpp-client.
+var kServerOnions = {
+  "riseup.net":                "4cjw6cwpeaeppfqz.onion",
+  "jabber.ccc.de":             "okj7xc6j2szr2y75.onion",
+  "jabber.otr.im":             "5rgdtlawqkcplz75.onion",
+  "jabber.calyxinstitute.org": "ijeeynrc6x2uy5ob.onion",
+}
+
 var accountWizard = {
   onload: function aw_onload() {
     let topProtoList = document.getElementById("topprotolist");
@@ -112,6 +120,21 @@ var accountWizard = {
     return textbox;
   },
 
+  insertOnionAddress: function aw_insertOnionAddress() {
+    // Currently, we only use onion addresses for XMPP.
+    if (this.proto.id == "prpl-jabber") {
+      // If the value of the domain is one for which there exists a
+      // hidden service, replace the address with the onion address.
+      this.jabberDomain = document.getElementById("username-split-0");
+      if (this.jabberDomain.value in kServerOnions) {
+        this.onionAddress = kServerOnions[this.jabberDomain.value];
+      }
+      else {
+        this.onionAddress = "";
+      }
+    }
+  },
+
   showUsernamePage: function aw_showUsernamePage() {
     let proto = this.proto.id;
     if ("userNameBoxes" in this && this.userNameProto == proto) {
@@ -173,11 +196,19 @@ var accountWizard = {
     document.getElementById("accountusername").next = next;
   },
 
+  setOnionAddress: function aw_setOnionAddress() {
+    if (this.proto.id == "prpl-jabber") {
+      document.getElementById("prpl-jabber-server").value = this.onionAddress;
+    }
+  },
+
   showAdvanced: function aw_showAdvanced() {
     // ensure we don't destroy user data if it's not necessary
     let id = this.proto.id;
-    if ("protoSpecOptId" in this && this.protoSpecOptId == id)
+    if ("protoSpecOptId" in this && this.protoSpecOptId == id) {
+      this.setOnionAddress();
       return;
+    }
     this.protoSpecOptId = id;
 
 /* FIXME
@@ -185,6 +216,7 @@ var accountWizard = {
       !this.proto.newMailNotification;
 */
     this.populateProtoSpecificBox();
+    this.setOnionAddress();
 
     let proxyVisible = this.proto.usePurpleProxy;
     if (proxyVisible) {
@@ -344,8 +376,16 @@ var accountWizard = {
       let label = bundle.getFormattedString("accountColon", [opt.opt.label]);
       rows.appendChild(this.createSummaryRow(label, opt.value));
     }
+
+    if (this.onionAddress) {
+      let onionLabel = document.getElementById("topProtocolsBundle");
+      let onion = document.getElementById("onionAddress");
+      onion.value = onionLabel.getFormattedString("onionAddress.label",
+                                  [this.onionAddress, this.jabberDomain.value]);
+    }
   },
 
+
   createAccount: function aw_createAccount() {
     let acc = Services.accounts.createAccount(this.username, this.proto.id);
     if (!this.proto.noPassword && this.password)
diff --git a/im/content/accountWizard.xul b/im/content/accountWizard.xul
index 73c9d93777..26b0bfa91c 100644
--- a/im/content/accountWizard.xul
+++ b/im/content/accountWizard.xul
@@ -62,7 +62,8 @@
               label="&accountUsernameTitle.label;"
               onpageshow="accountWizard.showUsernamePage();"
               onpagehide="accountWizard.hideUsernamePage();"
-              onpagerewound="return accountWizard.rewindFromUsernamePage();">
+              onpagerewound="return accountWizard.rewindFromUsernamePage();"
+              onpageadvanced="return accountWizard.insertOnionAddress();">
     <description id="usernameInfo"/>
     <separator/>
     <vbox id="userNameBox"/>
@@ -102,7 +103,7 @@
     <checkbox id="newMailNotification"
               label="&accountAdvanced.newMailNotification.label;" hidden="true"/>
 
-    <groupbox id="protoSpecificGroupbox" class="collapsable" closed="true"
+    <groupbox id="protoSpecificGroupbox" class="collapsable" closed="false"
               onkeypress="accountWizard.onGroupboxKeypress(event)">
       <caption id="protoSpecificCaption"
                onclick="accountWizard.toggleGroupbox('protoSpecificGroupbox')"/>
@@ -141,6 +142,7 @@
       </columns>
       <rows id="summaryRows"/>
     </grid>
+    <description id="onionAddress" />
     <separator/>
     <checkbox id="connectAutomatically" label= "&accountSummary.connectAutomatically.label;" checked="false"/>
   </wizardpage>
diff --git a/im/locales/en-US/chrome/instantbird/accountWizard.properties b/im/locales/en-US/chrome/instantbird/accountWizard.properties
index efb0b77aee..05a4deb462 100644
--- a/im/locales/en-US/chrome/instantbird/accountWizard.properties
+++ b/im/locales/en-US/chrome/instantbird/accountWizard.properties
@@ -18,3 +18,5 @@ topProtocol.prpl-twitter.description=Stay up to date with your Twitter timeline
 topProtocol.prpl-aim.description=Chat with your buddies on AOL Instant Messenger
 topProtocol.prpl-irc.description=Join IRC channels
 topProtocol.prpl-jabber.description=Chat using the open Jabber/XMPP protocol
+
+onionAddress.label=%S is %S's onion address.
-- 
2.16.1