From df43b942dcf002e4e7f0900c8c0de2fc3240a793 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Sun, 4 Feb 2024 02:30:00 -0500 Subject: [PATCH] Skipped authentication when not needed to fix broken test case. Related to #41. --- pysnmp/proto/secmod/rfc3414/service.py | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pysnmp/proto/secmod/rfc3414/service.py b/pysnmp/proto/secmod/rfc3414/service.py index 0560dd4da..13a8bd516 100644 --- a/pysnmp/proto/secmod/rfc3414/service.py +++ b/pysnmp/proto/secmod/rfc3414/service.py @@ -902,28 +902,30 @@ def processIncomingMsg(self, snmpEngine, messageProcessingModel, errorIndication=errind.authenticationFailure ) + hash = securityParameters.getComponentByPosition(4) try: authHandler.authenticateIncomingMsg( usmUserAuthKeyLocalized, - securityParameters.getComponentByPosition(4), + hash, wholeMsg ) except error.StatusInformation: - usmStatsWrongDigests, = mibBuilder.importSymbols( - '__SNMP-USER-BASED-SM-MIB', 'usmStatsWrongDigests') - usmStatsWrongDigests.syntax += 1 - raise error.StatusInformation( - errorIndication=errind.authenticationFailure, - oid=usmStatsWrongDigests.name, - val=usmStatsWrongDigests.syntax, - securityStateReference=securityStateReference, - securityLevel=securityLevel, - contextEngineId=contextEngineId, - contextName=contextName, - msgUserName=msgUserName, - maxSizeResponseScopedPDU=maxSizeResponseScopedPDU - ) + if len(hash) != 0: # don't throw error if hash is empty (and agent returned REPORT) + usmStatsWrongDigests, = mibBuilder.importSymbols( + '__SNMP-USER-BASED-SM-MIB', 'usmStatsWrongDigests') + usmStatsWrongDigests.syntax += 1 + raise error.StatusInformation( + errorIndication=errind.authenticationFailure, + oid=usmStatsWrongDigests.name, + val=usmStatsWrongDigests.syntax, + securityStateReference=securityStateReference, + securityLevel=securityLevel, + contextEngineId=contextEngineId, + contextName=contextName, + msgUserName=msgUserName, + maxSizeResponseScopedPDU=maxSizeResponseScopedPDU + ) debug.logger & debug.flagSM and debug.logger('processIncomingMsg: incoming msg authenticated')