net-snmp 3.5.5 → 3.6.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.
Files changed (3) hide show
  1. package/README.md +16 -0
  2. package/index.js +79 -52
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3154,6 +3154,22 @@ Example programs are included under the module's `example` directory.
3154
3154
 
3155
3155
  * Add missing return in getbulk feedCb callback non-repeaters error condition
3156
3156
 
3157
+ ## Version 3.5.6 - 20/10/2021
3158
+
3159
+ * Fix GetNext OID calculation for off-tree OIDs
3160
+
3161
+ ## Version 3.5.7 - 20/11/2021
3162
+
3163
+ * Fix handing of null varbinds in walk
3164
+
3165
+ ## Version 3.5.8 - 24/11/2021
3166
+
3167
+ * Fix processing of negative integers larger than 32 bits
3168
+
3169
+ ## Version 3.6.0 - 18/02/2022
3170
+
3171
+ * Add calculated key cache to remove authNoPriv and authPriv performance bottleneck
3172
+
3157
3173
  # License
3158
3174
 
3159
3175
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -428,13 +428,15 @@ function readUint (buffer, isSigned) {
428
428
  value += buffer.readByte ();
429
429
 
430
430
  if (isSigned && i <= 0) {
431
- if ((value & 0x80) == 0x80)
431
+ if ((value & 0x80) == 0x80) {
432
432
  signedBitSet = true;
433
+ }
433
434
  }
434
435
  }
435
436
 
436
- if (signedBitSet)
437
- value -= (1 << (i * 8));
437
+ if (signedBitSet) {
438
+ value -= 2 ** (i * 8);
439
+ }
438
440
 
439
441
  return value;
440
442
  }
@@ -932,17 +934,32 @@ Authentication.algorithms[AuthProtocols.sha] = {
932
934
  CRYPTO_ALGORITHM: 'sha1'
933
935
  };
934
936
 
937
+ Authentication.authToKeyCache = {};
938
+
939
+ Authentication.computeCacheKey = function (authProtocol, authPasswordString, engineID) {
940
+ var engineIDString = engineID.toString('base64');
941
+ return authProtocol + authPasswordString + engineIDString;
942
+ };
943
+
935
944
  // Adapted from RFC3414 Appendix A.2.1. Password to Key Sample Code for MD5
936
945
  Authentication.passwordToKey = function (authProtocol, authPasswordString, engineID) {
937
946
  var hashAlgorithm;
938
947
  var firstDigest;
939
948
  var finalDigest;
940
- var buf = Buffer.alloc (Authentication.HMAC_BUFFER_SIZE);
949
+ var buf;
941
950
  var bufOffset = 0;
942
951
  var passwordIndex = 0;
943
952
  var count = 0;
944
- var password = Buffer.from (authPasswordString);
953
+ var password;
945
954
  var cryptoAlgorithm = Authentication.algorithms[authProtocol].CRYPTO_ALGORITHM;
955
+
956
+ var cacheKey = Authentication.computeCacheKey(authProtocol, authPasswordString, engineID);
957
+ if (Authentication.authToKeyCache[cacheKey] !== undefined) {
958
+ return Authentication.authToKeyCache[cacheKey];
959
+ }
960
+
961
+ buf = Buffer.alloc (Authentication.HMAC_BUFFER_SIZE);
962
+ password = Buffer.from (authPasswordString);
946
963
 
947
964
  while (count < Authentication.HMAC_BUFFER_SIZE) {
948
965
  for (var i = 0; i < Authentication.HMAC_BLOCK_SIZE; i++) {
@@ -962,6 +979,7 @@ Authentication.passwordToKey = function (authProtocol, authPasswordString, engin
962
979
  finalDigest = hashAlgorithm.digest();
963
980
  // debug ("Localized key: " + finalDigest.toString('hex'));
964
981
 
982
+ Authentication.authToKeyCache[cacheKey] = finalDigest;
965
983
  return finalDigest;
966
984
  };
967
985
 
@@ -2642,7 +2660,7 @@ function walkCb (req, error, varbinds) {
2642
2660
  }
2643
2661
  }
2644
2662
 
2645
- if ( ! varbinds.length ) {
2663
+ if ( ! varbinds || ! varbinds.length ) {
2646
2664
  req.doneCb(null);
2647
2665
  return;
2648
2666
  }
@@ -3492,7 +3510,7 @@ MibNode.prototype.findChildImmediatelyBefore = function (index) {
3492
3510
  }
3493
3511
  }
3494
3512
  }
3495
- return this.children[sortedChildrenKeys[sortedChildrenKeys.length]];
3513
+ return this.children[sortedChildrenKeys[sortedChildrenKeys.length - 1]];
3496
3514
  };
3497
3515
 
3498
3516
  MibNode.prototype.isDescendant = function (address) {
@@ -3544,11 +3562,11 @@ MibNode.prototype.getConstraintsFromProvider = function () {
3544
3562
  };
3545
3563
 
3546
3564
  MibNode.prototype.setValue = function (newValue) {
3547
- var len;
3548
- var min;
3549
- var max;
3550
- var range;
3551
- var found = false;
3565
+ var len;
3566
+ var min;
3567
+ var max;
3568
+ var range;
3569
+ var found = false;
3552
3570
  var constraints = this.getConstraintsFromProvider ();
3553
3571
  if ( ! constraints ) {
3554
3572
  this.value = newValue;
@@ -3559,35 +3577,35 @@ MibNode.prototype.setValue = function (newValue) {
3559
3577
  return false;
3560
3578
  }
3561
3579
  } else if ( constraints.ranges ) {
3562
- for ( range of constraints.ranges ) {
3563
- min = "min" in range ? range.min : Number.MIN_SAFE_INTEGER;
3564
- max = "max" in range ? range.max : Number.MAX_SAFE_INTEGER;
3565
- if ( newValue >= min && newValue <= max ) {
3566
- found = true;
3567
- break;
3568
- }
3569
- }
3570
- if ( ! found ) {
3571
- return false;
3572
- }
3573
- } else if ( constraints.sizes ) {
3574
- // if size is constrained, value must have a length property
3575
- if ( ! ( "length" in newValue ) ) {
3576
- return false;
3577
- }
3578
- len = newValue.length;
3579
- for ( range of constraints.sizes ) {
3580
- min = "min" in range ? range.min : Number.MIN_SAFE_INTEGER;
3581
- max = "max" in range ? range.max : Number.MAX_SAFE_INTEGER;
3582
- if ( len >= min && len <= max ) {
3583
- found = true;
3584
- break;
3585
- }
3586
- }
3587
- if ( ! found ) {
3588
- return false;
3589
- }
3590
- }
3580
+ for ( range of constraints.ranges ) {
3581
+ min = "min" in range ? range.min : Number.MIN_SAFE_INTEGER;
3582
+ max = "max" in range ? range.max : Number.MAX_SAFE_INTEGER;
3583
+ if ( newValue >= min && newValue <= max ) {
3584
+ found = true;
3585
+ break;
3586
+ }
3587
+ }
3588
+ if ( ! found ) {
3589
+ return false;
3590
+ }
3591
+ } else if ( constraints.sizes ) {
3592
+ // if size is constrained, value must have a length property
3593
+ if ( ! ( "length" in newValue ) ) {
3594
+ return false;
3595
+ }
3596
+ len = newValue.length;
3597
+ for ( range of constraints.sizes ) {
3598
+ min = "min" in range ? range.min : Number.MIN_SAFE_INTEGER;
3599
+ max = "max" in range ? range.max : Number.MAX_SAFE_INTEGER;
3600
+ if ( len >= min && len <= max ) {
3601
+ found = true;
3602
+ break;
3603
+ }
3604
+ }
3605
+ if ( ! found ) {
3606
+ return false;
3607
+ }
3608
+ }
3591
3609
  this.value = newValue;
3592
3610
  return true;
3593
3611
  };
@@ -3824,7 +3842,16 @@ Mib.prototype.getTreeNode = function (oid) {
3824
3842
  var last = address.pop ();
3825
3843
  var parent = this.lookupAddress (address);
3826
3844
  if ( parent ) {
3827
- return (parent.findChildImmediatelyBefore (last) || parent);
3845
+ node = parent.findChildImmediatelyBefore (last);
3846
+ if ( !node )
3847
+ return parent;
3848
+ while ( true ) {
3849
+ // Find the last descendant
3850
+ var childrenAddresses = Object.keys (node.children).sort ( (a, b) => a - b);
3851
+ if ( childrenAddresses.length == 0 )
3852
+ return node;
3853
+ node = node.children[childrenAddresses[childrenAddresses.length - 1]];
3854
+ }
3828
3855
  }
3829
3856
  }
3830
3857
  return this.root;
@@ -3966,25 +3993,25 @@ Mib.prototype.setTableRowDefaultValues = function (name, values) {
3966
3993
  };
3967
3994
 
3968
3995
  Mib.prototype.setScalarRanges = function (name, ranges ) {
3969
- let provider = this.getProvider(name);
3970
- provider.constraints = { ranges };
3996
+ let provider = this.getProvider(name);
3997
+ provider.constraints = { ranges };
3971
3998
  };
3972
3999
 
3973
4000
  Mib.prototype.setTableColumnRanges = function(name, column, ranges ) {
3974
- let provider = this.getProvider(name);
3975
- let tc = provider.tableColumns;
3976
- tc[column].constraints = { ranges };
4001
+ let provider = this.getProvider(name);
4002
+ let tc = provider.tableColumns;
4003
+ tc[column].constraints = { ranges };
3977
4004
  };
3978
4005
 
3979
4006
  Mib.prototype.setScalarSizes = function (name, sizes ) {
3980
- let provider = this.getProvider(name);
3981
- provider.constraints = { sizes };
4007
+ let provider = this.getProvider(name);
4008
+ provider.constraints = { sizes };
3982
4009
  };
3983
4010
 
3984
4011
  Mib.prototype.setTableColumnSizes = function(name, column, sizes ) {
3985
- let provider = this.getProvider(name);
3986
- let tc = provider.tableColumns;
3987
- tc[column].constraints = { sizes };
4012
+ let provider = this.getProvider(name);
4013
+ let tc = provider.tableColumns;
4014
+ tc[column].constraints = { sizes };
3988
4015
  };
3989
4016
 
3990
4017
  Mib.prototype.registerProviders = function (providers) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.5.5",
3
+ "version": "3.6.0",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {