Skip to content

Commit ddb395d

Browse files
anuengineernandakumar131
authored andcommitted
HDDS-2226. S3 Secrets should use a strong RNG. (#1572)
(cherry picked from commit d59bcbf)
1 parent 5001c6b commit ddb395d

File tree

1 file changed

+5
-3
lines changed
  • hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone

1 file changed

+5
-3
lines changed

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.nio.file.Paths;
3131
import java.security.MessageDigest;
3232
import java.security.NoSuchAlgorithmException;
33+
import java.security.SecureRandom;
3334
import java.util.Collection;
3435
import java.util.Collections;
3536
import java.util.Optional;
@@ -39,7 +40,6 @@
3940
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
4041
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
4142
import org.apache.commons.compress.utils.IOUtils;
42-
import org.apache.commons.lang3.RandomStringUtils;
4343
import org.apache.commons.lang3.StringUtils;
4444
import org.apache.hadoop.conf.Configuration;
4545
import org.apache.hadoop.hdds.scm.HddsServerUtil;
@@ -70,6 +70,8 @@
7070
*/
7171
public final class OmUtils {
7272
public static final Logger LOG = LoggerFactory.getLogger(OmUtils.class);
73+
private static final SecureRandom SRAND = new SecureRandom();
74+
private static byte[] randomBytes = new byte[32];
7375

7476
private OmUtils() {
7577
}
@@ -246,9 +248,9 @@ public static byte[] getMD5Digest(String input) throws IOException {
246248

247249
public static byte[] getSHADigest() throws IOException {
248250
try {
251+
SRAND.nextBytes(randomBytes);
249252
MessageDigest sha = MessageDigest.getInstance(OzoneConsts.FILE_HASH);
250-
return sha.digest(RandomStringUtils.random(32)
251-
.getBytes(StandardCharsets.UTF_8));
253+
return sha.digest(randomBytes);
252254
} catch (NoSuchAlgorithmException ex) {
253255
throw new IOException("Error creating an instance of SHA-256 digest.\n" +
254256
"This could possibly indicate a faulty JRE");

0 commit comments

Comments
 (0)