Source: security/validator-config.js

  1. /**
  2. * Copyright (C) 2018 Regents of the University of California.
  3. * @author: Jeff Thompson <jefft0@remap.ucla.edu>
  4. * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/src/security/validator-config.cpp
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * A copy of the GNU Lesser General Public License is in the file COPYING.
  19. */
  20. /** @ignore */
  21. var CertificateFetcher = require('./v2/certificate-fetcher.js').CertificateFetcher; /** @ignore */
  22. var ValidationPolicyConfig = require('./v2/validation-policy-config.js').ValidationPolicyConfig; /** @ignore */
  23. var CertificateFetcherFromNetwork = require('./v2/certificate-fetcher-from-network.js').CertificateFetcherFromNetwork; /** @ignore */
  24. var Validator = require('./v2/validator.js').Validator;
  25. /**
  26. * ValidatorConfig extends Validator to implements a validator which can be
  27. * set up via a configuration file.
  28. *
  29. * The constructor has two forms:
  30. * ValidatorConfig(fetcher) - Create a ValidatorConfig that uses the given
  31. * certificate fetcher.
  32. * ValidatorConfig(face) - Create a ValidatorConfig that uses a
  33. * CertificateFetcherFromNetwork for the given Face.
  34. * @param {CertificateFetcher} fetcher the certificate fetcher to use.
  35. * @param {Face} face The face for the certificate fetcher to call
  36. * expressInterest.
  37. * @constructor
  38. */
  39. var ValidatorConfig = function ValidatorConfig(fetcherOrFace)
  40. {
  41. if (fetcherOrFace instanceof CertificateFetcher) {
  42. // Call the base constructor.
  43. Validator.call(this, new ValidationPolicyConfig(), fetcherOrFace);
  44. // TODO: Use getInnerPolicy().
  45. this.policyConfig_ = this.getPolicy();
  46. }
  47. else {
  48. // Call the base constructor.
  49. Validator.call
  50. (this, new ValidationPolicyConfig(),
  51. new CertificateFetcherFromNetwork(fetcherOrFace));
  52. // TODO: Use getInnerPolicy().
  53. this.policyConfig_ = this.getPolicy();
  54. }
  55. };
  56. ValidatorConfig.prototype = new Validator
  57. (new ValidationPolicyConfig(), new CertificateFetcherFromNetwork(null));
  58. ValidatorConfig.prototype.name = "ValidatorConfig";
  59. exports.ValidatorConfig = ValidatorConfig;
  60. /**
  61. * There are three forms of load:
  62. * load(filePath) - Load the configuration from the given config file.
  63. * load(input, inputName) - Load the configuration from the given input string.
  64. * load(configSection, inputName) - Load the configuration from the given
  65. * configSection.
  66. * Each of these forms of load replaces any existing configuration.
  67. * @param {String} filePath The The path of the config file.
  68. * @param {String} input The contents of the configuration rules, with lines
  69. * separated by "\n" or "\r\n".
  70. * @param {BoostInfoTree} The configuration section loaded from the config file.
  71. * It should have one "validator" section.
  72. * @param {String} inputName Used for log messages, etc.
  73. */
  74. ValidatorConfig.prototype.load = function
  75. (filePathOrInputOrConfigSection, inputName)
  76. {
  77. this.policyConfig_.load(filePathOrInputOrConfigSection, inputName);
  78. };