2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-09-09 22:46:45 +00:00

Have auth protocol be selectable

Also, add AES256 to privacy choices.
This commit is contained in:
Jarrod Johnson
2026-09-08 16:31:40 -04:00
parent d12fc1bc8b
commit b4b86ae909
3 changed files with 22 additions and 5 deletions
@@ -636,7 +636,11 @@ node = {
'snmp.privacyprotocol': {
'description': 'The privacy protocol to use for SNMPv3. If unset, '
'"des" is assumed.',
'validvalues': ('aes', 'des'),
'validvalues': ('aes', 'des', 'aes256'),
},
'snmp.authprotocol': {
'description': 'The authentication protocol to use for SNMPv3. If unset, "sha" is assumed.',
'validvalues': ('sha', 'md5', 'sha256'),
},
# 'secret.snmplocalizedkey': {
# 'description': ("SNMPv3 key localized to this node's SNMP Engine id"
@@ -21,7 +21,7 @@ import confluent.collective.manager as collective
def get_switchcreds(configmanager, switches):
switchcfg = configmanager.get_node_attributes(
switches, ('secret.hardwaremanagementuser', 'secret.snmpcommunity',
'secret.hardwaremanagementpassword', 'snmp.privacyprotocol',
'secret.hardwaremanagementpassword', 'snmp.privacyprotocol', 'snmp.authprotocol',
'collective.managercandidates'), decrypt=True)
switchauth = []
for switch in switches:
@@ -50,7 +50,9 @@ def get_switchcreds(configmanager, switches):
user = None
privacy_protocol = switchparms.get(
'snmp.privacyprotocol', {}).get('value', None)
switchauth.append((switch, password, user, configmanager, privacy_protocol))
auth_protocol = switchparms.get(
'snmp.authprotocol', {}).get('value', None)
switchauth.append((switch, password, user, configmanager, privacy_protocol, auth_protocol))
return switchauth
+13 -2
View File
@@ -38,7 +38,7 @@ async def _get_transport(name):
class Session(object):
def __init__(self, server, secret, username=None, context=None, privacy_protocol=None):
def __init__(self, server, secret, username=None, context=None, privacy_protocol=None, auth_protocol=None):
"""Create a new session to interrogate a switch
If username is not given, it is assumed that
@@ -59,14 +59,25 @@ class Session(object):
else:
if privacy_protocol == 'aes':
privproto = snmp.usmAesCfb128Protocol
elif privacy_protocol == 'aes256':
privproto = snmp.usmAesCfb256Protocol
elif privacy_protocol in ('des', None):
privproto = snmp.usmDESPrivProtocol
else:
raise exc.ConfluentException('Unsupported SNMPv3 privacy protocol '
'{0}'.format(privacy_protocol))
if auth_protocol == 'sha256':
authproto = snmp.usmHMAC192SHA256AuthProtocol
elif auth_protocol == 'md5':
authproto = snmp.usmHMACMD5AuthProtocol
elif auth_protocol in ('sha', None):
authproto = snmp.usmHMACSHAAuthProtocol
else:
raise exc.ConfluentException('Unsupported SNMPv3 auth protocol '
'{0}'.format(auth_protocol))
self.authdata = snmp.UsmUserData(
username, authKey=secret, privKey=secret,
authProtocol=snmp.usmHMACSHAAuthProtocol,
authProtocol=authproto,
privProtocol=privproto)
self.eng = snmp.SnmpEngine()