Skip to content

Commit f144dc7

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Replace md5 for fips"
2 parents 4174f4a + db7a633 commit f144dc7

File tree

7 files changed

+36
-29
lines changed

7 files changed

+36
-29
lines changed

lower-constraints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ oslo.reports==1.18.0
9191
oslo.serialization==2.28.1
9292
oslo.service==1.30.0
9393
oslo.upgradecheck==1.3.0
94-
oslo.utils==4.5.0
94+
oslo.utils==4.7.0
9595
oslotest==3.2.0
9696
packaging==20.4
9797
paramiko==2.4.1

octavia/amphorae/backends/agent/api_server/loadbalancer.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
import hashlib
1615
import io
1716
import os
1817
import re
@@ -24,6 +23,7 @@
2423
import jinja2
2524
from oslo_config import cfg
2625
from oslo_log import log as logging
26+
from oslo_utils.secretutils import md5
2727
import webob
2828
from werkzeug import exceptions
2929

@@ -56,7 +56,7 @@
5656
class Wrapped(object):
5757
def __init__(self, stream_):
5858
self.stream = stream_
59-
self.hash = hashlib.md5() # nosec
59+
self.hash = md5(usedforsecurity=False) # nosec
6060

6161
def read(self, line):
6262
block = self.stream.read(line)
@@ -86,7 +86,8 @@ def get_haproxy_config(self, lb_id):
8686
cfg = file.read()
8787
resp = webob.Response(cfg, content_type='text/plain')
8888
resp.headers['ETag'] = (
89-
hashlib.md5(octavia_utils.b(cfg)).hexdigest()) # nosec
89+
md5(octavia_utils.b(cfg),
90+
usedforsecurity=False).hexdigest()) # nosec
9091
return resp
9192

9293
def upload_haproxy_config(self, amphora_id, lb_id):
@@ -415,9 +416,10 @@ def get_certificate_md5(self, lb_id, filename):
415416

416417
with open(cert_path, 'r') as crt_file:
417418
cert = crt_file.read()
418-
md5 = hashlib.md5(octavia_utils.b(cert)).hexdigest() # nosec
419-
resp = webob.Response(json=dict(md5sum=md5))
420-
resp.headers['ETag'] = md5
419+
md5sum = md5(octavia_utils.b(cert),
420+
usedforsecurity=False).hexdigest() # nosec
421+
resp = webob.Response(json=dict(md5sum=md5sum))
422+
resp.headers['ETag'] = md5sum
421423
return resp
422424

423425
def delete_certificate(self, lb_id, filename):

octavia/amphorae/drivers/haproxy/rest_api_driver.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from oslo_context import context as oslo_context
2323
from oslo_log import log as logging
24+
from oslo_utils.secretutils import md5
2425
import requests
2526
import simplejson
2627
from stevedore import driver as stevedore_driver
@@ -468,20 +469,21 @@ def _process_tls_certificates(self, listener, amphora=None, obj_id=None):
468469
if amphora and obj_id:
469470
for cert in certs:
470471
pem = cert_parser.build_pem(cert)
471-
md5 = hashlib.md5(pem).hexdigest() # nosec
472+
md5sum = md5(pem, usedforsecurity=False).hexdigest() # nosec
472473
name = '{id}.pem'.format(id=cert.id)
473474
cert_filename_list.append(
474475
os.path.join(
475476
CONF.haproxy_amphora.base_cert_dir, obj_id, name))
476-
self._upload_cert(amphora, obj_id, pem, md5, name)
477+
self._upload_cert(amphora, obj_id, pem, md5sum, name)
477478

478479
if certs:
479480
# Build and upload the crt-list file for haproxy
480481
crt_list = "\n".join(cert_filename_list)
481482
crt_list = f'{crt_list}\n'.encode('utf-8')
482-
md5 = hashlib.md5(crt_list).hexdigest() # nosec
483+
md5sum = md5(crt_list,
484+
usedforsecurity=False).hexdigest() # nosec
483485
name = '{id}.pem'.format(id=listener.id)
484-
self._upload_cert(amphora, obj_id, crt_list, md5, name)
486+
self._upload_cert(amphora, obj_id, crt_list, md5sum, name)
485487
return {'tls_cert': tls_cert, 'sni_certs': sni_certs}
486488

487489
def _process_secret(self, listener, secret_ref, amphora=None, obj_id=None):
@@ -497,13 +499,13 @@ def _process_secret(self, listener, secret_ref, amphora=None, obj_id=None):
497499
secret = secret.encode('utf-8')
498500
except AttributeError:
499501
pass
500-
md5 = hashlib.md5(secret).hexdigest() # nosec
502+
md5sum = md5(secret, usedforsecurity=False).hexdigest() # nosec
501503
id = hashlib.sha1(secret).hexdigest() # nosec
502504
name = '{id}.pem'.format(id=id)
503505

504506
if amphora and obj_id:
505507
self._upload_cert(
506-
amphora, obj_id, pem=secret, md5=md5, name=name)
508+
amphora, obj_id, pem=secret, md5sum=md5sum, name=name)
507509
return name
508510

509511
def _process_listener_pool_certs(self, listener, amphora, obj_id):
@@ -536,10 +538,11 @@ def _process_pool_certs(self, listener, pool, amphora, obj_id):
536538
pem = pem.encode('utf-8')
537539
except AttributeError:
538540
pass
539-
md5 = hashlib.md5(pem).hexdigest() # nosec
541+
md5sum = md5(pem, usedforsecurity=False).hexdigest() # nosec
540542
name = '{id}.pem'.format(id=tls_cert.id)
541543
if amphora and obj_id:
542-
self._upload_cert(amphora, obj_id, pem=pem, md5=md5, name=name)
544+
self._upload_cert(amphora, obj_id, pem=pem,
545+
md5sum=md5sum, name=name)
543546
pool_cert_dict['client_cert'] = os.path.join(
544547
CONF.haproxy_amphora.base_cert_dir, obj_id, name)
545548
if pool.ca_tls_certificate_id:
@@ -555,10 +558,10 @@ def _process_pool_certs(self, listener, pool, amphora, obj_id):
555558

556559
return pool_cert_dict
557560

558-
def _upload_cert(self, amp, listener_id, pem, md5, name):
561+
def _upload_cert(self, amp, listener_id, pem, md5sum, name):
559562
try:
560563
if self.clients[amp.api_version].get_cert_md5sum(
561-
amp, listener_id, name, ignore=(404,)) == md5:
564+
amp, listener_id, name, ignore=(404,)) == md5sum:
562565
return
563566
except exc.NotFound:
564567
pass

octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
import hashlib
1615
import os
1716
import random
1817
import socket
@@ -23,6 +22,7 @@
2322
import fixtures
2423
from oslo_config import fixture as oslo_fixture
2524
from oslo_serialization import jsonutils
25+
from oslo_utils.secretutils import md5
2626
from oslo_utils import uuidutils
2727

2828
from octavia.amphorae.backends.agent import api_server
@@ -862,8 +862,8 @@ def _test_get_certificate_md5(self, distro, mock_exists):
862862
rv = self.centos_app.get('/' + api_server.VERSION +
863863
'/loadbalancer/123/certificates/test.pem')
864864
self.assertEqual(200, rv.status_code)
865-
self.assertEqual(dict(md5sum=hashlib.md5(octavia_utils.
866-
b(CONTENT)).hexdigest()),
865+
self.assertEqual(dict(md5sum=md5(octavia_utils.b(CONTENT),
866+
usedforsecurity=False).hexdigest()),
867867
jsonutils.loads(rv.data.decode('utf-8')))
868868

869869
def test_ubuntu_upload_certificate_md5(self):

octavia/tests/unit/amphorae/drivers/haproxy/test_rest_api_driver_0_5.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from oslo_config import cfg
1919
from oslo_config import fixture as oslo_fixture
20+
from oslo_utils.secretutils import md5
2021
from oslo_utils import uuidutils
2122
import requests
2223
import requests_mock
@@ -342,7 +343,7 @@ def test_process_secret(self, mock_upload_cert, mock_oslo):
342343
mock_oslo.return_value = fake_context
343344
self.driver.cert_manager.get_secret.reset_mock()
344345
self.driver.cert_manager.get_secret.return_value = fake_secret
345-
ref_md5 = hashlib.md5(fake_secret).hexdigest() # nosec
346+
ref_md5 = md5(fake_secret, usedforsecurity=False).hexdigest() # nosec
346347
ref_id = hashlib.sha1(fake_secret).hexdigest() # nosec
347348
ref_name = '{id}.pem'.format(id=ref_id)
348349

@@ -356,7 +357,7 @@ def test_process_secret(self, mock_upload_cert, mock_oslo):
356357
fake_context, sample_listener.client_ca_tls_certificate_id)
357358
mock_upload_cert.assert_called_once_with(
358359
self.amp, sample_listener.id, pem=fake_secret,
359-
md5=ref_md5, name=ref_name)
360+
md5sum=ref_md5, name=ref_name)
360361
self.assertEqual(ref_name, result)
361362

362363
@mock.patch('octavia.amphorae.drivers.haproxy.rest_api_driver.'
@@ -406,7 +407,7 @@ def test__process_pool_certs(self, mock_load_certs, mock_build_pem,
406407
mock_load_certs.return_value = pool_data
407408
fake_pem = b'fake pem'
408409
mock_build_pem.return_value = fake_pem
409-
ref_md5 = hashlib.md5(fake_pem).hexdigest() # nosec
410+
ref_md5 = md5(fake_pem, usedforsecurity=False).hexdigest() # nosec
410411
ref_name = '{id}.pem'.format(id=pool_cert.id)
411412
ref_path = '{cert_dir}/{list_id}/{name}'.format(
412413
cert_dir=fake_cert_dir, list_id=sample_listener.id, name=ref_name)
@@ -437,7 +438,7 @@ def test__process_pool_certs(self, mock_load_certs, mock_build_pem,
437438
mock_build_pem.assert_called_once_with(pool_cert)
438439
mock_upload_cert.assert_called_once_with(
439440
self.amp, sample_listener.id, pem=fake_pem,
440-
md5=ref_md5, name=ref_name)
441+
md5sum=ref_md5, name=ref_name)
441442
mock_secret.assert_has_calls(secret_calls)
442443
self.assertEqual(ref_result, result)
443444

octavia/tests/unit/amphorae/drivers/haproxy/test_rest_api_driver_1_0.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from oslo_config import cfg
1919
from oslo_config import fixture as oslo_fixture
20+
from oslo_utils.secretutils import md5
2021
from oslo_utils import uuidutils
2122
import requests
2223
import requests_mock
@@ -343,7 +344,7 @@ def test_process_secret(self, mock_upload_cert, mock_oslo):
343344
mock_oslo.return_value = fake_context
344345
self.driver.cert_manager.get_secret.reset_mock()
345346
self.driver.cert_manager.get_secret.return_value = fake_secret
346-
ref_md5 = hashlib.md5(fake_secret).hexdigest() # nosec
347+
ref_md5 = md5(fake_secret, usedforsecurity=False).hexdigest() # nosec
347348
ref_id = hashlib.sha1(fake_secret).hexdigest() # nosec
348349
ref_name = '{id}.pem'.format(id=ref_id)
349350

@@ -357,7 +358,7 @@ def test_process_secret(self, mock_upload_cert, mock_oslo):
357358
fake_context, sample_listener.client_ca_tls_certificate_id)
358359
mock_upload_cert.assert_called_once_with(
359360
self.amp, sample_listener.id, pem=fake_secret,
360-
md5=ref_md5, name=ref_name)
361+
md5sum=ref_md5, name=ref_name)
361362
self.assertEqual(ref_name, result)
362363

363364
@mock.patch('octavia.amphorae.drivers.haproxy.rest_api_driver.'
@@ -407,7 +408,7 @@ def test__process_pool_certs(self, mock_load_certs, mock_build_pem,
407408
mock_load_certs.return_value = pool_data
408409
fake_pem = b'fake pem'
409410
mock_build_pem.return_value = fake_pem
410-
ref_md5 = hashlib.md5(fake_pem).hexdigest() # nosec
411+
ref_md5 = md5(fake_pem, usedforsecurity=False).hexdigest() # nosec
411412
ref_name = '{id}.pem'.format(id=pool_cert.id)
412413
ref_path = '{cert_dir}/{lb_id}/{name}'.format(
413414
cert_dir=fake_cert_dir, lb_id=sample_listener.load_balancer.id,
@@ -439,7 +440,7 @@ def test__process_pool_certs(self, mock_load_certs, mock_build_pem,
439440
mock_build_pem.assert_called_once_with(pool_cert)
440441
mock_upload_cert.assert_called_once_with(
441442
self.amp, sample_listener.load_balancer.id, pem=fake_pem,
442-
md5=ref_md5, name=ref_name)
443+
md5sum=ref_md5, name=ref_name)
443444
mock_secret.assert_has_calls(secret_calls)
444445
self.assertEqual(ref_result, result)
445446

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ oslo.policy>=3.7.0 # Apache-2.0
2626
oslo.reports>=1.18.0 # Apache-2.0
2727
oslo.serialization>=2.28.1 # Apache-2.0
2828
oslo.upgradecheck>=1.3.0 # Apache-2.0
29-
oslo.utils>=4.5.0 # Apache-2.0
29+
oslo.utils>=4.7.0 # Apache-2.0
3030
pyasn1!=0.2.3,>=0.1.8 # BSD
3131
pyasn1-modules>=0.0.6 # BSD
3232
python-barbicanclient>=4.5.2 # Apache-2.0

0 commit comments

Comments
 (0)