diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-01-29 20:08:29 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-01-29 20:08:29 +0100 |
commit | ceba706df4847e160cafc8da5a9e2aba38a857ac (patch) | |
tree | f5a70f35ca2290e888fd18771113237fffca304e /src/main/java/de/pixart | |
parent | 475e29b622ef5c87e3a3b3a36020bf99958467cd (diff) |
use base64 encoding for file names uploaded with http
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/generator/IqGenerator.java | 21 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/XmppConnection.java | 2 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java index e2b462f76..adcf2b04f 100644 --- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java @@ -10,12 +10,14 @@ import org.whispersystems.libaxolotl.ecc.ECPublicKey; import org.whispersystems.libaxolotl.state.PreKeyRecord; import org.whispersystems.libaxolotl.state.SignedPreKeyRecord; +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 de.pixart.messenger.Config; import de.pixart.messenger.R; @@ -316,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); @@ -324,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/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 7a8e3cfe2..1cec0c909 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -1285,7 +1285,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) { |