diff options
author | elie <elie> | 2012-06-25 23:48:37 +0000 |
---|---|---|
committer | elie <elie> | 2012-06-25 23:48:37 +0000 |
commit | 92841c8dff3611c9aefd6c69f86e496e438bcf3a (patch) | |
tree | 3d27aa2b15536932293c638227fe4c3f90229c3c | |
parent | 91d3d54b53ec6c2089b03b279f39fd2505b2897b (diff) | |
download | pysnmp-git-92841c8dff3611c9aefd6c69f86e496e438bcf3a.tar.gz |
hex dumps of binary parts of the protocol added to ease system
operations analysis.
-rw-r--r-- | CHANGES.txt | 2 | ||||
-rw-r--r-- | pysnmp/carrier/asyncore/dgram/base.py | 4 | ||||
-rw-r--r-- | pysnmp/carrier/twisted/dgram/base.py | 4 | ||||
-rw-r--r-- | pysnmp/debug.py | 7 | ||||
-rw-r--r-- | pysnmp/proto/secmod/rfc3414/service.py | 10 |
5 files changed, 21 insertions, 6 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index f8dafcf3..4a1133b3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,8 @@ Revision 4.2.3 unpublished MIB values smiCreate()/smiWrite()/smiDestroy() methods. - MibTree.readTest[Get]Next() reworked to be called uniformely so user could tap on these methods at any level of the MIB tree. +- Hex dumps of binary parts of the protocol added to ease system + operations analysis. - Fix to SNMPv2 exception objects translation into SNMPv1 PDU and NEXT OIDs calculation. - Fix to MibTree class to properly report noSuchObject & noSuchInstance diff --git a/pysnmp/carrier/asyncore/dgram/base.py b/pysnmp/carrier/asyncore/dgram/base.py index 9d200f88..3a5ddfae 100644 --- a/pysnmp/carrier/asyncore/dgram/base.py +++ b/pysnmp/carrier/asyncore/dgram/base.py @@ -54,7 +54,7 @@ class DgramSocketTransport(AbstractSocketTransport): outgoingMessage, transportAddress = self.__outQueue.pop() if isinstance(transportAddress, TransportAddressPair): transportAddress = transportAddress.getRemoteAddr() - debug.logger & debug.flagIO and debug.logger('handle_write: transportAddress %r -> %r outgoingMessage %r' % (self.socket.getsockname(), transportAddress, outgoingMessage)) + debug.logger & debug.flagIO and debug.logger('handle_write: transportAddress %r -> %r outgoingMessage %s' % (self.socket.getsockname(), transportAddress, debug.hexdump(outgoingMessage))) try: self.socket.sendto(outgoingMessage, transportAddress) except socket.error: @@ -67,7 +67,7 @@ class DgramSocketTransport(AbstractSocketTransport): def handle_read(self): try: incomingMessage, transportAddress = self.socket.recvfrom(65535) - debug.logger & debug.flagIO and debug.logger('handle_read: transportAddress %r -> %r incomingMessage %r' % (transportAddress, self.socket.getsockname(), incomingMessage)) + debug.logger & debug.flagIO and debug.logger('handle_read: transportAddress %r -> %r incomingMessage %s' % (transportAddress, self.socket.getsockname(), debug.hexdump(incomingMessage))) transportAddress = TransportAddressPair( self.socket.getsockname(), transportAddress diff --git a/pysnmp/carrier/twisted/dgram/base.py b/pysnmp/carrier/twisted/dgram/base.py index 5d512088..5fff8731 100644 --- a/pysnmp/carrier/twisted/dgram/base.py +++ b/pysnmp/carrier/twisted/dgram/base.py @@ -28,7 +28,7 @@ class DgramTwistedTransport(DatagramProtocol, AbstractTwistedTransport): outgoingMessage, transportAddress = self._writeQ.pop(0) if isinstance(transportAddress, TransportAddressPair): transportAddress = transportAddress.getRemoteAddr() - debug.logger & debug.flagIO and debug.logger('startProtocol: transportAddress %r outgoingMessage %r' % (transportAddress, outgoingMessage)) + debug.logger & debug.flagIO and debug.logger('startProtocol: transportAddress %r outgoingMessage %s' % (transportAddress, debug.hexdump(outgoingMessage))) try: self.transport.write(outgoingMessage, transportAddress) except Exception: @@ -39,7 +39,7 @@ class DgramTwistedTransport(DatagramProtocol, AbstractTwistedTransport): self.closeTransport() def sendMessage(self, outgoingMessage, transportAddress): - debug.logger & debug.flagIO and debug.logger('startProtocol: %s transportAddress %r outgoingMessage %r' % ((self.transport is None and "queuing" or "sending"), transportAddress, outgoingMessage)) + debug.logger & debug.flagIO and debug.logger('startProtocol: %s transportAddress %r outgoingMessage %s' % ((self.transport is None and "queuing" or "sending"), transportAddress, debug.hexdump(outgoingMessage))) if self.transport is None: self._writeQ.append((outgoingMessage, transportAddress)) else: diff --git a/pysnmp/debug.py b/pysnmp/debug.py index 6500e2d6..ab826b9a 100644 --- a/pysnmp/debug.py +++ b/pysnmp/debug.py @@ -1,4 +1,5 @@ import sys +from pyasn1.compat.octets import octs2ints from pysnmp import error flagNone = 0x0000 @@ -58,3 +59,9 @@ logger = 0 def setLogger(l): global logger logger = l + +def hexdump(octets): + return ' '.join( + [ '%s%.2X' % (n%16 == 0 and ('\n%.5d: ' % n) or '', x) + for n,x in zip(range(len(octets)), octs2ints(octets)) ] + ) diff --git a/pysnmp/proto/secmod/rfc3414/service.py b/pysnmp/proto/secmod/rfc3414/service.py index 86ce39f4..57af91fb 100644 --- a/pysnmp/proto/secmod/rfc3414/service.py +++ b/pysnmp/proto/secmod/rfc3414/service.py @@ -329,7 +329,7 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): dataToEncrypt = encoder.encode(scopedPDU) - debug.logger & debug.flagSM and debug.logger('__generateRequestOrResponseMsg: scopedPDU encoded into %r' % (dataToEncrypt,)) + debug.logger & debug.flagSM and debug.logger('__generateRequestOrResponseMsg: scopedPDU encoded into %s' % debug.hexdump(dataToEncrypt)) ( encryptedData, privParameters ) = privHandler.encryptData( @@ -345,7 +345,7 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): 1, encryptedData, verifyConstraints=False ) - debug.logger & debug.flagSM and debug.logger('__generateRequestOrResponseMsg: scopedPDU ciphered') + debug.logger & debug.flagSM and debug.logger('__generateRequestOrResponseMsg: scopedPDU ciphered into %s' % debug.hexdump(encryptedData)) # 3.1.4b elif securityLevel == 1 or securityLevel == 2: @@ -396,6 +396,7 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): authenticatedWholeMsg = authHandler.authenticateOutgoingMsg( usmUserAuthKeyLocalized, wholeMsg ) + # 3.1.8b else: securityParameters.setComponentByPosition( @@ -411,6 +412,9 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): debug.logger & debug.flagSM and debug.logger('__generateRequestOrResponseMsg: plain outgoing msg: %s' % msg.prettyPrint()) authenticatedWholeMsg = encoder.encode(msg) + + debug.logger & debug.flagSM and debug.logger('__generateRequestOrResponseMsg: %s outgoing msg: %s' % (securityLevel > 1 and "authenticated" or "plain", debug.hexdump(authenticatedWholeMsg))) + # 3.1.9 return ( msg.getComponentByPosition(2), @@ -485,6 +489,8 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): # (48 - maximum SNMPv3 header length) maxSizeResponseScopedPDU = maxMessageSize - len(securityParameters)-48 + debug.logger & debug.flagSM and debug.logger('processIncomingMsg: securityParameters %s' % debug.hexdump(securityParameters)) + # 3.2.1 try: securityParameters, rest = decoder.decode( |