Skip to content

Commit

Permalink
Add support for SHA-2 authentication protocols
Browse files Browse the repository at this point in the history
The pysnmp library already supports these, so this is a matter of adding
the needed mappings from authprotocol string to pysnmp constant.
  • Loading branch information
matthijskooijman authored and vincentbernat committed Aug 3, 2024
1 parent abc4c21 commit 7df601f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions snimpy/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def __init__(self, host,
:param secname: Security name to use for SNMPv3 only.
:type secname: str
:param authprotocol: Authorization protocol to use for
SNMPv3. This can be `None` or either the string `SHA` or
`MD5`.
SNMPv3. This can be `None` or one of the strings `SHA`,
`MD5`, `SHA224`, `SHA256`, `SHA384` or `SHA512`.
:type authprotocol: None or str
:param authpassword: Authorization password if authorization
protocol is not `None`.
Expand Down Expand Up @@ -154,7 +154,11 @@ def __init__(self, host,
None: cmdgen.usmNoAuthProtocol,
"MD5": cmdgen.usmHMACMD5AuthProtocol,
"SHA": cmdgen.usmHMACSHAAuthProtocol,
"SHA1": cmdgen.usmHMACSHAAuthProtocol
"SHA1": cmdgen.usmHMACSHAAuthProtocol,
"SHA224": cmdgen.usmHMAC128SHA224AuthProtocol,
"SHA256": cmdgen.usmHMAC192SHA256AuthProtocol,
"SHA384": cmdgen.usmHMAC256SHA384AuthProtocol,
"SHA512": cmdgen.usmHMAC384SHA512AuthProtocol,
}[authprotocol]
except KeyError:
raise ValueError("{} is not an acceptable authentication "
Expand Down
2 changes: 1 addition & 1 deletion tests/test_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def testSnmpV3(self):

def testSnmpV3Protocols(self):
"""Check accepted auth and privacy protocols"""
for auth in ["MD5", "SHA"]:
for auth in ["MD5", "SHA", "SHA224", "SHA256", "SHA384", "SHA512"]:
for priv in ["AES", "AES128", "DES"]:
snmp.Session(host="localhost",
version=3,
Expand Down

0 comments on commit 7df601f

Please sign in to comment.