aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2017-01-26 18:39:25 +0100
committerDaniel Gultsch <daniel@gultsch.de>2017-01-26 18:39:25 +0100
commitc9e6d05fa0db1810f16980bffa661fa7ae5fd10d (patch)
tree48bbc56ce11adc77de84f4f5941f4755089deef5 /src
parentbbceee7f6172a4c3de203ff780ca5c9da4e3712b (diff)
use base64 encoding for file names uploaded with http
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java22
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java2
2 files changed, 22 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
index cb9ffd96..8393a011 100644
--- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
@@ -10,12 +10,15 @@ import org.whispersystems.libaxolotl.ecc.ECPublicKey;
import org.whispersystems.libaxolotl.state.PreKeyRecord;
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
+import java.util.UUID;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
@@ -315,7 +318,7 @@ public class IqGenerator extends AbstractGenerator {
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
packet.setTo(host);
Element request = packet.addChild("request", Xmlns.HTTP_UPLOAD);
- request.addChild("filename").setContent(file.getName());
+ request.addChild("filename").setContent(convertFilename(file.getName()));
request.addChild("size").setContent(String.valueOf(file.getExpectedSize()));
if (mime != null) {
request.addChild("content-type").setContent(mime);
@@ -323,6 +326,23 @@ public class IqGenerator extends AbstractGenerator {
return packet;
}
+ private static String convertFilename(String name) {
+ int pos = name.indexOf('.');
+ if (pos != -1) {
+ try {
+ UUID uuid = UUID.fromString(name.substring(0, pos));
+ ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
+ bb.putLong(uuid.getMostSignificantBits());
+ bb.putLong(uuid.getLeastSignificantBits());
+ return Base64.encodeToString(bb.array(), Base64.URL_SAFE) + name.substring(pos, name.length());
+ } catch (Exception e) {
+ return name;
+ }
+ } else {
+ return name;
+ }
+ }
+
public IqPacket generateCreateAccountWithCaptcha(Account account, String id, Data data) {
final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
register.setFrom(account.getJid().toBareJid());
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index ef5ff854..d80f44f4 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -1255,7 +1255,7 @@ public class XmppConnection implements Runnable {
}
private String nextRandomId() {
- return new BigInteger(50, mXmppConnectionService.getRNG()).toString(32);
+ return new BigInteger(50, mXmppConnectionService.getRNG()).toString(36);
}
public String sendIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {