Skip to content

Commit 1ab7067

Browse files
committed
Addressed new comments
1 parent 719053b commit 1ab7067

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/sonic-py-common/sonic_py_common/security_cipher.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def __init__(self):
3636
if not os.path.exists(self._file_path):
3737
with open(self._file_path, 'w') as file:
3838
file.writelines("#Auto generated file for storing the encryption passwords\n")
39-
file.writelines("TACPLUS : \nRADIUS : \nLDAP :\n")
39+
for feature in self._feature_list[1:]: # Skip the first "NA" entry
40+
file.write(f"{feature} : \n")
4041
os.chmod(self._file_path, 0o640)
4142
self._initialized = True
4243

@@ -119,15 +120,28 @@ def is_key_encrypt_enabled(self, table, entry):
119120
return data[key]
120121
return False
121122

122-
def del_cipher_pass(self):
123+
124+
def del_cipher_pass(self, feature_type):
125+
"""
126+
Removes only the password for the given feature_type while keeping the file structure intact.
127+
"""
123128
try:
124-
# Check if the file exists
125-
if os.path.exists(self._file_path):
126-
# Attempt to delete the file
127-
os.remove(self._file_path)
128-
syslog.syslog(syslog.LOG_INFO, "del_cipher_pass: {} file has been removed".format((self._file_path)))
129-
else:
130-
syslog.syslog(syslog.LOG_INFO, "del_cipher_pass: {} file doesn't exist".format((self._file_path)))
129+
os.chmod(self._file_path, 0o777)
130+
with open(self._file_path, "r") as file:
131+
lines = file.readlines()
132+
133+
updated_lines = []
134+
for line in lines:
135+
if line.strip().startswith(f"{feature_type} :"):
136+
updated_lines.append(f"{feature_type} : \n") # Remove password but keep format
137+
else:
138+
updated_lines.append(line)
139+
140+
with open(self._file_path, 'w') as file:
141+
file.writelines(updated_lines)
142+
os.chmod(self._file_path, 0o640)
143+
144+
syslog.syslog(syslog.LOG_INFO, "del_cipher_pass: Password for {} has been removed".format((feature_type)))
145+
131146
except Exception as e:
132147
syslog.syslog(syslog.LOG_ERR, "del_cipher_pass: {} Exception occurred: {}".format((e)))
133-

src/sonic-yang-models/yang-models/sonic-system-tacacs.yang

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,14 @@ module sonic-system-tacacs {
131131
default 5;
132132
}
133133

134+
leaf key_encrypt {
135+
type boolean;
136+
description "Indicates if the passkey is encrypted.";
137+
}
138+
134139
leaf passkey {
135140
type string {
136-
length "1..65";
141+
length "1..256";
137142
pattern "[^ #,]*" {
138143
error-message 'TACACS shared secret (Valid chars are ASCII printable except SPACE, "#", and ",")';
139144
}

0 commit comments

Comments
 (0)