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

Add FIPS support #1233

Merged
merged 2 commits into from
Oct 4, 2022
Merged
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
15 changes: 15 additions & 0 deletions S3/BaseUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from __future__ import absolute_import, division

import functools
import hashlib
import re
import sys

Expand Down Expand Up @@ -50,6 +52,19 @@
unicode = str


try:
md5 = hashlib.md5()
except Exception as exc:
try:
# md5 is disabled for FIPS-compliant Python builds.
# Since s3cmd does not use md5 in a security context,
# it is safe to allow the use of it by setting useforsecurity to False.
hashlib.md5(usedforsecurity=False)
md5 = functools.partial(hashlib.md5, usedforsecurity=False)
except:
raise exc


__all__ = []


Expand Down
7 changes: 1 addition & 6 deletions S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@

import select

try:
from hashlib import md5
except ImportError:
from md5 import md5

from .BaseUtils import (getListFromXml, getTextFromXml, getRootTagName,
decode_from_s3, encode_to_s3, s3_quote)
decode_from_s3, encode_to_s3, md5, s3_quote)
from .Utils import (convertHeaderTupleListToDict, hash_file_md5, unicodise,
deunicodise, check_bucket_name,
check_bucket_name_dns_support, getHostnameFromBucket,
Expand Down
3 changes: 1 addition & 2 deletions S3/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import string as string_mod
import random
import errno
from hashlib import md5
from logging import debug


Expand All @@ -30,7 +29,7 @@
import S3.Exceptions

from S3.BaseUtils import (base_urlencode_string, base_replace_nonprintables,
base_unicodise, base_deunicodise)
base_unicodise, base_deunicodise, md5)


__all__ = []
Expand Down