Browse Source

[Qt] seed OpenSSL PNRG with Windows event data

- see https://bitcointalk.org/index.php?topic=113496.msg1228193#msg1228193
  for the initial suggestion for this
- also ensure consistent debug.log message format
pull/145/head
Philip Kaufmann 10 years ago
parent
commit
674c070e5d
  1. 19
      src/qt/winshutdownmonitor.cpp

19
src/qt/winshutdownmonitor.cpp

@ -6,11 +6,14 @@
#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
#include "init.h"
#include "util.h"
#include <windows.h>
#include <QDebug>
#include <openssl/rand.h>
// If we don't want a message to be processed by Qt, return true and set result to
// the value that the window procedure should return. Otherwise return false.
bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult)
@ -19,6 +22,16 @@ bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pM
MSG *pMsg = static_cast<MSG *>(pMessage);
// Seed OpenSSL PRNG with Windows event data (e.g. mouse movements and other user interactions)
if (RAND_event(pMsg->message, pMsg->wParam, pMsg->lParam) == 0) {
// Warn only once as this is performance-critical
static bool warned = false;
if (!warned) {
LogPrint("%s: OpenSSL RAND_event() failed to seed OpenSSL PRNG with enough data.\n", __func__);
warned = true;
}
}
switch(pMsg->message)
{
case WM_QUERYENDSESSION:
@ -45,13 +58,13 @@ void WinShutdownMonitor::registerShutdownBlockReason(const QString& strReason, c
typedef BOOL (WINAPI *PSHUTDOWNBRCREATE)(HWND, LPCWSTR);
PSHUTDOWNBRCREATE shutdownBRCreate = (PSHUTDOWNBRCREATE)GetProcAddress(GetModuleHandleA("User32.dll"), "ShutdownBlockReasonCreate");
if (shutdownBRCreate == NULL) {
qWarning() << "registerShutdownBlockReason : GetProcAddress for ShutdownBlockReasonCreate failed";
qWarning() << "registerShutdownBlockReason: GetProcAddress for ShutdownBlockReasonCreate failed";
return;
}
if (shutdownBRCreate(mainWinId, strReason.toStdWString().c_str()))
qWarning() << "registerShutdownBlockReason : Successfully registered: " + strReason;
qWarning() << "registerShutdownBlockReason: Successfully registered: " + strReason;
else
qWarning() << "registerShutdownBlockReason : Failed to register: " + strReason;
qWarning() << "registerShutdownBlockReason: Failed to register: " + strReason;
}
#endif

Loading…
Cancel
Save