mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
work on passphrase data flow
This commit is contained in:
parent
6cc7b6141a
commit
8bd8267a47
@ -50,6 +50,7 @@ import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.InputData;
|
import org.sufficientlysecure.keychain.util.InputData;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@ -164,18 +165,41 @@ public class PgpSignEncryptOperation extends BaseOperation {
|
|||||||
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signingKey.getSecretKeyType() != SecretKeyType.DIVERT_TO_CARD) {
|
switch (signingKey.getSecretKeyType()) {
|
||||||
if (cryptoInput.getPassphrase() == null) {
|
case DIVERT_TO_CARD:
|
||||||
log.add(LogType.MSG_PSE_PENDING_PASSPHRASE, indent + 1);
|
case PASSPHRASE_EMPTY: {
|
||||||
return new PgpSignEncryptResult(log, RequiredInputParcel.createRequiredPassphrase(
|
if (!signingKey.unlock(new Passphrase())) {
|
||||||
signingKeyRing.getMasterKeyId(), signingKey.getKeyId(),
|
throw new AssertionError(
|
||||||
cryptoInput.getSignatureTime()));
|
"PASSPHRASE_EMPTY/DIVERT_TO_CARD keyphrase not unlocked with empty passphrase."
|
||||||
|
+ " This is a programming error!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PIN:
|
||||||
|
case PATTERN:
|
||||||
|
case PASSPHRASE: {
|
||||||
|
if (cryptoInput.getPassphrase() == null) {
|
||||||
|
log.add(LogType.MSG_PSE_PENDING_PASSPHRASE, indent + 1);
|
||||||
|
return new PgpSignEncryptResult(log, RequiredInputParcel.createRequiredPassphrase(
|
||||||
|
signingKeyRing.getMasterKeyId(), signingKey.getKeyId(),
|
||||||
|
cryptoInput.getSignatureTime()));
|
||||||
|
}
|
||||||
|
if (!signingKey.unlock(cryptoInput.getPassphrase())) {
|
||||||
|
log.add(LogType.MSG_PSE_ERROR_BAD_PASSPHRASE, indent);
|
||||||
|
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case GNU_DUMMY: {
|
||||||
|
log.add(LogType.MSG_PSE_ERROR_UNLOCK, indent);
|
||||||
|
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw new AssertionError("Unhandled SecretKeyType! (should not happen)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!signingKey.unlock(cryptoInput.getPassphrase())) {
|
|
||||||
log.add(LogType.MSG_PSE_ERROR_BAD_PASSPHRASE, indent);
|
|
||||||
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
@ -62,6 +62,11 @@ public abstract class CryptoOperationFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
|
onCryptoOperationCancelled();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_CODE_PASSPHRASE: {
|
case REQUEST_CODE_PASSPHRASE: {
|
||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
@ -116,4 +121,8 @@ public abstract class CryptoOperationFragment extends Fragment {
|
|||||||
|
|
||||||
protected abstract void cryptoOperation(CryptoInputParcel cryptoInput);
|
protected abstract void cryptoOperation(CryptoInputParcel cryptoInput);
|
||||||
|
|
||||||
|
protected void onCryptoOperationCancelled() {
|
||||||
|
// Nothing to do here, in most cases
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -253,8 +253,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
message = getString(R.string.yubikey_pin_for, userId);
|
message = getString(R.string.yubikey_pin_for, userId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
message = "This should not happen!";
|
throw new AssertionError("Unhandled SecretKeyType (should not happen)");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
@ -4,6 +4,7 @@ package org.sufficientlysecure.keychain.ui.base;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
@ -130,6 +131,11 @@ public abstract class BaseNfcActivity extends BaseActivity {
|
|||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_CODE_PASSPHRASE:
|
case REQUEST_CODE_PASSPHRASE:
|
||||||
|
if (resultCode != Activity.RESULT_OK) {
|
||||||
|
setResult(resultCode);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
CryptoInputParcel input = data.getParcelableExtra(PassphraseDialogActivity.RESULT_CRYPTO_INPUT);
|
CryptoInputParcel input = data.getParcelableExtra(PassphraseDialogActivity.RESULT_CRYPTO_INPUT);
|
||||||
mPin = input.getPassphrase();
|
mPin = input.getPassphrase();
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user