use Tor on http upload is account uses onion domain. fixes #3075
This commit is contained in:
parent
582178991b
commit
b9bdb3df55
|
@ -15,6 +15,7 @@ import java.util.TimeZone;
|
|||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.services.XmppConnectionService;
|
||||
import eu.siacs.conversations.utils.PhoneHelper;
|
||||
import eu.siacs.conversations.xml.Namespace;
|
||||
|
@ -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,9 +104,8 @@ public abstract class AbstractGenerator {
|
|||
return DATE_FORMAT.format(time);
|
||||
}
|
||||
|
||||
public List<String> getFeatures() {
|
||||
ArrayList<String> features = new ArrayList<>();
|
||||
features.addAll(Arrays.asList(FEATURES));
|
||||
public List<String> getFeatures(Account account) {
|
||||
ArrayList<String> features = new ArrayList<>(Arrays.asList(FEATURES));
|
||||
if (mXmppConnectionService.confirmMessages()) {
|
||||
features.addAll(Arrays.asList(MESSAGE_CONFIRMATION_FEATURES));
|
||||
}
|
||||
|
@ -115,7 +115,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 (mXmppConnectionService.broadcastLastActivity()) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -265,7 +265,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();
|
||||
|
@ -348,7 +348,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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -260,7 +260,7 @@ public class XmppConnection implements Runnable {
|
|||
if (useTor) {
|
||||
String destination;
|
||||
if (account.getHostname().isEmpty()) {
|
||||
destination = account.getServer().toString();
|
||||
destination = account.getServer();
|
||||
} else {
|
||||
destination = account.getHostname();
|
||||
this.verifiedHostname = destination;
|
||||
|
|
Loading…
Reference in New Issue