Skip to content

Commit d1805c5

Browse files
Ensure that the Password Change and Application Restore features comply with FIPS standards.
1 parent c04b919 commit d1805c5

File tree

4 files changed

+8
-50
lines changed

4 files changed

+8
-50
lines changed

web/pgadmin/browser/server_groups/servers/__init__.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from pgadmin.browser.utils import PGChildNodeView
2222
from pgadmin.utils.ajax import make_json_response, bad_request, forbidden, \
2323
make_response as ajax_response, internal_server_error, unauthorized, gone
24-
from pgadmin.utils.crypto import encrypt, decrypt, pqencryptpassword
24+
from pgadmin.utils.crypto import encrypt, decrypt
2525
from pgadmin.utils.menu import MenuItem
2626
from pgadmin.tools.sqleditor.utils.query_history import QueryHistory
2727
from pgadmin.tools.user_management.PgAdminPermissions import AllPermissionTypes
@@ -1881,16 +1881,11 @@ def change_password(self, gid, sid):
18811881
return unauthorized(gettext("Incorrect password."))
18821882

18831883
# Hash new password before saving it.
1884-
if manager.sversion >= 100000:
1885-
password = conn.pq_encrypt_password_conn(data['newPassword'],
1886-
manager.user)
1887-
if password is None:
1888-
# Unable to encrypt the password so used the
1889-
# old method of encryption
1890-
password = pqencryptpassword(data['newPassword'],
1891-
manager.user)
1892-
else:
1893-
password = pqencryptpassword(data['newPassword'], manager.user)
1884+
password = conn.pq_encrypt_password_conn(data['newPassword'],
1885+
manager.user)
1886+
if password is None:
1887+
return internal_server_error(errormsg="Unable to"
1888+
" change the password.")
18941889

18951890
SQL = render_template(
18961891
"/servers/sql/#{0}#/change_password.sql".format(

web/pgadmin/browser/server_groups/servers/tests/test_password_change.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ def setUp(self):
2727
utils.write_node_info("sid", server_dict)
2828

2929
@patch('pgadmin.browser.server_groups.servers.render_template')
30-
@patch('pgadmin.browser.server_groups.servers.pqencryptpassword')
3130
@patch('pgadmin.browser.server_groups.servers.decrypt')
3231
@patch('pgadmin.browser.server_groups.servers.get_driver')
3332
@patch('pgadmin.browser.server_groups.servers.db')
3433
@patch('pgadmin.browser.server_groups.servers.Server')
3534
@patch('pgadmin.browser.server_groups.servers.User')
3635
@patch('pgadmin.browser.server_groups.servers.current_user')
3736
def runTest(self, current_user_mock, user_mock, server_mock, db_mock,
38-
get_driver_mock, decrypt_mock, pqencryptpassword_mock,
37+
get_driver_mock, decrypt_mock,
3938
render_template_mock):
4039

4140
current_user_mock.id = 1
@@ -54,7 +53,6 @@ def runTest(self, current_user_mock, user_mock, server_mock, db_mock,
5453
['connection_execute_scalar_return_value'])
5554

5655
decrypt_mock.return_value = self.manager.password
57-
pqencryptpassword_mock.return_value = self.manager.password
5856

5957
class TestMockServer():
6058
def __init__(self, name, sid, password, passfile):

web/pgadmin/settings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def delete_tool_data(trans_id=None):
513513

514514
def compute_md5_hash_file(file_path, chunk_size=8192):
515515
"""Compute md5 hash for large files by reading in chunks."""
516-
md5_hash = hashlib.md5()
516+
md5_hash = hashlib.sha256()
517517

518518
# Open the file in binary mode
519519
with open(file_path, "rb") as file:

web/pgadmin/utils/crypto.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,3 @@ def pad(key):
7676

7777
# Add padding to make key 32 bytes long
7878
return key.ljust(32, padding_string)
79-
80-
81-
def pqencryptpassword(password, user):
82-
"""
83-
pqencryptpassword -- to encrypt a password
84-
This is intended to be used by client applications that wish to send
85-
commands like ALTER USER joe PASSWORD 'pwd'. The password need not
86-
be sent in cleartext if it is encrypted on the client side. This is
87-
good because it ensures the cleartext password won't end up in logs,
88-
pg_stat displays, etc. We export the function so that clients won't
89-
be dependent on low-level details like whether the enceyption is MD5
90-
or something else.
91-
92-
Arguments are the cleartext password, and the SQL name of the user it
93-
is for.
94-
95-
Return value is "md5" followed by a 32-hex-digit MD5 checksum..
96-
97-
Args:
98-
password:
99-
user:
100-
101-
Returns:
102-
103-
"""
104-
105-
m = hashlib.md5()
106-
107-
# Place salt at the end because it may be known by users trying to crack
108-
# the MD5 output.
109-
110-
m.update(password.encode())
111-
m.update(user.encode())
112-
113-
return "md5" + m.hexdigest()

0 commit comments

Comments
 (0)