Skip to content

Commit e486f3e

Browse files
baggio000Impala Public Jenkins
authored andcommitted
IMPALA-14385: Fix crashes using sha2() in FIPS CentOS 7
This commit fixes a crash in the sha2() function that occurs when Impala is run on a FIPS enabled OS, particularly CentOS 7. Running sha2() with 384 or 512-bit lengths would cause the impalad to crash with an OpenSSL assertion failure: "Low level API call to digest SHA384 forbidden in FIPS mode!" The root cause was the direct use of low-level OpenSSL API calls like SHA384(), SHA512(). OpenSSL 1.0 (used in RHEL/CentOS 7) is particularly strict and forbids these calls in FIPS mode, causing the module to terminate the process. This patch changes to use the high-level, FIPS compliant EVP_Digest API to perform the hash in sha2() function implementation. Tests: Ran sha2() in FIPS enabled CentOs 7 after the change and succeeded. Passed exhaustive tests. Change-Id: I694532350285534fd935c92b7a78bed91ded3cb5 Reviewed-on: http://gerrit.cloudera.org:8080/23373 Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
1 parent c78f7a7 commit e486f3e

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

be/src/exprs/utility-functions-ir.cc

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,35 +287,40 @@ StringVal UtilityFunctions::Sha2(FunctionContext* ctx, const StringVal& input_st
287287
return StringVal::null();
288288
}
289289

290-
StringVal sha_hash;
290+
const EVP_MD* md_alg = nullptr;
291+
int digest_length = 0;
291292

292293
switch(bit_len.val) {
293294
case 224:
294-
sha_hash = StringVal(ctx, SHA224_DIGEST_LENGTH);
295-
if (UNLIKELY(sha_hash.is_null)) return StringVal::null();
296-
SHA224(input_str.ptr, input_str.len, sha_hash.ptr);
295+
md_alg = EVP_sha224();
296+
digest_length = SHA224_DIGEST_LENGTH;
297297
break;
298298
case 256:
299-
sha_hash = StringVal(ctx, SHA256_DIGEST_LENGTH);
300-
if (UNLIKELY(sha_hash.is_null)) return StringVal::null();
301-
SHA256(input_str.ptr, input_str.len, sha_hash.ptr);
299+
md_alg = EVP_sha256();
300+
digest_length = SHA256_DIGEST_LENGTH;
302301
break;
303302
case 384:
304-
sha_hash = StringVal(ctx, SHA384_DIGEST_LENGTH);
305-
if (UNLIKELY(sha_hash.is_null)) return StringVal::null();
306-
SHA384(input_str.ptr, input_str.len, sha_hash.ptr);
303+
md_alg = EVP_sha384();
304+
digest_length = SHA384_DIGEST_LENGTH;
307305
break;
308306
case 512:
309-
sha_hash = StringVal(ctx, SHA512_DIGEST_LENGTH);
310-
if (UNLIKELY(sha_hash.is_null)) return StringVal::null();
311-
SHA512(input_str.ptr, input_str.len, sha_hash.ptr);
307+
md_alg = EVP_sha512();
308+
digest_length = SHA512_DIGEST_LENGTH;
312309
break;
313310
default:
314311
// Unsupported bit length.
315312
ctx->SetError(Substitute("Bit Length $0 is not supported", bit_len.val).c_str());
316313
return StringVal::null();
317314
}
318315

316+
StringVal sha_hash(ctx, digest_length);
317+
if (UNLIKELY(sha_hash.is_null)) return StringVal::null();
318+
319+
// Do not use low-level calls like SHA384(), which can be forbidden in FIPS mode.
320+
// This is the fips-compliant hashing implementation, which uses the high-level
321+
// EVP_Digest function.
322+
EVP_Digest(input_str.ptr, input_str.len, sha_hash.ptr, nullptr, md_alg, nullptr);
323+
319324
return StringFunctions::Lower(ctx, MathFunctions::HexString(ctx, sha_hash));
320325
}
321326

0 commit comments

Comments
 (0)