net-snmp 3.7.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: node_js
2
2
  node_js:
3
- - node
4
3
  - lts/*
4
+ - 14
5
5
  - 12
6
6
  - 10
7
7
  - 8
@@ -40,6 +40,24 @@
40
40
  "1.3.6.1.2.1.1.1.0"
41
41
  ]
42
42
  },
43
+ {
44
+ "type": "node",
45
+ "request": "launch",
46
+ "name": "SNMP community get bulk",
47
+ "skipFiles": [
48
+ "<node_internals>/**"
49
+ ],
50
+ "program": "${workspaceFolder}/example/snmp-get-bulk.js",
51
+ "args": [
52
+ "-v", "2c",
53
+ "-c", "public",
54
+ "-o", "1",
55
+ "-r", "20",
56
+ "127.0.0.1",
57
+ "1.3.6.1.2.1.1.9",
58
+ "1.3.6.1.2.1.2"
59
+ ]
60
+ },
43
61
  {
44
62
  "type": "node",
45
63
  "request": "launch",
package/README.md CHANGED
@@ -315,7 +315,7 @@ Actions
315
315
  - `4 - ECouldNotDecrypt`
316
316
  - `5 - EAuthFailure`
317
317
  - `6 - EReqResOidNoMatch`
318
- - `7 - ENonRepeaterCountMismatch`
318
+ - `7 - (no longer used)
319
319
  - `8 - EOutOfOrder`
320
320
  - `9 - EVersionNoMatch`
321
321
  - `10 - ECommunityNoMatch`
@@ -3203,6 +3203,18 @@ Example programs are included under the module's `example` directory.
3203
3203
 
3204
3204
  * Add SHA-2 authentication support (SHA-224, SHA-256, SHA-384, SHA-512)
3205
3205
 
3206
+ ## Version 3.7.1 - 05/06/2022
3207
+
3208
+ * Fix DES decrypt corruption issue
3209
+
3210
+ ## Version 3.7.2 - 05/06/2022
3211
+
3212
+ * Improve getBulk response handling
3213
+
3214
+ ## Version 3.8.0 - 07/06/2022
3215
+
3216
+ * Fix 32-bit unsigned integer writing
3217
+
3206
3218
  # License
3207
3219
 
3208
3220
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -11,7 +11,10 @@ var crypto = require ("crypto");
11
11
  var mibparser = require ("./lib/mib");
12
12
  var DEBUG = false;
13
13
 
14
- var MAX_INT32 = 2147483647;
14
+ var MIN_SIGNED_INT32 = -2147483648;
15
+ var MAX_SIGNED_INT32 = 2147483647;
16
+ var MIN_UNSIGNED_INT32 = 0;
17
+ var MAX_UNSIGNED_INT32 = 4294967295;
15
18
 
16
19
  function debug (line) {
17
20
  if ( DEBUG ) {
@@ -265,7 +268,7 @@ var ResponseInvalidCode = {
265
268
  4: "ECouldNotDecrypt",
266
269
  5: "EAuthFailure",
267
270
  6: "EReqResOidNoMatch",
268
- 7: "ENonRepeaterCountMismatch",
271
+ // 7: "ENonRepeaterCountMismatch", // no longer used
269
272
  8: "EOutOfOrder",
270
273
  9: "EVersionNoMatch",
271
274
  10: "ECommunityNoMatch",
@@ -378,71 +381,26 @@ function oidInSubtree (oidString, nextString) {
378
381
  return true;
379
382
  }
380
383
 
381
- /**
382
- ** Some SNMP agents produce integers on the wire such as 00 ff ff ff ff.
383
- ** The ASN.1 BER parser we use throws an error when parsing this, which we
384
- ** believe is correct. So, we decided not to bother the "asn1" developer(s)
385
- ** with this, instead opting to work around it here.
386
- **
387
- ** If an integer is 5 bytes in length we check if the first byte is 0, and if so
388
- ** simply drop it and parse it like it was a 4 byte integer, otherwise throw
389
- ** an error since the integer is too large.
390
- **/
391
-
392
- function readInt (buffer) {
393
- return readUint (buffer, true);
394
- }
395
-
396
- function readIpAddress (buffer) {
397
- var bytes = buffer.readString (ObjectType.IpAddress, true);
398
- if (bytes.length != 4)
399
- throw new ResponseInvalidError ("Length '" + bytes.length
400
- + "' of IP address '" + bytes.toString ("hex")
401
- + "' is not 4", ResponseInvalidCode.EIp4AddressSize);
402
- var value = bytes[0] + "." + bytes[1] + "." + bytes[2] + "." + bytes[3];
403
- return value;
404
- }
405
-
406
- function readUint (buffer, isSigned) {
407
- buffer.readByte ();
408
- var length = buffer.readByte ();
409
- var value = 0;
410
- var signedBitSet = false;
411
-
412
- // Handle BER long-form length encoding
413
- if ((length & 0x80) == 0x80) {
414
- var lengthOctets = (length & 0x7f);
415
- length = 0;
416
- for (var lengthOctet = 0; lengthOctet < lengthOctets; lengthOctet++) {
417
- length *= 256;
418
- length += buffer.readByte ();
419
- }
384
+ function readInt32 (buffer) {
385
+ var parsedInt = buffer.readInt ();
386
+ if ( ! Number.isInteger(parsedInt) ) {
387
+ throw new TypeError('Value read as integer ' + parsedInt + ' is not an integer');
420
388
  }
421
-
422
- if (length > 5) {
423
- throw new RangeError ("Integer too long '" + length + "'");
424
- } else if (length == 5) {
425
- if (buffer.readByte () !== 0)
426
- throw new RangeError ("Integer too long '" + length + "'");
427
- length = 4;
389
+ if ( parsedInt < MIN_SIGNED_INT32 || parsedInt > MAX_SIGNED_INT32 ) {
390
+ throw new RangeError('Read integer ' + parsedInt + ' is outside the signed 32-bit range');
428
391
  }
392
+ return parsedInt;
393
+ }
429
394
 
430
- for (var i = 0; i < length; i++) {
431
- value *= 256;
432
- value += buffer.readByte ();
433
-
434
- if (isSigned && i <= 0) {
435
- if ((value & 0x80) == 0x80) {
436
- signedBitSet = true;
437
- }
438
- }
395
+ function readUint32 (buffer) {
396
+ var parsedInt = buffer.readInt ();
397
+ if ( ! Number.isInteger(parsedInt) ) {
398
+ throw new TypeError('Value read as integer ' + parsedInt + ' is not an integer');
439
399
  }
440
-
441
- if (signedBitSet) {
442
- value -= 2 ** (i * 8);
400
+ if ( parsedInt < MIN_UNSIGNED_INT32 || parsedInt > MAX_UNSIGNED_INT32 ) {
401
+ throw new RangeError('Read integer ' + parsedInt + ' is outside the unsigned 32-bit range');
443
402
  }
444
-
445
- return value;
403
+ return parsedInt;
446
404
  }
447
405
 
448
406
  function readUint64 (buffer) {
@@ -451,12 +409,22 @@ function readUint64 (buffer) {
451
409
  return value;
452
410
  }
453
411
 
412
+ function readIpAddress (buffer) {
413
+ var bytes = buffer.readString (ObjectType.IpAddress, true);
414
+ if (bytes.length != 4)
415
+ throw new ResponseInvalidError ("Length '" + bytes.length
416
+ + "' of IP address '" + bytes.toString ("hex")
417
+ + "' is not 4", ResponseInvalidCode.EIp4AddressSize);
418
+ var value = bytes[0] + "." + bytes[1] + "." + bytes[2] + "." + bytes[3];
419
+ return value;
420
+ }
421
+
454
422
  function readVarbindValue (buffer, type) {
455
423
  var value;
456
424
  if (type == ObjectType.Boolean) {
457
425
  value = buffer.readBoolean ();
458
426
  } else if (type == ObjectType.Integer) {
459
- value = readInt (buffer);
427
+ value = readInt32 (buffer);
460
428
  } else if (type == ObjectType.OctetString) {
461
429
  value = buffer.readString (null, true);
462
430
  } else if (type == ObjectType.Null) {
@@ -468,11 +436,11 @@ function readVarbindValue (buffer, type) {
468
436
  } else if (type == ObjectType.IpAddress) {
469
437
  value = readIpAddress (buffer);
470
438
  } else if (type == ObjectType.Counter) {
471
- value = readUint (buffer);
439
+ value = readUint32 (buffer);
472
440
  } else if (type == ObjectType.Gauge) {
473
- value = readUint (buffer);
441
+ value = readUint32 (buffer);
474
442
  } else if (type == ObjectType.TimeTicks) {
475
- value = readUint (buffer);
443
+ value = readUint32 (buffer);
476
444
  } else if (type == ObjectType.Opaque) {
477
445
  value = buffer.readString (ObjectType.Opaque, true);
478
446
  } else if (type == ObjectType.Counter64) {
@@ -519,10 +487,24 @@ function readVarbinds (buffer, varbinds) {
519
487
  }
520
488
  }
521
489
 
522
- function writeUint (buffer, type, value) {
523
- var b = Buffer.alloc (4);
524
- b.writeUInt32BE (value, 0);
525
- buffer.writeBuffer (b, type);
490
+ function writeInt32 (buffer, type, value) {
491
+ if ( ! Number.isInteger(value) ) {
492
+ throw new TypeError('Value to write as integer ' + value + ' is not an integer');
493
+ }
494
+ if ( value < MIN_SIGNED_INT32 || value > MAX_SIGNED_INT32 ) {
495
+ throw new RangeError('Integer to write ' + value + ' is outside the signed 32-bit range');
496
+ }
497
+ buffer.writeInt(value, type);
498
+ }
499
+
500
+ function writeUint32 (buffer, type, value) {
501
+ if ( ! Number.isInteger(value) ) {
502
+ throw new TypeError('Value to write as integer ' + value + ' is not an integer');
503
+ }
504
+ if ( value < MIN_UNSIGNED_INT32 || value > MAX_UNSIGNED_INT32 ) {
505
+ throw new RangeError('Integer to write ' + value + ' is outside the unsigned 32-bit range');
506
+ }
507
+ buffer.writeInt(value, type);
526
508
  }
527
509
 
528
510
  function writeUint64 (buffer, value) {
@@ -544,7 +526,7 @@ function writeVarbinds (buffer, varbinds) {
544
526
  buffer.writeBoolean (value ? true : false);
545
527
  break;
546
528
  case ObjectType.Integer: // also Integer32
547
- buffer.writeInt (value);
529
+ writeInt32 (buffer, ObjectType.Integer, value);
548
530
  break;
549
531
  case ObjectType.OctetString:
550
532
  if (typeof value == "string")
@@ -566,13 +548,13 @@ function writeVarbinds (buffer, varbinds) {
566
548
  buffer.writeBuffer (Buffer.from (bytes), 64);
567
549
  break;
568
550
  case ObjectType.Counter: // also Counter32
569
- writeUint (buffer, ObjectType.Counter, value);
551
+ writeUint32 (buffer, ObjectType.Counter, value);
570
552
  break;
571
553
  case ObjectType.Gauge: // also Gauge32 & Unsigned32
572
- writeUint (buffer, ObjectType.Gauge, value);
554
+ writeUint32 (buffer, ObjectType.Gauge, value);
573
555
  break;
574
556
  case ObjectType.TimeTicks:
575
- writeUint (buffer, ObjectType.TimeTicks, value);
557
+ writeUint32 (buffer, ObjectType.TimeTicks, value);
576
558
  break;
577
559
  case ObjectType.Opaque:
578
560
  buffer.writeBuffer (value, ObjectType.Opaque);
@@ -609,11 +591,13 @@ var SimplePdu = function () {
609
591
  SimplePdu.prototype.toBuffer = function (buffer) {
610
592
  buffer.startSequence (this.type);
611
593
 
612
- buffer.writeInt (this.id);
613
- buffer.writeInt ((this.type == PduType.GetBulkRequest)
594
+ writeInt32 (buffer, ObjectType.Integer, this.id);
595
+ writeInt32 (buffer, ObjectType.Integer,
596
+ (this.type == PduType.GetBulkRequest)
614
597
  ? (this.options.nonRepeaters || 0)
615
598
  : 0);
616
- buffer.writeInt ((this.type == PduType.GetBulkRequest)
599
+ writeInt32 (buffer, ObjectType.Integer,
600
+ (this.type == PduType.GetBulkRequest)
617
601
  ? (this.options.maxRepetitions || 0)
618
602
  : 0);
619
603
 
@@ -633,9 +617,9 @@ SimplePdu.prototype.initializeFromBuffer = function (reader) {
633
617
  this.type = reader.peek ();
634
618
  reader.readSequence ();
635
619
 
636
- this.id = reader.readInt ();
637
- this.nonRepeaters = reader.readInt ();
638
- this.maxRepetitions = reader.readInt ();
620
+ this.id = readInt32 (reader);
621
+ this.nonRepeaters = readInt32 (reader);
622
+ this.maxRepetitions = readInt32 (reader);
639
623
 
640
624
  this.varbinds = [];
641
625
  readVarbinds (reader, this.varbinds);
@@ -740,9 +724,9 @@ TrapPdu.prototype.toBuffer = function (buffer) {
740
724
  buffer.writeOID (this.enterprise);
741
725
  buffer.writeBuffer (Buffer.from (this.agentAddr.split (".")),
742
726
  ObjectType.IpAddress);
743
- buffer.writeInt (this.generic);
744
- buffer.writeInt (this.specific);
745
- writeUint (buffer, ObjectType.TimeTicks,
727
+ writeInt32 (buffer, ObjectType.Integer, this.generic);
728
+ writeInt32 (buffer, ObjectType.Integer, this.specific);
729
+ writeUint32 (buffer, ObjectType.TimeTicks,
746
730
  this.upTime || Math.floor (process.uptime () * 100));
747
731
 
748
732
  writeVarbinds (buffer, this.varbinds);
@@ -756,9 +740,9 @@ TrapPdu.createFromBuffer = function (reader) {
756
740
 
757
741
  pdu.enterprise = reader.readOID ();
758
742
  pdu.agentAddr = readIpAddress (reader);
759
- pdu.generic = reader.readInt ();
760
- pdu.specific = reader.readInt ();
761
- pdu.upTime = readUint (reader);
743
+ pdu.generic = readInt32 (reader);
744
+ pdu.specific = readInt32 (reader);
745
+ pdu.upTime = readUint32 (reader);
762
746
 
763
747
  pdu.varbinds = [];
764
748
  readVarbinds (reader, pdu.varbinds);
@@ -811,9 +795,9 @@ var SimpleResponsePdu = function() {
811
795
  SimpleResponsePdu.prototype.toBuffer = function (writer) {
812
796
  writer.startSequence (this.type);
813
797
 
814
- writer.writeInt (this.id);
815
- writer.writeInt (this.errorStatus || 0);
816
- writer.writeInt (this.errorIndex || 0);
798
+ writeInt32 (writer, ObjectType.Integer, this.id);
799
+ writeInt32 (writer, this.errorStatus || 0);
800
+ writeInt32 (writer, ObjectType.Integer, this.errorIndex || 0);
817
801
  writeVarbinds (writer, this.varbinds);
818
802
  writer.endSequence ();
819
803
 
@@ -822,9 +806,9 @@ SimpleResponsePdu.prototype.toBuffer = function (writer) {
822
806
  SimpleResponsePdu.prototype.initializeFromBuffer = function (reader) {
823
807
  reader.readSequence (this.type);
824
808
 
825
- this.id = reader.readInt ();
826
- this.errorStatus = reader.readInt ();
827
- this.errorIndex = reader.readInt ();
809
+ this.id = readInt32 (reader);
810
+ this.errorStatus = readInt32 (reader);
811
+ this.errorIndex = readInt32 (reader);
828
812
 
829
813
  this.varbinds = [];
830
814
  readVarbinds (reader, this.varbinds);
@@ -879,7 +863,7 @@ var readPdu = function (reader, scoped) {
879
863
  var contextEngineID;
880
864
  var contextName;
881
865
  if ( scoped ) {
882
- reader.readSequence ();
866
+ reader = new ber.Reader (reader.readString (ber.Sequence | ber.Constructor, true));
883
867
  contextEngineID = reader.readString (ber.OctetString, true);
884
868
  contextName = reader.readString ();
885
869
  }
@@ -1051,9 +1035,9 @@ Encryption.encryptPdu = function (privProtocol, scopedPdu, privPassword, authPro
1051
1035
  return encryptFunction (scopedPdu, privProtocol, privPassword, authProtocol, engine);
1052
1036
  };
1053
1037
 
1054
- Encryption.decryptPdu = function (privProtocol, encryptedPdu, privParameters, privPassword, authProtocol, engine, forceAutoPaddingDisable) {
1038
+ Encryption.decryptPdu = function (privProtocol, encryptedPdu, privParameters, privPassword, authProtocol, engine) {
1055
1039
  var decryptFunction = Encryption.algorithms[privProtocol].decryptPdu;
1056
- return decryptFunction (encryptedPdu, privProtocol, privParameters, privPassword, authProtocol, engine, forceAutoPaddingDisable);
1040
+ return decryptFunction (encryptedPdu, privProtocol, privParameters, privPassword, authProtocol, engine);
1057
1041
  };
1058
1042
 
1059
1043
  Encryption.debugEncrypt = function (encryptionKey, iv, plainPdu, encryptedPdu) {
@@ -1179,7 +1163,7 @@ Encryption.encryptPduDes = function (scopedPdu, privProtocol, privPassword, auth
1179
1163
  };
1180
1164
  };
1181
1165
 
1182
- Encryption.decryptPduDes = function (encryptedPdu, privProtocol, privParameters, privPassword, authProtocol, engine, forceAutoPaddingDisable) {
1166
+ Encryption.decryptPduDes = function (encryptedPdu, privProtocol, privParameters, privPassword, authProtocol, engine) {
1183
1167
  var des = Encryption.algorithms[PrivProtocols.des];
1184
1168
  var privLocalizedKey;
1185
1169
  var decryptionKey;
@@ -1203,23 +1187,9 @@ Encryption.decryptPduDes = function (encryptedPdu, privProtocol, privParameters,
1203
1187
  }
1204
1188
 
1205
1189
  decipher = crypto.createDecipheriv (des.CRYPTO_ALGORITHM, decryptionKey, iv);
1206
- if ( forceAutoPaddingDisable ) {
1207
- decipher.setAutoPadding(false);
1208
- }
1190
+ decipher.setAutoPadding(false);
1209
1191
  decryptedPdu = decipher.update (encryptedPdu);
1210
- // This try-catch is a workaround for a seemingly incorrect error condition
1211
- // - where sometimes a decrypt error is thrown with decipher.final()
1212
- // It replaces this line which should have been sufficient:
1213
- // decryptedPdu = Buffer.concat ([decryptedPdu, decipher.final()]);
1214
- try {
1215
- decryptedPdu = Buffer.concat ([decryptedPdu, decipher.final()]);
1216
- } catch (error) {
1217
- // debug("Decrypt error: " + error);
1218
- decipher = crypto.createDecipheriv (des.CRYPTO_ALGORITHM, decryptionKey, iv);
1219
- decipher.setAutoPadding(false);
1220
- decryptedPdu = decipher.update (encryptedPdu);
1221
- decryptedPdu = Buffer.concat ([decryptedPdu, decipher.final()]);
1222
- }
1192
+ decryptedPdu = Buffer.concat ([decryptedPdu, decipher.final()]);
1223
1193
  // Encryption.debugDecrypt (decryptionKey, iv, encryptedPdu, decryptedPdu);
1224
1194
 
1225
1195
  return decryptedPdu;
@@ -1349,7 +1319,7 @@ Message.prototype.toBufferCommunity = function () {
1349
1319
 
1350
1320
  writer.startSequence ();
1351
1321
 
1352
- writer.writeInt (this.version);
1322
+ writeInt32 (writer, ObjectType.Integer, this.version);
1353
1323
  writer.writeString (this.community);
1354
1324
 
1355
1325
  this.pdu.toBuffer (writer);
@@ -1394,16 +1364,16 @@ Message.prototype.toBufferV3 = function () {
1394
1364
 
1395
1365
  writer.startSequence ();
1396
1366
 
1397
- writer.writeInt (this.version);
1367
+ writeInt32 (writer, ObjectType.Integer, this.version);
1398
1368
 
1399
1369
  // HeaderData
1400
1370
  writer.startSequence ();
1401
- writer.writeInt (this.msgGlobalData.msgID);
1402
- writer.writeInt (this.msgGlobalData.msgMaxSize);
1371
+ writeInt32 (writer, ObjectType.Integer, this.msgGlobalData.msgID);
1372
+ writeInt32 (writer, ObjectType.Integer, this.msgGlobalData.msgMaxSize);
1403
1373
  writer.writeByte (ber.OctetString);
1404
1374
  writer.writeByte (1);
1405
1375
  writer.writeByte (this.msgGlobalData.msgFlags);
1406
- writer.writeInt (this.msgGlobalData.msgSecurityModel);
1376
+ writeInt32 (writer, ObjectType.Integer, this.msgGlobalData.msgSecurityModel);
1407
1377
  writer.endSequence ();
1408
1378
 
1409
1379
  // msgSecurityParameters
@@ -1416,8 +1386,8 @@ Message.prototype.toBufferV3 = function () {
1416
1386
  } else {
1417
1387
  writer.writeBuffer (this.msgSecurityParameters.msgAuthoritativeEngineID, ber.OctetString);
1418
1388
  }
1419
- writer.writeInt (this.msgSecurityParameters.msgAuthoritativeEngineBoots);
1420
- writer.writeInt (this.msgSecurityParameters.msgAuthoritativeEngineTime);
1389
+ writeInt32 (writer, ObjectType.Integer, this.msgSecurityParameters.msgAuthoritativeEngineBoots);
1390
+ writeInt32 (writer, ObjectType.Integer, this.msgSecurityParameters.msgAuthoritativeEngineTime);
1421
1391
  writer.writeString (this.msgSecurityParameters.msgUserName);
1422
1392
 
1423
1393
  var msgAuthenticationParameters = '';
@@ -1491,23 +1461,10 @@ Message.prototype.decryptPdu = function (user, responseCb) {
1491
1461
  decryptedPduReader = new ber.Reader (decryptedPdu);
1492
1462
  this.pdu = readPdu(decryptedPduReader, true);
1493
1463
  return true;
1494
- // really really occasionally the decrypt truncates a single byte
1495
- // causing an ASN read failure in readPdu()
1496
- // in this case, disabling auto padding decrypts the PDU correctly
1497
- // this try-catch provides the workaround for this condition
1498
- } catch (possibleTruncationError) {
1499
- try {
1500
- decryptedPdu = Encryption.decryptPdu(user.privProtocol, this.encryptedPdu,
1501
- this.msgSecurityParameters.msgPrivacyParameters, user.privKey, user.authProtocol,
1502
- this.msgSecurityParameters.msgAuthoritativeEngineID, true);
1503
- decryptedPduReader = new ber.Reader (decryptedPdu);
1504
- this.pdu = readPdu(decryptedPduReader, true);
1505
- return true;
1506
- } catch (error) {
1507
- responseCb (new ResponseInvalidError ("Failed to decrypt PDU: " + error,
1508
- ResponseInvalidCode.ECouldNotDecrypt));
1509
- return false;
1510
- }
1464
+ } catch (error) {
1465
+ responseCb (new ResponseInvalidError ("Failed to decrypt PDU: " + error,
1466
+ ResponseInvalidCode.ECouldNotDecrypt));
1467
+ return false;
1511
1468
  }
1512
1469
 
1513
1470
  };
@@ -1690,7 +1647,7 @@ Message.createFromBuffer = function (buffer, user) {
1690
1647
 
1691
1648
  reader.readSequence ();
1692
1649
 
1693
- message.version = reader.readInt ();
1650
+ message.version = readInt32 (reader);
1694
1651
 
1695
1652
  if (message.version != 3) {
1696
1653
  message.community = reader.readString ();
@@ -1699,18 +1656,18 @@ Message.createFromBuffer = function (buffer, user) {
1699
1656
  // HeaderData
1700
1657
  message.msgGlobalData = {};
1701
1658
  reader.readSequence ();
1702
- message.msgGlobalData.msgID = reader.readInt ();
1703
- message.msgGlobalData.msgMaxSize = reader.readInt ();
1659
+ message.msgGlobalData.msgID = readInt32 (reader);
1660
+ message.msgGlobalData.msgMaxSize = readInt32 (reader);
1704
1661
  message.msgGlobalData.msgFlags = reader.readString (ber.OctetString, true)[0];
1705
- message.msgGlobalData.msgSecurityModel = reader.readInt ();
1662
+ message.msgGlobalData.msgSecurityModel = readInt32 (reader);
1706
1663
 
1707
1664
  // msgSecurityParameters
1708
1665
  message.msgSecurityParameters = {};
1709
1666
  var msgSecurityParametersReader = new ber.Reader (reader.readString (ber.OctetString, true));
1710
1667
  msgSecurityParametersReader.readSequence ();
1711
1668
  message.msgSecurityParameters.msgAuthoritativeEngineID = msgSecurityParametersReader.readString (ber.OctetString, true);
1712
- message.msgSecurityParameters.msgAuthoritativeEngineBoots = msgSecurityParametersReader.readInt ();
1713
- message.msgSecurityParameters.msgAuthoritativeEngineTime = msgSecurityParametersReader.readInt ();
1669
+ message.msgSecurityParameters.msgAuthoritativeEngineBoots = readInt32 (msgSecurityParametersReader);
1670
+ message.msgSecurityParameters.msgAuthoritativeEngineTime = readInt32 (msgSecurityParametersReader);
1714
1671
  message.msgSecurityParameters.msgUserName = msgSecurityParametersReader.readString ();
1715
1672
  message.msgSecurityParameters.msgAuthenticationParameters = msgSecurityParametersReader.readString (ber.OctetString, true);
1716
1673
  message.msgSecurityParameters.msgPrivacyParameters = Buffer.from(msgSecurityParametersReader.readString (ber.OctetString, true));
@@ -1895,6 +1852,7 @@ Session.prototype.get = function (oids, responseCb) {
1895
1852
 
1896
1853
  Session.prototype.getBulk = function () {
1897
1854
  var oids, nonRepeaters, maxRepetitions, responseCb;
1855
+ var reportOidMismatchErrors = this.reportOidMismatchErrors;
1898
1856
  var backwardsGetNexts = this.backwardsGetNexts;
1899
1857
 
1900
1858
  if (arguments.length >= 4) {
@@ -1916,71 +1874,59 @@ Session.prototype.getBulk = function () {
1916
1874
 
1917
1875
  function feedCb (req, message) {
1918
1876
  var pdu = message.pdu;
1877
+ var reqVarbinds = req.message.pdu.varbinds;
1919
1878
  var varbinds = [];
1920
1879
  var i = 0;
1921
1880
 
1922
- // first walk through and grab non-repeaters
1923
- if (pdu.varbinds.length < nonRepeaters) {
1924
- req.responseCb (new ResponseInvalidError ("Varbind count in "
1925
- + "response '" + pdu.varbinds.length + "' is less than "
1926
- + "non-repeaters '" + nonRepeaters + "' in request",
1927
- ResponseInvalidCode.ENonRepeaterCountMismatch));
1928
- return;
1929
- } else {
1930
- for ( ; i < nonRepeaters; i++) {
1931
- if (isVarbindError (pdu.varbinds[i])) {
1932
- varbinds.push (pdu.varbinds[i]);
1933
- } else if (! oidFollowsOid (req.message.pdu.varbinds[i].oid,
1934
- pdu.varbinds[i].oid)) {
1935
- req.responseCb (new ResponseInvalidError ("OID '"
1936
- + req.message.pdu.varbinds[i].oid + "' in request at "
1937
- + "positiion '" + i + "' does not precede "
1938
- + "OID '" + pdu.varbinds[i].oid + "' in response "
1881
+ for ( ; i < reqVarbinds.length && i < pdu.varbinds.length; i++) {
1882
+ if (isVarbindError (pdu.varbinds[i])) {
1883
+ if ( reportOidMismatchErrors && reqVarbinds[i].oid != pdu.varbinds[i].oid ) {
1884
+ req.responseCb (new ResponseInvalidError ("OID '" + reqVarbinds[i].oid
1885
+ + "' in request at position '" + i + "' does not "
1886
+ + "match OID '" + pdu.varbinds[i].oid + "' in response "
1887
+ + "at position '" + i + "'", ResponseInvalidCode.EReqResOidNoMatch));
1888
+ return;
1889
+ }
1890
+ } else {
1891
+ if ( ! backwardsGetNexts && ! oidFollowsOid (reqVarbinds[i].oid, pdu.varbinds[i].oid)) {
1892
+ req.responseCb (new ResponseInvalidError ("OID '" + reqVarbinds[i].oid
1893
+ + "' in request at positiion '" + i + "' does not "
1894
+ + "precede OID '" + pdu.varbinds[i].oid + "' in response "
1939
1895
  + "at position '" + i + "'", ResponseInvalidCode.EOutOfOrder));
1940
1896
  return;
1941
- } else {
1942
- varbinds.push (pdu.varbinds[i]);
1943
1897
  }
1944
1898
  }
1899
+ if (i < nonRepeaters)
1900
+ varbinds.push (pdu.varbinds[i]);
1901
+ else
1902
+ varbinds.push ([pdu.varbinds[i]]);
1945
1903
  }
1946
1904
 
1947
- var repeaters = req.message.pdu.varbinds.length - nonRepeaters;
1905
+ var repeaters = reqVarbinds.length - nonRepeaters;
1948
1906
 
1949
- // secondly walk through and grab repeaters
1950
- if (pdu.varbinds.length % (repeaters)) {
1951
- req.responseCb (new ResponseInvalidError ("Varbind count in "
1952
- + "response '" + pdu.varbinds.length + "' is not a "
1953
- + "multiple of repeaters '" + repeaters
1954
- + "' plus non-repeaters '" + nonRepeaters + "' in request",
1955
- ResponseInvalidCode.ENonRepeaterCountMismatch));
1956
- } else {
1957
- while (i < pdu.varbinds.length) {
1958
- for (var j = 0; j < repeaters; j++, i++) {
1959
- var reqIndex = nonRepeaters + j;
1960
- var respIndex = i;
1961
-
1962
- if (isVarbindError (pdu.varbinds[respIndex])) {
1963
- if (! varbinds[reqIndex])
1964
- varbinds[reqIndex] = [];
1965
- varbinds[reqIndex].push (pdu.varbinds[respIndex]);
1966
- } else if ( ! backwardsGetNexts && ! oidFollowsOid (
1967
- req.message.pdu.varbinds[reqIndex].oid,
1968
- pdu.varbinds[respIndex].oid)) {
1969
- req.responseCb (new ResponseInvalidError ("OID '"
1970
- + req.message.pdu.varbinds[reqIndex].oid
1971
- + "' in request at position '" + (reqIndex)
1972
- + "' does not precede OID '"
1973
- + pdu.varbinds[respIndex].oid
1974
- + "' in response at position '" + (respIndex) + "'",
1975
- ResponseInvalidCode.EOutOfOrder));
1976
- return;
1977
- } else {
1978
- if (! varbinds[reqIndex])
1979
- varbinds[reqIndex] = [];
1980
- varbinds[reqIndex].push (pdu.varbinds[respIndex]);
1981
- }
1907
+ for ( ; i < pdu.varbinds.length; i++) {
1908
+ var reqIndex = (i - nonRepeaters) % repeaters + nonRepeaters;
1909
+ var prevIndex = i - repeaters;
1910
+ var prevOid = pdu.varbinds[prevIndex].oid;
1911
+
1912
+ if (isVarbindError (pdu.varbinds[i])) {
1913
+ if ( reportOidMismatchErrors && prevOid != pdu.varbinds[i].oid ) {
1914
+ req.responseCb (new ResponseInvalidError ("OID '" + prevOid
1915
+ + "' in response at position '" + prevIndex + "' does not "
1916
+ + "match OID '" + pdu.varbinds[i].oid + "' in response "
1917
+ + "at position '" + i + "'", ResponseInvalidCode.EReqResOidNoMatch));
1918
+ return;
1919
+ }
1920
+ } else {
1921
+ if ( ! backwardsGetNexts && ! oidFollowsOid (prevOid, pdu.varbinds[i].oid)) {
1922
+ req.responseCb (new ResponseInvalidError ("OID '" + prevOid
1923
+ + "' in response at positiion '" + prevIndex + "' does not "
1924
+ + "precede OID '" + pdu.varbinds[i].oid + "' in response "
1925
+ + "at position '" + i + "'", ResponseInvalidCode.EOutOfOrder));
1926
+ return;
1982
1927
  }
1983
1928
  }
1929
+ varbinds[reqIndex].push (pdu.varbinds[i]);
1984
1930
  }
1985
1931
 
1986
1932
  req.responseCb (null, varbinds);
@@ -4454,7 +4400,7 @@ Mib.convertOidToAddress = function (oid) {
4454
4400
  throw new RangeError('object identifier component ' +
4455
4401
  address[i] + ' is negative');
4456
4402
  }
4457
- if (n > MAX_INT32) {
4403
+ if (n > MAX_SIGNED_INT32) {
4458
4404
  throw new RangeError('object identifier component ' +
4459
4405
  address[i] + ' is too large');
4460
4406
  }
@@ -6268,8 +6214,8 @@ exports.RequestTimedOutError = RequestTimedOutError;
6268
6214
  ** Added for testing
6269
6215
  **/
6270
6216
  exports.ObjectParser = {
6271
- readInt: readInt,
6272
- readUint: readUint,
6217
+ readInt32: readInt32,
6218
+ readUint32: readUint32,
6273
6219
  readVarbindValue: readVarbindValue
6274
6220
  };
6275
6221
  exports.Authentication = Authentication;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {
7
7
  "example": "example"
8
8
  },
9
9
  "dependencies": {
10
- "asn1-ber": "*",
10
+ "asn1-ber": "^1.2.0",
11
11
  "smart-buffer": "^4.1.0"
12
12
  },
13
13
  "devDependencies": {