lextudio / sharpsnmplib

Sharp SNMP Library- Open Source SNMP for .NET
https://sharpsnmp.com
MIT License
356 stars 152 forks source link

Exception on V3 Inform discovery messages #232

Closed lextudio-support closed 4 hours ago

lextudio-support commented 4 hours ago

Hi Lex,

I hope you can help with a problem responding to V3 Inform messages.

We have a device that is configured to send Informs to a trap receiver that we're writing using SharpSnmpLib.

We're using SNMP V3 for security (Auth/NoPriv) and have traps working very well.

Our problem comes when we try to respond to V3 Inform messages.

When I use an off the shelf trap receiver and follow the traffic using Wireshark I can see:

The device sends an empty Inform request to the manager. The manager responds with a Report including the AuthoritativeEngineID. The device sends the intended Inform, including all the expected OIDs and the AuthoritativeEngineID.

However when I compare that to the traffic using our SharpSnmpLib manager I can only see the following request:

The device sends an empty Inform request to the manager. Stepping into the code I can see that SharpSnmpLib is throwing a missing index exception:

at System.Collections.Generic.List1.get_Item(Int32 index) at Lextm.SharpSnmpLib.InformRequestPdu..ctor(Tuple2 length, Stream stream) at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream) at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream) at Lextm.SharpSnmpLib.Sequence..ctor(Tuple2 length, Stream stream) at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream) at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream) at Lextm.SharpSnmpLib.Sequence..ctor(Tuple2 length, Stream stream) at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream) at Lextm.SharpSnmpLib.Messaging.MessageFactory.ParseMessage(Int32 first, Stream stream, UserRegistry registry) at Lextm.SharpSnmpLib.Messaging.MessageFactory.ParseMessages(Byte[] buffer, Int32 index, Int32 length, UserRegistry registry) at Lextm.SharpSnmpLib.Messaging.ListenerBinding.HandleMessage(MessageParams param)

And on further examination I can see that the problem is with these lines in InformRequestPdu:

_time = (TimeTicks)Variables[0].Data; Variables.RemoveAt(0); Enterprise = (ObjectIdentifier)Variables[0].Data; Variables.RemoveAt(0); _length = length.Item2;

The problem is that the Inform request the device is sending contains no Variables at all – and therefore there is no data at either:

private readonly uint[] _timeId = new uint[] { 1, 3, 6, 1, 2, 1, 1, 3, 0 }; or private readonly uint[] _enterpriseId = new uint[] { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };

So – my first question is - as we are in control of the device software, should we insist that the two OIDs are populated; i.e. is this part of the standard?

And my second question is - does SharpSnmpLib support this security model, i.e. where the empty Inform is first sent to the manager to learn the engine Id?

Thanks in advance!

Stuart

Original Reported Date: 2012-12-07T22:48:49.447-08:00 Planned For Release: TritonMate (8.0) Original CodePlex ID: 7245

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Fixed in https://github.com/lextm/sharpsnmplib/commit/9a89862ed2b121fc5fbf5d8bb700ac7ccd9e7ddf

Original Posted Date: 2012-12-15T05:04:10.34-08:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

** Closed by lextm 12/15/2012 5:04AM

Original Posted Date: 2012-12-15T05:04:45.273-08:00

lextudio-support commented 4 hours ago

Original Closed Date: 2012-12-23T18:12:46.93-08:00