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

Update for FIPS Compliance #3291

Merged
merged 11 commits into from
Dec 22, 2023
2 changes: 1 addition & 1 deletion altair/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def check_data_type(data: DataType) -> None:
# Private utilities
# ==============================================================================
def _compute_data_hash(data_str: str) -> str:
return hashlib.md5(data_str.encode()).hexdigest()
return hashlib.sha256(data_str.encode()).hexdigest()[:32]


def _data_to_json_string(data: DataType) -> str:
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _dataset_name(values: Union[dict, list, core.InlineDataset]) -> str:
if values == [{}]:
return "empty"
values_json = json.dumps(values, sort_keys=True)
hsh = hashlib.md5(values_json.encode()).hexdigest()
hsh = hashlib.sha256(values_json.encode()).hexdigest()[:32]
return "data-" + hsh


Expand Down
4 changes: 4 additions & 0 deletions doc/releases/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ Version 5.3.0 (unreleased month day, year)

Enhancements
~~~~~~~~~~~~
- Support restrictive FIPS-compliant environment (#3291)

Bug Fixes
~~~~~~~~~

Backward-Incompatible Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Changed hash function from ``md5`` to a truncated ``sha256`` non-cryptograhic hash (#3291)

Version 5.2.0 (released Nov 28, 2023)
-------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion sphinxext/altairgallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def save_example_pngs(examples, image_dir, make_thumbnails=True):
filename = example["name"] + (".svg" if example["use_svg"] else ".png")
image_file = os.path.join(image_dir, filename)

example_hash = hashlib.md5(example["code"].encode()).hexdigest()
example_hash = hashlib.sha256(example["code"].encode()).hexdigest()[:32]
hashes_match = hashes.get(filename, "") == example_hash

if hashes_match and os.path.exists(image_file):
Expand Down
4 changes: 2 additions & 2 deletions sphinxext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def dict_hash(dct):
serialized = json.dumps(dct, sort_keys=True)

try:
m = hashlib.md5(serialized)
m = hashlib.sha256(serialized)[:32]
except TypeError:
m = hashlib.md5(serialized.encode())
m = hashlib.sha256(serialized.encode())[:32]

return m.hexdigest()
9 changes: 1 addition & 8 deletions tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,7 @@ def test_save_html(basic_chart, inline):

def test_to_url(basic_chart):
share_url = basic_chart.to_url()
expected_vegalite_encoding = (
"N4Igxg9gdgZglgcxALlANzgUwO4tJKAFzigFcJSBnAdTgBNCALFAZgAY2AacaYsiygAlMiRoVYcAvpO5"
"0AhoTl4QUOQFtMKEPMUBaMACY5LTAA4AnACM55ugFY6ARgBspgOz2zh03Wfs5bCwsIDIganIATgDWyoQ"
"AngAOmsgg1hEh3JhQkHQkSKggAB7K8JgANnRaStzxSVpQEGokcmUZIHElWBValiA1ickgAI6kckRwisR"
"omtLcACSUYIyY4VpihAmUyAD029MIcgB0CBOMpJaHcBDbi8vhe5gHumUTmHt2hy6HLIcAVpTQPraBRyS"
"iYQiUZQ6OT6IwmCzWWwOFzuTymby+fyBYLIADaoCUKQAgkDesgDKYZAStAAhUkoOx2KkgQkgADC9OQABY"
"WMzWQARTnmRx8rQAUU5phFnGpKQAYpy7LyZSytABxTmOcyilKCSVuHUgACSioMkgAutIgA"
)
expected_vegalite_encoding = "N4Igxg9gdgZglgcxALlANzgUwO4tJKAFzigFcJSBnAdTgBNCALFAZgAY2AacaYsiygAlMiRoVYcAvpO50AhoTl4QUOQFtMKEPMUBaAOwA2ABwAWFi1NyTcgEb7TtuabAswc-XTZhMczLdNDAEYQGRA1OQAnAGtlQgBPAAdNZBAnSNDuTChIOhIkVBAAD2V4TAAbOi0lbgTkrSgINRI5csyQeNKsSq1bEFqklJAAR1I5IjhFYjRNaW4AEkowRkwIrTFCRMpkAHodmYQ5ADoEScZSWyO4CB2llYj9zEPdcsnMfYBWI6DDI5YjgBWlGg-W0CjklEwhEoyh0cgMJnMlmsxjsDicLjcHi8Pj8AWCKAA2qAlKkAIKgvrIABMxhkJK0ACFKSgPh96SBSSAAMIs5DmDlcgAifIAnEFBVoAKJ84wSzgM1IAMT5HxYktSAHE+UFRRqQIJZfp9QBJVXUyQAXWkQA"

assert (
share_url
Expand Down