From 8eb880295475a1a48fcf660b4c21d46b8cf25043 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Tue, 14 Feb 2017 10:42:22 +0100 Subject: required pyasn1 version is now 0.2.3 added matchTags, matchConstraints flags to .setComponentBy() call --- CHANGES.txt | 3 +++ pysnmp/proto/api/v1.py | 26 ++++++++++++-------------- pysnmp/proto/api/v2c.py | 14 +++++++------- pysnmp/proto/mpmod/rfc2576.py | 4 ++-- pysnmp/proto/mpmod/rfc3412.py | 31 ++++++++++++++++--------------- pysnmp/proto/secmod/rfc2576.py | 4 ++-- pysnmp/proto/secmod/rfc3414/service.py | 18 +++++++++--------- requirements.txt | 2 +- setup.py | 4 ++-- 9 files changed, 54 insertions(+), 52 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index bdd1bfa0..335dde6c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,9 @@ Revision 4.3.4, released 2017-02-XX - Fix to low-level SNMP API example to accommodate changed pyasn1 SEQUENCE supporting iterator protocol. +- The pyasn1 version dependency bumped (0.2.3), SEQUENCE/SEQUENCE OF + API calls adjusted to accommodate changed pyasn1 API (in part + of .setComponentBy*() kw flags). - Fixed crash on SNMP engine's invalid message counter increment. Revision 4.3.3, released 2017-02-04 diff --git a/pysnmp/proto/api/v1.py b/pysnmp/proto/api/v1.py index a863afd5..9b62f76a 100644 --- a/pysnmp/proto/api/v1.py +++ b/pysnmp/proto/api/v1.py @@ -39,8 +39,7 @@ class VarBindAPI(object): varBind.setComponentByPosition(0, oid) if val is None: val = null - varBind.setComponentByPosition(1).getComponentByPosition(1).setComponentByType(val.getTagSet(), val, 1, - verifyConstraints=False) + varBind.setComponentByPosition(1).getComponentByPosition(1).setComponentByType(val.getTagSet(), val, verifyConstraints=False, matchTags=False, matchConstraints=False, innerFlag=True) return varBind @staticmethod @@ -59,13 +58,13 @@ class PDUAPI(object): def setDefaults(self, pdu): pdu.setComponentByPosition( - 0, getNextRequestID(), verifyConstraints=False + 0, getNextRequestID(), verifyConstraints=False, matchTags=False, matchConstraints=False ) pdu.setComponentByPosition( - 1, self._errorStatus, verifyConstraints=False + 1, self._errorStatus, verifyConstraints=False, matchTags=False, matchConstraints=False ) pdu.setComponentByPosition( - 2, self._errorIndex, verifyConstraints=False + 2, self._errorIndex, verifyConstraints=False, matchTags=False, matchConstraints=False ) pdu.setComponentByPosition(3) @@ -171,11 +170,11 @@ class TrapPDUAPI(object): except Exception: agentAddress = IpAddress('0.0.0.0') self._networkAddress = NetworkAddress().setComponentByPosition(0, agentAddress) - pdu.setComponentByPosition(0, self._entOid, verifyConstraints=False) - pdu.setComponentByPosition(1, self._networkAddress, verifyConstraints=False) - pdu.setComponentByPosition(2, self._genericTrap, verifyConstraints=False) - pdu.setComponentByPosition(3, self._zeroInt, verifyConstraints=False) - pdu.setComponentByPosition(4, self._zeroTime, verifyConstraints=False) + pdu.setComponentByPosition(0, self._entOid, verifyConstraints=False, matchTags=False, matchConstraints=False) + pdu.setComponentByPosition(1, self._networkAddress, verifyConstraints=False, matchTags=False, matchConstraints=False) + pdu.setComponentByPosition(2, self._genericTrap, verifyConstraints=False, matchTags=False, matchConstraints=False) + pdu.setComponentByPosition(3, self._zeroInt, verifyConstraints=False, matchTags=False, matchConstraints=False) + pdu.setComponentByPosition(4, self._zeroTime, verifyConstraints=False, matchTags=False, matchConstraints=False) pdu.setComponentByPosition(5) @staticmethod @@ -257,8 +256,8 @@ class MessageAPI(object): _community = univ.OctetString('public') def setDefaults(self, msg): - msg.setComponentByPosition(0, self._version, verifyConstraints=False) - msg.setComponentByPosition(1, self._community, verifyConstraints=False) + msg.setComponentByPosition(0, self._version, verifyConstraints=False, matchTags=False, matchConstraints=False) + msg.setComponentByPosition(1, self._community, verifyConstraints=False, matchTags=False, matchConstraints=False) return msg @staticmethod @@ -283,8 +282,7 @@ class MessageAPI(object): @staticmethod def setPDU(msg, value): - msg.setComponentByPosition(2).getComponentByPosition(2).setComponentByType(value.getTagSet(), value, 1, - verifyConstraints=False) + msg.setComponentByPosition(2).getComponentByPosition(2).setComponentByType(value.getTagSet(), value, verifyConstraints=False, matchTags=False, matchConstraints=False, innerFlag=True) def getResponse(self, reqMsg): rspMsg = Message() diff --git a/pysnmp/proto/api/v2c.py b/pysnmp/proto/api/v2c.py index 960c0c74..29e0ee3d 100644 --- a/pysnmp/proto/api/v2c.py +++ b/pysnmp/proto/api/v2c.py @@ -63,13 +63,13 @@ class PDUAPI(v1.PDUAPI): def setEndOfMibError(self, pdu, errorIndex): varBindList = self.getVarBindList(pdu) varBindList[errorIndex - 1].setComponentByPosition( - 1, rfc1905.endOfMibView, verifyConstraints=False + 1, rfc1905.endOfMibView, verifyConstraints=False, matchTags=False, matchConstraints=False ) def setNoSuchInstanceError(self, pdu, errorIndex): varBindList = self.getVarBindList(pdu) varBindList[errorIndex - 1].setComponentByPosition( - 1, rfc1905.noSuchInstance, verifyConstraints=False + 1, rfc1905.noSuchInstance, verifyConstraints=False, matchTags=False, matchConstraints=False ) @@ -83,13 +83,13 @@ class BulkPDUAPI(PDUAPI): def setDefaults(self, pdu): PDUAPI.setDefaults(self, pdu) pdu.setComponentByPosition( - 0, getNextRequestID(), verifyConstraints=False + 0, getNextRequestID(), verifyConstraints=False, matchTags=False, matchConstraints=False ) pdu.setComponentByPosition( - 1, self._nonRepeaters, verifyConstraints=False + 1, self._nonRepeaters, verifyConstraints=False, matchTags=False, matchConstraints=False ) pdu.setComponentByPosition( - 2, self._maxRepetitions, verifyConstraints=False + 2, self._maxRepetitions, verifyConstraints=False, matchTags=False, matchConstraints=False ) pdu.setComponentByPosition(3) @@ -160,8 +160,8 @@ class MessageAPI(v1.MessageAPI): _version = rfc1901.version.clone(1) def setDefaults(self, msg): - msg.setComponentByPosition(0, self._version, verifyConstraints=False) - msg.setComponentByPosition(1, self._community, verifyConstraints=False) + msg.setComponentByPosition(0, self._version, verifyConstraints=False, matchTags=False, matchConstraints=False) + msg.setComponentByPosition(1, self._community, verifyConstraints=False, matchTags=False, matchConstraints=False) return msg def getResponse(self, reqMsg): diff --git a/pysnmp/proto/mpmod/rfc2576.py b/pysnmp/proto/mpmod/rfc2576.py index 7211e5a5..668eade2 100644 --- a/pysnmp/proto/mpmod/rfc2576.py +++ b/pysnmp/proto/mpmod/rfc2576.py @@ -63,7 +63,7 @@ class SnmpV1MessageProcessingModel(AbstractMessageProcessingModel): msg.setComponentByPosition(0, self.messageProcessingModelID) msg.setComponentByPosition(2) msg.getComponentByPosition(2).setComponentByType( - pdu.tagSet, pdu, verifyConstraints=False + pdu.tagSet, pdu, verifyConstraints=False, matchTags=False, matchConstraints=False ) # rfc3412: 7.1.7 @@ -193,7 +193,7 @@ class SnmpV1MessageProcessingModel(AbstractMessageProcessingModel): msg.setComponentByPosition(0, messageProcessingModel) msg.setComponentByPosition(2) msg.getComponentByPosition(2).setComponentByType( - pdu.tagSet, pdu, verifyConstraints=False + pdu.tagSet, pdu, verifyConstraints=False, matchTags=False, matchConstraints=False ) # att: msgId not set back to PDU as it's up to responder app diff --git a/pysnmp/proto/mpmod/rfc3412.py b/pysnmp/proto/mpmod/rfc3412.py index 7a53b4b1..8ea6d4a1 100644 --- a/pysnmp/proto/mpmod/rfc3412.py +++ b/pysnmp/proto/mpmod/rfc3412.py @@ -140,7 +140,7 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): scopedPDU.setComponentByPosition(1, contextName) scopedPDU.setComponentByPosition(2) scopedPDU.getComponentByPosition(2).setComponentByType( - pdu.tagSet, pdu, verifyConstraints=False + pdu.tagSet, pdu, verifyConstraints=False, matchTags=False, matchConstraints=False ) # 7.1.7 @@ -148,12 +148,12 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): # 7.1.7a msg.setComponentByPosition( - 0, self.messageProcessingModelID, verifyConstraints=False + 0, self.messageProcessingModelID, verifyConstraints=False, matchTags=False, matchConstraints=False ) headerData = msg.setComponentByPosition(1).getComponentByPosition(1) # 7.1.7b - headerData.setComponentByPosition(0, msgID, verifyConstraints=False) + headerData.setComponentByPosition(0, msgID, verifyConstraints=False, matchTags=False, matchConstraints=False) snmpEngineMaxMessageSize, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols( '__SNMP-FRAMEWORK-MIB', 'snmpEngineMaxMessageSize') @@ -161,7 +161,7 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): # 7.1.7c # XXX need to coerce MIB value as it has incompatible constraints set headerData.setComponentByPosition( - 1, snmpEngineMaxMessageSize.syntax, verifyConstraints=False + 1, snmpEngineMaxMessageSize.syntax, verifyConstraints=False, matchTags=False, matchConstraints=False ) # 7.1.7d @@ -181,7 +181,7 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): msgFlags |= 0x04 headerData.setComponentByPosition( - 2, self._msgFlags[msgFlags], verifyConstraints=False + 2, self._msgFlags[msgFlags], verifyConstraints=False, matchTags=False, matchConstraints=False ) # 7.1.7e @@ -207,12 +207,12 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): securityLevel = 1 # Clear possible auth&priv flags headerData.setComponentByPosition( - 2, self._msgFlags[msgFlags & 0xfc], verifyConstraints=False + 2, self._msgFlags[msgFlags & 0xfc], verifyConstraints=False, matchTags=False, matchConstraints=False ) # XXX scopedPDU = self.__scopedPDU scopedPDU.setComponentByPosition( - 0, self._emptyStr, verifyConstraints=False + 0, self._emptyStr, verifyConstraints=False, matchTags=False, matchConstraints=False ) scopedPDU.setComponentByPosition(1, contextName) scopedPDU.setComponentByPosition(2) @@ -222,7 +222,7 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): pMod.apiPDU.setDefaults(emptyPdu) scopedPDU.getComponentByPosition(2).setComponentByType( - emptyPdu.tagSet, emptyPdu, verifyConstraints=False + emptyPdu.tagSet, emptyPdu, verifyConstraints=False, matchTags=False, matchConstraints=False ) debug.logger & debug.flagMP and debug.logger('prepareOutgoingMessage: force engineID discovery') else: @@ -367,20 +367,21 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): scopedPDU.setComponentByPosition(1, contextName) scopedPDU.setComponentByPosition(2) scopedPDU.getComponentByPosition(2).setComponentByType( - pdu.tagSet, pdu, verifyConstraints=False + pdu.tagSet, pdu, verifyConstraints=False, matchTags=False, matchConstraints=False ) # 7.1.7 msg = self._snmpMsgSpec # 7.1.7a - msg.setComponentByPosition(0, self.messageProcessingModelID, - verifyConstraints=False) + msg.setComponentByPosition( + 0, self.messageProcessingModelID, verifyConstraints=False, matchTags=False, matchConstraints=False + ) headerData = msg.setComponentByPosition(1).getComponentByPosition(1) # 7.1.7b - headerData.setComponentByPosition(0, msgID, verifyConstraints=False) + headerData.setComponentByPosition(0, msgID, verifyConstraints=False, matchTags=False, matchConstraints=False) snmpEngineMaxMessageSize, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols( '__SNMP-FRAMEWORK-MIB', 'snmpEngineMaxMessageSize') @@ -388,7 +389,7 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): # 7.1.7c # XXX need to coerce MIB value as it has incompatible constraints set headerData.setComponentByPosition( - 1, snmpEngineMaxMessageSize.syntax, verifyConstraints=False + 1, snmpEngineMaxMessageSize.syntax, verifyConstraints=False, matchTags=False, matchConstraints=False ) # 7.1.7d @@ -406,12 +407,12 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): msgFlags |= 0x04 headerData.setComponentByPosition( - 2, self._msgFlags[msgFlags], verifyConstraints=False + 2, self._msgFlags[msgFlags], verifyConstraints=False, matchTags=False, matchConstraints=False ) # 7.1.7e headerData.setComponentByPosition( - 3, securityModel, verifyConstraints=False + 3, securityModel, verifyConstraints=False, matchTags=False, matchConstraints=False ) debug.logger & debug.flagMP and debug.logger('prepareResponseMessage: %s' % (msg.prettyPrint(),)) diff --git a/pysnmp/proto/secmod/rfc2576.py b/pysnmp/proto/secmod/rfc2576.py index 3ef0778e..757ba03c 100644 --- a/pysnmp/proto/secmod/rfc2576.py +++ b/pysnmp/proto/secmod/rfc2576.py @@ -302,7 +302,7 @@ class SnmpV1SecurityModel(base.AbstractSecurityModel): msg.setComponentByPosition(1, securityParameters) msg.setComponentByPosition(2) msg.getComponentByPosition(2).setComponentByType( - pdu.tagSet, pdu, verifyConstraints=False + pdu.tagSet, pdu, verifyConstraints=False, matchTags=False, matchConstraints=False ) debug.logger & debug.flagMP and debug.logger('generateRequestMsg: %s' % (msg.prettyPrint(),)) @@ -332,7 +332,7 @@ class SnmpV1SecurityModel(base.AbstractSecurityModel): msg.setComponentByPosition(1, communityName) msg.setComponentByPosition(2) msg.getComponentByPosition(2).setComponentByType( - pdu.tagSet, pdu, verifyConstraints=False + pdu.tagSet, pdu, verifyConstraints=False, matchTags=False, matchConstraints=False ) debug.logger & debug.flagMP and debug.logger('generateResponseMsg: %s' % (msg.prettyPrint(),)) diff --git a/pysnmp/proto/secmod/rfc3414/service.py b/pysnmp/proto/secmod/rfc3414/service.py index 03e480af..4b4213c6 100644 --- a/pysnmp/proto/secmod/rfc3414/service.py +++ b/pysnmp/proto/secmod/rfc3414/service.py @@ -324,7 +324,7 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): scopedPDUData = msg.setComponentByPosition(3).getComponentByPosition(3) scopedPDUData.setComponentByPosition( - 0, scopedPDU, verifyConstraints=False + 0, scopedPDU, verifyConstraints=False, matchTags=False, matchConstraints=False ) # 3.1.6a @@ -390,10 +390,10 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): ) securityParameters.setComponentByPosition( - 5, privParameters, verifyConstraints=False + 5, privParameters, verifyConstraints=False, matchTags=False, matchConstraints=False ) scopedPDUData.setComponentByPosition( - 1, encryptedData, verifyConstraints=False + 1, encryptedData, verifyConstraints=False, matchTags=False, matchConstraints=False ) debug.logger & debug.flagSM and debug.logger( @@ -407,18 +407,18 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): # 3.1.5 securityParameters.setComponentByPosition( - 0, securityEngineID, verifyConstraints=False + 0, securityEngineID, verifyConstraints=False, matchTags=False, matchConstraints=False ) securityParameters.setComponentByPosition( - 1, snmpEngineBoots, verifyConstraints=False + 1, snmpEngineBoots, verifyConstraints=False, matchTags=False, matchConstraints=False ) securityParameters.setComponentByPosition( - 2, snmpEngineTime, verifyConstraints=False + 2, snmpEngineTime, verifyConstraints=False, matchTags=False, matchConstraints=False ) # 3.1.7 securityParameters.setComponentByPosition( - 3, usmUserName, verifyConstraints=False + 3, usmUserName, verifyConstraints=False, matchTags=False, matchConstraints=False ) # 3.1.8a @@ -469,14 +469,14 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): # 3.1.8b else: securityParameters.setComponentByPosition( - 4, '', verifyConstraints=False + 4, '', verifyConstraints=False, matchTags=False, matchConstraints=False ) debug.logger & debug.flagSM and debug.logger( '__generateRequestOrResponseMsg: %s' % (securityParameters.prettyPrint(),)) try: - msg.setComponentByPosition(2, encoder.encode(securityParameters), verifyConstraints=False) + msg.setComponentByPosition(2, encoder.encode(securityParameters), verifyConstraints=False, matchTags=False, matchConstraints=False) except PyAsn1Error: debug.logger & debug.flagSM and debug.logger( diff --git a/requirements.txt b/requirements.txt index ce2d70c6..313e30af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -pyasn1>=0.1.8 +pyasn1>=0.2.3 pysmi pycryptodome diff --git a/setup.py b/setup.py index a8c200ed..62edc969 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ try: from setuptools import setup params = { - 'install_requires': ['pyasn1>=0.1.8', 'pysmi', 'pycryptodome'], + 'install_requires': ['pyasn1>=0.2.3', 'pysmi', 'pycryptodome'], 'zip_safe': True } @@ -72,7 +72,7 @@ except ImportError: params = {} if sys.version_info[:2] > (2, 4): - params['requires'] = ['pyasn1(>=0.1.8)', 'pysmi', 'pycryptodome'] + params['requires'] = ['pyasn1(>=0.2.3)', 'pysmi', 'pycryptodome'] doclines = [x.strip() for x in (__doc__ or '').split('\n') if x] -- cgit v1.2.1