Skip to content

Commit

Permalink
Updates to log messages: (#1060)
Browse files Browse the repository at this point in the history
- changing warn to error (or vice versa) as needed.
- minor textual corrections/changes.
- log public key if peer fails key validation.
  • Loading branch information
SatpalSandhu61 committed May 7, 2020
1 parent cdb589a commit eea577e
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey pr
secretBox.cryptoBoxBeforenm(precomputed, publicKey.getKeyBytes(), privateKey.getKeyBytes());

if (jnaclResult == -1) {
LOGGER.warn("Could not compute the shared key for pub {} and priv {}", publicKey, REDACTED);
LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, REDACTED);
LOGGER.debug("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey);
throw new EncryptorException("JNacl could not compute the shared key");
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, f
output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes());

if (jnaclResult == -1) {
LOGGER.warn("Could not create sealed payload using shared key {}", sharedKey);
LOGGER.error("Could not create sealed payload using shared key {}", sharedKey);
LOGGER.debug("Could not create sealed payload using shared key {}", sharedKey);
throw new EncryptorException("jnacl could not seal the payload using the shared key");
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public byte[] openAfterPrecomputation(final byte[] cipherText, final Nonce nonce
paddedOutput, paddedInput, paddedInput.length, nonce.getNonceBytes(), sharedKey.getKeyBytes());

if (jnaclResult == -1) {
LOGGER.warn("Could not open sealed payload using shared key {}", sharedKey);
LOGGER.error("Could not open sealed payload using shared key {}", sharedKey);
LOGGER.debug("Could not open sealed payload using shared key {}", sharedKey);
throw new EncryptorException("jnacl could not open the payload using the shared key");
}
Expand Down Expand Up @@ -204,7 +204,7 @@ public KeyPair generateNewKeys() {
final int jnaclResult = secretBox.cryptoBoxKeypair(publicKey, privateKey);

if (jnaclResult == -1) {
LOGGER.warn("Unable to generate a new keypair!");
LOGGER.error("Unable to generate a new keypair!");
throw new EncryptorException("jnacl could not generate a new public/private keypair");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey pr
output, publicKey.getKeyBytes(), privateKey.getKeyBytes());

if (sodiumResult == -1) {
LOGGER.warn("Could not compute the shared key for pub {} and priv {}", publicKey, REDACTED);
LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, REDACTED);
LOGGER.debug("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey);
throw new EncryptorException("Kalium could not compute the shared key");
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public byte[] seal(
privateKey.getKeyBytes());

if (sodiumResult == -1) {
LOGGER.warn("Could not create sealed payload using public key {} and private key {}", publicKey, REDACTED);
LOGGER.error("Could not create sealed payload using public key {} and private key {}", publicKey, REDACTED);
LOGGER.debug(
"Could not create sealed payload using public key {} and private key {}", publicKey, privateKey);
throw new EncryptorException("Kalium could not seal the payload using the provided keys directly");
Expand Down Expand Up @@ -169,7 +169,7 @@ public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, f
output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes());

if (sodiumResult == -1) {
LOGGER.warn("Could not create sealed payload using shared key {}", sharedKey);
LOGGER.error("Could not create sealed payload using shared key {}", sharedKey);
LOGGER.debug("Could not create sealed payload using shared key {}", sharedKey);
throw new EncryptorException("Kalium could not seal the payload using the shared key");
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public byte[] openAfterPrecomputation(final byte[] encryptedPayload, final Nonce
paddedOutput, paddedInput, paddedInput.length, nonce.getNonceBytes(), sharedKey.getKeyBytes());

if (sodiumResult == -1) {
LOGGER.warn("Could not open sealed payload using shared key {}", sharedKey);
LOGGER.error("Could not open sealed payload using shared key {}", sharedKey);
LOGGER.debug("Could not open sealed payload using shared key {}", sharedKey);
throw new EncryptorException("Kalium could not open the payload using the shared key");
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public KeyPair generateNewKeys() {
final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, privateKey);

if (sodiumResult == -1) {
LOGGER.warn("Unable to generate a new keypair!");
LOGGER.error("Unable to generate a new keypair!");
throw new EncryptorException("Kalium could not generate a new public/private keypair");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void run() {
LOGGER.debug("Started service {}", service);
} catch (Throwable ex) {
LOGGER.trace(null, ex);
LOGGER.warn(
LOGGER.error(
"Exception thrown : {} While starting service {}",
Optional.ofNullable(ex.getCause()).orElse(ex).getMessage(),
service);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DecodingExceptionMapper implements ExceptionMapper<DecodingExceptio

@Override
public Response toResponse(final DecodingException exception) {
LOGGER.error("Error decoding message: {}", exception.getMessage());
LOGGER.warn("Failed to decode message: {}", exception.getMessage());
LOGGER.debug(null, exception);

return Response.status(Response.Status.BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Response toResponse(final Throwable ex) {
final Throwable rootCause = ExceptionUtils.getRootCause(ex);
final Throwable cause = (rootCause == null) ? ex : rootCause;

LOGGER.error("Error occured: {}. Root cause: {}", ex.getMessage(), cause.getMessage());
LOGGER.error("Error occurred: {}. Root cause: {}", ex.getMessage(), cause.getMessage());
LOGGER.debug(null, ex);
LOGGER.debug(null, cause);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class EntityNotFoundExceptionMapper implements ExceptionMapper<EntityNotF

@Override
public Response toResponse(final EntityNotFoundException ex) {
LOGGER.error("Entity not found: {}", ex.getMessage());
LOGGER.warn("Entity not found: {}", ex.getMessage());
LOGGER.debug(null, ex);

return Response.status(Response.Status.NOT_FOUND).entity(ex.getMessage()).type(MediaType.TEXT_PLAIN).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundExceptio

@Override
public Response toResponse(final NotFoundException ex) {
LOGGER.error("Entity not found: {}", ex.getMessage());
LOGGER.warn("Entity not found: {}", ex.getMessage());
LOGGER.debug(null, ex);

return Response.status(Status.NOT_FOUND).entity(ex.getMessage()).type(MediaType.TEXT_PLAIN).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Response toResponse(final WebApplicationException exception) {
LOGGER.debug("{}", exception.getClass());
LOGGER.debug("{}", exception.getCause() == null ? "No cause" : exception.getCause().getClass());

LOGGER.error("{}", exception.getMessage());
LOGGER.warn("{}", exception.getMessage());

final Response.Status returnStatus;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Response partyInfo(@ApiParam(required = true) final byte[] payload) {

final boolean isValid = Objects.equals(decodedValidationData, dataToEncrypt);
if (!isValid) {
LOGGER.warn("Invalid key found {} recipient will be ignored.", r.getUrl());
LOGGER.warn("Invalid key {} found, {} recipient will be ignored.", key, r.getUrl());
LOGGER.debug("Response from {} was {}", url, decodedValidationData);
}

Expand Down

0 comments on commit eea577e

Please sign in to comment.