InvalidCertificateHandler.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // InvalidCertificateHandler.h
  3. //
  4. // Library: NetSSL_OpenSSL
  5. // Package: SSLCore
  6. // Module: InvalidCertificateHandler
  7. //
  8. // Definition of the InvalidCertificateHandler 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_InvalidCertificateHandler_INCLUDED
  16. #define NetSSL_InvalidCertificateHandler_INCLUDED
  17. #include "Poco/Net/NetSSL.h"
  18. #include "Poco/Net/VerificationErrorArgs.h"
  19. namespace Poco {
  20. namespace Net {
  21. class NetSSL_API InvalidCertificateHandler
  22. /// A InvalidCertificateHandler is invoked whenever an error occurs verifying the certificate. It allows the user
  23. /// to inspect and accept/reject the certificate.
  24. /// One can install one's own InvalidCertificateHandler by implementing this interface. Note that
  25. /// in the implementation file of the subclass the following code must be present (assuming you use the namespace My_API
  26. /// and the name of your handler class is MyGuiHandler):
  27. ///
  28. /// #include "Poco/Net/CertificateHandlerFactory.h"
  29. /// ...
  30. /// POCO_REGISTER_CHFACTORY(My_API, MyGuiHandler)
  31. ///
  32. /// One can either set the handler directly in the startup code of the main method of ones application by calling
  33. ///
  34. /// SSLManager::instance().initialize(mypassphraseHandler, myguiHandler, mySSLContext)
  35. ///
  36. /// or in case one uses Poco::Util::Application one can rely on an XML configuration and put the following entry
  37. /// under the path openSSL.invalidCertificateHandler:
  38. ///
  39. /// <invalidCertificateHandler>
  40. /// <name>MyGuiHandler<name>
  41. /// <options>
  42. /// [...] // Put optional config params for the handler here
  43. /// </options>
  44. /// </invalidCertificateHandler>
  45. ///
  46. /// Note that the name of the InvalidCertificateHandler must be same as the one provided to the POCO_REGISTER_CHFACTORY macro.
  47. {
  48. public:
  49. InvalidCertificateHandler(bool handleErrorsOnServerSide);
  50. /// Creates the InvalidCertificateHandler.
  51. ///
  52. /// Set handleErrorsOnServerSide to true if the certificate handler is used on the server side.
  53. /// Automatically registers at one of the SSLManager::VerificationError events.
  54. virtual ~InvalidCertificateHandler();
  55. /// Destroys the InvalidCertificateHandler.
  56. virtual void onInvalidCertificate(const void* pSender, VerificationErrorArgs& errorCert) = 0;
  57. /// Receives the questionable certificate in parameter errorCert. If one wants to accept the
  58. /// certificate, call errorCert.setIgnoreError(true).
  59. protected:
  60. bool _handleErrorsOnServerSide;
  61. /// Stores if the certificate handler gets invoked by the server (i.e. a client certificate is wrong)
  62. /// or the client (a server certificate is wrong)
  63. };
  64. } } // namespace Poco::Net
  65. #endif // NetSSL_InvalidCertificateHandler_INCLUDED