mirror of
https://github.com/debauchee/barrier.git
synced 2024-12-23 19:12:14 +03:00
lib/net: Make format_ssl_fingerprint() easier to use
This commit is contained in:
parent
0e406d4918
commit
7f71924a86
@ -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;
|
||||
|
@ -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, ":");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user