Loweynet
リビジョン | 69719d3c17c5e3f8810a4c5f3bde56229f5127fc (tree) |
---|---|
日時 | 2012-06-02 00:24:44 |
作者 | s_kawamoto <s_kawamoto@user...> |
コミッター | s_kawamoto |
Change OpenSSL context mode flags.
@@ -39,6 +39,7 @@ typedef long (__cdecl* _SSL_get_verify_result)(const SSL*); | ||
39 | 39 | typedef SSL_SESSION* (__cdecl* _SSL_get_session)(SSL*); |
40 | 40 | typedef int (__cdecl* _SSL_set_session)(SSL*, SSL_SESSION*); |
41 | 41 | typedef X509_STORE* (__cdecl* _SSL_CTX_get_cert_store)(const SSL_CTX*); |
42 | +typedef long (__cdecl* _SSL_CTX_ctrl)(SSL_CTX*, int, long, void*); | |
42 | 43 | typedef BIO_METHOD* (__cdecl* _BIO_s_mem)(); |
43 | 44 | typedef BIO* (__cdecl* _BIO_new)(BIO_METHOD*); |
44 | 45 | typedef int (__cdecl* _BIO_free)(BIO*); |
@@ -72,6 +73,7 @@ _SSL_get_verify_result p_SSL_get_verify_result; | ||
72 | 73 | _SSL_get_session p_SSL_get_session; |
73 | 74 | _SSL_set_session p_SSL_set_session; |
74 | 75 | _SSL_CTX_get_cert_store p_SSL_CTX_get_cert_store; |
76 | +_SSL_CTX_ctrl p_SSL_CTX_ctrl; | |
75 | 77 | _BIO_s_mem p_BIO_s_mem; |
76 | 78 | _BIO_new p_BIO_new; |
77 | 79 | _BIO_free p_BIO_free; |
@@ -144,7 +146,8 @@ BOOL LoadOpenSSL() | ||
144 | 146 | || !(p_SSL_get_verify_result = (_SSL_get_verify_result)GetProcAddress(g_hOpenSSL, "SSL_get_verify_result")) |
145 | 147 | || !(p_SSL_get_session = (_SSL_get_session)GetProcAddress(g_hOpenSSL, "SSL_get_session")) |
146 | 148 | || !(p_SSL_set_session = (_SSL_set_session)GetProcAddress(g_hOpenSSL, "SSL_set_session")) |
147 | - || !(p_SSL_CTX_get_cert_store = (_SSL_CTX_get_cert_store)GetProcAddress(g_hOpenSSL, "SSL_CTX_get_cert_store"))) | |
149 | + || !(p_SSL_CTX_get_cert_store = (_SSL_CTX_get_cert_store)GetProcAddress(g_hOpenSSL, "SSL_CTX_get_cert_store")) | |
150 | + || !(p_SSL_CTX_ctrl = (_SSL_CTX_ctrl)GetProcAddress(g_hOpenSSL, "SSL_CTX_ctrl"))) | |
148 | 151 | { |
149 | 152 | if(g_hOpenSSL) |
150 | 153 | FreeLibrary(g_hOpenSSL); |
@@ -345,7 +348,10 @@ BOOL SetSSLRootCertificate(const void* pData, DWORD Length) | ||
345 | 348 | r = FALSE; |
346 | 349 | EnterCriticalSection(&g_OpenSSLLock); |
347 | 350 | if(!g_pOpenSSLCTX) |
351 | + { | |
348 | 352 | g_pOpenSSLCTX = p_SSL_CTX_new(p_SSLv23_method()); |
353 | + p_SSL_CTX_ctrl(g_pOpenSSLCTX, SSL_CTRL_MODE, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_AUTO_RETRY, NULL); | |
354 | + } | |
349 | 355 | if(g_pOpenSSLCTX) |
350 | 356 | { |
351 | 357 | if(pStore = p_SSL_CTX_get_cert_store(g_pOpenSSLCTX)) |
@@ -450,7 +456,10 @@ BOOL AttachSSL(SOCKET s, SOCKET parent, BOOL* pbAborted) | ||
450 | 456 | Time = timeGetTime(); |
451 | 457 | EnterCriticalSection(&g_OpenSSLLock); |
452 | 458 | if(!g_pOpenSSLCTX) |
459 | + { | |
453 | 460 | g_pOpenSSLCTX = p_SSL_CTX_new(p_SSLv23_method()); |
461 | + p_SSL_CTX_ctrl(g_pOpenSSLCTX, SSL_CTRL_MODE, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_AUTO_RETRY, NULL); | |
462 | + } | |
454 | 463 | if(g_pOpenSSLCTX) |
455 | 464 | { |
456 | 465 | if(ppSSL = GetUnusedSSLPointer()) |
@@ -611,6 +620,7 @@ int FTPS_closesocket(SOCKET s) | ||
611 | 620 | // send相当の関数 |
612 | 621 | int FTPS_send(SOCKET s, const char * buf, int len, int flags) |
613 | 622 | { |
623 | + int r; | |
614 | 624 | SSL** ppSSL; |
615 | 625 | if(!g_bOpenSSLLoaded) |
616 | 626 | return send(s, buf, len, flags); |
@@ -619,12 +629,16 @@ int FTPS_send(SOCKET s, const char * buf, int len, int flags) | ||
619 | 629 | LeaveCriticalSection(&g_OpenSSLLock); |
620 | 630 | if(!ppSSL) |
621 | 631 | return send(s, buf, len, flags); |
622 | - return p_SSL_write(*ppSSL, buf, len); | |
632 | + r = p_SSL_write(*ppSSL, buf, len); | |
633 | + if(r < 0) | |
634 | + return SOCKET_ERROR; | |
635 | + return r; | |
623 | 636 | } |
624 | 637 | |
625 | 638 | // recv相当の関数 |
626 | 639 | int FTPS_recv(SOCKET s, char * buf, int len, int flags) |
627 | 640 | { |
641 | + int r; | |
628 | 642 | SSL** ppSSL; |
629 | 643 | if(!g_bOpenSSLLoaded) |
630 | 644 | return recv(s, buf, len, flags); |
@@ -634,8 +648,12 @@ int FTPS_recv(SOCKET s, char * buf, int len, int flags) | ||
634 | 648 | if(!ppSSL) |
635 | 649 | return recv(s, buf, len, flags); |
636 | 650 | if(flags & MSG_PEEK) |
637 | - return p_SSL_peek(*ppSSL, buf, len); | |
638 | - return p_SSL_read(*ppSSL, buf, len); | |
651 | + r = p_SSL_peek(*ppSSL, buf, len); | |
652 | + else | |
653 | + r = p_SSL_read(*ppSSL, buf, len); | |
654 | + if(r < 0) | |
655 | + return SOCKET_ERROR; | |
656 | + return r; | |
639 | 657 | } |
640 | 658 | |
641 | 659 | // IPv6対応 |