commit
30aea38713
|
@ -114,14 +114,15 @@ public class PgpEngine {
|
|||
}
|
||||
}
|
||||
|
||||
public void encrypt(Account account, final Message message,
|
||||
final OnPgpEngineResult callback) {
|
||||
public void encrypt(final Message message,final OnPgpEngineResult callback) {
|
||||
long[] keys = { message.getConversation().getContact().getPgpKeyId() };
|
||||
Intent params = new Intent();
|
||||
params.setAction(OpenPgpApi.ACTION_ENCRYPT);
|
||||
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys);
|
||||
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid());
|
||||
|
||||
if (message.getType() == Message.TYPE_TEXT) {
|
||||
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, account.getJid());
|
||||
|
||||
InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
|
||||
final OutputStream os = new ByteArrayOutputStream();
|
||||
|
@ -151,20 +152,11 @@ public class PgpEngine {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void encrypt(final Message message, final OnPgpEngineResult callback) {
|
||||
} else if (message.getType() == Message.TYPE_IMAGE) {
|
||||
try {
|
||||
Log.d("xmppService","calling to encrypt file");
|
||||
JingleFile inputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, true);
|
||||
JingleFile outputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, false);
|
||||
outputFile.createNewFile();
|
||||
long[] keys = { message.getConversation().getContact().getPgpKeyId() };
|
||||
Intent params = new Intent();
|
||||
params.setAction(OpenPgpApi.ACTION_ENCRYPT);
|
||||
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys);
|
||||
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid());
|
||||
InputStream is = new FileInputStream(inputFile);
|
||||
OutputStream os = new FileOutputStream(outputFile);
|
||||
api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
|
||||
|
@ -193,6 +185,7 @@ public class PgpEngine {
|
|||
Log.d("xmppService","io exception during file encrypt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long fetchKeyId(Account account, String status, String signature) {
|
||||
if ((signature == null) || (api == null)) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
|
|||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
@ -16,6 +17,7 @@ import eu.siacs.conversations.entities.Conversation;
|
|||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.utils.ExceptionHelper;
|
||||
import eu.siacs.conversations.utils.UIHelper;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
|
@ -63,8 +65,10 @@ 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_ATTACH_FILE_DIALOG = 0x48502;
|
||||
private static final int REQUEST_SEND_PGP_IMAGE = 0x53883;
|
||||
private static final int REQUEST_ATTACH_FILE = 0x73824;
|
||||
public static final int REQUEST_ENCRYPT_MESSAGE = 0x378018;
|
||||
|
||||
protected SlidingPaneLayout spl;
|
||||
|
||||
|
@ -329,7 +333,7 @@ public class ConversationActivity extends XmppActivity {
|
|||
attachFileIntent.setType("image/*");
|
||||
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
|
||||
startActivityForResult(chooser, ATTACH_FILE);
|
||||
startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -349,7 +353,7 @@ public class ConversationActivity extends XmppActivity {
|
|||
|
||||
@Override
|
||||
public void userInputRequried(PendingIntent pi) {
|
||||
ConversationActivity.this.runIntent(pi, REQUEST_SEND_PGP_IMAGE);
|
||||
ConversationActivity.this.runIntent(pi, REQUEST_ATTACH_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -448,7 +452,7 @@ public class ConversationActivity extends XmppActivity {
|
|||
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
|
||||
item.setChecked(true);
|
||||
} else {
|
||||
announcePgp(conversation.getAccount());
|
||||
announcePgp(conversation.getAccount(),conversation);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -634,13 +638,33 @@ public class ConversationActivity extends XmppActivity {
|
|||
if (selectedFragment != null) {
|
||||
selectedFragment.hidePgpPassphraseBox();
|
||||
}
|
||||
} else if (requestCode == ATTACH_FILE) {
|
||||
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
|
||||
final Conversation conversation = getSelectedConversation();
|
||||
String presence = conversation.getNextPresence();
|
||||
if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) {
|
||||
xmppConnectionService.attachImageToConversation(conversation, presence, data.getData());
|
||||
} else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
||||
pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, data.getData(), new OnPgpEngineResult() {
|
||||
attachPgpFile(conversation,data.getData());
|
||||
} else {
|
||||
Log.d(LOGTAG,"unknown next message encryption: "+conversation.getNextEncryption());
|
||||
}
|
||||
} else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
|
||||
|
||||
} else if (requestCode == REQUEST_ATTACH_FILE) {
|
||||
attachFile();
|
||||
} else if (requestCode == REQUEST_ANNOUNCE_PGP) {
|
||||
announcePgp(getSelectedConversation().getAccount(),getSelectedConversation());
|
||||
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
|
||||
encryptTextMessage();
|
||||
} else {
|
||||
Log.d(LOGTAG,"unknown result code:"+requestCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void attachPgpFile(Conversation conversation, Uri uri) {
|
||||
String presence = conversation.getNextPresence();
|
||||
pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, uri, new OnPgpEngineResult() {
|
||||
|
||||
@Override
|
||||
public void userInputRequried(PendingIntent pi) {
|
||||
|
@ -649,11 +673,10 @@ public class ConversationActivity extends XmppActivity {
|
|||
|
||||
@Override
|
||||
public void success() {
|
||||
conversation.getMessages().add(pendingMessage);
|
||||
pendingMessage.setStatus(Message.STATUS_OFFERED);
|
||||
pendingMessage.getConversation().getMessages().add(pendingMessage);
|
||||
xmppConnectionService.databaseBackend.createMessage(pendingMessage);
|
||||
xmppConnectionService.sendMessage(pendingMessage, null);
|
||||
xmppConnectionService.updateUi(conversation, false);
|
||||
xmppConnectionService.updateUi(pendingMessage.getConversation(), false);
|
||||
pendingMessage = null;
|
||||
}
|
||||
|
||||
|
@ -662,11 +685,6 @@ public class ConversationActivity extends XmppActivity {
|
|||
Log.d(LOGTAG,"pgp error"+openPgpError.getMessage());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Log.d(LOGTAG,"unknown next message encryption: "+conversation.getNextEncryption());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConversationList() {
|
||||
|
@ -872,4 +890,36 @@ public class ConversationActivity extends XmppActivity {
|
|||
return bitmapWorkerTaskReference.get();
|
||||
}
|
||||
}
|
||||
|
||||
public void encryptTextMessage() {
|
||||
xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage, new OnPgpEngineResult() {
|
||||
|
||||
@Override
|
||||
public void userInputRequried(
|
||||
PendingIntent pi) {
|
||||
activity.runIntent(
|
||||
pi,
|
||||
ConversationActivity.REQUEST_SEND_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void success() {
|
||||
xmppConnectionService.sendMessage(pendingMessage, null);
|
||||
pendingMessage = null;
|
||||
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
|
||||
.findFragmentByTag("conversation");
|
||||
if (selectedFragment != null) {
|
||||
selectedFragment.clearInputField();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(
|
||||
OpenPgpError openPgpError) {
|
||||
// TODO Auto-generated method
|
||||
// stub
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -664,10 +664,10 @@ public class ConversationFragment extends Fragment {
|
|||
}
|
||||
|
||||
protected void sendPgpMessage(final Message message) {
|
||||
activity.pendingMessage = message;
|
||||
final ConversationActivity activity = (ConversationActivity) getActivity();
|
||||
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
||||
final Contact contact = message.getConversation().getContact();
|
||||
final Account account = message.getConversation().getAccount();
|
||||
if (activity.hasPgp()) {
|
||||
if (contact.getPgpKeyId() != 0) {
|
||||
xmppService.getPgpEngine().hasKey(contact,
|
||||
|
@ -677,37 +677,12 @@ public class ConversationFragment extends Fragment {
|
|||
public void userInputRequried(PendingIntent pi) {
|
||||
activity.runIntent(
|
||||
pi,
|
||||
ConversationActivity.REQUEST_SEND_MESSAGE);
|
||||
ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void success() {
|
||||
xmppService.getPgpEngine().encrypt(account,
|
||||
message, new OnPgpEngineResult() {
|
||||
|
||||
@Override
|
||||
public void userInputRequried(
|
||||
PendingIntent pi) {
|
||||
activity.runIntent(
|
||||
pi,
|
||||
ConversationActivity.REQUEST_SEND_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void success() {
|
||||
xmppService.sendMessage(
|
||||
message, null);
|
||||
chatMsg.setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(
|
||||
OpenPgpError openPgpError) {
|
||||
// TODO Auto-generated method
|
||||
// stub
|
||||
|
||||
}
|
||||
});
|
||||
activity.encryptTextMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -809,4 +784,8 @@ public class ConversationFragment extends Fragment {
|
|||
public void setText(String text) {
|
||||
this.pastedText = text;
|
||||
}
|
||||
|
||||
public void clearInputField() {
|
||||
this.chatMsg.setText("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -279,7 +279,7 @@ public class ManageAccountActivity extends XmppActivity {
|
|||
} else if (item.getItemId()==R.id.mgmt_account_announce_pgp) {
|
||||
if (activity.hasPgp()) {
|
||||
mode.finish();
|
||||
announcePgp(selectedAccountForActionMode);
|
||||
announcePgp(selectedAccountForActionMode,null);
|
||||
}
|
||||
} else if (item.getItemId() == R.id.mgmt_otr_key) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
|
@ -458,7 +458,7 @@ public class ManageAccountActivity extends XmppActivity {
|
|||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == REQUEST_ANNOUNCE_PGP) {
|
||||
announcePgp(selectedAccountForActionMode);
|
||||
announcePgp(selectedAccountForActionMode,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import eu.siacs.conversations.R;
|
|||
import eu.siacs.conversations.crypto.OnPgpEngineResult;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.services.XmppConnectionService;
|
||||
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
|
||||
import eu.siacs.conversations.utils.ExceptionHelper;
|
||||
|
@ -162,7 +163,7 @@ public abstract class XmppActivity extends Activity {
|
|||
startActivity(viewConversationIntent);
|
||||
}
|
||||
|
||||
protected void announcePgp(final Account account) {
|
||||
protected void announcePgp(final Account account, final Conversation conversation) {
|
||||
xmppConnectionService.getPgpEngine().generateSignature(account, "online", new OnPgpEngineResult() {
|
||||
|
||||
@Override
|
||||
|
@ -178,6 +179,9 @@ public abstract class XmppActivity extends Activity {
|
|||
public void success() {
|
||||
xmppConnectionService.databaseBackend.updateAccount(account);
|
||||
xmppConnectionService.sendPgpPresence(account, account.getPgpSignature());
|
||||
if (conversation!=null) {
|
||||
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue