mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 18:40:19 -05:00
Result parcel refactorings (WIP)
This commit is contained in:
parent
a3e7406b3d
commit
8724916866
@ -138,7 +138,7 @@
|
|||||||
android:label="@string/title_select_recipients"
|
android:label="@string/title_select_recipients"
|
||||||
android:launchMode="singleTop" />
|
android:launchMode="singleTop" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.EncryptFileActivity"
|
android:name=".ui.EncryptFilesActivity"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||||
android:label="@string/title_encrypt_files"
|
android:label="@string/title_encrypt_files"
|
||||||
android:windowSoftInputMode="stateHidden">
|
android:windowSoftInputMode="stateHidden">
|
||||||
|
@ -22,7 +22,7 @@ import android.os.Environment;
|
|||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.sufficientlysecure.keychain.remote.ui.AppsListActivity;
|
import org.sufficientlysecure.keychain.remote.ui.AppsListActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.DecryptActivity;
|
import org.sufficientlysecure.keychain.ui.DecryptActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.EncryptFileActivity;
|
import org.sufficientlysecure.keychain.ui.EncryptFilesActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.EncryptTextActivity;
|
import org.sufficientlysecure.keychain.ui.EncryptTextActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.KeyListActivity;
|
import org.sufficientlysecure.keychain.ui.KeyListActivity;
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public final class Constants {
|
|||||||
public static final class DrawerItems {
|
public static final class DrawerItems {
|
||||||
public static final Class KEY_LIST = KeyListActivity.class;
|
public static final Class KEY_LIST = KeyListActivity.class;
|
||||||
public static final Class ENCRYPT_TEXT = EncryptTextActivity.class;
|
public static final Class ENCRYPT_TEXT = EncryptTextActivity.class;
|
||||||
public static final Class ENCRYPT_FILE = EncryptFileActivity.class;
|
public static final Class ENCRYPT_FILE = EncryptFilesActivity.class;
|
||||||
public static final Class DECRYPT = DecryptActivity.class;
|
public static final Class DECRYPT = DecryptActivity.class;
|
||||||
public static final Class REGISTERED_APPS_LIST = AppsListActivity.class;
|
public static final Class REGISTERED_APPS_LIST = AppsListActivity.class;
|
||||||
public static final Class[] ARRAY = new Class[]{
|
public static final Class[] ARRAY = new Class[]{
|
||||||
|
@ -48,7 +48,7 @@ import java.io.File;
|
|||||||
|
|
||||||
public class DecryptFilesFragment extends DecryptFragment {
|
public class DecryptFilesFragment extends DecryptFragment {
|
||||||
public static final String ARG_URI = "uri";
|
public static final String ARG_URI = "uri";
|
||||||
// public static final String ARG_FROM_VIEW_INTENT = "view_intent";
|
// public static final String ARG_FROM_VIEW_INTENT = "view_intent";
|
||||||
public static final String ARG_OPEN_DIRECTLY = "open_directly";
|
public static final String ARG_OPEN_DIRECTLY = "open_directly";
|
||||||
|
|
||||||
private static final int REQUEST_CODE_INPUT = 0x00007003;
|
private static final int REQUEST_CODE_INPUT = 0x00007003;
|
||||||
@ -204,20 +204,28 @@ public class DecryptFilesFragment extends DecryptFragment {
|
|||||||
// get returned data bundle
|
// get returned data bundle
|
||||||
Bundle returnData = message.getData();
|
Bundle returnData = message.getData();
|
||||||
|
|
||||||
DecryptVerifyResult result =
|
DecryptVerifyResult pgpResult =
|
||||||
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
|
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
|
||||||
|
|
||||||
switch (result.getResult()) {
|
if (pgpResult.isPending()) {
|
||||||
case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
|
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
|
||||||
showPassphraseDialog(result.getKeyIdPassphraseNeeded());
|
DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) {
|
||||||
return;
|
showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
|
||||||
case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
|
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
|
||||||
|
DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) {
|
||||||
showPassphraseDialog(Constants.key.symmetric);
|
showPassphraseDialog(Constants.key.symmetric);
|
||||||
return;
|
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
|
||||||
|
DecryptVerifyResult.RESULT_PENDING_NFC) {
|
||||||
|
// TODO
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Unhandled pending result!");
|
||||||
|
}
|
||||||
|
} else if (pgpResult.success()) {
|
||||||
|
// go on...
|
||||||
|
askForOutputFilename(pgpResult.getDecryptMetadata().getFilename());
|
||||||
|
} else {
|
||||||
|
pgpResult.createNotify(getActivity()).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// go on...
|
|
||||||
askForOutputFilename(result.getDecryptMetadata().getFilename());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -284,41 +292,45 @@ public class DecryptFilesFragment extends DecryptFragment {
|
|||||||
// get returned data bundle
|
// get returned data bundle
|
||||||
Bundle returnData = message.getData();
|
Bundle returnData = message.getData();
|
||||||
|
|
||||||
DecryptVerifyResult result =
|
DecryptVerifyResult pgpResult =
|
||||||
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
|
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
|
||||||
|
|
||||||
if (result.isPending()) {
|
if (pgpResult.isPending()) {
|
||||||
switch (result.getResult()) {
|
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
|
||||||
case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
|
DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) {
|
||||||
showPassphraseDialog(result.getKeyIdPassphraseNeeded());
|
showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
|
||||||
return;
|
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
|
||||||
case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
|
DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) {
|
||||||
showPassphraseDialog(Constants.key.symmetric);
|
showPassphraseDialog(Constants.key.symmetric);
|
||||||
return;
|
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
|
||||||
|
DecryptVerifyResult.RESULT_PENDING_NFC) {
|
||||||
|
// TODO
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Unhandled pending result!");
|
||||||
}
|
}
|
||||||
// error, we can't work with this!
|
} else if (pgpResult.success()) {
|
||||||
result.createNotify(getActivity());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// display signature result in activity
|
// display signature result in activity
|
||||||
onResult(result);
|
onResult(pgpResult);
|
||||||
|
|
||||||
if (mDeleteAfter.isChecked()) {
|
if (mDeleteAfter.isChecked()) {
|
||||||
// Create and show dialog to delete original file
|
// Create and show dialog to delete original file
|
||||||
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(mInputUri);
|
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(mInputUri);
|
||||||
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
|
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
|
||||||
setInputUri(null);
|
setInputUri(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// A future open after decryption feature
|
// A future open after decryption feature
|
||||||
if () {
|
if () {
|
||||||
Intent viewFile = new Intent(Intent.ACTION_VIEW);
|
Intent viewFile = new Intent(Intent.ACTION_VIEW);
|
||||||
viewFile.setData(mOutputUri);
|
viewFile.setData(mOutputUri);
|
||||||
startActivity(viewFile);
|
startActivity(viewFile);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
|
pgpResult.createNotify(getActivity()).show();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -126,34 +126,37 @@ public class DecryptTextFragment extends DecryptFragment {
|
|||||||
// get returned data bundle
|
// get returned data bundle
|
||||||
Bundle returnData = message.getData();
|
Bundle returnData = message.getData();
|
||||||
|
|
||||||
DecryptVerifyResult result =
|
DecryptVerifyResult pgpResult =
|
||||||
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
|
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
|
||||||
|
|
||||||
if (result.isPending()) {
|
if (pgpResult.isPending()) {
|
||||||
switch (result.getResult()) {
|
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
|
||||||
case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
|
DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) {
|
||||||
showPassphraseDialog(result.getKeyIdPassphraseNeeded());
|
showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
|
||||||
return;
|
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
|
||||||
case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
|
DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) {
|
||||||
showPassphraseDialog(Constants.key.symmetric);
|
showPassphraseDialog(Constants.key.symmetric);
|
||||||
return;
|
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
|
||||||
|
DecryptVerifyResult.RESULT_PENDING_NFC) {
|
||||||
|
// TODO
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Unhandled pending result!");
|
||||||
}
|
}
|
||||||
// error, we can't work with this!
|
} else if (pgpResult.success()) {
|
||||||
result.createNotify(getActivity()).show();
|
|
||||||
return;
|
byte[] decryptedMessage = returnData
|
||||||
|
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);
|
||||||
|
mMessage.setText(new String(decryptedMessage));
|
||||||
|
mMessage.setHorizontallyScrolling(false);
|
||||||
|
|
||||||
|
pgpResult.createNotify(getActivity()).show();
|
||||||
|
|
||||||
|
// display signature result in activity
|
||||||
|
onResult(pgpResult);
|
||||||
|
} else {
|
||||||
|
pgpResult.createNotify(getActivity()).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] decryptedMessage = returnData
|
|
||||||
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);
|
|
||||||
mMessage.setText(new String(decryptedMessage));
|
|
||||||
mMessage.setHorizontallyScrolling(false);
|
|
||||||
|
|
||||||
result.createNotify(getActivity()).show();
|
|
||||||
|
|
||||||
// display signature result in activity
|
|
||||||
onResult(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.nfc.NfcActivity;
|
||||||
|
|
||||||
|
public class EncryptActivity extends DrawerActivity {
|
||||||
|
protected void startNfcSign(String pin, byte[] hashToSign, int hashAlgo) {
|
||||||
|
Intent data = new Intent();
|
||||||
|
|
||||||
|
// build PendingIntent for Yubikey NFC operations
|
||||||
|
Intent intent = new Intent(this, NfcActivity.class);
|
||||||
|
intent.setAction(NfcActivity.ACTION_SIGN_HASH);
|
||||||
|
// pass params through to activity that it can be returned again later to repeat pgp operation
|
||||||
|
intent.putExtra(NfcActivity.EXTRA_DATA, data);
|
||||||
|
intent.putExtra(NfcActivity.EXTRA_PIN, pin);
|
||||||
|
|
||||||
|
intent.putExtra(NfcActivity.EXTRA_NFC_HASH_TO_SIGN, hashToSign);
|
||||||
|
intent.putExtra(NfcActivity.EXTRA_NFC_HASH_ALGO, hashAlgo);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|
||||||
|
startActivityForResult(intent, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startPassphraseDialog(long subkeyId) {
|
||||||
|
Intent data = new Intent();
|
||||||
|
|
||||||
|
// build PendingIntent for Yubikey NFC operations
|
||||||
|
Intent intent = new Intent(this, PassphraseDialogActivity.class);
|
||||||
|
// pass params through to activity that it can be returned again later to repeat pgp operation
|
||||||
|
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId);
|
||||||
|
|
||||||
|
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|
||||||
|
startActivityForResult(intent, 0);
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,6 @@ import android.app.ProgressDialog;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
@ -32,15 +31,13 @@ import android.view.MenuItem;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
|
import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
|
||||||
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
|
|
||||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||||
import org.sufficientlysecure.keychain.helper.ShareHelper;
|
import org.sufficientlysecure.keychain.helper.ShareHelper;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.results.SignEncryptResult;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Notify;
|
import org.sufficientlysecure.keychain.util.Notify;
|
||||||
|
|
||||||
@ -48,7 +45,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EncryptFileActivity extends DrawerActivity implements EncryptActivityInterface {
|
public class EncryptFilesActivity extends EncryptActivity implements EncryptActivityInterface {
|
||||||
|
|
||||||
/* Intents */
|
/* Intents */
|
||||||
public static final String ACTION_ENCRYPT_DATA = OpenKeychainIntents.ENCRYPT_DATA;
|
public static final String ACTION_ENCRYPT_DATA = OpenKeychainIntents.ENCRYPT_DATA;
|
||||||
@ -194,24 +191,44 @@ public class EncryptFileActivity extends DrawerActivity implements EncryptActivi
|
|||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
|
||||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
Notify.showNotify(EncryptFileActivity.this, R.string.encrypt_sign_successful, Notify.Style.INFO);
|
Notify.showNotify(EncryptFilesActivity.this, R.string.encrypt_sign_successful, Notify.Style.INFO);
|
||||||
|
|
||||||
if (mDeleteAfterEncrypt) {
|
SignEncryptResult pgpResult =
|
||||||
for (Uri inputUri : mInputUris) {
|
message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
|
||||||
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(inputUri);
|
|
||||||
deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
|
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();
|
||||||
}
|
}
|
||||||
mInputUris.clear();
|
|
||||||
notifyUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mShareAfterEncrypt) {
|
if (mShareAfterEncrypt) {
|
||||||
// Share encrypted message/file
|
// Share encrypted message/file
|
||||||
startActivity(sendWithChooserExcludingEncrypt(message));
|
startActivity(sendWithChooserExcludingEncrypt(message));
|
||||||
|
} else {
|
||||||
|
// Save encrypted file
|
||||||
|
Notify.showNotify(EncryptFilesActivity.this,
|
||||||
|
R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Save encrypted file
|
pgpResult.createNotify(EncryptFilesActivity.this).show();
|
||||||
Notify.showNotify(EncryptFileActivity.this,
|
|
||||||
R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,25 +353,25 @@ public class EncryptFileActivity extends DrawerActivity implements EncryptActivi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
if (mSigningKeyId != 0 && PassphraseCacheService.getCachedPassphrase(this, mSigningKeyId) == null) {
|
// if (mSigningKeyId != 0 && PassphraseCacheService.getCachedPassphrase(this, mSigningKeyId) == null) {
|
||||||
PassphraseDialogFragment.show(this, mSigningKeyId,
|
// PassphraseDialogFragment.show(this, mSigningKeyId,
|
||||||
new Handler() {
|
// new Handler() {
|
||||||
@Override
|
// @Override
|
||||||
public void handleMessage(Message message) {
|
// public void handleMessage(Message message) {
|
||||||
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
// if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
||||||
// restart
|
// // restart
|
||||||
startEncrypt();
|
// startEncrypt();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
} catch (PassphraseCacheService.KeyNotFoundException e) {
|
// } catch (PassphraseCacheService.KeyNotFoundException e) {
|
||||||
Log.e(Constants.TAG, "Key not found!", e);
|
// Log.e(Constants.TAG, "Key not found!", e);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -43,10 +43,9 @@ import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class EncryptFileFragment extends Fragment implements EncryptActivityInterface.UpdateListener {
|
public class EncryptFilesFragment extends Fragment implements EncryptActivityInterface.UpdateListener {
|
||||||
public static final String ARG_URIS = "uris";
|
public static final String ARG_URIS = "uris";
|
||||||
|
|
||||||
private static final int REQUEST_CODE_INPUT = 0x00007003;
|
private static final int REQUEST_CODE_INPUT = 0x00007003;
|
||||||
@ -115,9 +114,9 @@ public class EncryptFileFragment extends Fragment implements EncryptActivityInte
|
|||||||
|
|
||||||
private void addInputUri() {
|
private void addInputUri() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
FileHelper.openDocument(EncryptFileFragment.this, "*/*", true, REQUEST_CODE_INPUT);
|
FileHelper.openDocument(EncryptFilesFragment.this, "*/*", true, REQUEST_CODE_INPUT);
|
||||||
} else {
|
} else {
|
||||||
FileHelper.openFile(EncryptFileFragment.this, mEncryptInterface.getInputUris().isEmpty() ?
|
FileHelper.openFile(EncryptFilesFragment.this, mEncryptInterface.getInputUris().isEmpty() ?
|
||||||
null : mEncryptInterface.getInputUris().get(mEncryptInterface.getInputUris().size() - 1),
|
null : mEncryptInterface.getInputUris().get(mEncryptInterface.getInputUris().size() - 1),
|
||||||
"*/*", REQUEST_CODE_INPUT);
|
"*/*", REQUEST_CODE_INPUT);
|
||||||
}
|
}
|
@ -46,7 +46,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EncryptTextActivity extends DrawerActivity implements EncryptActivityInterface {
|
public class EncryptTextActivity extends EncryptActivity implements EncryptActivityInterface {
|
||||||
|
|
||||||
/* Intents */
|
/* Intents */
|
||||||
public static final String ACTION_ENCRYPT_TEXT = OpenKeychainIntents.ENCRYPT_TEXT;
|
public static final String ACTION_ENCRYPT_TEXT = OpenKeychainIntents.ENCRYPT_TEXT;
|
||||||
@ -192,39 +192,35 @@ public class EncryptTextActivity extends DrawerActivity implements EncryptActivi
|
|||||||
|
|
||||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
|
|
||||||
SignEncryptResult result =
|
SignEncryptResult pgpResult =
|
||||||
message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
|
message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
|
||||||
|
|
||||||
if (result.isPending()) {
|
if (pgpResult.isPending()) {
|
||||||
Log.d(Constants.TAG, "result.getResult() " + result.getResult());
|
if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
|
||||||
if ((result.getResult() & SignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
|
|
||||||
SignEncryptResult.RESULT_PENDING_PASSPHRASE) {
|
SignEncryptResult.RESULT_PENDING_PASSPHRASE) {
|
||||||
Log.d(Constants.TAG, "passp");
|
startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
|
||||||
startPassphraseDialog(result.getKeyIdPassphraseNeeded());
|
} else if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_NFC) ==
|
||||||
} else if ((result.getResult() & SignEncryptResult.RESULT_PENDING_NFC) ==
|
|
||||||
SignEncryptResult.RESULT_PENDING_NFC) {
|
SignEncryptResult.RESULT_PENDING_NFC) {
|
||||||
Log.d(Constants.TAG, "nfc");
|
|
||||||
|
|
||||||
// use after nfc sign
|
// use after nfc sign
|
||||||
//// data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, result.getNfcTimestamp().getTime());
|
//// data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, result.getNfcTimestamp().getTime());
|
||||||
startNfcSign("123456", result.getNfcHash(), result.getNfcAlgo());
|
startNfcSign("123456", pgpResult.getNfcHash(), pgpResult.getNfcAlgo());
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unhandled pending result!");
|
throw new RuntimeException("Unhandled pending result!");
|
||||||
}
|
}
|
||||||
|
} else if (pgpResult.success()) {
|
||||||
} else if (result.success()) {
|
|
||||||
if (mShareAfterEncrypt) {
|
if (mShareAfterEncrypt) {
|
||||||
// Share encrypted message/file
|
// Share encrypted message/file
|
||||||
startActivity(sendWithChooserExcludingEncrypt(message));
|
startActivity(sendWithChooserExcludingEncrypt(message));
|
||||||
} else {
|
} else {
|
||||||
// Copy to clipboard
|
// Copy to clipboard
|
||||||
copyToClipboard(message);
|
copyToClipboard(message);
|
||||||
result.createNotify(EncryptTextActivity.this).show();
|
pgpResult.createNotify(EncryptTextActivity.this).show();
|
||||||
// Notify.showNotify(EncryptTextActivity.this,
|
// Notify.showNotify(EncryptTextActivity.this,
|
||||||
// R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
|
// R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.createNotify(EncryptTextActivity.this).show();
|
pgpResult.createNotify(EncryptTextActivity.this).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,36 +236,6 @@ public class EncryptTextActivity extends DrawerActivity implements EncryptActivi
|
|||||||
startService(intent);
|
startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startNfcSign(String pin, byte[] hashToSign, int hashAlgo) {
|
|
||||||
Intent data = new Intent();
|
|
||||||
|
|
||||||
// build PendingIntent for Yubikey NFC operations
|
|
||||||
Intent intent = new Intent(this, NfcActivity.class);
|
|
||||||
intent.setAction(NfcActivity.ACTION_SIGN_HASH);
|
|
||||||
// pass params through to activity that it can be returned again later to repeat pgp operation
|
|
||||||
intent.putExtra(NfcActivity.EXTRA_DATA, data);
|
|
||||||
intent.putExtra(NfcActivity.EXTRA_PIN, pin);
|
|
||||||
|
|
||||||
intent.putExtra(NfcActivity.EXTRA_NFC_HASH_TO_SIGN, hashToSign);
|
|
||||||
intent.putExtra(NfcActivity.EXTRA_NFC_HASH_ALGO, hashAlgo);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
|
|
||||||
startActivityForResult(intent, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startPassphraseDialog(long subkeyId) {
|
|
||||||
Intent data = new Intent();
|
|
||||||
|
|
||||||
// build PendingIntent for Yubikey NFC operations
|
|
||||||
Intent intent = new Intent(this, PassphraseDialogActivity.class);
|
|
||||||
// pass params through to activity that it can be returned again later to repeat pgp operation
|
|
||||||
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId);
|
|
||||||
|
|
||||||
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
|
|
||||||
startActivityForResult(intent, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Bundle createEncryptBundle() {
|
private Bundle createEncryptBundle() {
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
|
@ -35,8 +35,6 @@ import android.support.v4.content.CursorLoader;
|
|||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v4.widget.CursorAdapter;
|
import android.support.v4.widget.CursorAdapter;
|
||||||
import android.support.v4.widget.NoScrollableSwipeRefreshLayout;
|
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
@ -394,9 +392,9 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
protected void encrypt(ActionMode mode, long[] masterKeyIds) {
|
protected void encrypt(ActionMode mode, long[] masterKeyIds) {
|
||||||
Intent intent = new Intent(getActivity(), EncryptFileActivity.class);
|
Intent intent = new Intent(getActivity(), EncryptFilesActivity.class);
|
||||||
intent.setAction(EncryptFileActivity.ACTION_ENCRYPT_DATA);
|
intent.setAction(EncryptFilesActivity.ACTION_ENCRYPT_DATA);
|
||||||
intent.putExtra(EncryptFileActivity.EXTRA_ENCRYPTION_KEY_IDS, masterKeyIds);
|
intent.putExtra(EncryptFilesActivity.EXTRA_ENCRYPTION_KEY_IDS, masterKeyIds);
|
||||||
// used instead of startActivity set actionbar based on callingPackage
|
// used instead of startActivity set actionbar based on callingPackage
|
||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
|
|
||||||
|
@ -302,9 +302,9 @@ public class ViewKeyMainFragment extends LoaderFragment implements
|
|||||||
intent.setAction(EncryptTextActivity.ACTION_ENCRYPT_TEXT);
|
intent.setAction(EncryptTextActivity.ACTION_ENCRYPT_TEXT);
|
||||||
intent.putExtra(EncryptTextActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
intent.putExtra(EncryptTextActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
||||||
} else {
|
} else {
|
||||||
intent = new Intent(getActivity(), EncryptFileActivity.class);
|
intent = new Intent(getActivity(), EncryptFilesActivity.class);
|
||||||
intent.setAction(EncryptFileActivity.ACTION_ENCRYPT_DATA);
|
intent.setAction(EncryptFilesActivity.ACTION_ENCRYPT_DATA);
|
||||||
intent.putExtra(EncryptFileActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
intent.putExtra(EncryptFilesActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
||||||
}
|
}
|
||||||
// used instead of startActivity set actionbar based on callingPackage
|
// used instead of startActivity set actionbar based on callingPackage
|
||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/encrypt_file_fragment"
|
android:id="@+id/encrypt_file_fragment"
|
||||||
android:name="org.sufficientlysecure.keychain.ui.EncryptFileFragment"
|
android:name="org.sufficientlysecure.keychain.ui.EncryptFilesFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user