-
Notifications
You must be signed in to change notification settings - Fork 134
TACACSPLUS_PASSKEY_ENCRYPTION support Part - II #81
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
Changes from 14 commits
8b909b8
48e7d1d
c877edb
b37ddcd
945f4f2
5b61c0c
7cb53e6
43641de
66b57b5
c6c8e0a
977a268
a7d01d6
0a1b098
7b14786
911e2c0
bb5e5ee
d745364
1d85eb6
9285df1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ LIMITS_CONF = "/etc/security/limits.conf" | |
| TACPLUS_SERVER_PASSKEY_DEFAULT = "" | ||
| TACPLUS_SERVER_TIMEOUT_DEFAULT = "5" | ||
| TACPLUS_SERVER_AUTH_TYPE_DEFAULT = "pap" | ||
| TACACS_SECRET_SALT = "2e6593364d369fba925092e0c1c51466c276faa127f20d18cc5ed8ae52bedbcd" | ||
|
|
||
| # RADIUS | ||
| RADIUS_SERVER_AUTH_PORT_DEFAULT = "1812" | ||
|
|
@@ -76,6 +77,38 @@ CFG_DB = "CONFIG_DB" | |
| STATE_DB = "STATE_DB" | ||
|
|
||
|
|
||
| def get_salt(): | ||
| file_path = "/etc/shadow" | ||
| target_username = "admin" | ||
| salt = TACACS_SECRET_SALT | ||
|
|
||
| # Read the file and search for the "admin" username | ||
| try: | ||
| with open(file_path, 'r') as file: | ||
| for line in file: | ||
| if "admin:" in line: | ||
| # Format: username:$id$salt$hashed | ||
| parts = line.split('$') | ||
| if len(parts) == 4: | ||
| salt = parts[2] | ||
| break | ||
|
|
||
| except FileNotFoundError: | ||
| syslog.syslog(syslog.LOG_ERR, "File not found: {}".format(file_path)) | ||
| except Exception as e: | ||
| syslog.syslog(syslog.LOG_ERR, "output: {}".format(str(e))) | ||
| return salt | ||
|
|
||
| def decrypt_passkey(secret): | ||
| salt = get_salt() | ||
| cmd = "echo " + format(secret) + " | openssl enc -aes-128-cbc -a -d -salt -pbkdf2 -pass pass:" + salt | ||
| proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) | ||
| output, errs = proc.communicate() | ||
|
|
||
| if not errs: | ||
| output = output.decode('utf-8') | ||
| return output, errs | ||
|
|
||
| def signal_handler(sig, frame): | ||
| if sig == signal.SIGHUP: | ||
| syslog.syslog(syslog.LOG_INFO, "HostCfgd: signal 'SIGHUP' is caught and ignoring..") | ||
|
|
@@ -500,6 +533,14 @@ class AaaCfg(object): | |
| server = tacplus_global.copy() | ||
| server['ip'] = addr | ||
| server.update(self.tacplus_servers[addr]) | ||
| if server['passkey'] is not None: | ||
| config_db = ConfigDBConnector() | ||
| config_db.connect() | ||
| output, errs = decrypt_passkey(server['passkey']) | ||
|
||
| if not errs: | ||
| server['passkey'] = output | ||
| else: | ||
| syslog.syslog(syslog.LOG_ERR, "{}: decrypt_passkey failed.".format(addr)) | ||
| servers_conf.append(server) | ||
| servers_conf = sorted(servers_conf, key=lambda t: int(t['priority']), reverse=True) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.