forked from etingof/pysnmp
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AES 256 test cases and improved test helpers.
- Loading branch information
Showing
8 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import pytest | ||
from pysnmp.hlapi.v3arch.asyncio import * | ||
from pysnmp.proto.errind import DecryptionError, UnknownUserName, WrongDigest | ||
from tests.agent_context import AGENT_PORT, AgentContextManager | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_usm_sha_aes256(): | ||
async with AgentContextManager(): | ||
snmpEngine = SnmpEngine() | ||
authData = UsmUserData( | ||
"usr-sha-aes256", | ||
"authkey1", | ||
"privkey1", | ||
authProtocol=USM_AUTH_HMAC96_SHA, | ||
privProtocol=USM_PRIV_CFB256_AES, | ||
) | ||
errorIndication, errorStatus, errorIndex, varBinds = await getCmd( | ||
snmpEngine, | ||
authData, | ||
await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), | ||
ContextData(), | ||
ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), | ||
) | ||
|
||
assert errorIndication is None | ||
assert errorStatus == 0 | ||
assert len(varBinds) == 1 | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::sysDescr.0" | ||
isinstance(varBinds[0][1], OctetString) | ||
|
||
snmpEngine.closeDispatcher() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_usm_sha_aes256_wrong_auth(): | ||
async with AgentContextManager(): | ||
snmpEngine = SnmpEngine() | ||
authData = UsmUserData( | ||
"usr-sha-aes", | ||
"authkey1", | ||
"privkey1", | ||
authProtocol=USM_AUTH_HMAC96_MD5, # wrongly use usmHMACMD5AuthProtocol | ||
privProtocol=USM_PRIV_CFB256_AES, | ||
) | ||
errorIndication, errorStatus, errorIndex, varBinds = await getCmd( | ||
snmpEngine, | ||
authData, | ||
await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), | ||
ContextData(), | ||
ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), | ||
) | ||
|
||
assert isinstance(errorIndication, WrongDigest) | ||
assert str(errorIndication) == "Wrong SNMP PDU digest" | ||
|
||
snmpEngine.closeDispatcher() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_usm_sha_aes256_wrong_user(): | ||
async with AgentContextManager(): | ||
snmpEngine = SnmpEngine() | ||
authData = UsmUserData( | ||
"usr-sha-aes-not-exist", | ||
"authkey1", | ||
"privkey1", | ||
authProtocol=USM_AUTH_HMAC96_SHA, | ||
privProtocol=USM_PRIV_CFB256_AES, | ||
) | ||
errorIndication, errorStatus, errorIndex, varBinds = await getCmd( | ||
snmpEngine, | ||
authData, | ||
await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), | ||
ContextData(), | ||
ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), | ||
) | ||
|
||
assert isinstance(errorIndication, UnknownUserName) | ||
assert str(errorIndication) == "Unknown USM user" | ||
|
||
snmpEngine.closeDispatcher() |