Remove default ctor for HostInfo - force to call static method for gatering info

dependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
Grzegorz Rychlik 2020-03-20 10:11:38 +01:00
parent 9e3811450d
commit 3baed23752
3 changed files with 18 additions and 19 deletions

View File

@ -37,43 +37,43 @@ namespace FSecure
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HostInfo::HostInfo() : m_OsVersionInfo{ sizeof m_OsVersionInfo }
HostInfo HostInfo::Gather()
{
// Reserve buffers for winapi calls.
DWORD computerNameBufferLength = MAX_COMPUTERNAME_LENGTH + 1, userNameBufferLength = UNLEN + 1;
m_ComputerName.resize(computerNameBufferLength);
m_UserName.resize(userNameBufferLength);
std::string computerName(computerNameBufferLength, '\0');
std::string userName(userNameBufferLength, '\0');
// Get name of the computer.
if (::GetComputerNameA(m_ComputerName.data(), &computerNameBufferLength))
m_ComputerName.resize(computerNameBufferLength);
if (::GetComputerNameA(computerName.data(), &computerNameBufferLength))
computerName.resize(computerNameBufferLength);
else
m_ComputerName.resize(0);
computerName.resize(0);
// Get the user name.
if (::GetUserNameA(m_UserName.data(), &userNameBufferLength))
m_UserName.resize(userNameBufferLength - 1);
if (::GetUserNameA(userName.data(), &userNameBufferLength))
userName.resize(userNameBufferLength - 1);
else
m_UserName.resize(0);
userName.resize(0);
RTL_OSVERSIONINFOEXW osVersionInfo{ sizeof(osVersionInfo) };
using fnRtlGetVersion = NTSTATUS(NTAPI*)(PRTL_OSVERSIONINFOEXW lpVersionInformation);
auto RtlGetVersion = (fnRtlGetVersion)GetProcAddress(GetModuleHandleW(OBF(L"ntdll.dll")), OBF("RtlGetVersion"));
if (RtlGetVersion)
{
RtlGetVersion(&m_OsVersionInfo);
}
RtlGetVersion(&osVersionInfo);
m_ProcessId = ::GetCurrentProcessId();
m_IsElevated = IsElevated();
DWORD processId = ::GetCurrentProcessId();
std::string domain;
LPWSTR buf = nullptr;
if (NETSETUP_JOIN_STATUS status; NERR_Success == ::NetGetJoinInformation(nullptr, &buf, &status))
{
SCOPE_GUARD( ::NetApiBufferFree(buf); );
if(status == NetSetupDomainName)
m_Domain = WidestringToString(buf);
domain = WidestringToString(buf);
}
return HostInfo(std::move(computerName), std::move(userName), std::move(domain), std::move(osVersionInfo), processId, IsElevated());
}
HostInfo::HostInfo(std::string computerName, std::string userName, std::string domain, RTL_OSVERSIONINFOEXW osVersionInfo, DWORD processId, bool isElevated)
@ -84,7 +84,6 @@ namespace FSecure
, m_ProcessId(processId)
, m_IsElevated(isElevated)
{
}
HostInfo::HostInfo(const json& json)

View File

@ -19,7 +19,7 @@ namespace FSecure
bool m_IsElevated; ///< Is process run with elevated rights
/// Gather info about host.
HostInfo();
static HostInfo Gather();
/// Aggregate constructor.
HostInfo(std::string computerName, std::string userName, std::string domain, RTL_OSVERSIONINFOEXW osVersionInfo, DWORD processId, bool isElevated);

View File

@ -135,7 +135,7 @@ namespace FSecure::C3::Core
static std::unique_ptr<InitializeRouteQuery> Create(RouteId sendersRid, BuildId buildId, Crypto::PublicKey gatewayEncryptionKey, Crypto::PublicKey agentsPublicEncryptionKey, HashT grcHash, int32_t timestamp, ResponseType responseType = ResponseType::None)
{
auto query = std::make_unique<InitializeRouteQuery>(sendersRid, responseType);
query->m_QueryPacketBody = Crypto::EncryptAnonymously(ByteVector::Create(buildId, agentsPublicEncryptionKey.ToByteVector(), grcHash, timestamp, HostInfo()), gatewayEncryptionKey);
query->m_QueryPacketBody = Crypto::EncryptAnonymously(ByteVector::Create(buildId, agentsPublicEncryptionKey.ToByteVector(), grcHash, timestamp, HostInfo::Gather()), gatewayEncryptionKey);
return query;
}