lib/net: Extract fingerprint formatting out of SecureSocket

This commit is contained in:
Povilas Kanapickas 2021-11-01 02:52:29 +02:00
parent bf667a429c
commit 0e406d4918
4 changed files with 65 additions and 21 deletions

View File

@ -16,6 +16,7 @@
*/
#include "SecureSocket.h"
#include "SecureUtils.h"
#include "net/TSocketMultiplexerMethodJob.h"
#include "base/TMethodEventJob.h"
@ -656,25 +657,6 @@ SecureSocket::disconnect()
sendEvent(getEvents()->forIStream().inputShutdown());
}
void SecureSocket::formatFingerprint(std::string& fingerprint, bool hex, bool separator)
{
if (hex) {
// to hexadecimal
barrier::string::toHex(fingerprint, 2);
}
// all uppercase
barrier::string::uppercase(fingerprint);
if (separator) {
// add colon to separate each 2 characters
size_t separators = fingerprint.size() / 2;
for (size_t i = 1; i < separators; i++) {
fingerprint.insert(i * 3 - 1, ":");
}
}
}
bool
SecureSocket::verifyCertFingerprint()
{
@ -693,7 +675,7 @@ SecureSocket::verifyCertFingerprint()
// format fingerprint into hexdecimal format with colon separator
std::string fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen);
formatFingerprint(fingerprint);
format_ssl_fingerprint(fingerprint);
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
std::string trustedServersFilename;

View File

@ -68,7 +68,6 @@ private:
void showError(const std::string& reason);
std::string getError();
void disconnect();
void formatFingerprint(std::string& fingerprint, bool hex = true, bool separator = true);
bool verifyCertFingerprint();
MultiplexerJobStatus serviceConnect(ISocketMultiplexerJob*, bool, bool, bool);

View File

@ -0,0 +1,38 @@
/*
barrier -- mouse and keyboard sharing utility
Copyright (C) Barrier contributors
This package is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
found in the file LICENSE that should have accompanied this file.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SecureUtils.h"
#include "base/String.h"
void format_ssl_fingerprint(std::string& fingerprint, bool hex, bool separator)
{
if (hex) {
// to hexadecimal
barrier::string::toHex(fingerprint, 2);
}
// all uppercase
barrier::string::uppercase(fingerprint);
if (separator) {
// add colon to separate each 2 characters
size_t separators = fingerprint.size() / 2;
for (size_t i = 1; i < separators; i++) {
fingerprint.insert(i * 3 - 1, ":");
}
}
}

25
src/lib/net/SecureUtils.h Normal file
View File

@ -0,0 +1,25 @@
/*
barrier -- mouse and keyboard sharing utility
Copyright (C) Barrier contributors
This package is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
found in the file LICENSE that should have accompanied this file.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BARRIER_LIB_NET_SECUREUTILS_H
#define BARRIER_LIB_NET_SECUREUTILS_H
#include <string>
void format_ssl_fingerprint(std::string& fingerprint, bool hex = true, bool separator = true);
#endif // BARRIER_LIB_NET_SECUREUTILS_H