ability to download pgp encrypted files over http as well

This commit is contained in:
iNPUTmice 2014-10-22 19:05:15 +02:00
parent c067bf96b0
commit d04afe453a
2 changed files with 9 additions and 5 deletions

View file

@ -20,9 +20,7 @@ import org.apache.http.conn.ssl.StrictHostnameVerifier;
import android.content.Intent; import android.content.Intent;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Downloadable; import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
@ -63,12 +61,17 @@ public class HttpConnection implements Downloadable {
this.message.setDownloadable(this); this.message.setDownloadable(this);
try { try {
mUrl = new URL(message.getBody()); mUrl = new URL(message.getBody());
String path = mUrl.getPath();
if (path != null && (path.endsWith(".pgp") || path.endsWith(".gpg"))) {
this.message.setEncryption(Message.ENCRYPTION_PGP);
}
this.file = mXmppConnectionService.getFileBackend().getFile( this.file = mXmppConnectionService.getFileBackend().getFile(
message, false); message, false);
String reference = mUrl.getRef(); String reference = mUrl.getRef();
if (reference != null && reference.length() == 96) { if (reference != null && reference.length() == 96) {
this.file.setKey(CryptoHelper.hexToBytes(reference)); this.file.setKey(CryptoHelper.hexToBytes(reference));
} }
if (this.message.getEncryption() == Message.ENCRYPTION_OTR if (this.message.getEncryption() == Message.ENCRYPTION_OTR
&& this.file.getKey() == null) { && this.file.getKey() == null) {
this.message.setEncryption(Message.ENCRYPTION_NONE); this.message.setEncryption(Message.ENCRYPTION_NONE);
@ -95,6 +98,7 @@ public class HttpConnection implements Downloadable {
mXmppConnectionService.sendBroadcast(intent); mXmppConnectionService.sendBroadcast(intent);
message.setDownloadable(null); message.setDownloadable(null);
mHttpConnectionManager.finishConnection(this); mHttpConnectionManager.finishConnection(this);
mXmppConnectionService.updateConversationUi();
} }
private void changeStatus(int status) { private void changeStatus(int status) {

View file

@ -435,9 +435,9 @@ public class ConversationFragment extends Fragment {
}); });
} }
for (Message message : this.conversation.getMessages()) { for (Message message : this.conversation.getMessages()) {
if ((message.getEncryption() == Message.ENCRYPTION_PGP) if (message.getEncryption() == Message.ENCRYPTION_PGP
&& ((message.getStatus() == Message.STATUS_RECEIVED) || (message && (message.getStatus() == Message.STATUS_RECEIVED || message
.getStatus() == Message.STATUS_SEND))) { .getStatus() >= Message.STATUS_SEND) && message.getDownloadable() == null) {
if (!mEncryptedMessages.contains(message)) { if (!mEncryptedMessages.contains(message)) {
mEncryptedMessages.add(message); mEncryptedMessages.add(message);
} }