transform aesgcm:// links back to https:// before connecting through Tor
fixes #2444
This commit is contained in:
parent
1ac0c2f453
commit
6c34763d32
|
@ -70,9 +70,9 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
this.message.setTransferable(this);
|
this.message.setTransferable(this);
|
||||||
try {
|
try {
|
||||||
if (message.hasFileOnRemoteHost()) {
|
if (message.hasFileOnRemoteHost()) {
|
||||||
mUrl = message.getFileParams().url;
|
mUrl = CryptoHelper.toHttpsUrl(message.getFileParams().url);
|
||||||
} else {
|
} else {
|
||||||
mUrl = new URL(message.getBody());
|
mUrl = CryptoHelper.toHttpsUrl(new URL(message.getBody()));
|
||||||
}
|
}
|
||||||
String[] parts = mUrl.getPath().toLowerCase().split("\\.");
|
String[] parts = mUrl.getPath().toLowerCase().split("\\.");
|
||||||
String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null;
|
String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null;
|
||||||
|
@ -91,8 +91,8 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
}
|
}
|
||||||
message.setRelativeFilePath(message.getUuid() + "." + extension);
|
message.setRelativeFilePath(message.getUuid() + "." + extension);
|
||||||
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
||||||
String reference = mUrl.getRef();
|
final String reference = mUrl.getRef();
|
||||||
if (reference != null && reference.length() == 96) {
|
if (reference != null && reference.matches("([A-Fa-f0-9]{2}){48}")) {
|
||||||
this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
|
this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +332,14 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
|
|
||||||
private void updateImageBounds() {
|
private void updateImageBounds() {
|
||||||
message.setType(Message.TYPE_FILE);
|
message.setType(Message.TYPE_FILE);
|
||||||
mXmppConnectionService.getFileBackend().updateFileParams(message, mUrl);
|
final URL url;
|
||||||
|
final String ref = mUrl.getRef();
|
||||||
|
if (ref != null && ref.matches("([A-Fa-f0-9]{2}){48}")) {
|
||||||
|
url = CryptoHelper.toAesGcmUrl(mUrl);
|
||||||
|
} else {
|
||||||
|
url = mUrl;
|
||||||
|
}
|
||||||
|
mXmppConnectionService.getFileBackend().updateFileParams(message, url);
|
||||||
mXmppConnectionService.updateMessage(message);
|
mXmppConnectionService.updateMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
import eu.siacs.conversations.http.AesGcmURLStreamHandler;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
|
|
||||||
|
@ -238,7 +239,18 @@ public final class CryptoHelper {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return new URL("aesgcm"+url.toString().substring(url.getProtocol().length()));
|
return new URL(AesGcmURLStreamHandler.PROTOCOL_NAME+url.toString().substring(url.getProtocol().length()));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static URL toHttpsUrl(URL url) {
|
||||||
|
if (!url.getProtocol().equalsIgnoreCase(AesGcmURLStreamHandler.PROTOCOL_NAME)) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new URL("https"+url.toString().substring(url.getProtocol().length()));
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue