mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
More finegrained errors
This commit is contained in:
parent
79238cbcce
commit
3f703fa4ea
@ -36,7 +36,9 @@ public class ApgService extends Service {
|
|||||||
private enum error {
|
private enum error {
|
||||||
ARGUMENTS_MISSING,
|
ARGUMENTS_MISSING,
|
||||||
APG_FAILURE,
|
APG_FAILURE,
|
||||||
NO_MATCHING_SECRET_KEY
|
NO_MATCHING_SECRET_KEY,
|
||||||
|
PRIVATE_KEY_PASSPHRASE_WRONG,
|
||||||
|
PRIVATE_KEY_PASSPHRASE_MISSING
|
||||||
}
|
}
|
||||||
|
|
||||||
/** all arguments that can be passed by calling application */
|
/** all arguments that can be passed by calling application */
|
||||||
@ -50,7 +52,8 @@ public class ApgService extends Service {
|
|||||||
FORCE_V3_SIGNATURE, // whether to force v3 signature
|
FORCE_V3_SIGNATURE, // whether to force v3 signature
|
||||||
COMPRESSION, // what compression to use for encrypted output
|
COMPRESSION, // what compression to use for encrypted output
|
||||||
SIGNATURE_KEY, // key for signing
|
SIGNATURE_KEY, // key for signing
|
||||||
PRIVATE_KEY_PASSPHRASE // passphrase for encrypted private key
|
PRIVATE_KEY_PASSPHRASE
|
||||||
|
// passphrase for encrypted private key
|
||||||
}
|
}
|
||||||
|
|
||||||
/** all things that might be returned */
|
/** all things that might be returned */
|
||||||
@ -58,7 +61,8 @@ public class ApgService extends Service {
|
|||||||
ERRORS, // string array list with errors
|
ERRORS, // string array list with errors
|
||||||
WARNINGS, // string array list with warnings
|
WARNINGS, // string array list with warnings
|
||||||
ERROR, // numeric error
|
ERROR, // numeric error
|
||||||
RESULT // en-/decrypted
|
RESULT
|
||||||
|
// en-/decrypted
|
||||||
}
|
}
|
||||||
|
|
||||||
/** required arguments for each AIDL function */
|
/** required arguments for each AIDL function */
|
||||||
@ -377,9 +381,17 @@ public class ApgService extends Service {
|
|||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Exception in encrypt");
|
Log.e(TAG, "Exception in encrypt");
|
||||||
pReturn.getStringArrayList(ret.ERRORS.name()).add("Internal failure (" + e.getClass() + ") in APG when encrypting: " + e.getMessage());
|
String _msg = e.getMessage();
|
||||||
|
if (_msg == getBaseContext().getString(R.string.error_noSignaturePassPhrase)) {
|
||||||
pReturn.putInt(ret.ERROR.name(), error.APG_FAILURE.ordinal());
|
pReturn.getStringArrayList(ret.ERRORS.name()).add("Cannot encrypt (" + arg.PRIVATE_KEY_PASSPHRASE.name() + " missing): " + _msg);
|
||||||
|
pReturn.putInt(ret.ERROR.name(), error.PRIVATE_KEY_PASSPHRASE_MISSING.ordinal());
|
||||||
|
} else if (_msg == getBaseContext().getString(R.string.error_couldNotExtractPrivateKey)) {
|
||||||
|
pReturn.getStringArrayList(ret.ERRORS.name()).add("Cannot encrypt (" + arg.PRIVATE_KEY_PASSPHRASE.name() + " probably wrong): " + _msg);
|
||||||
|
pReturn.putInt(ret.ERROR.name(), error.PRIVATE_KEY_PASSPHRASE_WRONG.ordinal());
|
||||||
|
} else {
|
||||||
|
pReturn.getStringArrayList(ret.ERRORS.name()).add("Internal failure (" + e.getClass() + ") in APG when encrypting: " + e.getMessage());
|
||||||
|
pReturn.putInt(ret.ERROR.name(), error.APG_FAILURE.ordinal());
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Log.v(TAG, "Encrypted");
|
Log.v(TAG, "Encrypted");
|
||||||
@ -411,8 +423,8 @@ public class ApgService extends Service {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _passphrase = pArgs.getString(arg.SYMMETRIC_PASSPHRASE.name()) != null ? pArgs.getString(arg.SYMMETRIC_PASSPHRASE.name()) : pArgs.getString(arg.PRIVATE_KEY_PASSPHRASE
|
String _passphrase = pArgs.getString(arg.SYMMETRIC_PASSPHRASE.name()) != null ? pArgs.getString(arg.SYMMETRIC_PASSPHRASE.name()) : pArgs
|
||||||
.name());
|
.getString(arg.PRIVATE_KEY_PASSPHRASE.name());
|
||||||
|
|
||||||
InputStream inStream = new ByteArrayInputStream(pArgs.getString(arg.MESSAGE.name()).getBytes());
|
InputStream inStream = new ByteArrayInputStream(pArgs.getString(arg.MESSAGE.name()).getBytes());
|
||||||
InputData in = new InputData(inStream, 0); // XXX what size in second parameter?
|
InputData in = new InputData(inStream, 0); // XXX what size in second parameter?
|
||||||
@ -423,11 +435,15 @@ public class ApgService extends Service {
|
|||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Exception in decrypt");
|
Log.e(TAG, "Exception in decrypt");
|
||||||
if (e.getMessage() == getBaseContext().getString(R.string.error_noSecretKeyFound)) {
|
String _msg = e.getMessage();
|
||||||
pReturn.getStringArrayList(ret.ERRORS.name()).add("Cannot decrypt: " + e.getMessage());
|
if (_msg == getBaseContext().getString(R.string.error_noSecretKeyFound)) {
|
||||||
|
pReturn.getStringArrayList(ret.ERRORS.name()).add("Cannot decrypt: " + _msg);
|
||||||
pReturn.putInt(ret.ERROR.name(), error.NO_MATCHING_SECRET_KEY.ordinal());
|
pReturn.putInt(ret.ERROR.name(), error.NO_MATCHING_SECRET_KEY.ordinal());
|
||||||
|
} else if (_msg == getBaseContext().getString(R.string.error_wrongPassPhrase)) {
|
||||||
|
pReturn.getStringArrayList(ret.ERRORS.name()).add("Cannot decrypt (" + arg.PRIVATE_KEY_PASSPHRASE.name() + " wrong/missing): " + _msg);
|
||||||
|
pReturn.putInt(ret.ERROR.name(), error.PRIVATE_KEY_PASSPHRASE_WRONG.ordinal());
|
||||||
} else {
|
} else {
|
||||||
pReturn.getStringArrayList(ret.ERRORS.name()).add("Internal failure (" + e.getClass() + ") in APG when decrypting: " + e.getMessage());
|
pReturn.getStringArrayList(ret.ERRORS.name()).add("Internal failure (" + e.getClass() + ") in APG when decrypting: " + _msg);
|
||||||
pReturn.putInt(ret.ERROR.name(), error.APG_FAILURE.ordinal());
|
pReturn.putInt(ret.ERROR.name(), error.APG_FAILURE.ordinal());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user