Skip to content

Commit 811677e

Browse files
committed
Improved Encryption Logging
1 parent 645e3aa commit 811677e

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

common/src/main/java/com/genexus/util/Encryption.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.genexus.common.interfaces.SpecificImplementation;
66
import java.nio.charset.StandardCharsets;
77

8+
import com.genexus.diagnostics.core.ILogger;
9+
import com.genexus.diagnostics.core.LogManager;
810
import org.apache.commons.codec.binary.Base64;
911
import org.bouncycastle.crypto.BlockCipher;
1012
import org.bouncycastle.crypto.BufferedBlockCipher;
@@ -23,6 +25,7 @@
2325

2426
public class Encryption
2527
{
28+
public static final ILogger logger = LogManager.getLogger(Encryption.class);
2629
public static String AJAX_ENCRYPTION_KEY = "GX_AJAX_KEY";
2730
public static String AJAX_ENCRYPTION_IV = "GX_AJAX_IV";
2831
public static String AJAX_SECURITY_TOKEN = "AJAX_SECURITY_TOKEN";
@@ -180,12 +183,12 @@ public static String decrypt64(String value, String key, boolean safeEncoding)
180183
}
181184
catch (InvalidKeyException e)
182185
{
183-
System.err.println(e);
186+
logger.error("decrypt64 error", e);
184187
throw new InvalidGXKeyException(e.getMessage());
185188
}
186189
catch(UnsupportedEncodingException e)
187190
{
188-
System.err.println(e);
191+
logger.error("decrypt64 error", e);
189192
throw new RuntimeException(e.getMessage());
190193
}
191194
catch (ArrayIndexOutOfBoundsException e)
@@ -374,7 +377,7 @@ public static String encryptRijndael(String plainText, String key) {
374377
try {
375378
outputBytes = aesCipher(inputBytes, true, key, GX_AJAX_PRIVATE_IV);
376379
} catch (DataLengthException | IllegalStateException | InvalidCipherTextException e) {
377-
e.printStackTrace();
380+
logger.error("encryptRijndael error", e);
378381
return "";
379382
}
380383
return Hex.toHexString(outputBytes);

java/src/main/java/com/genexus/security/web/WebSecurityHelper.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,5 @@ public static boolean verify(String pgmName, String issuer, String value, String
5656
}
5757
return ret;
5858
}
59-
60-
/*public static boolean verify(String pgmName, String issuer, String value, String jwtToken, WebSecureToken token)
61-
{
62-
boolean ok = SecureTokenHelper.Verify(jwtToken, token, GetSecretKey());
63-
return ok && !string.IsNullOrEmpty(pgmName) && token.ProgramName == pgmName && issuer == token.Issuer &&
64-
*/
59+
6560
}

java/src/main/java/com/genexus/webpanels/WebUtils.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.genexus.diagnostics.core.ILogger;
1818
import com.genexus.diagnostics.core.LogManager;
1919
import com.genexus.xml.XMLReader;
20+
import org.apache.commons.lang.StringUtils;
2021

2122

2223
public class WebUtils
@@ -437,29 +438,32 @@ public static String decryptParm(Object parm, String encryptionKey) {
437438

438439
public static String parmsEncryptionKey(com.genexus.ModelContext context)
439440
{
440-
String GXKey = "";
441441
String keySourceType = com.genexus.Application.getClientPreferences().getUSE_ENCRYPTION();
442-
if (!keySourceType.equals("")) {
443-
GXKey = getEncryptionKey(context, keySourceType);
444-
}
445-
return GXKey;
442+
if (keySourceType.equals(""))
443+
return "";
444+
return getEncryptionKey(context, keySourceType);
446445
}
447446

448447
public static String getEncryptionKey(com.genexus.ModelContext context, String keySourceType){
449448
if (keySourceType.equals(""))
450449
{
451450
keySourceType = com.genexus.Application.getClientPreferences().getUSE_ENCRYPTION();
452451
}
453-
String GXKey = "";
452+
453+
String encryptionKey;
454454
if (keySourceType.equalsIgnoreCase("SESSION"))
455455
{
456-
GXKey = com.genexus.util.Encryption.decrypt64(((HttpContext) context.getHttpContext()).getCookie("GX_SESSION_ID"), context.getServerKey());
456+
encryptionKey = com.genexus.util.Encryption.decrypt64(((HttpContext) context.getHttpContext()).getCookie("GX_SESSION_ID"), context.getServerKey());
457457
}
458458
else
459459
{
460-
GXKey = context.getSiteKey();
461-
}
462-
return GXKey;
460+
encryptionKey = context.getSiteKey();
461+
}
462+
if (StringUtils.isEmpty(encryptionKey)) {
463+
logger.error("Encryption Key cannot be empty");
464+
logger.debug(keySourceType);
465+
}
466+
return encryptionKey;
463467
}
464468

465469
private static final String gxApplicationClassesFileName = "GXApplicationClasses.txt";

0 commit comments

Comments
 (0)