send urls pointing to pgp encrypted files directly in body+oob

This commit is contained in:
Daniel Gultsch 2017-04-05 21:01:29 +02:00
parent 3b3121b9c5
commit 26badb7f4c
6 changed files with 37 additions and 35 deletions

View file

@ -139,6 +139,11 @@ public class MessageGenerator extends AbstractGenerator {
public MessagePacket generatePgpChat(Message message) {
MessagePacket packet = preparePacket(message);
if (message.hasFileOnRemoteHost()) {
final String url = message.getFileParams().url.toString();
packet.setBody(url);
packet.addChild("x",Namespace.OOB).addChild("url").setContent(url);
} else {
if (Config.supportUnencrypted()) {
packet.setBody(PGP_FALLBACK_MESSAGE);
}
@ -147,8 +152,9 @@ public class MessageGenerator extends AbstractGenerator {
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
packet.addChild("x", "jabber:x:encrypted").setContent(message.getBody());
}
packet.addChild("encryption","urn:xmpp:eme:0")
.setAttribute("namespace","jabber:x:encrypted");
packet.addChild("encryption", "urn:xmpp:eme:0")
.setAttribute("namespace", "jabber:x:encrypted");
}
return packet;
}

View file

@ -197,27 +197,7 @@ public class HttpUploadConnection implements Transferable {
mXmppConnectionService.getFileBackend().updateMediaScanner(file);
message.setTransferable(null);
message.setCounterpart(message.getConversation().getJid().toBareJid());
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
mXmppConnectionService.getPgpEngine().encrypt(message, new UiCallback<Message>() {
@Override
public void success(Message message) {
mXmppConnectionService.resendMessage(message,delayed);
}
@Override
public void error(int errorCode, Message object) {
Log.d(Config.LOGTAG,"pgp encryption failed");
fail("pgp encryption failed");
}
@Override
public void userInputRequried(PendingIntent pi, Message object) {
fail("pgp encryption failed");
}
});
} else {
mXmppConnectionService.resendMessage(message, delayed);
}
} else {
Log.d(Config.LOGTAG,"http upload failed because response code was "+code);
fail("http upload failed because response code was "+code);

View file

@ -415,7 +415,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
}
if ((body != null || pgpEncrypted != null || axolotlEncrypted != null || oobUrl != null) && !isMucStatusMessage) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query);
final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query);
final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI;
if (serverMsgId == null) {
@ -474,6 +474,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} else if (body == null && oobUrl != null) {
message = new Message(conversation, oobUrl, Message.ENCRYPTION_NONE, status);
message.setOob(true);
if (CryptoHelper.isPgpEncryptedUrl(oobUrl)) {
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
}
} else {
message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
}
@ -483,7 +486,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
message.setServerMsgId(serverMsgId);
message.setCarbon(isCarbon);
message.setTime(timestamp);
message.setOob(body != null && body.equals(oobUrl));
if (body != null && body.equals(oobUrl)) {
message.setOob(true);
if (CryptoHelper.isPgpEncryptedUrl(oobUrl)) {
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
}
}
message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
if (conversationMultiMode) {
final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart);
@ -624,7 +632,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
}
}
} else if (!packet.hasChild("body")){ //no body
Conversation conversation = mXmppConnectionService.find(account, from.toBareJid());
final Conversation conversation = mXmppConnectionService.find(account, from.toBareJid());
if (isTypeGroupChat) {
if (packet.hasChild("subject")) {
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {

View file

@ -185,7 +185,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
filesize = params.size / (1024 * 1024)+ " MiB";
} else if (params.size >= 1024) {
filesize = params.size / 1024 + " KiB";
} else {
} else if (params.size > 0){
filesize = params.size + " B";
}
if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) {

View file

@ -243,4 +243,12 @@ public final class CryptoHelper {
return url;
}
}
public static boolean isPgpEncryptedUrl(String url) {
if (url == null) {
return false;
}
final String u = url.toLowerCase();
return !u.contains(" ") && (u.startsWith("https://") || u.startsWith("http://")) && u.endsWith(".pgp");
}
}