Skip to content

Commit

Permalink
Merge pull request OpenLiberty#14 from utle/FIPSwork-audit
Browse files Browse the repository at this point in the history
Move messageDigest getInstance to CryptoUtil
  • Loading branch information
mshah0722 authored Nov 14, 2024
2 parents 742fc4a + 948746f commit 21c5233
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,30 @@ public static MessageDigest getMessageDigest(String algorithm) throws NoSuchAlgo
public static MessageDigest getMessageDigestForLTPA() {
MessageDigest md1 = null;
try {
if (fipsEnabled && isOpenJCEPlusFIPSAvailable()) {
md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA256,
OPENJCE_PLUS_FIPS_NAME);
} else if (fipsEnabled && isIBMJCEPlusFIPSAvailable()) {
md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA256,
IBMJCE_PLUS_FIPS_NAME);
// if (fipsEnabled && isOpenJCEPlusFIPSAvailable()) {
// md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA256,
// OPENJCE_PLUS_FIPS_NAME);
// } else if (fipsEnabled && isIBMJCEPlusFIPSAvailable()) {
// md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA256,
// IBMJCE_PLUS_FIPS_NAME);
// } else if (isOpenJCEPlusAvailable()) {
// md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA,
// OPENJCE_PLUS_NAME);
// } else if (isIBMJCEAvailable()) {
// md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA,
// IBMJCE_NAME);
// } else {
// md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA);
// }

if (fipsEnabled) {
if (isSemeruFips()) {
md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA256,
OPENJCE_PLUS_FIPS_NAME);
} else {
md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA256,
IBMJCE_PLUS_FIPS_NAME);
}
} else if (isOpenJCEPlusAvailable()) {
md1 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA,
OPENJCE_PLUS_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,31 @@ public class LTPAToken2 implements Token, Serializable {

static {
MessageDigest m1 = null, m2 = null;
try {
if (fipsEnabled && CryptoUtils.isOpenJCEPlusFIPSAvailable()) {
m1 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA256, CryptoUtils.OPENJCE_PLUS_FIPS_NAME);
m2 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA256, CryptoUtils.OPENJCE_PLUS_FIPS_NAME);
} else if (fipsEnabled && CryptoUtils.isIBMJCEPlusFIPSAvailable()) {
m1 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA256, CryptoUtils.IBMJCE_PLUS_FIPS_NAME);
m2 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA256, CryptoUtils.IBMJCE_PLUS_FIPS_NAME);
} else {
m1 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA);
m2 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA);
}
} catch (Exception e) {
if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
Tr.event(tc, "Failed to initialize MessageDigest for SHA algorithm: " + e);
}
}
// try {
// if (fipsEnabled && CryptoUtils.isOpenJCEPlusFIPSAvailable()) {
// m1 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA256, CryptoUtils.OPENJCE_PLUS_FIPS_NAME);
// m2 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA256, CryptoUtils.OPENJCE_PLUS_FIPS_NAME);
// } else if (fipsEnabled && CryptoUtils.isIBMJCEPlusFIPSAvailable()) {
// m1 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA256, CryptoUtils.IBMJCE_PLUS_FIPS_NAME);
// m2 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA256, CryptoUtils.IBMJCE_PLUS_FIPS_NAME);
// } else if (CryptoUtils.isOpenJCEPlusAvailable()) {
// m1 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA, CryptoUtils.OPENJCE_PLUS_NAME);
// m2 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA, CryptoUtils.OPENJCE_PLUS_NAME);
// } else if (CryptoUtils.isIBMJCEAvailable()) {
// m1 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA, CryptoUtils.IBMJCE_NAME);
// m2 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA, CryptoUtils.IBMJCE_NAME);
// } else {
// m1 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA);
// m2 = MessageDigest.getInstance(CryptoUtils.MESSAGE_DIGEST_ALGORITHM_SHA);
// }
// } catch (Exception e) {
// if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
// Tr.event(tc, "Error creating digest; " + e);
// }
// }
m1 = CryptoUtils.getMessageDigestForLTPA();
m2 = CryptoUtils.getMessageDigestForLTPA();

md1JCE = m1;
md2JCE = m2;
lockObj1 = new Object();
Expand Down

0 comments on commit 21c5233

Please sign in to comment.