• R/O
  • SSH
  • HTTPS

ttssh2: コミット


コミットメタ情報

リビジョン7973 (tree)
日時2019-08-15 23:15:25
作者yutakapon

ログメッセージ

WindowsMe/NT4.0ではCryptAcquireContextWによるエントロピー取得ができないため、
新しく処理(OpenSSL 1.0.2ベース)を追加する。
CryptAcquireContextW.txtパッチとは異なり、当該パッチではCryptAcquireContextWの
利用は残すため、Windows2000以降では当該パッチではCryptAcquireContextWが使われる。
チケット #36876

変更サマリ

差分

--- branches/openssl_1_1_1_v2/libs/openssl_patch/CryptAcquireContextW2.txt (nonexistent)
+++ branches/openssl_1_1_1_v2/libs/openssl_patch/CryptAcquireContextW2.txt (revision 7973)
@@ -0,0 +1,273 @@
1+*** openssl-1.1.1c.org/crypto/rand/rand_win.c 2019-05-28 22:12:20.000000000 +0900
2+--- openssl/crypto/rand/rand_win.c 2019-08-15 22:46:14.892369300 +0900
3+***************
4+*** 39,44 ****
5+--- 39,80 ----
6+ # define INTEL_DEF_PROV L"Intel Hardware Cryptographic Service Provider"
7+ # endif
8+
9++
10++ #if 0
11++ typedef struct tagCURSORINFO {
12++ DWORD cbSize;
13++ DWORD flags;
14++ HCURSOR hCursor;
15++ POINT ptScreenPos;
16++ } CURSORINFO, *PCURSORINFO, *LPCURSORINFO;
17++ #endif
18++
19++ typedef HWND(WINAPI *GETFOREGROUNDWINDOW) (VOID);
20++ typedef BOOL(WINAPI *GETCURSORINFO) (PCURSORINFO);
21++ typedef DWORD(WINAPI *GETQUEUESTATUS) (UINT);
22++
23++ typedef HANDLE(WINAPI *CREATETOOLHELP32SNAPSHOT) (DWORD, DWORD);
24++ typedef BOOL(WINAPI *CLOSETOOLHELP32SNAPSHOT) (HANDLE);
25++ typedef BOOL(WINAPI *HEAP32FIRST) (LPHEAPENTRY32, DWORD, size_t);
26++ typedef BOOL(WINAPI *HEAP32NEXT) (LPHEAPENTRY32);
27++ //typedef BOOL(WINAPI *HEAP32LIST) (HANDLE, LPHEAPLIST32);
28++ //typedef BOOL(WINAPI *PROCESS32) (HANDLE, LPPROCESSENTRY32);
29++ //typedef BOOL(WINAPI *THREAD32) (HANDLE, LPTHREADENTRY32);
30++ //typedef BOOL(WINAPI *MODULE32) (HANDLE, LPMODULEENTRY32);
31++
32++ static void add_RAND_buffer(void *srcbuf, int srcnum, void *dstbuf, int *dstoff, int dstmax)
33++ {
34++ int off = *dstoff;
35++
36++ if (off + srcnum > dstmax)
37++ return;
38++
39++ memcpy((unsigned char*)dstbuf + off , srcbuf, srcnum);
40++ off += srcnum;
41++
42++ *dstoff = off;
43++ }
44++
45+ size_t rand_pool_acquire_entropy(RAND_POOL *pool)
46+ {
47+ # ifndef USE_BCRYPTGENRANDOM
48+*************** size_t rand_pool_acquire_entropy(RAND_PO
49+*** 115,120 ****
50+--- 151,373 ----
51+ return entropy_available;
52+ # endif
53+
54++ /*
55++ * for Windows 9x, NT4.0
56++ */
57++ bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
58++ buffer = rand_pool_add_begin(pool, bytes_needed);
59++ if (buffer != NULL) {
60++ size_t sum = 0;
61++ int off = 0;
62++ DWORD w;
63++ HMODULE user = NULL;
64++ HMODULE kernel = LoadLibrary(TEXT("KERNEL32.DLL"));
65++ MEMORYSTATUS m;
66++
67++ user = LoadLibrary(TEXT("USER32.DLL"));
68++ if (user) {
69++ GETCURSORINFO cursor;
70++ GETFOREGROUNDWINDOW win;
71++ GETQUEUESTATUS queue;
72++
73++ win =
74++ (GETFOREGROUNDWINDOW) GetProcAddress(user,
75++ "GetForegroundWindow");
76++ cursor = (GETCURSORINFO) GetProcAddress(user, "GetCursorInfo");
77++ queue = (GETQUEUESTATUS) GetProcAddress(user, "GetQueueStatus");
78++
79++ if (win) {
80++ /* window handle */
81++ HWND h = win();
82++ add_RAND_buffer(&h, sizeof(h), buffer, &off, bytes_needed);
83++ }
84++ if (cursor) {
85++ /*
86++ * unfortunately, its not safe to call GetCursorInfo() on NT4
87++ * even though it exists in SP3 (or SP6) and higher.
88++ */
89++ //if (check_winnt() && !check_win_minplat(5))
90++ // cursor = 0;
91++ }
92++ if (cursor) {
93++ /* cursor position */
94++ /* assume 2 bytes of entropy */
95++ CURSORINFO ci;
96++ ci.cbSize = sizeof(CURSORINFO);
97++ if (cursor(&ci))
98++ add_RAND_buffer(&ci, ci.cbSize, buffer, &off, bytes_needed);
99++ }
100++
101++ if (queue) {
102++ /* message queue status */
103++ /* assume 1 byte of entropy */
104++ w = queue(QS_ALLEVENTS);
105++ add_RAND_buffer(&w, sizeof(w), buffer, &off, bytes_needed);
106++ }
107++
108++ FreeLibrary(user);
109++ }
110++
111++ #if 0
112++ if (kernel) {
113++ CREATETOOLHELP32SNAPSHOT snap;
114++ CLOSETOOLHELP32SNAPSHOT close_snap;
115++ HANDLE handle;
116++
117++ HEAP32FIRST heap_first;
118++ HEAP32NEXT heap_next;
119++ HEAP32LIST heaplist_first, heaplist_next;
120++ PROCESS32 process_first, process_next;
121++ THREAD32 thread_first, thread_next;
122++ MODULE32 module_first, module_next;
123++
124++ HEAPLIST32 hlist;
125++ HEAPENTRY32 hentry;
126++ PROCESSENTRY32 p;
127++ THREADENTRY32 t;
128++ MODULEENTRY32 m;
129++ DWORD starttime = 0;
130++
131++ snap = (CREATETOOLHELP32SNAPSHOT)
132++ GetProcAddress(kernel, "CreateToolhelp32Snapshot");
133++ close_snap = (CLOSETOOLHELP32SNAPSHOT)
134++ GetProcAddress(kernel, "CloseToolhelp32Snapshot");
135++ heap_first = (HEAP32FIRST) GetProcAddress(kernel, "Heap32First");
136++ heap_next = (HEAP32NEXT) GetProcAddress(kernel, "Heap32Next");
137++ heaplist_first =
138++ (HEAP32LIST) GetProcAddress(kernel, "Heap32ListFirst");
139++ heaplist_next =
140++ (HEAP32LIST) GetProcAddress(kernel, "Heap32ListNext");
141++ process_first =
142++ (PROCESS32) GetProcAddress(kernel, "Process32First");
143++ process_next =
144++ (PROCESS32) GetProcAddress(kernel, "Process32Next");
145++ thread_first = (THREAD32) GetProcAddress(kernel, "Thread32First");
146++ thread_next = (THREAD32) GetProcAddress(kernel, "Thread32Next");
147++ module_first = (MODULE32) GetProcAddress(kernel, "Module32First");
148++ module_next = (MODULE32) GetProcAddress(kernel, "Module32Next");
149++
150++ if (snap && heap_first && heap_next && heaplist_first &&
151++ heaplist_next && process_first && process_next &&
152++ thread_first && thread_next && module_first &&
153++ module_next && (handle = snap(TH32CS_SNAPALL, 0))
154++ != INVALID_HANDLE_VALUE) {
155++ /* heap list and heap walking */
156++ /*
157++ * HEAPLIST32 contains 3 fields that will change with each
158++ * entry. Consider each field a source of 1 byte of entropy.
159++ * HEAPENTRY32 contains 5 fields that will change with each
160++ * entry. Consider each field a source of 1 byte of entropy.
161++ */
162++ ZeroMemory(&hlist, sizeof(HEAPLIST32));
163++ hlist.dwSize = sizeof(HEAPLIST32);
164++ if (good)
165++ starttime = GetTickCount();
166++ # ifdef _MSC_VER
167++ if (heaplist_first(handle, &hlist)) {
168++ /*
169++ * following discussion on dev ML, exception on WinCE (or
170++ * other Win platform) is theoretically of unknown
171++ * origin; prevent infinite loop here when this
172++ * theoretical case occurs; otherwise cope with the
173++ * expected (MSDN documented) exception-throwing
174++ * behaviour of Heap32Next() on WinCE.
175++ *
176++ * based on patch in original message by Tanguy Fautré
177++ * (2009/03/02) Subject: RAND_poll() and
178++ * CreateToolhelp32Snapshot() stability
179++ */
180++ int ex_cnt_limit = 42;
181++ do {
182++ add_RAND_buffer(&hlist, hlist.dwSize, buffer, &off, bytes_needed);
183++ __try {
184++ ZeroMemory(&hentry, sizeof(HEAPENTRY32));
185++ hentry.dwSize = sizeof(HEAPENTRY32);
186++ if (heap_first(&hentry,
187++ hlist.th32ProcessID,
188++ hlist.th32HeapID)) {
189++ int entrycnt = 80;
190++ do
191++ add_RAND_buffer(&hentry, hentry.dwSize, buffer, &off, bytes_needed);
192++ while (heap_next(&hentry)
193++ && (!good || NOTTOOLONG(starttime))
194++ && --entrycnt > 0);
195++ }
196++ }
197++ __except(EXCEPTION_EXECUTE_HANDLER) {
198++ /*
199++ * ignore access violations when walking the heap
200++ * list
201++ */
202++ ex_cnt_limit--;
203++ }
204++ } while (heaplist_next(handle, &hlist)
205++ && (!good || NOTTOOLONG(starttime))
206++ && ex_cnt_limit > 0);
207++ }
208++ # endif
209++
210++ /* process walking */
211++ /*
212++ * PROCESSENTRY32 contains 9 fields that will change with
213++ * each entry. Consider each field a source of 1 byte of
214++ * entropy.
215++ */
216++ p.dwSize = sizeof(PROCESSENTRY32);
217++
218++ if (good)
219++ starttime = GetTickCount();
220++ if (process_first(handle, &p))
221++ do
222++ add_RAND_buffer(&p, p.dwSize, buffer, &off, bytes_needed);
223++ while (process_next(handle, &p)
224++ && (!good || NOTTOOLONG(starttime)));
225++
226++ /* thread walking */
227++ /*
228++ * THREADENTRY32 contains 6 fields that will change with each
229++ * entry. Consider each field a source of 1 byte of entropy.
230++ */
231++ t.dwSize = sizeof(THREADENTRY32);
232++ if (good)
233++ starttime = GetTickCount();
234++ if (thread_first(handle, &t))
235++ do
236++ add_RAND_buffer(&t, t.dwSize, buffer, &off, bytes_needed);
237++ while (thread_next(handle, &t)
238++ && (!good || NOTTOOLONG(starttime)));
239++
240++ /* module walking */
241++ /*
242++ * MODULEENTRY32 contains 9 fields that will change with each
243++ * entry. Consider each field a source of 1 byte of entropy.
244++ */
245++ m.dwSize = sizeof(MODULEENTRY32);
246++ if (good)
247++ starttime = GetTickCount();
248++ if (module_first(handle, &m))
249++ do
250++ add_RAND_buffer(&m, m.dwSize, buffer, &off, bytes_needed);
251++ while (module_next(handle, &m)
252++ && (!good || NOTTOOLONG(starttime)));
253++ if (close_snap)
254++ close_snap(handle);
255++ else
256++ CloseHandle(handle);
257++
258++ }
259++
260++ FreeLibrary(kernel);
261++ }
262++ #endif
263++
264++ rand_pool_add_end(pool, bytes_needed, 8 * bytes_needed);
265++ entropy_available = rand_pool_entropy_available(pool);
266++
267++ if (entropy_available > 0)
268++ return entropy_available;
269++ }
270++
271+ return rand_pool_entropy_available(pool);
272+ }
273+
--- branches/openssl_1_1_1_v2/libs/openssl_patch/check_patch.bat (revision 7972)
+++ branches/openssl_1_1_1_v2/libs/openssl_patch/check_patch.bat (revision 7973)
@@ -66,9 +66,22 @@
6666 popd
6767
6868
69+rem WindowsMe/NT4.0ではCryptAcquireContextWによるエントロピー取得が
70+rem できないため、新しく処理を追加する。CryptAcquireContextWの利用は残す。
6971 :patch7
72+findstr /c:"void add_RAND_buffer" ..\openssl\crypto\rand\rand_win.c
73+if ERRORLEVEL 1 goto fail7
74+goto patch8
75+:fail7
76+pushd ..
77+%folder%\patch %cmdopt1% < %folder%\CryptAcquireContextW2.txt
78+%folder%\patch %cmdopt2% < %folder%\CryptAcquireContextW2.txt
79+popd
7080
7181
82+:patch8
83+
84+
7285 :patch_end
7386 echo "パッチは適用されています"
7487 timeout 5
旧リポジトリブラウザで表示