Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion zvmsdk/sdkwsgi/handlers/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def file_import(self, fileobj):
target_fpath = '/'.join([importDir, fname])

# The following steps save the imported file into sdkserver
checksum = hashlib.md5()
checksum = utils.get_hash_object()
bytes_written = 0

with open(target_fpath, 'wb') as f:
Expand Down
2 changes: 1 addition & 1 deletion zvmsdk/smtclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,7 @@ def _scheme2backend(self, scheme):
def _get_md5sum(self, fpath):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rename this function as it may return something else than MD5 sum.

"""Calculate the md5sum of the specific image file"""
try:
current_md5 = hashlib.md5()
current_md5 = zvmutils.get_hash_object()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also rename the current_md5 variable.

if isinstance(fpath, six.string_types) and os.path.exists(fpath):
with open(fpath, "rb") as fh:
for chunk in self._read_chunks(fh):
Expand Down
20 changes: 20 additions & 0 deletions zvmsdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import traceback
import threading
import string
import hashlib

from zvmsdk import config
from zvmsdk import constants
Expand Down Expand Up @@ -1315,3 +1316,22 @@ def get_lpar_name(zhypinfo=None):
zhypinfo = get_zhypinfo(filter='all')
lpar_name = zhypinfo['lpar']['layer_name']
return lpar_name


def is_fips_enabled():
if not os.path.exists('/proc/sys/crypto/fips_enabled'):
return False

try:
with open('/proc/sys/crypto/fips_enabled', 'r') as infile:
return infile.read().strip() == '1'
except Exception as ex:
LOG.warning(f'Encountered error while checking FIPS status. Error={str(ex)}')
return False


def get_hash_object():
if is_fips_enabled():
return hashlib.sha256()
else:
return hashlib.md5()
Loading