Removed all incidents of e.printStackTrace, wrapped errors with

NoDashFatalExceptions instead of overwriting
This commit is contained in:
Dave
2014-12-26 17:15:54 +02:00
parent 3b97efec74
commit ee72415e63
10 changed files with 69 additions and 55 deletions

View File

@@ -50,7 +50,7 @@ public abstract class NoInfluence implements Serializable {
try {
keyGen = KeyGenerator.getInstance(NoUtil.CIPHER_KEY_SPEC);
} catch (NoSuchAlgorithmException e) {
throw new NoDashFatalException("Value for CIPHER_KEY_SPEC is not valid.");
throw new NoDashFatalException("Value for CIPHER_KEY_SPEC is not valid.", e);
}
keyGen.init(NoUtil.AES_STRENGTH);
SecretKey secretKey = keyGen.generateKey();
@@ -72,7 +72,7 @@ public abstract class NoInfluence implements Serializable {
baos.close();
return encrypted;
} catch (IOException e) {
throw new NoDashFatalException("Unable to write NoInfluence object to byte stream.");
throw new NoDashFatalException("Unable to write NoInfluence object to byte stream.", e);
}
}
@@ -86,7 +86,7 @@ public abstract class NoInfluence implements Serializable {
bais.close();
return noInfluence;
} catch (IOException e) {
throw new NoDashFatalException("Unable to read out provided data stream.");
throw new NoDashFatalException("Unable to read out provided data stream.", e);
}
}

View File

@@ -8,6 +8,9 @@ import java.util.UUID;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
import com.sun.org.apache.xml.internal.security.utils.Base64;
import nodash.core.NoCore;
import nodash.core.NoUtil;
import nodash.exceptions.NoByteSetBadDecryptionException;
@@ -109,7 +112,8 @@ public final class NoSession implements Serializable {
return file;
}
public void confirmSave(byte[] confirmData, char[] password) throws NoSessionConfirmedException, NoSessionExpiredException, NoSessionNotAwaitingConfirmationException, NoUserNotValidException {
public void confirmSave(byte[] confirmData, char[] password) throws NoSessionConfirmedException, NoSessionExpiredException,
NoSessionNotAwaitingConfirmationException, NoUserNotValidException {
this.check();
if (this.state != NoState.AWAITING_CONFIRMATION) {
throw new NoSessionNotAwaitingConfirmationException();
@@ -138,15 +142,14 @@ public final class NoSession implements Serializable {
try {
NoCore.hashSphere.removeHash(this.original.createHashString());
} catch (IOException e) {
throw new NoDashFatalException("Unable to remove hash on confirm.");
throw new NoDashFatalException("Unable to remove hash on confirm.", e);
}
}
/* 5.2.2: add new hash to array */
try {
NoCore.hashSphere.insertHash(this.current.createHashString());
} catch (IOException e) {
e.printStackTrace();
throw new NoDashFatalException("Unable to remove hash on confirm.");
throw new NoDashFatalException("Unable to remove hash on confirm.", e);
}
/* 5.2.3: clear influences as they will not need to be re-applied */
@@ -185,7 +188,11 @@ public final class NoSession implements Serializable {
}
public byte[] getEncryptedUUID() {
return NoUtil.encrypt(this.uuid.toString().getBytes());
try {
return NoUtil.encrypt(Base64.decode(this.uuid.toString()));
} catch (Base64DecodingException e) {
throw new NoDashFatalException("Base64DecodingException while decoding session UUID.", e);
}
}
public String getEncryptedUUIDAsString() {

View File

@@ -45,6 +45,7 @@ import javax.crypto.spec.SecretKeySpec;
import sun.security.rsa.RSAPublicKeyImpl;
import nodash.core.NoUtil;
import nodash.exceptions.NoByteSetBadDecryptionException;
import nodash.exceptions.NoDashFatalException;
public class NoUser implements Serializable {
private static final long serialVersionUID = 7132405837081692211L;
@@ -57,19 +58,26 @@ public class NoUser implements Serializable {
private ArrayList<NoAction> outgoing = new ArrayList<NoAction>();
public NoUser() {
KeyPairGenerator kpg;
try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance(NoUtil.KEYPAIR_ALGORITHM);
kpg.initialize(NoUtil.RSA_STRENGTH, SecureRandom.getInstance(NoUtil.SECURERANDOM_ALGORITHM, NoUtil.SECURERANDOM_PROVIDER));
KeyPair keyPair = kpg.generateKeyPair();
this.publicKey = keyPair.getPublic();
this.privateKey = keyPair.getPrivate();
this.influences = 0;
this.actions = 0;
kpg = KeyPairGenerator.getInstance(NoUtil.KEYPAIR_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
throw new NoDashFatalException("Value for KEYPAIR_ALGORITHM is not valid.", e);
}
try {
kpg.initialize(NoUtil.RSA_STRENGTH, SecureRandom.getInstance(NoUtil.SECURERANDOM_ALGORITHM, NoUtil.SECURERANDOM_PROVIDER));
} catch (NoSuchAlgorithmException e) {
throw new NoDashFatalException("Value for SECURERANDOM_ALGORITHM not valid.", e);
} catch (NoSuchProviderException e) {
throw new NoDashFatalException("Value for SECURERANDOM_PROVIDER not valid.", e);
}
KeyPair keyPair = kpg.generateKeyPair();
this.publicKey = keyPair.getPublic();
this.privateKey = keyPair.getPrivate();
this.influences = 0;
this.actions = 0;
}
public final byte[] createFile(char[] password) {
@@ -84,11 +92,10 @@ public class NoUser implements Serializable {
baos.close();
return encrypted;
} catch (IOException e) {
e.printStackTrace();
throw new NoDashFatalException("IO Exception encountered while generating encrypted user file byte stream.", e);
} finally {
this.outgoing = temp;
}
return null;
}
public final byte[] createHash() {
@@ -101,11 +108,10 @@ public class NoUser implements Serializable {
byte[] userBytes = baos.toByteArray();
return NoUtil.getHashFromByteArray(userBytes);
} catch (IOException e) {
e.printStackTrace();
throw new NoDashFatalException("IO Exception encountered while generating user hash.", e);
} finally {
this.outgoing = temp;
}
return null;
}
public final String createHashString() {

View File

@@ -48,7 +48,7 @@ public abstract class NoTargetedAction extends NoAction {
}
} catch (NoCannotGetInfluenceException e) {
if (e.getResponseInfluence() != null) {
throw new NoDashFatalException("Unsourced action has generated an error with an undeliverable influence.");
throw new NoDashFatalException("Unsourced action has generated an error with an undeliverable influence.", e);
}
}
}