Skip to content
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

[TACACS] Encrypt TACACS secret key with predefined shared key. #3327

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions config/aaa.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import click
import ipaddress
import re
import subprocess
from swsscommon.swsscommon import ConfigDBConnector
from .validated_config_db_connector import ValidatedConfigDBConnector
from jsonpatch import JsonPatchConflict
from jsonpointer import JsonPointerException
import utilities_common.cli as clicommon

TAC_PLUS_PASSKEY_MAX_LEN = 65
ADHOC_VALIDATION = True
RADIUS_MAXSERVERS = 8
RADIUS_PASSKEY_MAX_LEN = 65
VALID_CHARS_MSG = "Valid chars are ASCII printable except SPACE, '#', and ','"
TACPLUS_SECRET_PASSWORD = "ktbSJeed7apq9dZHOD1O5wW9cvSaRWjW767qLyFEurDTSNEvHdYspaCuEzZcMg8R"


def encrypt_data(secret):
cmd = ['openssl', 'enc', '-aes-128-cbc', '-A', '-a', '-salt', '-pbkdf2',
'-pass', 'pass:' + TACPLUS_SECRET_PASSWORD]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, universal_newlines=True)
outsecret, errs = p.communicate(input=secret)
return outsecret, errs


def is_secret(secret):
return bool(re.match('^' + '[^ #,]*' + '$', secret))
Expand Down Expand Up @@ -240,7 +253,20 @@ def passkey(ctx, secret):
if ctx.obj == 'default':
del_table_key('TACPLUS', 'global', 'passkey')
elif secret:
add_table_kv('TACPLUS', 'global', 'passkey', secret)
if len(secret) > TAC_PLUS_PASSKEY_MAX_LEN:
click.echo('Maximum of %d chars can be configured' % TAC_PLUS_PASSKEY_MAX_LEN)
return
elif not is_secret(secret):
click.echo(VALID_CHARS_MSG)
return

outsecret, errs = encrypt_data(secret)
if not errs:
add_table_kv('TACPLUS', 'global', 'passkey', outsecret)
else:
click.echo('Key configuration failed' % errs)
return

else:
click.echo('Argument "secret" is required')
tacacs.add_command(passkey)
Expand Down Expand Up @@ -278,7 +304,13 @@ def add(address, timeout, key, auth_type, port, pri, use_mgmt_vrf):
if timeout is not None:
data['timeout'] = str(timeout)
if key is not None:
data['passkey'] = key
outsecret, errs = encrypt_data(key)
if not errs:
data['passkey'] = outsecret
else:
click.echo('Key configuration failed' % errs)
return

if use_mgmt_vrf :
data['vrf'] = "mgmt"
try:
Expand Down
Loading