net-snmp 3.5.8 → 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 +4 -0
  2. package/index.js +70 -54
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3166,6 +3166,10 @@ Example programs are included under the module's `example` directory.
3166
3166
 
3167
3167
  * Fix processing of negative integers larger than 32 bits
3168
3168
 
3169
+ ## Version 3.6.0 - 18/02/2022
3170
+
3171
+ * Add calculated key cache to remove authNoPriv and authPriv performance bottleneck
3172
+
3169
3173
  # License
3170
3174
 
3171
3175
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -427,16 +427,16 @@ function readUint (buffer, isSigned) {
427
427
  value *= 256;
428
428
  value += buffer.readByte ();
429
429
 
430
- if (isSigned && i <= 0) {
431
- if ((value & 0x80) == 0x80) {
432
- signedBitSet = true;
433
- }
434
- }
430
+ if (isSigned && i <= 0) {
431
+ if ((value & 0x80) == 0x80) {
432
+ signedBitSet = true;
433
+ }
434
+ }
435
435
  }
436
436
 
437
- if (signedBitSet) {
438
- value -= 2 ** (i * 8);
439
- }
437
+ if (signedBitSet) {
438
+ value -= 2 ** (i * 8);
439
+ }
440
440
 
441
441
  return value;
442
442
  }
@@ -934,17 +934,32 @@ Authentication.algorithms[AuthProtocols.sha] = {
934
934
  CRYPTO_ALGORITHM: 'sha1'
935
935
  };
936
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
+
937
944
  // Adapted from RFC3414 Appendix A.2.1. Password to Key Sample Code for MD5
938
945
  Authentication.passwordToKey = function (authProtocol, authPasswordString, engineID) {
939
946
  var hashAlgorithm;
940
947
  var firstDigest;
941
948
  var finalDigest;
942
- var buf = Buffer.alloc (Authentication.HMAC_BUFFER_SIZE);
949
+ var buf;
943
950
  var bufOffset = 0;
944
951
  var passwordIndex = 0;
945
952
  var count = 0;
946
- var password = Buffer.from (authPasswordString);
953
+ var password;
947
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);
948
963
 
949
964
  while (count < Authentication.HMAC_BUFFER_SIZE) {
950
965
  for (var i = 0; i < Authentication.HMAC_BLOCK_SIZE; i++) {
@@ -964,6 +979,7 @@ Authentication.passwordToKey = function (authProtocol, authPasswordString, engin
964
979
  finalDigest = hashAlgorithm.digest();
965
980
  // debug ("Localized key: " + finalDigest.toString('hex'));
966
981
 
982
+ Authentication.authToKeyCache[cacheKey] = finalDigest;
967
983
  return finalDigest;
968
984
  };
969
985
 
@@ -3546,11 +3562,11 @@ MibNode.prototype.getConstraintsFromProvider = function () {
3546
3562
  };
3547
3563
 
3548
3564
  MibNode.prototype.setValue = function (newValue) {
3549
- var len;
3550
- var min;
3551
- var max;
3552
- var range;
3553
- var found = false;
3565
+ var len;
3566
+ var min;
3567
+ var max;
3568
+ var range;
3569
+ var found = false;
3554
3570
  var constraints = this.getConstraintsFromProvider ();
3555
3571
  if ( ! constraints ) {
3556
3572
  this.value = newValue;
@@ -3561,35 +3577,35 @@ MibNode.prototype.setValue = function (newValue) {
3561
3577
  return false;
3562
3578
  }
3563
3579
  } else if ( constraints.ranges ) {
3564
- for ( range of constraints.ranges ) {
3565
- min = "min" in range ? range.min : Number.MIN_SAFE_INTEGER;
3566
- max = "max" in range ? range.max : Number.MAX_SAFE_INTEGER;
3567
- if ( newValue >= min && newValue <= max ) {
3568
- found = true;
3569
- break;
3570
- }
3571
- }
3572
- if ( ! found ) {
3573
- return false;
3574
- }
3575
- } else if ( constraints.sizes ) {
3576
- // if size is constrained, value must have a length property
3577
- if ( ! ( "length" in newValue ) ) {
3578
- return false;
3579
- }
3580
- len = newValue.length;
3581
- for ( range of constraints.sizes ) {
3582
- min = "min" in range ? range.min : Number.MIN_SAFE_INTEGER;
3583
- max = "max" in range ? range.max : Number.MAX_SAFE_INTEGER;
3584
- if ( len >= min && len <= max ) {
3585
- found = true;
3586
- break;
3587
- }
3588
- }
3589
- if ( ! found ) {
3590
- return false;
3591
- }
3592
- }
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
+ }
3593
3609
  this.value = newValue;
3594
3610
  return true;
3595
3611
  };
@@ -3977,25 +3993,25 @@ Mib.prototype.setTableRowDefaultValues = function (name, values) {
3977
3993
  };
3978
3994
 
3979
3995
  Mib.prototype.setScalarRanges = function (name, ranges ) {
3980
- let provider = this.getProvider(name);
3981
- provider.constraints = { ranges };
3996
+ let provider = this.getProvider(name);
3997
+ provider.constraints = { ranges };
3982
3998
  };
3983
3999
 
3984
4000
  Mib.prototype.setTableColumnRanges = function(name, column, ranges ) {
3985
- let provider = this.getProvider(name);
3986
- let tc = provider.tableColumns;
3987
- tc[column].constraints = { ranges };
4001
+ let provider = this.getProvider(name);
4002
+ let tc = provider.tableColumns;
4003
+ tc[column].constraints = { ranges };
3988
4004
  };
3989
4005
 
3990
4006
  Mib.prototype.setScalarSizes = function (name, sizes ) {
3991
- let provider = this.getProvider(name);
3992
- provider.constraints = { sizes };
4007
+ let provider = this.getProvider(name);
4008
+ provider.constraints = { sizes };
3993
4009
  };
3994
4010
 
3995
4011
  Mib.prototype.setTableColumnSizes = function(name, column, sizes ) {
3996
- let provider = this.getProvider(name);
3997
- let tc = provider.tableColumns;
3998
- tc[column].constraints = { sizes };
4012
+ let provider = this.getProvider(name);
4013
+ let tc = provider.tableColumns;
4014
+ tc[column].constraints = { sizes };
3999
4015
  };
4000
4016
 
4001
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.8",
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": {