Merge pull request #4399

674c070 [Qt] seed OpenSSL PNRG with Windows event data (Philip Kaufmann)
This commit is contained in:
Wladimir J. van der Laan 2014-07-07 10:31:18 +02:00
commit 642c8e75bc
No known key found for this signature in database
GPG key ID: 74810B012346C9A6

View file

@ -6,11 +6,14 @@
#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000 #if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
#include "init.h" #include "init.h"
#include "util.h"
#include <windows.h> #include <windows.h>
#include <QDebug> #include <QDebug>
#include <openssl/rand.h>
// If we don't want a message to be processed by Qt, return true and set result to // 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. // the value that the window procedure should return. Otherwise return false.
bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult) 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); 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) switch(pMsg->message)
{ {
case WM_QUERYENDSESSION: case WM_QUERYENDSESSION: