From 5c72c8232fba6cf1f935d0c2887f75fa1ab7134f Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Tue, 23 Dec 2014 00:58:59 +0000 Subject: [PATCH] Show fingerprints with colons --- include/znc/IRCNetwork.h | 2 +- include/znc/ZNCString.h | 3 ++- src/IRCSock.cpp | 2 +- src/ZNCString.cpp | 42 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/znc/IRCNetwork.h b/include/znc/IRCNetwork.h index 71a5b026..edebc59a 100644 --- a/include/znc/IRCNetwork.h +++ b/include/znc/IRCNetwork.h @@ -122,7 +122,7 @@ public: bool IsLastServer() const; const SCString& GetTrustedFingerprints() const { return m_ssTrustedFingerprints; } - void AddTrustedFingerprint(const CString& sFP) { m_ssTrustedFingerprints.insert(sFP.AsLower()); } + void AddTrustedFingerprint(const CString& sFP) { m_ssTrustedFingerprints.insert(sFP.Escape_n(CString::EHEXCOLON, CString::EHEXCOLON)); } void DelTrustedFingerprint(const CString& sFP) { m_ssTrustedFingerprints.erase(sFP); } void SetIRCConnectEnabled(bool b); diff --git a/include/znc/ZNCString.h b/include/znc/ZNCString.h index 4942fa11..32f9b3d6 100644 --- a/include/znc/ZNCString.h +++ b/include/znc/ZNCString.h @@ -78,7 +78,8 @@ public: ESQL, ENAMEDFMT, EDEBUG, - EMSGTAG + EMSGTAG, + EHEXCOLON, } EEscape; static const CaseSensitivity CaseSensitive = CaseSensitivity::CaseSensitive; diff --git a/src/IRCSock.cpp b/src/IRCSock.cpp index 5a58ef40..59063154 100644 --- a/src/IRCSock.cpp +++ b/src/IRCSock.cpp @@ -1148,7 +1148,7 @@ void CIRCSock::SockError(int iErrno, const CString& sDescription) { } CString sSHA1; if (GetPeerFingerprint(sSHA1)) - m_pNetwork->PutStatus("SHA1: " + sSHA1); + m_pNetwork->PutStatus("SHA1: " + sSHA1.Escape_n(CString::EHEXCOLON, CString::EHEXCOLON)); CString sSHA256 = GetSSLPeerFingerprint(); m_pNetwork->PutStatus("SHA-256: " + sSHA256); m_pNetwork->PutStatus("If you trust this certificate, do /znc AddTrustedServerFingerprint " + sSHA256); diff --git a/src/ZNCString.cpp b/src/ZNCString.cpp index e8ce010f..dc9633ef 100644 --- a/src/ZNCString.cpp +++ b/src/ZNCString.cpp @@ -184,6 +184,8 @@ CString::EEscape CString::ToEscape(const CString& sEsc) { return EDEBUG; } else if (sEsc.Equals("MSGTAG")) { return EMSGTAG; + } else if (sEsc.Equals("HEXCOLON")) { + return EHEXCOLON; } return EASCII; @@ -350,6 +352,35 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const { } } + break; + case EHEXCOLON: { + while (!isxdigit(*p) && a < iLength) { + a++; + p++; + } + if (a == iLength) { + continue; + } + if (isdigit(*p)) { + ch = (unsigned char)((*p - '0') << 4); + } else { + ch = (unsigned char)((tolower(*p) - 'a' +10) << 4); + } + a++; + p++; + while (!isxdigit(*p) && a < iLength) { + a++; + p++; + } + if (a == iLength) { + continue; + } + if (isdigit(*p)) { + ch |= (unsigned char)(*p - '0'); + } else { + ch |= (unsigned char)(tolower(*p) - 'a' +10); + } + } break; } @@ -419,11 +450,20 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const { } else if (ch == '\n') { sRet += '\\'; sRet += 'n'; } else { sRet += ch; } + break; + case EHEXCOLON: { + sRet += tolower(szHex[ch >> 4]); + sRet += tolower(szHex[ch & 0xf]); + sRet += ":"; + } break; } } - sRet.reserve(0); + if (eTo == EHEXCOLON) { + sRet.TrimRight(":"); + } + return sRet; }