keyring.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef ISC_SERVER_COMMON_KEYRING_H
  15. #define ISC_SERVER_COMMON_KEYRING_H
  16. #include <boost/shared_ptr.hpp>
  17. #include <dns/tsigkey.h>
  18. #include <config/ccsession.h>
  19. /**
  20. * \file keyring.h
  21. * \brief TSIG keyring loaded from configuration.
  22. *
  23. * This file contains routines for loading a TSIG key ring from
  24. * the tsig_keys configuration section and keeping them up to date
  25. * on updates.
  26. *
  27. * You simply initialize/load the keyring with isc::server_common::initKeyring
  28. * and then just use the key ring referred to by isc::server_common::keyring. It
  29. * is automatically reloaded, when the configuration updates, so you no longer
  30. * needs to care about it.
  31. *
  32. * If you want to keep a key (or session) for longer time or your application
  33. * is multithreaded, you might want to have a copy of the shared pointer to
  34. * hold a reference. Otherwise an update might replace the keyring and delete
  35. * the keys in the old one.
  36. *
  37. * Also note that, while the interface doesn't prevent application from
  38. * modifying the keyring, it is not a good idea to do so. As mentioned above,
  39. * it might get reloaded at any time, which would replace the modified keyring.
  40. * The possibility to modify it is side effect of simpler implementation and
  41. * shorter code, not a goal.
  42. */
  43. namespace isc {
  44. namespace server_common {
  45. /**
  46. * \brief The key ring itself
  47. *
  48. * This is where the key ring is stored. You can directly use it to your needs,
  49. * but you need to call initKeyring first, otherwise you'll find a NULL pointer
  50. * here only.
  51. */
  52. extern boost::shared_ptr<dns::TSIGKeyRing> keyring;
  53. /**
  54. * \brief Load the key ring for the first time
  55. *
  56. * This loads the key ring from configuration to keyring. It also registers for
  57. * config updates, so from now on, it'll be kept up to date.
  58. *
  59. * You can unload the key ring with deinitKeyring.
  60. *
  61. * If it is already loaded, this function does nothing. So, if more than one
  62. * part of an application needs to use the key ring, they all can just call
  63. * this independently to ensure the keyring is loaded.
  64. *
  65. * \param session The configuration session used to talk to the config manager.
  66. */
  67. void
  68. initKeyring(config::ModuleCCSession& session);
  69. /**
  70. * \brief Unload the key ring
  71. *
  72. * This can be used to unload the key ring. It will reset the keyring to NULL
  73. * and stop receiving updates of the configuration.
  74. *
  75. * The need for this function should be quite rare, as it isn't required to be
  76. * called before application shutdown. And not calling it has only small
  77. * performance penalty -- the keyring will be kept in memory and updated when
  78. * the user changes configuration.
  79. *
  80. * This does nothing if the key ring is not loaded currently.
  81. *
  82. * \param session The configuration session used to talk to the config manager.
  83. *
  84. * \todo What do we do when the data that come are invalid? Should we ignore it,
  85. * as walidity should have been checked already in the config manager, or
  86. * throw? What about when we get an update and it's invalid?
  87. */
  88. void
  89. deinitKeyring(config::ModuleCCSession& session);
  90. }
  91. }
  92. #endif