diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-05-06 21:34:30 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-05-06 21:34:30 +0200 |
commit | 461f2ffb16ebb877a1ab28e8815b07196e424a36 (patch) | |
tree | 6532617f4be9137d87077d0b49470ef2f47af8a0 /src/eu/siacs/conversations/ui | |
parent | f7033cb7e06740576d23e1f8fbf473db337e13fe (diff) |
basic pgp encrypted file transfer
Diffstat (limited to 'src/eu/siacs/conversations/ui')
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationActivity.java | 46 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationFragment.java | 12 |
2 files changed, 48 insertions, 10 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index fc19ecc7b..85025108d 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -6,7 +6,10 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import org.openintents.openpgp.OpenPgpError; + import eu.siacs.conversations.R; +import eu.siacs.conversations.crypto.OnPgpEngineResult; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; @@ -18,9 +21,11 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.app.AlertDialog; import android.app.FragmentTransaction; +import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; +import android.content.IntentSender.SendIntentException; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; @@ -59,6 +64,7 @@ public class ConversationActivity extends XmppActivity { public static final int REQUEST_SEND_MESSAGE = 0x75441; public static final int REQUEST_DECRYPT_PGP = 0x76783; private static final int ATTACH_FILE = 0x48502; + private static final int REQUEST_SEND_PGP_IMAGE = 0x53883; protected SlidingPaneLayout spl; @@ -69,6 +75,8 @@ public class ConversationActivity extends XmppActivity { private boolean paneShouldBeOpen = true; private boolean useSubject = true; private ArrayAdapter<Conversation> listAdapter; + + public Message pendingMessage = null; private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() { @@ -581,10 +589,42 @@ public class ConversationActivity extends XmppActivity { selectedFragment.hidePgpPassphraseBox(); } } else if (requestCode == ATTACH_FILE) { - Conversation conversation = getSelectedConversation(); + final Conversation conversation = getSelectedConversation(); String presence = conversation.getNextPresence(); - xmppConnectionService.attachImageToConversation(conversation, presence, data.getData()); - + if (conversation.nextMessageEncryption == Message.ENCRYPTION_NONE) { + xmppConnectionService.attachImageToConversation(conversation, presence, data.getData()); + } else if (conversation.nextMessageEncryption == Message.ENCRYPTION_PGP) { + pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, data.getData(), new OnPgpEngineResult() { + + @Override + public void userInputRequried(PendingIntent pi) { + Log.d(LOGTAG,"user input requried"); + try { + startIntentSenderForResult(pi.getIntentSender(), + ConversationActivity.REQUEST_SEND_PGP_IMAGE, null, 0, + 0, 0); + } catch (SendIntentException e1) { + Log.d("xmppService","failed to start intent to send message"); + } + } + + @Override + public void success() { + conversation.getMessages().add(pendingMessage); + pendingMessage.setStatus(Message.STATUS_OFFERED); + xmppConnectionService.databaseBackend.createMessage(pendingMessage); + xmppConnectionService.sendMessage(pendingMessage, null); + xmppConnectionService.updateUi(conversation, false); + } + + @Override + public void error(OpenPgpError openPgpError) { + Log.d(LOGTAG,"pgp error"+openPgpError.getMessage()); + } + }); + } else { + Log.d(LOGTAG,"unknown next message encryption: "+conversation.nextMessageEncryption); + } } } } diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index c2373cf17..dab03552e 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -269,7 +269,7 @@ public class ConversationFragment extends Fragment { String filesize = ""; - if (item.getType() == Message.TYPE_IMAGE) { + if ((item.getType() == Message.TYPE_IMAGE)&&((item.getEncryption() == Message.ENCRYPTION_DECRYPTED)||(item.getEncryption() == Message.ENCRYPTION_NONE))) { String[] fileParams = item.getBody().split(","); if ((fileParams.length>=1)&&(item.getStatus() != Message.STATUS_PREPARING)) { long size = Long.parseLong(fileParams[0]); @@ -510,7 +510,7 @@ public class ConversationFragment extends Fragment { ConversationActivity activity = (ConversationActivity) getActivity(); if (this.conversation != null) { for (Message message : this.conversation.getMessages()) { - if (message.getEncryption() == Message.ENCRYPTION_PGP) { + if ((message.getEncryption() == Message.ENCRYPTION_PGP)&&(message.getStatus() == Message.STATUS_RECIEVED)) { decryptMessage(message); break; } @@ -594,7 +594,7 @@ public class ConversationFragment extends Fragment { } protected void sendPgpMessage(final Message message) { - ConversationActivity activity = (ConversationActivity) getActivity(); + final ConversationActivity activity = (ConversationActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; final Contact contact = message.getConversation().getContact(); final Account account = message.getConversation().getAccount(); @@ -604,7 +604,6 @@ public class ConversationFragment extends Fragment { @Override public void userInputRequried(PendingIntent pi) { - Log.d("xmppService","hasKey returned user input required"); try { getActivity().startIntentSenderForResult(pi.getIntentSender(), ConversationActivity.REQUEST_SEND_MESSAGE, null, 0, @@ -616,13 +615,12 @@ public class ConversationFragment extends Fragment { @Override public void success() { - Log.d("xmppService","hasKey returned success"); - xmppService.getPgpEngine().encrypt(account, contact.getPgpKeyId(), message,new OnPgpEngineResult() { + xmppService.getPgpEngine().encrypt(account, message,new OnPgpEngineResult() { @Override public void userInputRequried(PendingIntent pi) { try { - getActivity().startIntentSenderForResult(pi.getIntentSender(), + activity.startIntentSenderForResult(pi.getIntentSender(), ConversationActivity.REQUEST_SEND_MESSAGE, null, 0, 0, 0); } catch (SendIntentException e1) { |