aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-06-17 00:13:34 +0200
committerChristian Schneppe <christian@pix-art.de>2018-06-17 00:13:34 +0200
commit0d297def28a9e1e848a0020ae140f304957114ca (patch)
treee5efecc425c64769aaae2babc34cff274cf78069 /src/main
parent483ca6466febf2a7a19c18ec4b934f2b2b6f3226 (diff)
use Tor on http upload is account uses onion domain
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/generator/AbstractGenerator.java17
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java6
-rw-r--r--src/main/java/de/pixart/messenger/generator/PresenceGenerator.java4
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java4
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpUploadConnection.java2
-rw-r--r--src/main/java/de/pixart/messenger/parser/IqParser.java7
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java2
7 files changed, 22 insertions, 20 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java b/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java
index a87a37885..37a098300 100644
--- a/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java
@@ -15,6 +15,7 @@ import java.util.TimeZone;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.crypto.axolotl.AxolotlService;
+import de.pixart.messenger.entities.Account;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.utils.PhoneHelper;
@@ -73,7 +74,7 @@ public abstract class AbstractGenerator {
return mXmppConnectionService.getString(R.string.app_name) + " " + getIdentityVersion();
}
- public String getIdentityType() {
+ String getIdentityType() {
if ("chromium".equals(android.os.Build.BRAND)) {
return "pc";
} else {
@@ -81,9 +82,9 @@ public abstract class AbstractGenerator {
}
}
- public String getCapHash() {
+ String getCapHash(final Account account) {
StringBuilder s = new StringBuilder();
- s.append("client/" + getIdentityType() + "//" + getIdentityName() + "<");
+ s.append("client/").append(getIdentityType()).append("//").append(getIdentityName()).append('<');
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
@@ -91,8 +92,8 @@ public abstract class AbstractGenerator {
return null;
}
- for (String feature : getFeatures()) {
- s.append(feature + "<");
+ for (String feature : getFeatures(account)) {
+ s.append(feature).append('<');
}
byte[] sha1 = md.digest(s.toString().getBytes());
return new String(Base64.encode(sha1, Base64.DEFAULT)).trim();
@@ -103,8 +104,8 @@ public abstract class AbstractGenerator {
return DATE_FORMAT.format(time);
}
- public List<String> getFeatures() {
- ArrayList<String> features = new ArrayList<>();
+ public List<String> getFeatures(Account account) {
+ ArrayList<String> features = new ArrayList<>(Arrays.asList(FEATURES));
features.addAll(Arrays.asList(FEATURES));
if (mXmppConnectionService.confirmMessages()) {
features.addAll(Arrays.asList(MESSAGE_CONFIRMATION_FEATURES));
@@ -115,7 +116,7 @@ public abstract class AbstractGenerator {
if (Config.supportOmemo()) {
features.add(AxolotlService.PEP_DEVICE_LIST_NOTIFY);
}
- if (!mXmppConnectionService.useTorToConnect()) {
+ if (!mXmppConnectionService.useTorToConnect() && !account.isOnion()) {
features.addAll(Arrays.asList(PRIVACY_SENSITIVE));
}
if (Config.supportOtr()) {
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index 159e730f3..eab087975 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -41,7 +41,7 @@ public class IqGenerator extends AbstractGenerator {
super(service);
}
- public IqPacket discoResponse(final IqPacket request) {
+ public IqPacket discoResponse(final Account account, final IqPacket request) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.RESULT);
packet.setId(request.getId());
packet.setTo(request.getFrom());
@@ -51,7 +51,7 @@ public class IqGenerator extends AbstractGenerator {
identity.setAttribute("category", "client");
identity.setAttribute("type", getIdentityType());
identity.setAttribute("name", getIdentityName());
- for (final String feature : getFeatures()) {
+ for (final String feature : getFeatures(account)) {
query.addChild("feature").setAttribute("var", feature);
}
return packet;
@@ -113,7 +113,7 @@ public class IqGenerator extends AbstractGenerator {
return publish(node, item, null);
}
- protected IqPacket retrieve(String node, Element item) {
+ private IqPacket retrieve(String node, Element item) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB);
final Element items = pubsub.addChild("items");
diff --git a/src/main/java/de/pixart/messenger/generator/PresenceGenerator.java b/src/main/java/de/pixart/messenger/generator/PresenceGenerator.java
index b66f6b184..95221ce31 100644
--- a/src/main/java/de/pixart/messenger/generator/PresenceGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/PresenceGenerator.java
@@ -48,11 +48,11 @@ public class PresenceGenerator extends AbstractGenerator {
packet.addChild("show").setContent(status.toShowString());
}
packet.setFrom(account.getJid());
- String sig = account.getPgpSignature();
+ final String sig = account.getPgpSignature();
if (includePgpAnnouncement && sig != null && mXmppConnectionService.getPgpEngine() != null) {
packet.addChild("x", "jabber:x:signed").setContent(sig);
}
- String capHash = getCapHash();
+ final String capHash = getCapHash(account);
if (capHash != null) {
Element cap = packet.addChild("c",
"http://jabber.org/protocol/caps");
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
index e0829c39c..b35e0aa83 100644
--- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
@@ -272,7 +272,7 @@ public class HttpDownloadConnection implements Transferable {
Log.d(Config.LOGTAG, "retrieve file size. interactive:" + String.valueOf(interactive));
changeStatus(STATUS_CHECKING);
HttpURLConnection connection;
- if (mUseTor) {
+ if (mUseTor || message.getConversation().getAccount().isOnion()) {
connection = (HttpURLConnection) mUrl.openConnection(HttpConnectionManager.getProxy());
} else {
connection = (HttpURLConnection) mUrl.openConnection();
@@ -357,7 +357,7 @@ public class HttpDownloadConnection implements Transferable {
PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_download_" + message.getUuid());
try {
wakeLock.acquire();
- if (mUseTor) {
+ if (mUseTor || message.getConversation().getAccount().isOnion()) {
connection = (HttpURLConnection) mUrl.openConnection(HttpConnectionManager.getProxy());
} else {
connection = (HttpURLConnection) mUrl.openConnection();
diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
index 9acdfa11a..090e7ad07 100644
--- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
@@ -167,7 +167,7 @@ public class HttpUploadConnection implements Transferable {
final int readTimeout = (expectedFileSize / 2048) + Config.SOCKET_TIMEOUT; //assuming a minimum transfer speed of 16kbit/s
wakeLock.acquire(readTimeout);
Log.d(Config.LOGTAG, "uploading to " + slot.getPutUrl().toString() + " w/ read timeout of " + readTimeout + "s");
- if (mUseTor) {
+ if (mUseTor || message.getConversation().getAccount().isOnion()) {
connection = (HttpURLConnection) slot.getPutUrl().openConnection(HttpConnectionManager.getProxy());
} else {
connection = (HttpURLConnection) slot.getPutUrl().openConnection();
diff --git a/src/main/java/de/pixart/messenger/parser/IqParser.java b/src/main/java/de/pixart/messenger/parser/IqParser.java
index 04ce4afaa..fae27730d 100644
--- a/src/main/java/de/pixart/messenger/parser/IqParser.java
+++ b/src/main/java/de/pixart/messenger/parser/IqParser.java
@@ -285,7 +285,8 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
final boolean isGet = packet.getType() == IqPacket.TYPE.GET;
if (packet.getType() == IqPacket.TYPE.ERROR || packet.getType() == IqPacket.TYPE.TIMEOUT) {
return;
- } else if (packet.hasChild("query", Namespace.ROSTER) && packet.fromServer(account)) {
+ }
+ if (packet.hasChild("query", Namespace.ROSTER) && packet.fromServer(account)) {
final Element query = packet.findChild("query");
// If this is in response to a query for the whole roster:
if (packet.getType() == IqPacket.TYPE.RESULT) {
@@ -362,7 +363,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
mXmppConnectionService.getJingleConnectionManager()
.deliverIbbPacket(account, packet);
} else if (packet.hasChild("query", "http://jabber.org/protocol/disco#info")) {
- final IqPacket response = mXmppConnectionService.getIqGenerator().discoResponse(packet);
+ final IqPacket response = mXmppConnectionService.getIqGenerator().discoResponse(account, packet);
mXmppConnectionService.sendIqPacket(account, response, null);
} else if (packet.hasChild("query", "jabber:iq:version") && isGet) {
final IqPacket response = mXmppConnectionService.getIqGenerator().versionResponse(packet);
@@ -372,7 +373,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
mXmppConnectionService.sendIqPacket(account, response, null);
} else if (packet.hasChild("time", "urn:xmpp:time") && isGet) {
final IqPacket response;
- if (mXmppConnectionService.useTorToConnect()) {
+ if (mXmppConnectionService.useTorToConnect() || account.isOnion()) {
response = packet.generateResponse(IqPacket.TYPE.ERROR);
final Element error = response.addChild("error");
error.setAttribute("type", "cancel");
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index c65c11278..a279308e0 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -289,7 +289,7 @@ public class XmppConnection implements Runnable {
} else if (useTor) {
String destination;
if (account.getHostname().isEmpty()) {
- destination = account.getServer().toString();
+ destination = account.getServer();
} else {
destination = account.getHostname();
this.verifiedHostname = destination;