mirror of
https://github.com/znc/znc.git
synced 2026-08-06 00:43:19 +02:00
Merge pull request #1019 from jpnurmi/ssl
CZNC: add missing SSL-related getters and setters
This commit is contained in:
+55
-36
@@ -1099,42 +1099,13 @@ bool CZNC::LoadGlobal(CConfig& config, CString& sError) {
|
||||
m_bProtectWebSessions = sVal.ToBool();
|
||||
if (config.FindStringEntry("hideversion", sVal))
|
||||
m_bHideVersion = sVal.ToBool();
|
||||
|
||||
if (config.FindStringEntry("sslprotocols", m_sSSLProtocols)) {
|
||||
VCString vsProtocols;
|
||||
m_sSSLProtocols.Split(" ", vsProtocols, false, "", "", true, true);
|
||||
|
||||
for (CString& sProtocol : vsProtocols) {
|
||||
unsigned int uFlag = 0;
|
||||
bool bEnable = sProtocol.TrimPrefix("+");
|
||||
bool bDisable = sProtocol.TrimPrefix("-");
|
||||
|
||||
if (sProtocol.Equals("All")) {
|
||||
uFlag = ~0;
|
||||
} else if (sProtocol.Equals("SSLv2")) {
|
||||
uFlag = Csock::EDP_SSLv2;
|
||||
} else if (sProtocol.Equals("SSLv3")) {
|
||||
uFlag = Csock::EDP_SSLv3;
|
||||
} else if (sProtocol.Equals("TLSv1")) {
|
||||
uFlag = Csock::EDP_TLSv1;
|
||||
} else if (sProtocol.Equals("TLSv1.1")) {
|
||||
uFlag = Csock::EDP_TLSv1_1;
|
||||
} else if (sProtocol.Equals("TLSv1.2")) {
|
||||
uFlag = Csock::EDP_TLSv1_2;
|
||||
} else {
|
||||
CUtils::PrintError("Invalid SSLProtocols value [" + sProtocol + "]");
|
||||
CUtils::PrintError("The syntax is [SSLProtocols = [+|-]<protocol> ...]");
|
||||
CUtils::PrintError("Available protocols are [SSLv2, SSLv3, TLSv1, TLSv1.1, TLSv1.2]");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bEnable) {
|
||||
m_uDisabledSSLProtocols &= ~uFlag;
|
||||
} else if (bDisable) {
|
||||
m_uDisabledSSLProtocols |= uFlag;
|
||||
} else {
|
||||
m_uDisabledSSLProtocols = ~uFlag;
|
||||
}
|
||||
if (config.FindStringEntry("sslprotocols", sVal)) {
|
||||
if (!SetSSLProtocols(sVal)) {
|
||||
VCString vsProtocols = GetAvailableSSLProtocols();
|
||||
CUtils::PrintError("Invalid SSLProtocols value [" + sVal + "]");
|
||||
CUtils::PrintError("The syntax is [SSLProtocols = [+|-]<protocol> ...]");
|
||||
CUtils::PrintError("Available protocols are [" + CString(", ").Join(vsProtocols.begin(), vsProtocols.end()) + "]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1906,6 +1877,54 @@ void CZNC::SetConnectDelay(unsigned int i) {
|
||||
m_uiConnectDelay = i;
|
||||
}
|
||||
|
||||
VCString CZNC::GetAvailableSSLProtocols()
|
||||
{
|
||||
// NOTE: keep in sync with SetSSLProtocols()
|
||||
return {"SSLv2", "SSLv3", "TLSv1", "TLSV1.1", "TLSv1.2"};
|
||||
}
|
||||
|
||||
bool CZNC::SetSSLProtocols(const CString& sProtocols)
|
||||
{
|
||||
VCString vsProtocols;
|
||||
sProtocols.Split(" ", vsProtocols, false, "", "", true, true);
|
||||
|
||||
unsigned int uDisabledProtocols = Csock::EDP_SSL;
|
||||
for (CString& sProtocol : vsProtocols) {
|
||||
unsigned int uFlag = 0;
|
||||
bool bEnable = sProtocol.TrimPrefix("+");
|
||||
bool bDisable = sProtocol.TrimPrefix("-");
|
||||
|
||||
// NOTE: keep in sync with GetAvailableSSLProtocols()
|
||||
if (sProtocol.Equals("All")) {
|
||||
uFlag = ~0;
|
||||
} else if (sProtocol.Equals("SSLv2")) {
|
||||
uFlag = Csock::EDP_SSLv2;
|
||||
} else if (sProtocol.Equals("SSLv3")) {
|
||||
uFlag = Csock::EDP_SSLv3;
|
||||
} else if (sProtocol.Equals("TLSv1")) {
|
||||
uFlag = Csock::EDP_TLSv1;
|
||||
} else if (sProtocol.Equals("TLSv1.1")) {
|
||||
uFlag = Csock::EDP_TLSv1_1;
|
||||
} else if (sProtocol.Equals("TLSv1.2")) {
|
||||
uFlag = Csock::EDP_TLSv1_2;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bEnable) {
|
||||
uDisabledProtocols &= ~uFlag;
|
||||
} else if (bDisable) {
|
||||
uDisabledProtocols |= uFlag;
|
||||
} else {
|
||||
uDisabledProtocols = ~uFlag;
|
||||
}
|
||||
}
|
||||
|
||||
m_sSSLProtocols = sProtocols;
|
||||
m_uDisabledSSLProtocols = uDisabledProtocols;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CZNC::EnableConnectQueue() {
|
||||
if (!m_pConnectQueueTimer && !m_uiConnectPaused && !m_lpConnectQueue.empty()) {
|
||||
m_pConnectQueueTimer = new CConnectQueueTimer(m_uiConnectDelay);
|
||||
|
||||
Reference in New Issue
Block a user