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

[SECURITY] CVE-2019-16303 - JHipster Vulnerability Fix - Use CSPRNG in RandomUtil #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions src/main/java/com/caf/valididty/service/util/RandomUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,34 @@

import org.apache.commons.lang3.RandomStringUtils;

import java.security.SecureRandom;

/**
* Utility class for generating random Strings.
*/
public final class RandomUtil {
private static final SecureRandom SECURE_RANDOM = new SecureRandom();

private static final int DEF_COUNT = 20;

static {
SECURE_RANDOM.nextBytes(new byte[64]);
}

private RandomUtil() {
}

private static String generateRandomAlphanumericString() {
return RandomStringUtils.random(DEF_COUNT, 0, 0, true, true, null, SECURE_RANDOM);
}

/**
* Generate a password.
*
* @return the generated password
*/
public static String generatePassword() {
return RandomStringUtils.randomAlphanumeric(DEF_COUNT);
return generateRandomAlphanumericString();
}

/**
Expand All @@ -27,7 +38,7 @@ public static String generatePassword() {
* @return the generated activation key
*/
public static String generateActivationKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
return generateRandomAlphanumericString();
}

/**
Expand All @@ -36,6 +47,6 @@ public static String generateActivationKey() {
* @return the generated reset key
*/
public static String generateResetKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
return generateRandomAlphanumericString();
}
}