Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions pysnmp/proto/mpmod/rfc3412.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ def prepare_response_message(
or pduType is not None
and pduType not in rfc3411.CONFIRMED_CLASS_PDUS
):
if securityModel in snmpEngine.security_models:
smHandler = snmpEngine.security_models[securityModel]
smHandler.release_state_information(securityStateReference)
raise error.StatusInformation(errorIndication=errind.loopTerminated)

# 7.1.3c
Expand Down Expand Up @@ -523,6 +526,9 @@ def prepare_response_message(
elif securityLevel == 3:
msgFlags |= 0x03
else:
if securityModel in snmpEngine.security_models:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def prepare_data_elements in rfc3412.py already blocked invalid msgFlags from being passed on, so it is impossible to have a securityLevel value here.

smHandler = snmpEngine.security_models[securityModel]
smHandler.release_state_information(securityStateReference)
raise error.ProtocolError("Unknown securityLevel %s" % securityLevel)

if pdu.tagSet in rfc3411.CONFIRMED_CLASS_PDUS: # XXX not needed?
Expand Down
10 changes: 10 additions & 0 deletions pysnmp/proto/secmod/rfc3414/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ def process_incoming_message(
"processIncomingMsg: scopedPduData not plaintext %s"
% scopedPduData.prettyPrint()
)
self._cache.pop(securityStateReference)
raise error.StatusInformation(
errorIndication=errind.unknownEngineID
)
Expand All @@ -1073,6 +1074,7 @@ def process_incoming_message(
"processIncomingMsg: will not discover EngineID"
)
# free securityStateReference XXX
self._cache.pop(securityStateReference)
raise error.StatusInformation(
errorIndication=errind.unknownEngineID
)
Expand Down Expand Up @@ -1154,6 +1156,7 @@ def process_incoming_message(
"__SNMPv2-MIB", "snmpInGenErrs"
)
snmpInGenErrs.syntax += 1
self._cache.pop(securityStateReference)
raise error.StatusInformation(errorIndication=errind.invalidMsg)
else:
# empty username used for engineID discovery
Expand Down Expand Up @@ -1255,6 +1258,7 @@ def process_incoming_message(
if usmUserAuthProtocol in self.AUTH_SERVICES:
authHandler = self.AUTH_SERVICES[usmUserAuthProtocol]
else:
self._cache.pop(securityStateReference)
raise error.StatusInformation(
errorIndication=errind.authenticationFailure
)
Expand Down Expand Up @@ -1346,6 +1350,7 @@ def process_incoming_message(
)
)
else:
self._cache.pop(securityStateReference)
raise error.ProtocolError("Peer SNMP engine info missing")

# 3.2.7a
Expand Down Expand Up @@ -1417,6 +1422,7 @@ def process_incoming_message(
)
> 150
):
self._cache.pop(securityStateReference)
raise error.StatusInformation(
errorIndication=errind.notInTimeWindow, msgUserName=msgUserName
)
Expand All @@ -1426,11 +1432,13 @@ def process_incoming_message(
if usmUserPrivProtocol in self.PRIV_SERVICES:
privHandler = self.PRIV_SERVICES[usmUserPrivProtocol]
else:
self._cache.pop(securityStateReference)
raise error.StatusInformation(
errorIndication=errind.decryptionError, msgUserName=msgUserName
)
encryptedPDU = scopedPduData.getComponentByPosition(1)
if encryptedPDU is None: # no ciphertext
self._cache.pop(securityStateReference)
raise error.StatusInformation(
errorIndication=errind.decryptionError, msgUserName=msgUserName
)
Expand Down Expand Up @@ -1494,13 +1502,15 @@ def process_incoming_message(
)

if eoo.endOfOctets.isSameTypeWith(scopedPDU):
self._cache.pop(securityStateReference)
raise error.StatusInformation(
errorIndication=errind.decryptionError, msgUserName=msgUserName
)
else:
# 3.2.8b
scopedPDU = scopedPduData.getComponentByPosition(0)
if scopedPDU is None: # no plaintext
self._cache.pop(securityStateReference)
raise error.StatusInformation(
errorIndication=errind.decryptionError, msgUserName=msgUserName
)
Expand Down
1 change: 1 addition & 0 deletions tests/manager_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):

self.manager.transport_dispatcher.job_finished(1)
self.manager.close_dispatcher()
self.manager._close()