lib/net: Extract fingerprint formatting out of SecureSocket
This commit is contained in:
parent
bf667a429c
commit
0e406d4918
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SecureSocket.h"
|
#include "SecureSocket.h"
|
||||||
|
#include "SecureUtils.h"
|
||||||
|
|
||||||
#include "net/TSocketMultiplexerMethodJob.h"
|
#include "net/TSocketMultiplexerMethodJob.h"
|
||||||
#include "base/TMethodEventJob.h"
|
#include "base/TMethodEventJob.h"
|
||||||
|
@ -656,25 +657,6 @@ SecureSocket::disconnect()
|
||||||
sendEvent(getEvents()->forIStream().inputShutdown());
|
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
|
bool
|
||||||
SecureSocket::verifyCertFingerprint()
|
SecureSocket::verifyCertFingerprint()
|
||||||
{
|
{
|
||||||
|
@ -693,7 +675,7 @@ SecureSocket::verifyCertFingerprint()
|
||||||
|
|
||||||
// format fingerprint into hexdecimal format with colon separator
|
// format fingerprint into hexdecimal format with colon separator
|
||||||
std::string fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen);
|
std::string fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen);
|
||||||
formatFingerprint(fingerprint);
|
format_ssl_fingerprint(fingerprint);
|
||||||
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
|
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
|
||||||
|
|
||||||
std::string trustedServersFilename;
|
std::string trustedServersFilename;
|
||||||
|
|
|
@ -68,7 +68,6 @@ private:
|
||||||
void showError(const std::string& reason);
|
void showError(const std::string& reason);
|
||||||
std::string getError();
|
std::string getError();
|
||||||
void disconnect();
|
void disconnect();
|
||||||
void formatFingerprint(std::string& fingerprint, bool hex = true, bool separator = true);
|
|
||||||
bool verifyCertFingerprint();
|
bool verifyCertFingerprint();
|
||||||
|
|
||||||
MultiplexerJobStatus serviceConnect(ISocketMultiplexerJob*, bool, bool, bool);
|
MultiplexerJobStatus serviceConnect(ISocketMultiplexerJob*, bool, bool, bool);
|
||||||
|
|
|
@ -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, ":");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
Loading…
Reference in New Issue