|
15 | 15 |
|
16 | 16 | #include "Poco/NObserver.h" |
17 | 17 | #include <Poco/Net/Context.h> |
| 18 | +#include <Poco/Net/AcceptCertificateHandler.h> |
18 | 19 | #include "Poco/Net/SocketNotification.h" |
19 | 20 | #include "Poco/Net/NetException.h" |
20 | 21 | #include "Poco/Net/WebSocketImpl.h" |
@@ -74,9 +75,32 @@ namespace OpenWifi { |
74 | 75 | const auto &Cas = MicroServiceConfigPath("ucentral.websocket.host.0.cas", ""); |
75 | 76 | const auto &ClientCasFile = MicroServiceConfigPath("ucentral.websocket.host.0.clientcas", ""); |
76 | 77 |
|
| 78 | + // Read the security mode from websocket configuration |
| 79 | + const auto &SecurityMode = |
| 80 | + MicroServiceConfigGetString("ucentral.websocket.host.0.security", "relaxed"); |
| 81 | + |
| 82 | + // Parse security mode string to verification mode |
| 83 | + Poco::Net::Context::VerificationMode VerificationLevel = Poco::Net::Context::VERIFY_RELAXED; |
| 84 | + if (SecurityMode == "strict") { |
| 85 | + VerificationLevel = Poco::Net::Context::VERIFY_STRICT; |
| 86 | + } else if (SecurityMode == "none") { |
| 87 | + VerificationLevel = Poco::Net::Context::VERIFY_NONE; |
| 88 | + } else if (SecurityMode == "relaxed") { |
| 89 | + VerificationLevel = Poco::Net::Context::VERIFY_RELAXED; |
| 90 | + } else if (SecurityMode == "once") { |
| 91 | + VerificationLevel = Poco::Net::Context::VERIFY_ONCE; |
| 92 | + } |
| 93 | + |
| 94 | + // Determine if we should accept all certificates (when security is "none") |
| 95 | + bool acceptAllCerts = (VerificationLevel == Poco::Net::Context::VERIFY_NONE); |
| 96 | + |
| 97 | + poco_information(Logger(), |
| 98 | + fmt::format("RTTY device socket security mode: {} (acceptAllCerts: {})", |
| 99 | + SecurityMode, acceptAllCerts)); |
| 100 | + |
77 | 101 | Poco::Net::Context::Params P; |
78 | 102 |
|
79 | | - P.verificationMode = Poco::Net::Context::VERIFY_ONCE; |
| 103 | + P.verificationMode = acceptAllCerts ? Poco::Net::Context::VERIFY_RELAXED : VerificationLevel; |
80 | 104 | P.verificationDepth = 9; |
81 | 105 | P.loadDefaultCAs = RootCas.empty(); |
82 | 106 | P.cipherList = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"; |
@@ -109,6 +133,13 @@ namespace OpenWifi { |
109 | 133 | DeviceSecureContext->disableProtocols(Poco::Net::Context::PROTO_TLSV1 | |
110 | 134 | Poco::Net::Context::PROTO_TLSV1_1); |
111 | 135 |
|
| 136 | + // Accept all certificates when security mode is "none" |
| 137 | + if (acceptAllCerts) { |
| 138 | + DeviceSecureContext->setInvalidCertificateHandler( |
| 139 | + Poco::SharedPtr<Poco::Net::InvalidCertificateHandler>( |
| 140 | + new Poco::Net::AcceptCertificateHandler(true))); |
| 141 | + } |
| 142 | + |
112 | 143 | SSL_CTX *SSLCtxDevice = DeviceSecureContext->sslContext(); |
113 | 144 | SSL_CTX_dane_enable(SSLCtxDevice); |
114 | 145 | Poco::Net::IPAddress Addr(Poco::Net::IPAddress::wildcard( |
|
0 commit comments