1 | // |
---|---|
2 | // Utility.cpp |
3 | // |
4 | // Library: NetSSL_OpenSSL |
5 | // Package: SSLCore |
6 | // Module: Utility |
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/Utility.h" |
16 | #include "Poco/String.h" |
17 | #include "Poco/Util/OptionException.h" |
18 | #include <openssl/err.h> |
19 | |
20 | |
21 | namespace Poco { |
22 | namespace Net { |
23 | |
24 | |
25 | Context::VerificationMode Utility::convertVerificationMode(const std::string& vMode) |
26 | { |
27 | std::string mode = Poco::toLower(vMode); |
28 | Context::VerificationMode verMode = Context::VERIFY_STRICT; |
29 | |
30 | if (mode == "none") |
31 | verMode = Context::VERIFY_NONE; |
32 | else if (mode == "relaxed") |
33 | verMode = Context::VERIFY_RELAXED; |
34 | else if (mode == "strict") |
35 | verMode = Context::VERIFY_STRICT; |
36 | else if (mode == "once") |
37 | verMode = Context::VERIFY_ONCE; |
38 | else |
39 | throw Poco::InvalidArgumentException("Invalid verification mode. Should be relaxed, strict or once but got", vMode); |
40 | |
41 | return verMode; |
42 | } |
43 | |
44 | |
45 | std::string Utility::convertCertificateError(long errCode) |
46 | { |
47 | std::string errMsg(X509_verify_cert_error_string(errCode)); |
48 | return errMsg; |
49 | } |
50 | |
51 | |
52 | std::string Utility::getLastError() |
53 | { |
54 | unsigned long errCode = ERR_get_error(); |
55 | if (errCode != 0) |
56 | { |
57 | char buffer[256]; |
58 | ERR_error_string_n(errCode, buffer, sizeof(buffer)); |
59 | return std::string(buffer); |
60 | } |
61 | else return "No error"; |
62 | } |
63 | |
64 | |
65 | void Utility::clearErrorStack() |
66 | { |
67 | ERR_clear_error(); |
68 | } |
69 | |
70 | |
71 | } } // namespace Poco::Net |
72 |