generalize NfcOperationParcel to RequiredInputParcel, including passphrases
This commit is contained in:
@@ -166,7 +166,7 @@ public class CertifyKeyFragment extends CryptoOperationFragment
|
||||
Notify.showNotify(getActivity(), getString(R.string.select_key_to_certify),
|
||||
Notify.Style.ERROR);
|
||||
} else {
|
||||
cryptoOperation();
|
||||
cryptoOperation(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -307,15 +307,6 @@ public class CertifyKeyFragment extends CryptoOperationFragment
|
||||
mUserIdsAdapter.swapCursor(null);
|
||||
}
|
||||
|
||||
protected void cryptoOperation() {
|
||||
cryptoOperation((CryptoInputParcel) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cryptoOperation(String passphrase) {
|
||||
cryptoOperation((CryptoInputParcel) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
|
||||
// Bail out if there is not at least one user id selected
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler.MessageStatus;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.NfcOperationsParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
|
||||
|
||||
public abstract class CryptoOperationFragment extends Fragment {
|
||||
@@ -19,17 +19,28 @@ public abstract class CryptoOperationFragment extends Fragment {
|
||||
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
||||
public static final int REQUEST_CODE_NFC = 0x00008002;
|
||||
|
||||
private void startPassphraseDialog(long subkeyId) {
|
||||
Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
|
||||
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId);
|
||||
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
||||
}
|
||||
private void initiateInputActivity(RequiredInputParcel requiredInput) {
|
||||
|
||||
switch (requiredInput.mType) {
|
||||
case NFC_DECRYPT:
|
||||
case NFC_SIGN: {
|
||||
Intent intent = new Intent(getActivity(), NfcOperationActivity.class);
|
||||
intent.putExtra(NfcOperationActivity.EXTRA_PIN, "123456");
|
||||
intent.putExtra(NfcOperationActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||
startActivityForResult(intent, REQUEST_CODE_NFC);
|
||||
return;
|
||||
}
|
||||
|
||||
case PASSPHRASE: {
|
||||
Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
|
||||
intent.putExtra(PassphraseDialogActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unhandled pending result!");
|
||||
|
||||
private void initiateNfcInput(NfcOperationsParcel nfcOps) {
|
||||
Intent intent = new Intent(getActivity(), NfcOperationActivity.class);
|
||||
intent.putExtra(NfcOperationActivity.EXTRA_PIN, "123456");
|
||||
intent.putExtra(NfcOperationActivity.EXTRA_NFC_OPS, nfcOps);
|
||||
startActivityForResult(intent, REQUEST_CODE_NFC);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,8 +48,9 @@ public abstract class CryptoOperationFragment extends Fragment {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_PASSPHRASE: {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
String passphrase = data.getStringExtra(PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE);
|
||||
cryptoOperation(passphrase);
|
||||
CryptoInputParcel cryptoInput =
|
||||
data.getParcelableExtra(PassphraseDialogActivity.RESULT_DATA);
|
||||
cryptoOperation(cryptoInput);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -67,16 +79,9 @@ public abstract class CryptoOperationFragment extends Fragment {
|
||||
InputPendingResult result = data.getParcelable(CertifyResult.EXTRA_RESULT);
|
||||
|
||||
if (result != null && result.isPending()) {
|
||||
if (result.isPassphrasePending()) {
|
||||
startPassphraseDialog(result.getPassphraseKeyId());
|
||||
return true;
|
||||
} else if (result.isNfcPending()) {
|
||||
NfcOperationsParcel requiredInput = result.getNfcOperationsParcel();
|
||||
initiateNfcInput(requiredInput);
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled pending result!");
|
||||
}
|
||||
RequiredInputParcel requiredInput = result.getRequiredInputParcel();
|
||||
initiateInputActivity(requiredInput);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +89,5 @@ public abstract class CryptoOperationFragment extends Fragment {
|
||||
}
|
||||
|
||||
protected abstract void cryptoOperation(CryptoInputParcel cryptoInput);
|
||||
protected abstract void cryptoOperation(String passphrase);
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.NfcOperationsParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
|
||||
|
||||
public abstract class EncryptActivity extends BaseActivity {
|
||||
@@ -62,11 +62,11 @@ public abstract class EncryptActivity extends BaseActivity {
|
||||
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
||||
}
|
||||
|
||||
protected void startNfcSign(long keyId, String pin, NfcOperationsParcel nfcOps) {
|
||||
protected void startNfcSign(long keyId, String pin, RequiredInputParcel nfcOps) {
|
||||
|
||||
Intent intent = new Intent(this, NfcOperationActivity.class);
|
||||
intent.putExtra(NfcOperationActivity.EXTRA_PIN, pin);
|
||||
intent.putExtra(NfcOperationActivity.EXTRA_NFC_OPS, nfcOps);
|
||||
intent.putExtra(NfcOperationActivity.EXTRA_REQUIRED_INPUT, nfcOps);
|
||||
// TODO respect keyid(?)
|
||||
|
||||
startActivityForResult(intent, REQUEST_CODE_NFC);
|
||||
@@ -144,7 +144,7 @@ public abstract class EncryptActivity extends BaseActivity {
|
||||
} else if ((pgpResult.getResult() & PgpSignEncryptResult.RESULT_PENDING_NFC) ==
|
||||
PgpSignEncryptResult.RESULT_PENDING_NFC) {
|
||||
|
||||
NfcOperationsParcel parcel = NfcOperationsParcel.createNfcSignOperation(
|
||||
RequiredInputParcel parcel = RequiredInputParcel.createNfcSignOperation(
|
||||
pgpResult.getNfcHash(),
|
||||
pgpResult.getNfcAlgo(),
|
||||
input.getSignatureTime());
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.spongycastle.util.encoders.Hex;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.NfcOperationsParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.util.Iso7816TLV;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.nio.ByteBuffer;
|
||||
public class NfcOperationActivity extends BaseActivity {
|
||||
|
||||
public static final String EXTRA_PIN = "pin";
|
||||
public static final String EXTRA_NFC_OPS = "nfc_operations";
|
||||
public static final String EXTRA_REQUIRED_INPUT = "required_input";
|
||||
|
||||
public static final String RESULT_DATA = "result_data";
|
||||
|
||||
@@ -52,7 +52,7 @@ public class NfcOperationActivity extends BaseActivity {
|
||||
|
||||
private String mPin;
|
||||
|
||||
NfcOperationsParcel mNfcOperations;
|
||||
RequiredInputParcel mNfcOperations;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -69,7 +69,7 @@ public class NfcOperationActivity extends BaseActivity {
|
||||
|
||||
Bundle data = intent.getExtras();
|
||||
|
||||
mNfcOperations = data.getParcelable(EXTRA_NFC_OPS);
|
||||
mNfcOperations = data.getParcelable(EXTRA_REQUIRED_INPUT);
|
||||
mPin = data.getString(EXTRA_PIN);
|
||||
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
||||
@@ -53,6 +54,9 @@ import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
@@ -63,7 +67,9 @@ import org.sufficientlysecure.keychain.util.Preferences;
|
||||
*/
|
||||
public class PassphraseDialogActivity extends FragmentActivity {
|
||||
public static final String MESSAGE_DATA_PASSPHRASE = "passphrase";
|
||||
public static final String RESULT_DATA = "result_data";
|
||||
|
||||
public static final String EXTRA_REQUIRED_INPUT = "required_input";
|
||||
public static final String EXTRA_SUBKEY_ID = "secret_key_id";
|
||||
|
||||
// special extra for OpenPgpService
|
||||
@@ -86,7 +92,16 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
|
||||
// this activity itself has no content view (see manifest)
|
||||
|
||||
long keyId = getIntent().getLongExtra(EXTRA_SUBKEY_ID, 0);
|
||||
long keyId;
|
||||
if (getIntent().hasExtra(EXTRA_SUBKEY_ID)) {
|
||||
keyId = getIntent().getLongExtra(EXTRA_SUBKEY_ID, 0);
|
||||
} else {
|
||||
RequiredInputParcel requiredInput = getIntent().getParcelableExtra(EXTRA_REQUIRED_INPUT);
|
||||
if (requiredInput.mType != RequiredInputType.PASSPHRASE) {
|
||||
throw new AssertionError("Wrong required input type for PassphraseDialogActivity!");
|
||||
}
|
||||
keyId = requiredInput.getSubKeyId();
|
||||
}
|
||||
|
||||
Intent serviceIntent = getIntent().getParcelableExtra(EXTRA_DATA);
|
||||
|
||||
@@ -410,6 +425,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
// also return passphrase back to activity
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(MESSAGE_DATA_PASSPHRASE, passphrase);
|
||||
returnIntent.putExtra(RESULT_DATA, new CryptoInputParcel(null, passphrase));
|
||||
getActivity().setResult(RESULT_OK, returnIntent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user