Skip to content

Commit

Permalink
Merge pull request #241 from Stivius/fix/display_hash
Browse files Browse the repository at this point in the history
fix: remove volume serial from display hash calculation
  • Loading branch information
dasgarner authored Apr 29, 2021
2 parents 00125e7 + 3e3c432 commit 0af4e78
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 53 deletions.
49 changes: 2 additions & 47 deletions player/common/system/HardwareKeyGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common/Utils.hpp"
#include "common/system/System.hpp"
#include "common/logger/Logging.hpp"
#include "config/AppConfig.hpp"

#include <boost/process/child.hpp>
Expand All @@ -12,7 +13,7 @@ namespace bp = boost::process;

HardwareKey HardwareKeyGenerator::generate()
{
auto key = cpuid() + static_cast<std::string>(System::macAddress()) + volumeSerial();
auto key = cpuid() + static_cast<std::string>(System::macAddress());

return HardwareKey{Md5Hash::fromString(key)};
}
Expand All @@ -38,49 +39,3 @@ inline void HardwareKeyGenerator::nativeCpuid(unsigned int* eax,
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "0"(*eax), "2"(*ecx) : "memory");
}

std::string HardwareKeyGenerator::volumeSerial()
{
const std::string SERIAL_PREFIX{"ID_SERIAL_SHORT"};

auto line = executeAndGrepFirstLine("udevadm info " + currentDrive(), SERIAL_PREFIX);

return retrieveResult(std::regex{SERIAL_PREFIX + "=(.+)"}, line);
}

std::string HardwareKeyGenerator::currentDrive()
{
const std::string DEVICE_PREFIX{"/dev/"};

auto line = executeAndGrepFirstLine("df " + AppConfig::playerBinary(), DEVICE_PREFIX);

return DEVICE_PREFIX + retrieveResult(std::regex{DEVICE_PREFIX + "([^\\s]+)"}, line);
}

std::string HardwareKeyGenerator::retrieveResult(const std::regex& regex, const std::string& line)
{
const int SERIAL_CAPTURE_GROUP = 1;

std::smatch result;
if (std::regex_search(line, result, regex))
{
return result[SERIAL_CAPTURE_GROUP].str();
}

return {};
}

std::string HardwareKeyGenerator::executeAndGrepFirstLine(const std::string& command, const std::string& grepSearch)
{
bp::pipe pipe;
bp::ipstream stream;

bp::child commandProcess(command, bp::std_out > pipe);
bp::child grepProcess("grep " + grepSearch, bp::std_in<pipe, bp::std_out> stream);

commandProcess.wait();
grepProcess.wait();

std::string line;
std::getline(stream, line);
return line;
}
5 changes: 0 additions & 5 deletions player/common/system/HardwareKeyGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@ class HardwareKeyGenerator
private:
static std::string cpuid();
static void nativeCpuid(unsigned int* eax, unsigned int* ebx, unsigned int* ecx, unsigned int* edx);
static std::string macAddress();
static std::string volumeSerial();
static std::string currentDrive();
static std::string executeAndGrepFirstLine(const std::string& command, const std::string& grepSearch);
static std::string retrieveResult(const std::regex& regex, const std::string& line);
};
3 changes: 2 additions & 1 deletion player/common/system/MacAddressFetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ MacAddress MacAddressFetcher::fetch()

return MacAddress{retrieveMacAddress(socket, interfaceRequest)};
}
catch (std::exception&)
catch (std::exception& e)
{
Log::info("Failed to get MAC address: {}", e.what());
return UndefinedMacAddress;
}
}
Expand Down
2 changes: 2 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ parts:
stage:
- -usr/lib/x86_64-linux-gnu/libLLVM-10.so.1
- -usr/share/doc/libllvm10/changelog.Debian.gz
- -usr/share/doc/gcc-11-base/changelog.Debian.gz
- -lib/x86_64-linux-gnu/libgcc_s.so.1
after: [g++-8]

gst-plugins-base:
Expand Down

0 comments on commit 0af4e78

Please sign in to comment.