Skip to content

Commit

Permalink
Added check to avoid keyring call to get server password if save_pass…
Browse files Browse the repository at this point in the history
…word flag is not set
  • Loading branch information
nikhil-mohite committed Jan 5, 2024
1 parent fdaedac commit 3d7d47c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
9 changes: 5 additions & 4 deletions web/pgadmin/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,18 +724,19 @@ def set_master_password():

try:
all_server = Server.query.all()
saved_password_servers = [server for server in all_server if
server.save_password]
# pgAdmin will use the OS password manager to store the server
# password, here migrating the existing saved server password to
# OS password manager
if keyring.get_password(
if len(saved_password_servers) > 0 and keyring.get_password(
KEY_RING_SERVICE_NAME, KEY_RING_DESKTOP_USER.format(
desktop_user.username)) or enc_key:
is_migrated = False

for server in all_server:
for server in saved_password_servers:
if enc_key:
if server.password and config.ALLOW_SAVE_PASSWORD \
and server.save_password:
if server.password and config.ALLOW_SAVE_PASSWORD:
name = KEY_RING_USERNAME_FORMAT.format(server.name,
server.id)
password = decrypt(server.password,
Expand Down
12 changes: 7 additions & 5 deletions web/pgadmin/browser/server_groups/servers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,10 +1519,11 @@ def connect(self, gid, sid):
conn = manager.connection()

crypt_key = None
if config.DISABLED_LOCAL_PASSWORD_STORAGE or \
not keyring.get_password(KEY_RING_SERVICE_NAME,
KEY_RING_DESKTOP_USER.format(
current_user.username)):
if server.save_password and \
(config.DISABLED_LOCAL_PASSWORD_STORAGE or not
keyring.get_password(
KEY_RING_SERVICE_NAME,KEY_RING_DESKTOP_USER.format(
current_user.username))):
# Get enc key
crypt_key_present, crypt_key = get_crypt_key()
if not crypt_key_present:
Expand All @@ -1536,7 +1537,8 @@ def connect(self, gid, sid):
and server.tunnel_password is None:
prompt_tunnel_password = True
else:
if not config.DISABLED_LOCAL_PASSWORD_STORAGE:
if not config.DISABLED_LOCAL_PASSWORD_STORAGE and \
server.save_password:
# Get password form OS password manager
tunnel_password = keyring.get_password(
KEY_RING_SERVICE_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, name, id, username, use_ssh_tunnel,
self.tunnel_password = tunnel_password
self.tunnel_keep_alive = tunnel_keep_alive
self.service = service
self.save_password = 0
self.shared = None

mock_server_obj = TestMockServer(
Expand Down

0 comments on commit 3d7d47c

Please sign in to comment.