Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SecurityUtility only prints Exception name without errorstack #30520

Open
wants to merge 4 commits into
base: integration
Choose a base branch
from
Open
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 @@ -31,7 +31,8 @@
*/
public class AESKeyManager {
private static final AtomicReference<KeyStringResolver> _resolver = new AtomicReference<KeyStringResolver>();

private static final boolean DEBUG = Boolean.getBoolean("enableDebug"); // Used exclusively for debugging securityUtility

public static enum KeyVersion {
AES_V0("PBKDF2WithHmacSHA1", 84756, 128, new byte[] { -89, -94, -125, 57, 76, 90, -77, 79, 50, 21, 10, -98, 47, 23, 17, 56, -61, 46, 125, -128 }),
AES_V1("PBKDF2WithHmacSHA512", 300000, 256, new byte[] { -89, -63, 22, 15, -121, 11, 102, 75, -91, 68, -94, -89, 96, 83, -21, -69, -45, 29, 26, 106, -18, 69, 60, -6,
Expand All @@ -47,7 +48,9 @@ public static enum KeyVersion {
private final int iterations;
private final int keyLength;
private final byte[] salt;



private KeyVersion(String alg, int iterations, int keyLength, byte[] salt) {
this.alg = alg;
this.iterations = iterations;
Expand All @@ -67,8 +70,14 @@ private KeyHolder get(char[] keyChars) {
// Still use this holder for returns even if I do not end up caching it.
holder = holder2;
} catch (InvalidKeySpecException e) {
if (Boolean.getBoolean("enableDebug")) {
securityUtilDebug("InvalidKeySpecException received. Returning null", e);
}
return null;
} catch (NoSuchAlgorithmException e) {
if (Boolean.getBoolean("enableDebug")) {
securityUtilDebug("InvalidKeySpecException received. Returning null", e);
}
return null;
}

Expand All @@ -78,6 +87,14 @@ private KeyHolder get(char[] keyChars) {
}
}

// Used exclusively for debugging securityUtility
private static void securityUtilDebug(String message, Throwable throwable) {
if (DEBUG) {
System.out.println("[DEBUG] " + message);
throwable.printStackTrace(System.out); // Prints the exception stack trace
}
}

private static class KeyHolder {
private final char[] keyChars;
private final Key key;
Expand Down Expand Up @@ -170,4 +187,4 @@ public static IvParameterSpec getIV(KeyVersion version, String cryptoKey) {
public static IvParameterSpec getIV(String cryptoKey) {
return getHolder(KeyVersion.AES_V0, cryptoKey).getIv();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation and others.
* Copyright (c) 2011,2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -141,6 +141,7 @@ SecurityUtilityReturnCodes runProgram(String[] args) {
stderr.println("");
stderr.println(CommandUtils.getMessage("error", e.toString()));
stderr.println(help.getTaskUsage(task));
e.printStackTrace(stderr);
return SecurityUtilityReturnCodes.ERR_GENERIC;
}
}
Expand Down