mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
send urls pointing to pgp encrypted files directly in body+oob
This commit is contained in:
parent
3b3121b9c5
commit
26badb7f4c
@ -139,16 +139,22 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
|
|
||||||
public MessagePacket generatePgpChat(Message message) {
|
public MessagePacket generatePgpChat(Message message) {
|
||||||
MessagePacket packet = preparePacket(message);
|
MessagePacket packet = preparePacket(message);
|
||||||
if (Config.supportUnencrypted()) {
|
if (message.hasFileOnRemoteHost()) {
|
||||||
packet.setBody(PGP_FALLBACK_MESSAGE);
|
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);
|
||||||
|
}
|
||||||
|
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
|
packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody());
|
||||||
|
} 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");
|
||||||
}
|
}
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
|
||||||
packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody());
|
|
||||||
} 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");
|
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class HttpDownloadConnection implements Transferable {
|
|||||||
|| this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL)
|
|| this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL)
|
||||||
&& this.file.getKey() == null) {
|
&& this.file.getKey() == null) {
|
||||||
this.message.setEncryption(Message.ENCRYPTION_NONE);
|
this.message.setEncryption(Message.ENCRYPTION_NONE);
|
||||||
}
|
}
|
||||||
checkFileSize(interactive);
|
checkFileSize(interactive);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -197,27 +197,7 @@ public class HttpUploadConnection implements Transferable {
|
|||||||
mXmppConnectionService.getFileBackend().updateMediaScanner(file);
|
mXmppConnectionService.getFileBackend().updateMediaScanner(file);
|
||||||
message.setTransferable(null);
|
message.setTransferable(null);
|
||||||
message.setCounterpart(message.getConversation().getJid().toBareJid());
|
message.setCounterpart(message.getConversation().getJid().toBareJid());
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
mXmppConnectionService.resendMessage(message, delayed);
|
||||||
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 {
|
} else {
|
||||||
Log.d(Config.LOGTAG,"http upload failed because response code was "+code);
|
Log.d(Config.LOGTAG,"http upload failed because response code was "+code);
|
||||||
fail("http upload failed because response code was "+code);
|
fail("http upload failed because response code was "+code);
|
||||||
|
@ -415,7 +415,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((body != null || pgpEncrypted != null || axolotlEncrypted != null || oobUrl != null) && !isMucStatusMessage) {
|
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;
|
final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI;
|
||||||
|
|
||||||
if (serverMsgId == null) {
|
if (serverMsgId == null) {
|
||||||
@ -474,6 +474,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||||||
} else if (body == null && oobUrl != null) {
|
} else if (body == null && oobUrl != null) {
|
||||||
message = new Message(conversation, oobUrl, Message.ENCRYPTION_NONE, status);
|
message = new Message(conversation, oobUrl, Message.ENCRYPTION_NONE, status);
|
||||||
message.setOob(true);
|
message.setOob(true);
|
||||||
|
if (CryptoHelper.isPgpEncryptedUrl(oobUrl)) {
|
||||||
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
|
message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
|
||||||
}
|
}
|
||||||
@ -483,7 +486,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||||||
message.setServerMsgId(serverMsgId);
|
message.setServerMsgId(serverMsgId);
|
||||||
message.setCarbon(isCarbon);
|
message.setCarbon(isCarbon);
|
||||||
message.setTime(timestamp);
|
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");
|
message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
|
||||||
if (conversationMultiMode) {
|
if (conversationMultiMode) {
|
||||||
final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart);
|
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
|
} 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 (isTypeGroupChat) {
|
||||||
if (packet.hasChild("subject")) {
|
if (packet.hasChild("subject")) {
|
||||||
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
|
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
|
||||||
|
@ -185,7 +185,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
|||||||
filesize = params.size / (1024 * 1024)+ " MiB";
|
filesize = params.size / (1024 * 1024)+ " MiB";
|
||||||
} else if (params.size >= 1024) {
|
} else if (params.size >= 1024) {
|
||||||
filesize = params.size / 1024 + " KiB";
|
filesize = params.size / 1024 + " KiB";
|
||||||
} else {
|
} else if (params.size > 0){
|
||||||
filesize = params.size + " B";
|
filesize = params.size + " B";
|
||||||
}
|
}
|
||||||
if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) {
|
if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) {
|
||||||
|
@ -243,4 +243,12 @@ public final class CryptoHelper {
|
|||||||
return url;
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user