mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
Handle wrong/no passphrase
This commit is contained in:
parent
5d7f8809fc
commit
c4bf7c5d11
@ -117,12 +117,19 @@ public class CryptoProviderDemoActivity extends Activity {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private void handleError(CryptoError error) {
|
private void handleError(final CryptoError error) {
|
||||||
Toast.makeText(mActivity, "onError id:" + error.getErrorId() + "\n\n" + error.getMessage(),
|
mActivity.runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(mActivity,
|
||||||
|
"onError id:" + error.getErrorId() + "\n\n" + error.getMessage(),
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
|
Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
|
||||||
Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
|
Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void encryptOnClick(View view) {
|
public void encryptOnClick(View view) {
|
||||||
byte[] inputBytes = mMessage.getText().toString().getBytes();
|
byte[] inputBytes = mMessage.getText().toString().getBytes();
|
||||||
|
@ -20,6 +20,8 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
public class CryptoError implements Parcelable {
|
public class CryptoError implements Parcelable {
|
||||||
|
public static final int ID_NO_WRONG_PASSPHRASE = 1;
|
||||||
|
|
||||||
int errorId;
|
int errorId;
|
||||||
String message;
|
String message;
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class CryptoService extends Service {
|
|||||||
} else {
|
} else {
|
||||||
Log.d(Constants.TAG, "Passphrase dialog canceled!");
|
Log.d(Constants.TAG, "Passphrase dialog canceled!");
|
||||||
|
|
||||||
// TODO: stop thread?!
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ public class CryptoService extends Service {
|
|||||||
public static final int SUCCESS = 1;
|
public static final int SUCCESS = 1;
|
||||||
public static final int NO_SUCCESS = 0;
|
public static final int NO_SUCCESS = 0;
|
||||||
|
|
||||||
private boolean success;
|
private boolean success = false;
|
||||||
|
|
||||||
public boolean isSuccess() {
|
public boolean isSuccess() {
|
||||||
return success;
|
return success;
|
||||||
@ -203,7 +203,7 @@ public class CryptoService extends Service {
|
|||||||
public static final int CANCEL = 0;
|
public static final int CANCEL = 0;
|
||||||
public static final String PUB_KEY_IDS = "pub_key_ids";
|
public static final String PUB_KEY_IDS = "pub_key_ids";
|
||||||
|
|
||||||
private boolean newSelection;
|
private boolean newSelection = false;
|
||||||
private long[] pubKeyIds;
|
private long[] pubKeyIds;
|
||||||
|
|
||||||
public boolean isNewSelection() {
|
public boolean isNewSelection() {
|
||||||
@ -246,6 +246,11 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
if (sign) {
|
if (sign) {
|
||||||
String passphrase = getCachedPassphrase(appSettings.getKeyId());
|
String passphrase = getCachedPassphrase(appSettings.getKeyId());
|
||||||
|
if (passphrase == null) {
|
||||||
|
callback.onError(new CryptoError(CryptoError.ID_NO_WRONG_PASSPHRASE,
|
||||||
|
"No or wrong passphrase!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PgpMain.encryptAndSign(mContext, null, inputData, outputStream,
|
PgpMain.encryptAndSign(mContext, null, inputData, outputStream,
|
||||||
appSettings.isAsciiArmor(), appSettings.getCompression(), keyIds, null,
|
appSettings.isAsciiArmor(), appSettings.getCompression(), keyIds, null,
|
||||||
@ -288,6 +293,11 @@ public class CryptoService extends Service {
|
|||||||
OutputStream outputStream = new ByteArrayOutputStream();
|
OutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
String passphrase = getCachedPassphrase(appSettings.getKeyId());
|
String passphrase = getCachedPassphrase(appSettings.getKeyId());
|
||||||
|
if (passphrase == null) {
|
||||||
|
callback.onError(new CryptoError(CryptoError.ID_NO_WRONG_PASSPHRASE,
|
||||||
|
"No or wrong passphrase!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PgpMain.signText(this, null, inputData, outputStream, appSettings.getKeyId(),
|
PgpMain.signText(this, null, inputData, outputStream, appSettings.getKeyId(),
|
||||||
passphrase, appSettings.getHashAlgorithm(), Preferences.getPreferences(this)
|
passphrase, appSettings.getHashAlgorithm(), Preferences.getPreferences(this)
|
||||||
@ -334,6 +344,11 @@ public class CryptoService extends Service {
|
|||||||
Log.d(Constants.TAG, "secretKeyId " + secretKeyId);
|
Log.d(Constants.TAG, "secretKeyId " + secretKeyId);
|
||||||
|
|
||||||
String passphrase = getCachedPassphrase(secretKeyId);
|
String passphrase = getCachedPassphrase(secretKeyId);
|
||||||
|
if (passphrase == null) {
|
||||||
|
callback.onError(new CryptoError(CryptoError.ID_NO_WRONG_PASSPHRASE,
|
||||||
|
"No or wrong passphrase!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if (signedOnly) {
|
// if (signedOnly) {
|
||||||
// resultData = PgpMain.verifyText(this, this, inputData, outStream,
|
// resultData = PgpMain.verifyText(this, this, inputData, outStream,
|
||||||
@ -501,7 +516,7 @@ public class CryptoService extends Service {
|
|||||||
public static final int DISALLOW = 0;
|
public static final int DISALLOW = 0;
|
||||||
public static final String PACKAGE_NAME = "package_name";
|
public static final String PACKAGE_NAME = "package_name";
|
||||||
|
|
||||||
private boolean allowed;
|
private boolean allowed = false;
|
||||||
private String packageName;
|
private String packageName;
|
||||||
|
|
||||||
public boolean isAllowed() {
|
public boolean isAllowed() {
|
||||||
|
@ -173,6 +173,8 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
Toast.makeText(activity,
|
Toast.makeText(activity,
|
||||||
R.string.error_couldNotExtractPrivateKey,
|
R.string.error_couldNotExtractPrivateKey,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
sendMessageToHandler(MESSAGE_CANCEL);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
clickSecretKey = PgpHelper.getKeyNum(ProviderHelper
|
clickSecretKey = PgpHelper.getKeyNum(ProviderHelper
|
||||||
@ -187,11 +189,15 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
Toast.makeText(activity, R.string.wrongPassPhrase,
|
Toast.makeText(activity, R.string.wrongPassPhrase,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
sendMessageToHandler(MESSAGE_CANCEL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(activity, R.string.error_couldNotExtractPrivateKey,
|
Toast.makeText(activity, R.string.error_couldNotExtractPrivateKey,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
sendMessageToHandler(MESSAGE_CANCEL);
|
||||||
return; // ran out of keys to try
|
return; // ran out of keys to try
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user