Removed all incidents of e.printStackTrace, wrapped errors with
NoDashFatalExceptions instead of overwriting
This commit is contained in:
@@ -19,7 +19,7 @@ public abstract class NoConfigBase implements NoConfigInterface {
|
||||
keyGenerator.init(NoUtil.AES_STRENGTH);
|
||||
this.secretKey = keyGenerator.generateKey();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_KEY_SPEC not valid.");
|
||||
throw new NoDashFatalException("Value for CIPHER_KEY_SPEC not valid.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class NoConfigDefault extends NoConfigBase implements Serializable
|
||||
|
||||
Files.write(file.toPath(), data, StandardOpenOption.CREATE_NEW);
|
||||
} catch (IOException e) {
|
||||
throw new NoDashFatalException("Unable to save config, including generated secret key.");
|
||||
throw new NoDashFatalException("Unable to save config, including generated secret key.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class NoConfigDefault extends NoConfigBase implements Serializable
|
||||
try {
|
||||
noConfig = (NoConfigDefault) ois.readObject();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoDashFatalException("Given bytestream does not compile into a configuration object.");
|
||||
throw new NoDashFatalException("Given bytestream does not compile into a configuration object.", e);
|
||||
}
|
||||
return noConfig;
|
||||
}
|
||||
|
||||
@@ -84,14 +84,14 @@ public final class NoUtil {
|
||||
try {
|
||||
skf = SecretKeyFactory.getInstance(NoUtil.PBE_TYPE);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new NoDashFatalException("Value for PBE_TYPE is not valid.");
|
||||
throw new NoDashFatalException("Value for PBE_TYPE is not valid.", e);
|
||||
}
|
||||
KeySpec spec = new PBEKeySpec(password, NoCore.config.getSecretKey().getEncoded(), 65536, 256);
|
||||
SecretKey key;
|
||||
try {
|
||||
key = skf.generateSecret(spec);
|
||||
} catch (InvalidKeySpecException e) {
|
||||
throw new NoDashFatalException("PBE manager unable to derive key from password.");
|
||||
throw new NoDashFatalException("PBE manager unable to derive key from password.", e);
|
||||
}
|
||||
NoUtil.wipeChars(password);
|
||||
return key.getEncoded();
|
||||
@@ -102,9 +102,8 @@ public final class NoUtil {
|
||||
MessageDigest messageDigest = MessageDigest.getInstance(NoUtil.DIGEST_TYPE);
|
||||
return messageDigest.digest(bytes);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
throw new NoDashFatalException("Value for DIGEST_TYPE not valid.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte[] decryptByteArray(byte[] data, char[] password) throws IllegalBlockSizeException, BadPaddingException {
|
||||
@@ -126,24 +125,23 @@ public final class NoUtil {
|
||||
try {
|
||||
cipher = Cipher.getInstance(NoUtil.CIPHER_TYPE);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_TYPE is not valid (no such algorithm).");
|
||||
throw new NoDashFatalException("Value for CIPHER_TYPE is not valid (no such algorithm).", e);
|
||||
} catch (NoSuchPaddingException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_TYPE is not valid (no such padding).");
|
||||
throw new NoDashFatalException("Value for CIPHER_TYPE is not valid (no such padding).", e);
|
||||
}
|
||||
SecretKeySpec secretKey = new SecretKeySpec(key, NoUtil.CIPHER_KEY_SPEC);
|
||||
try {
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
|
||||
} catch (InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
throw new NoDashFatalException("Secret key is invalid.");
|
||||
throw new NoDashFatalException("Secret key is invalid.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
return cipher.doFinal(data);
|
||||
} catch (IllegalBlockSizeException e) {
|
||||
throw new NoDashFatalException("Block size exception encountered during encryption.");
|
||||
throw new NoDashFatalException("Block size exception encountered during encryption.", e);
|
||||
} catch (BadPaddingException e) {
|
||||
throw new NoDashFatalException("Bad padding exception encountered during encryption.");
|
||||
throw new NoDashFatalException("Bad padding exception encountered during encryption.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,16 +154,15 @@ public final class NoUtil {
|
||||
try {
|
||||
cipher = Cipher.getInstance(NoUtil.CIPHER_TYPE);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_TYPE is not valid (no such algorithm).");
|
||||
throw new NoDashFatalException("Value for CIPHER_TYPE is not valid (no such algorithm).", e);
|
||||
} catch (NoSuchPaddingException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_TYPE is not valid (no such padding).");
|
||||
throw new NoDashFatalException("Value for CIPHER_TYPE is not valid (no such padding).", e);
|
||||
}
|
||||
SecretKeySpec secretKey = new SecretKeySpec(key, NoUtil.CIPHER_KEY_SPEC);
|
||||
try {
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKey);
|
||||
} catch (InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
throw new NoDashFatalException("Secret key is invalid.");
|
||||
throw new NoDashFatalException("Secret key is invalid.", e);
|
||||
}
|
||||
|
||||
return cipher.doFinal(data);
|
||||
@@ -180,19 +177,19 @@ public final class NoUtil {
|
||||
try {
|
||||
cipher = Cipher.getInstance(NoUtil.CIPHER_RSA_TYPE);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_RSA_TYPE is not valid (no such algorithm).");
|
||||
throw new NoDashFatalException("Value for CIPHER_RSA_TYPE is not valid (no such algorithm).", e);
|
||||
} catch (NoSuchPaddingException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_RSA_TYPE is not valid (no such padding).");
|
||||
throw new NoDashFatalException("Value for CIPHER_RSA_TYPE is not valid (no such padding).", e);
|
||||
}
|
||||
try {
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
return cipher.doFinal(data);
|
||||
} catch (InvalidKeyException e){
|
||||
throw new NoDashFatalException("Public key invalid.");
|
||||
throw new NoDashFatalException("Public key invalid.", e);
|
||||
} catch (IllegalBlockSizeException e) {
|
||||
throw new NoDashFatalException("Unable to encrypt data stream with public key.");
|
||||
throw new NoDashFatalException("Unable to encrypt data stream with public key.", e);
|
||||
} catch (BadPaddingException e) {
|
||||
throw new NoDashFatalException("Unable to encrypt data stream with public key.");
|
||||
throw new NoDashFatalException("Unable to encrypt data stream with public key.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,9 +198,9 @@ public final class NoUtil {
|
||||
try {
|
||||
cipher = Cipher.getInstance(NoUtil.CIPHER_RSA_TYPE);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_RSA_TYPE is not valid (no such algorithm).");
|
||||
throw new NoDashFatalException("Value for CIPHER_RSA_TYPE is not valid (no such algorithm).", e);
|
||||
} catch (NoSuchPaddingException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_RSA_TYPE is not valid (no such padding).");
|
||||
throw new NoDashFatalException("Value for CIPHER_RSA_TYPE is not valid (no such padding).", e);
|
||||
}
|
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
return cipher.doFinal(data);
|
||||
|
||||
@@ -62,9 +62,9 @@ public final class NoHashSphereDefault implements NoHashSphereInterface {
|
||||
ois.close();
|
||||
bais.close();
|
||||
} catch (IOException e){
|
||||
throw new NoDashFatalException("Unable to load up given database file.");
|
||||
throw new NoDashFatalException("Unable to load up given database file.", e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoDashFatalException("Database file not in a verifiable format.");
|
||||
throw new NoDashFatalException("Database file not in a verifiable format.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public final class NoSessionSphere {
|
||||
try {
|
||||
session.consume(nbs);
|
||||
} catch (NoByteSetBadDecryptionException e) {
|
||||
e.printStackTrace();
|
||||
throw new NoDashFatalException("Bad byte sets on consumption.", e);
|
||||
}
|
||||
} /* 2.2 Alternatively, no NoByteSets to consume */
|
||||
|
||||
@@ -173,15 +173,15 @@ public final class NoSessionSphere {
|
||||
try {
|
||||
result.data = NoSessionSphere.save(result.cookie, password);
|
||||
} catch (NoDashSessionBadUUIDException e) {
|
||||
throw new NoDashFatalException("Immediately generated cookie throwing bad cookie error.");
|
||||
throw new NoDashFatalException("Immediately generated cookie throwing bad cookie error.", e);
|
||||
} catch (NoSessionExpiredException e) {
|
||||
throw new NoDashFatalException("Session expired before it was even returned to client.");
|
||||
throw new NoDashFatalException("Session expired before it was even returned to client.", e);
|
||||
} catch (NoSessionConfirmedException e) {
|
||||
throw new NoDashFatalException("Session is in confirmed state before it was returned to client.");
|
||||
throw new NoDashFatalException("Session is in confirmed state before it was returned to client.", e);
|
||||
} catch (NoSessionNotChangedException e) {
|
||||
throw new NoDashFatalException("Session claims to be unchanged but user is newly registered.");
|
||||
throw new NoDashFatalException("Session claims to be unchanged but user is newly registered.", e);
|
||||
} catch (NoSessionAlreadyAwaitingConfirmationException e) {
|
||||
throw new NoDashFatalException("Session claims to be awaiting confirmation before returning data to the user.");
|
||||
throw new NoDashFatalException("Session claims to be awaiting confirmation before returning data to the user.", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user