PrivateKeyPassphraseHandler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // PrivateKeyPassphraseHandler.h
  3. //
  4. // Library: NetSSL_OpenSSL
  5. // Package: SSLCore
  6. // Module: PrivateKeyPassphraseHandler
  7. //
  8. // Definition of the PrivateKeyPassphraseHandler class.
  9. //
  10. // Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef NetSSL_PrivateKeyPassphraseHandler_INCLUDED
  16. #define NetSSL_PrivateKeyPassphraseHandler_INCLUDED
  17. #include "Poco/Net/NetSSL.h"
  18. namespace Poco {
  19. namespace Net {
  20. class NetSSL_API PrivateKeyPassphraseHandler
  21. /// A passphrase handler is needed whenever the private key of a certificate is loaded and the certificate is protected
  22. /// by a passphrase. The PrivateKeyPassphraseHandler's task is to provide that passphrase.
  23. /// One can install one's own PrivateKeyPassphraseHandler by implementing this interface. Note that
  24. /// in the implementation file of the subclass the following code must be present (assuming you use the namespace My_API
  25. /// and the name of your handler class is MyGuiHandler):
  26. ///
  27. /// #include "Poco/Net/PrivateKeyFactory.h"
  28. /// ...
  29. /// POCO_REGISTER_KEYFACTORY(My_API, MyGuiHandler)
  30. ///
  31. /// One can either set the handler directly in the startup code of the main method of ones application by calling
  32. ///
  33. /// SSLManager::instance().initialize(myguiHandler, myInvalidCertificateHandler, mySSLContext)
  34. ///
  35. /// or in case one's application extends Poco::Util::Application one can use an XML configuration and put the following entry
  36. /// under the path openSSL.privateKeyPassphraseHandler:
  37. ///
  38. /// <privateKeyPassphraseHandler>
  39. /// <name>MyGuiHandler</name>
  40. /// <options>
  41. /// [...] // Put optional config params for the handler here
  42. /// </options>
  43. /// </privateKeyPassphraseHandler>
  44. ///
  45. /// Note that the name of the passphrase handler must be same as the one provided to the POCO_REGISTER_KEYFACTORY macro.
  46. {
  47. public:
  48. PrivateKeyPassphraseHandler(bool onServerSide);
  49. /// Creates the PrivateKeyPassphraseHandler. Automatically registers at the SSLManager::PrivateKeyPassword event.
  50. virtual ~PrivateKeyPassphraseHandler();
  51. /// Destroys the PrivateKeyPassphraseHandler.
  52. virtual void onPrivateKeyRequested(const void* pSender, std::string& privateKey) = 0;
  53. /// Returns the requested private key in the parameter privateKey.
  54. bool serverSide() const;
  55. private:
  56. bool _serverSide;
  57. };
  58. //
  59. // inlines
  60. //
  61. inline bool PrivateKeyPassphraseHandler::serverSide() const
  62. {
  63. return _serverSide;
  64. }
  65. } } // namespace Poco::Net
  66. #endif // NetSSL_PrivateKeyPassphraseHandler_INCLUDED