aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java2
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java8
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java113
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java112
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java31
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java148
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcActivity.java11
7 files changed, 171 insertions, 254 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java
index 2e4620813..c7d6455ab 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java
@@ -569,7 +569,7 @@ public class PgpSignEncrypt {
log.add(LogType.MSG_SE_PENDING_NFC, indent);
SignEncryptResult result =
new SignEncryptResult(SignEncryptResult.RESULT_PENDING_NFC, log);
- result.setNfcData(e.hashToSign, e.hashAlgo, e.creationTimestamp);
+ result.setNfcData(e.hashToSign, e.hashAlgo, e.creationTimestamp, mSignaturePassphrase);
Log.d(Constants.TAG, "e.hashToSign"+ Hex.toHexString(e.hashToSign));
return result;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java
index 84eb29a62..0f3c93385 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java
@@ -35,6 +35,7 @@ public class SignEncryptResult extends OperationResult {
byte[] mNfcHash;
int mNfcAlgo;
Date mNfcTimestamp;
+ String mNfcPassphrase;
public long getKeyIdPassphraseNeeded() {
return mKeyIdPassphraseNeeded;
@@ -44,10 +45,11 @@ public class SignEncryptResult extends OperationResult {
mKeyIdPassphraseNeeded = keyIdPassphraseNeeded;
}
- public void setNfcData(byte[] nfcHash, int nfcAlgo, Date nfcTimestamp) {
+ public void setNfcData(byte[] nfcHash, int nfcAlgo, Date nfcTimestamp, String passphrase) {
mNfcHash = nfcHash;
mNfcAlgo = nfcAlgo;
mNfcTimestamp = nfcTimestamp;
+ mNfcPassphrase = passphrase;
}
public byte[] getNfcHash() {
@@ -62,6 +64,10 @@ public class SignEncryptResult extends OperationResult {
return mNfcTimestamp;
}
+ public String getNfcPassphrase() {
+ return mNfcPassphrase;
+ }
+
public boolean isPending() {
return (mResult & RESULT_PENDING) == RESULT_PENDING;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
index c1c3409f8..9a41f4fbc 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
@@ -1,12 +1,29 @@
package org.sufficientlysecure.keychain.ui;
+import android.app.ProgressDialog;
import android.content.Intent;
+import android.os.Bundle;
+import android.os.Message;
+import android.os.Messenger;
-public class EncryptActivity extends DrawerActivity {
+import org.openintents.openpgp.util.OpenPgpApi;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.service.KeychainIntentService;
+import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
+import org.sufficientlysecure.keychain.service.results.SignEncryptResult;
+
+import java.util.Date;
+
+public abstract class EncryptActivity extends DrawerActivity {
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
public static final int REQUEST_CODE_NFC = 0x00008002;
+ // For NFC data
+ protected String mSigningKeyPassphrase = null;
+ protected Date mNfcTimestamp = null;
+ protected byte[] mNfcHash = null;
+
protected void startPassphraseDialog(long subkeyId) {
Intent intent = new Intent(this, PassphraseDialogActivity.class);
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId);
@@ -28,5 +45,99 @@ public class EncryptActivity extends DrawerActivity {
startActivityForResult(intent, REQUEST_CODE_NFC);
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case REQUEST_CODE_PASSPHRASE: {
+ if (resultCode == RESULT_OK && data != null) {
+ mSigningKeyPassphrase = data.getStringExtra(PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE);
+ startEncrypt();
+ return;
+ }
+ break;
+ }
+
+ case REQUEST_CODE_NFC: {
+ if (resultCode == RESULT_OK && data != null) {
+ mNfcHash = data.getByteArrayExtra(OpenPgpApi.EXTRA_NFC_SIGNED_HASH);
+ startEncrypt();
+ return;
+ }
+ break;
+ }
+
+ default: {
+ super.onActivityResult(requestCode, resultCode, data);
+ break;
+ }
+ }
+ }
+
+ public void startEncrypt() {
+ if (!inputIsValid()) {
+ // Notify was created by inputIsValid.
+ return;
+ }
+
+ // Send all information needed to service to edit key in other thread
+ Intent intent = new Intent(this, KeychainIntentService.class);
+ intent.setAction(KeychainIntentService.ACTION_SIGN_ENCRYPT);
+ intent.putExtra(KeychainIntentService.EXTRA_DATA, createEncryptBundle());
+
+ // Message is received after encrypting is done in KeychainIntentService
+ KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(this,
+ getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) {
+ public void handleMessage(Message message) {
+ // handle messages by standard KeychainIntentServiceHandler first
+ super.handleMessage(message);
+
+ if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
+ SignEncryptResult pgpResult =
+ message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
+
+ if (pgpResult.isPending()) {
+ if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
+ SignEncryptResult.RESULT_PENDING_PASSPHRASE) {
+ startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
+ } else if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_NFC) ==
+ SignEncryptResult.RESULT_PENDING_NFC) {
+
+ mNfcTimestamp = pgpResult.getNfcTimestamp();
+ startNfcSign(pgpResult.getNfcPassphrase(), pgpResult.getNfcHash(), pgpResult.getNfcAlgo());
+ } else {
+ throw new RuntimeException("Unhandled pending result!");
+ }
+ return;
+ }
+
+ if (pgpResult.success()) {
+ onEncryptSuccess(message, pgpResult);
+ } else {
+ pgpResult.createNotify(EncryptActivity.this).show();
+ }
+
+ // no matter the result, reset parameters
+ mSigningKeyPassphrase = null;
+ mNfcHash = null;
+ mNfcTimestamp = null;
+ }
+ }
+ };
+ // Create a new Messenger for the communication back
+ Messenger messenger = new Messenger(serviceHandler);
+ intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
+
+ // show progress dialog
+ serviceHandler.showProgressDialog(this);
+
+ // start service with intent
+ startService(intent);
+ }
+
+ protected abstract boolean inputIsValid();
+
+ protected abstract void onEncryptSuccess(Message message, SignEncryptResult result);
+
+ protected abstract Bundle createEncryptBundle();
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java
index 28fcb0b10..dc97bc8fb 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java
@@ -18,12 +18,10 @@
package org.sufficientlysecure.keychain.ui;
-import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
-import android.os.Messenger;
import android.support.v4.app.Fragment;
import android.view.Menu;
import android.view.MenuItem;
@@ -35,7 +33,6 @@ import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.ShareHelper;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
-import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.results.SignEncryptResult;
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
@@ -172,76 +169,28 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
startEncrypt();
}
- public void startEncrypt() {
- if (!inputIsValid()) {
- // Notify was created by inputIsValid.
- return;
- }
-
- // Send all information needed to service to edit key in other thread
- Intent intent = new Intent(this, KeychainIntentService.class);
- intent.setAction(KeychainIntentService.ACTION_SIGN_ENCRYPT);
- intent.putExtra(KeychainIntentService.EXTRA_DATA, createEncryptBundle());
-
- // Message is received after encrypting is done in KeychainIntentService
- KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(this,
- getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) {
- public void handleMessage(Message message) {
- // handle messages by standard KeychainIntentServiceHandler first
- super.handleMessage(message);
-
- if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
- SignEncryptResult pgpResult =
- message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
-
- if (pgpResult.isPending()) {
- if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
- SignEncryptResult.RESULT_PENDING_PASSPHRASE) {
- startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
- } else if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_NFC) ==
- SignEncryptResult.RESULT_PENDING_NFC) {
-
- // use after nfc sign
-//// data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, result.getNfcTimestamp().getTime());
- startNfcSign("123456", pgpResult.getNfcHash(), pgpResult.getNfcAlgo());
- } else {
- throw new RuntimeException("Unhandled pending result!");
- }
- } else if (pgpResult.success()) {
- if (mDeleteAfterEncrypt) {
- for (Uri inputUri : mInputUris) {
- DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(inputUri);
- deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
- }
- mInputUris.clear();
- notifyUpdate();
- }
-
- if (mShareAfterEncrypt) {
- // Share encrypted message/file
- startActivity(sendWithChooserExcludingEncrypt(message));
- } else {
- // Save encrypted file
- pgpResult.createNotify(EncryptFilesActivity.this).show();
- }
- } else {
- pgpResult.createNotify(EncryptFilesActivity.this).show();
- }
- }
+ @Override
+ public void onEncryptSuccess(Message message, SignEncryptResult pgpResult) {
+ if (mDeleteAfterEncrypt) {
+ for (Uri inputUri : mInputUris) {
+ DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(inputUri);
+ deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
}
- };
- // Create a new Messenger for the communication back
- Messenger messenger = new Messenger(serviceHandler);
- intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
-
- // show progress dialog
- serviceHandler.showProgressDialog(this);
+ mInputUris.clear();
+ notifyUpdate();
+ }
- // start service with intent
- startService(intent);
+ if (mShareAfterEncrypt) {
+ // Share encrypted message/file
+ startActivity(sendWithChooserExcludingEncrypt(message));
+ } else {
+ // Save encrypted file
+ pgpResult.createNotify(EncryptFilesActivity.this).show();
+ }
}
- private Bundle createEncryptBundle() {
+ @Override
+ protected Bundle createEncryptBundle() {
// fill values for this action
Bundle data = new Bundle();
@@ -267,6 +216,9 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
} else {
data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_MASTER_ID, mSigningKeyId);
data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptionKeyIds);
+ data.putString(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_PASSPHRASE, mSigningKeyPassphrase);
+ data.putSerializable(KeychainIntentService.ENCRYPT_SIGNATURE_NFC_TIMESTAMP, mNfcTimestamp);
+ data.putByteArray(KeychainIntentService.ENCRYPT_SIGNATURE_NFC_HASH, mNfcHash);
}
return data;
}
@@ -312,7 +264,7 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
return sendIntent;
}
- private boolean inputIsValid() {
+ protected boolean inputIsValid() {
// file checks
if (mInputUris.isEmpty()) {
@@ -349,26 +301,6 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
Notify.showNotify(this, R.string.select_encryption_key, Notify.Style.ERROR);
return false;
}
-
-// try {
-// if (mSigningKeyId != 0 && PassphraseCacheService.getCachedPassphrase(this, mSigningKeyId) == null) {
-// PassphraseDialogFragment.show(this, mSigningKeyId,
-// new Handler() {
-// @Override
-// public void handleMessage(Message message) {
-// if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
-// // restart
-// startEncrypt();
-// }
-// }
-// }
-// );
-//
-// return false;
-// }
-// } catch (PassphraseCacheService.KeyNotFoundException e) {
-// Log.e(Constants.TAG, "Key not found!", e);
-// }
}
return true;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java
index 23021ce44..8569877af 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java
@@ -37,6 +37,7 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
+import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.FileHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
@@ -56,7 +57,6 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
// view
private View mAddView;
private View mShareFile;
- private View mEncryptFile;
private ListView mSelectedFiles;
private SelectedFilesAdapter mAdapter = new SelectedFilesAdapter();
private final Map<Uri, Bitmap> thumbnailCache = new HashMap<Uri, Bitmap>();
@@ -78,8 +78,8 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.encrypt_file_fragment, container, false);
- mEncryptFile = view.findViewById(R.id.action_encrypt_file);
- mEncryptFile.setOnClickListener(new View.OnClickListener() {
+ View vEncryptFile = view.findViewById(R.id.action_encrypt_file);
+ vEncryptFile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
encryptClicked(false);
@@ -130,31 +130,12 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
mEncryptInterface.getInputUris().add(inputUri);
mEncryptInterface.notifyUpdate();
mSelectedFiles.requestFocus();
-
- /**
- * We hide the encrypt to file button if multiple files are selected.
- *
- * With Android L it will be possible to select a target directory for multiple files, so we might want to
- * change this later
- */
-
- if (mEncryptInterface.getInputUris().size() > 1) {
- mEncryptFile.setVisibility(View.GONE);
- } else {
- mEncryptFile.setVisibility(View.VISIBLE);
- }
}
private void delInputUri(int position) {
mEncryptInterface.getInputUris().remove(position);
mEncryptInterface.notifyUpdate();
mSelectedFiles.requestFocus();
-
- if (mEncryptInterface.getInputUris().size() > 1) {
- mEncryptFile.setVisibility(View.GONE);
- } else {
- mEncryptFile.setVisibility(View.VISIBLE);
- }
}
private void showOutputFileDialog() {
@@ -185,7 +166,11 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
mEncryptInterface.getOutputUris().add(TemporaryStorageProvider.createFile(getActivity(), targetName));
}
mEncryptInterface.startEncrypt(true);
- } else if (mEncryptInterface.getInputUris().size() == 1) {
+ } else {
+ if (mEncryptInterface.getInputUris().size() > 1) {
+ Notify.showNotify(getActivity(), R.string.error_multi_not_supported, Notify.Style.ERROR);
+ return;
+ }
showOutputFileDialog();
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java
index 6598ec50c..f4d2040ed 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java
@@ -18,17 +18,14 @@
package org.sufficientlysecure.keychain.ui;
-import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
-import android.os.Messenger;
import android.support.v4.app.Fragment;
import android.view.Menu;
import android.view.MenuItem;
-import org.openintents.openpgp.util.OpenPgpApi;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
@@ -37,13 +34,11 @@ import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.ShareHelper;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
-import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.results.SignEncryptResult;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.ui.util.Notify;
import java.util.ArrayList;
-import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@@ -71,9 +66,6 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
private String mEncryptionUserIds[] = null;
// TODO Constants.key.none? What's wrong with a null value?
private long mSigningKeyId = Constants.key.none;
- private String mSigningKeyPassphrase = null;
- private Date mNfcTimestamp = null;
- private byte[] mNfcHash = null;
private String mPassphrase = "";
private boolean mShareAfterEncrypt = false;
private ArrayList<Uri> mInputUris;
@@ -176,105 +168,22 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
startEncrypt();
}
- public void startEncrypt() {
- if (!inputIsValid()) {
- // Notify was created by inputIsValid.
- return;
- }
-
- // Send all information needed to service to edit key in other thread
- Intent intent = new Intent(this, KeychainIntentService.class);
- intent.setAction(KeychainIntentService.ACTION_SIGN_ENCRYPT);
- intent.putExtra(KeychainIntentService.EXTRA_DATA, createEncryptBundle());
-
- // Message is received after encrypting is done in KeychainIntentService
- KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(this,
- getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) {
- public void handleMessage(Message message) {
- // handle messages by standard KeychainIntentServiceHandler first
- super.handleMessage(message);
-
- if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
-
- SignEncryptResult pgpResult =
- message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
-
- if (pgpResult.isPending()) {
- if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
- SignEncryptResult.RESULT_PENDING_PASSPHRASE) {
- startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
- } else if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_NFC) ==
- SignEncryptResult.RESULT_PENDING_NFC) {
-
- mNfcTimestamp = pgpResult.getNfcTimestamp();
- startNfcSign("123456", pgpResult.getNfcHash(), pgpResult.getNfcAlgo());
- } else {
- throw new RuntimeException("Unhandled pending result!");
- }
- } else {
- if (pgpResult.success()) {
- if (mShareAfterEncrypt) {
- // Share encrypted message/file
- startActivity(sendWithChooserExcludingEncrypt(message));
- } else {
- // Copy to clipboard
- copyToClipboard(message);
- pgpResult.createNotify(EncryptTextActivity.this).show();
- // Notify.showNotify(EncryptTextActivity.this,
- // R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
- }
- } else {
- pgpResult.createNotify(EncryptTextActivity.this).show();
- }
-
- // no matter the result, reset parameters
- mSigningKeyPassphrase = null;
- mNfcHash = null;
- mNfcTimestamp = null;
- }
- }
- }
- };
- // Create a new Messenger for the communication back
- Messenger messenger = new Messenger(serviceHandler);
- intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
-
- // show progress dialog
- serviceHandler.showProgressDialog(this);
-
- // start service with intent
- startService(intent);
- }
-
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch (requestCode) {
- case REQUEST_CODE_PASSPHRASE: {
- if (resultCode == RESULT_OK && data != null) {
- mSigningKeyPassphrase = data.getStringExtra(PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE);
- startEncrypt();
- return;
- }
- break;
- }
-
- case REQUEST_CODE_NFC: {
- if (resultCode == RESULT_OK && data != null) {
- mNfcHash = data.getByteArrayExtra(OpenPgpApi.EXTRA_NFC_SIGNED_HASH);
- startEncrypt();
- return;
- }
- break;
- }
-
- default: {
- super.onActivityResult(requestCode, resultCode, data);
- break;
- }
+ protected void onEncryptSuccess(Message message, SignEncryptResult pgpResult) {
+ if (mShareAfterEncrypt) {
+ // Share encrypted message/file
+ startActivity(sendWithChooserExcludingEncrypt(message));
+ } else {
+ // Copy to clipboard
+ copyToClipboard(message);
+ pgpResult.createNotify(EncryptTextActivity.this).show();
+ // Notify.showNotify(EncryptTextActivity.this,
+ // R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
}
}
- private Bundle createEncryptBundle() {
+ @Override
+ protected Bundle createEncryptBundle() {
// fill values for this action
Bundle data = new Bundle();
@@ -298,7 +207,6 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_MASTER_ID, mSigningKeyId);
data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptionKeyIds);
data.putString(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_PASSPHRASE, mSigningKeyPassphrase);
- data.putLongArray(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_PASSPHRASE, mEncryptionKeyIds);
data.putSerializable(KeychainIntentService.ENCRYPT_SIGNATURE_NFC_TIMESTAMP, mNfcTimestamp);
data.putByteArray(KeychainIntentService.ENCRYPT_SIGNATURE_NFC_HASH, mNfcHash);
}
@@ -344,7 +252,7 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
return sendIntent;
}
- private boolean inputIsValid() {
+ protected boolean inputIsValid() {
if (mMessage == null) {
Notify.showNotify(this, R.string.error_message, Notify.Style.ERROR);
return false;
@@ -372,36 +280,6 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
Notify.showNotify(this, R.string.select_encryption_or_signature_key, Notify.Style.ERROR);
return false;
}
-
-// try {
-// // TODO This should really not be decided here. We do need the info for the passphrase
-// // TODO dialog fragment though, so that's just the way it is for now.
-// if (mSigningKeyId != 0) {
-// CachedPublicKeyRing signingRing =
-// new ProviderHelper(this).getCachedPublicKeyRing(mSigningKeyId);
-// long sigSubKeyId = signingRing.getSignId();
-// // Make sure the passphrase is cached, then start over.
-// if (PassphraseCacheService.getCachedPassphrase(this, sigSubKeyId) == null) {
-// PassphraseDialogFragment.show(this, sigSubKeyId,
-// new Handler() {
-// @Override
-// public void handleMessage(Message message) {
-// if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
-// // restart
-// startEncrypt();
-// }
-// }
-// }
-// );
-//
-// return false;
-// }
-// }
-// } catch (PgpGeneralException e) {
-// Log.e(Constants.TAG, "Key not found!", e);
-// } catch (PassphraseCacheService.KeyNotFoundException e) {
-// Log.e(Constants.TAG, "Key not found!", e);
-// }
}
return true;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcActivity.java
index cd2d9cb85..fb2209d3e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcActivity.java
@@ -43,6 +43,7 @@ public class NfcActivity extends ActionBarActivity {
// always
public static final String EXTRA_PIN = "pin";
+ public static final String EXTRA_FINGERPRINT = "fingerprint";
// special extra for OpenPgpService
public static final String EXTRA_DATA = "data";
@@ -63,6 +64,8 @@ public class NfcActivity extends ActionBarActivity {
private String mPin;
+ private byte[] mFingerprint;
+
// sign
private byte[] mHashToSign;
private int mHashAlgo;
@@ -83,6 +86,9 @@ public class NfcActivity extends ActionBarActivity {
Bundle data = intent.getExtras();
String action = intent.getAction();
+ // TODO check fingerprint
+ // mFingerprint = data.getByteArray(EXTRA_FINGERPRINT);
+
if (ACTION_SIGN_HASH.equals(action)) {
mAction = action;
mPin = data.getString(EXTRA_PIN);
@@ -369,9 +375,8 @@ public class NfcActivity extends ActionBarActivity {
}
// Make sure the signature we received is actually the expected number of bytes long!
- // TODO this is only right for RSA 2048 bit keys. Do we support anything else right now?
- if (signature.length() != 512) {
- toast("Bad signature length! Expected 256 bytes, got " + signature.length() / 2);
+ if (signature.length() != 256 && signature.length() != 512) {
+ toast("Bad signature length! Expected 128 or 256 bytes, got " + signature.length() / 2);
return null;
}