Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ public void authorize() {
return;
}

if (cryptoManager.configure(activity.getApplicationContext(), password)) {
onAuthorizationSuccessful();
} else {
onAuthorizationFailed();
try {
boolean isAuthorized = cryptoManager.configure(activity.getApplicationContext(),
password);

if (isAuthorized) {
onAuthorizationSuccessful();
} else {
onAuthorizationFailed();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public final class AesCryptorFactory implements CryptorFactory {
@Override
public AesCryptor create(char[] password, Class<? extends AesCryptor> cryptorClass)
throws NoSuchAlgorithmException {
throws NoSuchAlgorithmException, ReflectiveOperationException {
byte[] salt = AesCryptor.generatePasswordBasedSalt(password);

try {
Expand All @@ -21,7 +21,7 @@ public AesCryptor create(char[] password, Class<? extends AesCryptor> cryptorCla
| InstantiationException
| InvocationTargetException
| NoSuchMethodException e) {
throw new RuntimeException(e);
throw new ReflectiveOperationException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ public final class CryptoManager {
* @param context The application context.
* @param password The password to use for decryption.
* @return {@code true} if configuration was successful, {@code false} if decryption failed.
* @throws RuntimeException if an unexpected I/O error occurs.
* @throws IOException if an I/O error occurs.
*/
public boolean configure(Context context, char[] password) {
public boolean configure(Context context, char[] password) throws IOException {
try {
this.secrets = tryGetSecretsWithFallback(context, password);
return true;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (DecryptionFailedException e) {
return false;
}
Expand Down Expand Up @@ -217,11 +215,10 @@ public void destroySecrets() {
* @param context The application context.
* @param password The password for decryption.
* @return The retrieved {@link CryptoSecrets}.
* @throws IOException if an I/O error occurs.
* @throws DecryptionFailedException if decryption fails with both cryptors.
*/
private CryptoSecrets tryGetSecretsWithFallback(Context context, char[] password)
throws IOException, DecryptionFailedException {
throws DecryptionFailedException {
try {
return getSecrets(context, password, AesGcmCryptor.class);
} catch (DecryptionFailedException e) {
Expand Down Expand Up @@ -319,6 +316,7 @@ private void setKeyHash(String keyHash) {

/**
* Removes old key hash file that was in older versions of NoteSR.
*
* @param context application context
* @throws IOException if failed to delete file
*/
Expand Down
Loading