1 | // |
---|---|
2 | // KeyFileHandler.cpp |
3 | // |
4 | // Library: NetSSL_OpenSSL |
5 | // Package: SSLCore |
6 | // Module: KeyFileHandler |
7 | // |
8 | // Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Net/KeyFileHandler.h" |
16 | #include "Poco/Net/SSLManager.h" |
17 | #include "Poco/File.h" |
18 | #include "Poco/Util/AbstractConfiguration.h" |
19 | #include "Poco/Util/Application.h" |
20 | #include "Poco/Util/OptionException.h" |
21 | |
22 | |
23 | namespace Poco { |
24 | namespace Net { |
25 | |
26 | |
27 | const std::string KeyFileHandler::CFG_PRIV_KEY_FILE("privateKeyPassphraseHandler.options.password"); |
28 | |
29 | |
30 | KeyFileHandler::KeyFileHandler(bool server):PrivateKeyPassphraseHandler(server) |
31 | { |
32 | } |
33 | |
34 | |
35 | KeyFileHandler::~KeyFileHandler() |
36 | { |
37 | } |
38 | |
39 | |
40 | void KeyFileHandler::onPrivateKeyRequested(const void* pSender, std::string& privateKey) |
41 | { |
42 | try |
43 | { |
44 | Poco::Util::AbstractConfiguration& config = Poco::Util::Application::instance().config(); |
45 | std::string prefix = serverSide() ? SSLManager::CFG_SERVER_PREFIX : SSLManager::CFG_CLIENT_PREFIX; |
46 | if (!config.hasProperty(prefix + CFG_PRIV_KEY_FILE)) |
47 | throw Poco::Util::EmptyOptionException(std::string("Missing Configuration Entry: ") + prefix + CFG_PRIV_KEY_FILE); |
48 | |
49 | privateKey = config.getString(prefix + CFG_PRIV_KEY_FILE); |
50 | } |
51 | catch (Poco::NullPointerException&) |
52 | { |
53 | throw Poco::IllegalStateException( |
54 | "An application configuration is required to obtain the private key passphrase, " |
55 | "but no Poco::Util::Application instance is available." |
56 | ); |
57 | } |
58 | } |
59 | |
60 | |
61 | } } // namespace Poco::Net |
62 |