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 | |
16 | |
17 | #ifndef NetSSL_PrivateKeyPassphraseHandler_INCLUDED |
18 | #define NetSSL_PrivateKeyPassphraseHandler_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Net/NetSSL.h" |
22 | |
23 | |
24 | namespace Poco { |
25 | namespace Net { |
26 | |
27 | |
28 | class NetSSL_API PrivateKeyPassphraseHandler |
29 | /// A passphrase handler is needed whenever the private key of a certificate is loaded and the certificate is protected |
30 | /// by a passphrase. The PrivateKeyPassphraseHandler's task is to provide that passphrase. |
31 | /// One can install one's own PrivateKeyPassphraseHandler by implementing this interface. Note that |
32 | /// in the implementation file of the subclass the following code must be present (assuming you use the namespace My_API |
33 | /// and the name of your handler class is MyGuiHandler): |
34 | /// |
35 | /// #include "Poco/Net/PrivateKeyFactory.h" |
36 | /// ... |
37 | /// POCO_REGISTER_KEYFACTORY(My_API, MyGuiHandler) |
38 | /// |
39 | /// One can either set the handler directly in the startup code of the main method of ones application by calling |
40 | /// |
41 | /// SSLManager::instance().initialize(myguiHandler, myInvalidCertificateHandler, mySSLContext) |
42 | /// |
43 | /// or in case one's application extends Poco::Util::Application one can use an XML configuration and put the following entry |
44 | /// under the path openSSL.privateKeyPassphraseHandler: |
45 | /// |
46 | /// <privateKeyPassphraseHandler> |
47 | /// <name>MyGuiHandler</name> |
48 | /// <options> |
49 | /// [...] // Put optional config params for the handler here |
50 | /// </options> |
51 | /// </privateKeyPassphraseHandler> |
52 | /// |
53 | /// Note that the name of the passphrase handler must be same as the one provided to the POCO_REGISTER_KEYFACTORY macro. |
54 | { |
55 | public: |
56 | PrivateKeyPassphraseHandler(bool onServerSide); |
57 | /// Creates the PrivateKeyPassphraseHandler. Automatically registers at the SSLManager::PrivateKeyPassword event. |
58 | |
59 | virtual ~PrivateKeyPassphraseHandler(); |
60 | /// Destroys the PrivateKeyPassphraseHandler. |
61 | |
62 | virtual void onPrivateKeyRequested(const void* pSender, std::string& privateKey) = 0; |
63 | /// Returns the requested private key in the parameter privateKey. |
64 | |
65 | bool serverSide() const; |
66 | |
67 | private: |
68 | bool _serverSide; |
69 | }; |
70 | |
71 | |
72 | // |
73 | // inlines |
74 | // |
75 | inline bool PrivateKeyPassphraseHandler::serverSide() const |
76 | { |
77 | return _serverSide; |
78 | } |
79 | |
80 | |
81 | } } // namespace Poco::Net |
82 | |
83 | |
84 | #endif // NetSSL_PrivateKeyPassphraseHandler_INCLUDED |
85 | |