6
6
7
7
#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
8
8
#include " init.h"
9
+ #include " util.h"
9
10
10
11
#include < windows.h>
11
12
12
13
#include < QDebug>
13
14
15
+ #include < openssl/rand.h>
16
+
14
17
// If we don't want a message to be processed by Qt, return true and set result to
15
18
// the value that the window procedure should return. Otherwise return false.
16
19
bool WinShutdownMonitor::nativeEventFilter (const QByteArray &eventType, void *pMessage, long *pnResult)
@@ -19,6 +22,16 @@ bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pM
19
22
20
23
MSG *pMsg = static_cast <MSG *>(pMessage);
21
24
25
+ // Seed OpenSSL PRNG with Windows event data (e.g. mouse movements and other user interactions)
26
+ if (RAND_event (pMsg->message , pMsg->wParam , pMsg->lParam ) == 0 ) {
27
+ // Warn only once as this is performance-critical
28
+ static bool warned = false ;
29
+ if (!warned) {
30
+ LogPrint (" %s: OpenSSL RAND_event() failed to seed OpenSSL PRNG with enough data.\n " , __func__);
31
+ warned = true ;
32
+ }
33
+ }
34
+
22
35
switch (pMsg->message )
23
36
{
24
37
case WM_QUERYENDSESSION:
@@ -45,13 +58,13 @@ void WinShutdownMonitor::registerShutdownBlockReason(const QString& strReason, c
45
58
typedef BOOL (WINAPI *PSHUTDOWNBRCREATE)(HWND, LPCWSTR);
46
59
PSHUTDOWNBRCREATE shutdownBRCreate = (PSHUTDOWNBRCREATE)GetProcAddress (GetModuleHandleA (" User32.dll" ), " ShutdownBlockReasonCreate" );
47
60
if (shutdownBRCreate == NULL ) {
48
- qWarning () << " registerShutdownBlockReason : GetProcAddress for ShutdownBlockReasonCreate failed" ;
61
+ qWarning () << " registerShutdownBlockReason: GetProcAddress for ShutdownBlockReasonCreate failed" ;
49
62
return ;
50
63
}
51
64
52
65
if (shutdownBRCreate (mainWinId, strReason.toStdWString ().c_str ()))
53
- qWarning () << " registerShutdownBlockReason : Successfully registered: " + strReason;
66
+ qWarning () << " registerShutdownBlockReason: Successfully registered: " + strReason;
54
67
else
55
- qWarning () << " registerShutdownBlockReason : Failed to register: " + strReason;
68
+ qWarning () << " registerShutdownBlockReason: Failed to register: " + strReason;
56
69
}
57
70
#endif
0 commit comments