lib/net: Make format_ssl_fingerprint() easier to use

This commit is contained in:
Povilas Kanapickas 2021-11-01 02:52:30 +02:00
parent 0e406d4918
commit 7f71924a86
3 changed files with 9 additions and 7 deletions

View File

@ -675,7 +675,7 @@ SecureSocket::verifyCertFingerprint()
// format fingerprint into hexdecimal format with colon separator
std::string fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen);
format_ssl_fingerprint(fingerprint);
fingerprint = format_ssl_fingerprint(fingerprint);
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
std::string trustedServersFilename;

View File

@ -18,21 +18,22 @@
#include "SecureUtils.h"
#include "base/String.h"
void format_ssl_fingerprint(std::string& fingerprint, bool hex, bool separator)
std::string format_ssl_fingerprint(const std::string& fingerprint, bool hex, bool separator)
{
std::string result = fingerprint;
if (hex) {
// to hexadecimal
barrier::string::toHex(fingerprint, 2);
barrier::string::toHex(result, 2);
}
// all uppercase
barrier::string::uppercase(fingerprint);
barrier::string::uppercase(result);
if (separator) {
// add colon to separate each 2 characters
size_t separators = fingerprint.size() / 2;
size_t separators = result.size() / 2;
for (size_t i = 1; i < separators; i++) {
fingerprint.insert(i * 3 - 1, ":");
result.insert(i * 3 - 1, ":");
}
}
}

View File

@ -20,6 +20,7 @@
#include <string>
void format_ssl_fingerprint(std::string& fingerprint, bool hex = true, bool separator = true);
std::string format_ssl_fingerprint(const std::string& fingerprint,
bool hex = true, bool separator = true);
#endif // BARRIER_LIB_NET_SECUREUTILS_H