OSDN Git Service

Change OpenSSL context mode flags.
authors_kawamoto <s_kawamoto@users.sourceforge.jp>
Fri, 1 Jun 2012 15:24:44 +0000 (00:24 +0900)
committers_kawamoto <s_kawamoto@users.sourceforge.jp>
Fri, 1 Jun 2012 15:24:44 +0000 (00:24 +0900)
FFFTP_Eng_Release/FFFTP.exe
Release/FFFTP.exe
socketwrapper.c

index 2520f75..cff0ced 100644 (file)
Binary files a/FFFTP_Eng_Release/FFFTP.exe and b/FFFTP_Eng_Release/FFFTP.exe differ
index 56b1c17..c7f1781 100644 (file)
Binary files a/Release/FFFTP.exe and b/Release/FFFTP.exe differ
index 0c1be4a..6090cc2 100644 (file)
@@ -39,6 +39,7 @@ typedef long (__cdecl* _SSL_get_verify_result)(const SSL*);
 typedef SSL_SESSION* (__cdecl* _SSL_get_session)(SSL*);\r
 typedef int (__cdecl* _SSL_set_session)(SSL*, SSL_SESSION*);\r
 typedef X509_STORE* (__cdecl* _SSL_CTX_get_cert_store)(const SSL_CTX*);\r
 typedef SSL_SESSION* (__cdecl* _SSL_get_session)(SSL*);\r
 typedef int (__cdecl* _SSL_set_session)(SSL*, SSL_SESSION*);\r
 typedef X509_STORE* (__cdecl* _SSL_CTX_get_cert_store)(const SSL_CTX*);\r
+typedef long (__cdecl* _SSL_CTX_ctrl)(SSL_CTX*, int, long, void*);\r
 typedef BIO_METHOD* (__cdecl* _BIO_s_mem)();\r
 typedef BIO* (__cdecl* _BIO_new)(BIO_METHOD*);\r
 typedef int (__cdecl* _BIO_free)(BIO*);\r
 typedef BIO_METHOD* (__cdecl* _BIO_s_mem)();\r
 typedef BIO* (__cdecl* _BIO_new)(BIO_METHOD*);\r
 typedef int (__cdecl* _BIO_free)(BIO*);\r
@@ -72,6 +73,7 @@ _SSL_get_verify_result p_SSL_get_verify_result;
 _SSL_get_session p_SSL_get_session;\r
 _SSL_set_session p_SSL_set_session;\r
 _SSL_CTX_get_cert_store p_SSL_CTX_get_cert_store;\r
 _SSL_get_session p_SSL_get_session;\r
 _SSL_set_session p_SSL_set_session;\r
 _SSL_CTX_get_cert_store p_SSL_CTX_get_cert_store;\r
+_SSL_CTX_ctrl p_SSL_CTX_ctrl;\r
 _BIO_s_mem p_BIO_s_mem;\r
 _BIO_new p_BIO_new;\r
 _BIO_free p_BIO_free;\r
 _BIO_s_mem p_BIO_s_mem;\r
 _BIO_new p_BIO_new;\r
 _BIO_free p_BIO_free;\r
@@ -144,7 +146,8 @@ BOOL LoadOpenSSL()
                || !(p_SSL_get_verify_result = (_SSL_get_verify_result)GetProcAddress(g_hOpenSSL, "SSL_get_verify_result"))\r
                || !(p_SSL_get_session = (_SSL_get_session)GetProcAddress(g_hOpenSSL, "SSL_get_session"))\r
                || !(p_SSL_set_session = (_SSL_set_session)GetProcAddress(g_hOpenSSL, "SSL_set_session"))\r
                || !(p_SSL_get_verify_result = (_SSL_get_verify_result)GetProcAddress(g_hOpenSSL, "SSL_get_verify_result"))\r
                || !(p_SSL_get_session = (_SSL_get_session)GetProcAddress(g_hOpenSSL, "SSL_get_session"))\r
                || !(p_SSL_set_session = (_SSL_set_session)GetProcAddress(g_hOpenSSL, "SSL_set_session"))\r
-               || !(p_SSL_CTX_get_cert_store = (_SSL_CTX_get_cert_store)GetProcAddress(g_hOpenSSL, "SSL_CTX_get_cert_store")))\r
+               || !(p_SSL_CTX_get_cert_store = (_SSL_CTX_get_cert_store)GetProcAddress(g_hOpenSSL, "SSL_CTX_get_cert_store"))\r
+               || !(p_SSL_CTX_ctrl = (_SSL_CTX_ctrl)GetProcAddress(g_hOpenSSL, "SSL_CTX_ctrl")))\r
        {\r
                if(g_hOpenSSL)\r
                        FreeLibrary(g_hOpenSSL);\r
        {\r
                if(g_hOpenSSL)\r
                        FreeLibrary(g_hOpenSSL);\r
@@ -345,7 +348,10 @@ BOOL SetSSLRootCertificate(const void* pData, DWORD Length)
        r = FALSE;\r
        EnterCriticalSection(&g_OpenSSLLock);\r
        if(!g_pOpenSSLCTX)\r
        r = FALSE;\r
        EnterCriticalSection(&g_OpenSSLLock);\r
        if(!g_pOpenSSLCTX)\r
+       {\r
                g_pOpenSSLCTX = p_SSL_CTX_new(p_SSLv23_method());\r
                g_pOpenSSLCTX = p_SSL_CTX_new(p_SSLv23_method());\r
+               p_SSL_CTX_ctrl(g_pOpenSSLCTX, SSL_CTRL_MODE, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_AUTO_RETRY, NULL);\r
+       }\r
        if(g_pOpenSSLCTX)\r
        {\r
                if(pStore = p_SSL_CTX_get_cert_store(g_pOpenSSLCTX))\r
        if(g_pOpenSSLCTX)\r
        {\r
                if(pStore = p_SSL_CTX_get_cert_store(g_pOpenSSLCTX))\r
@@ -450,7 +456,10 @@ BOOL AttachSSL(SOCKET s, SOCKET parent, BOOL* pbAborted)
        Time = timeGetTime();\r
        EnterCriticalSection(&g_OpenSSLLock);\r
        if(!g_pOpenSSLCTX)\r
        Time = timeGetTime();\r
        EnterCriticalSection(&g_OpenSSLLock);\r
        if(!g_pOpenSSLCTX)\r
+       {\r
                g_pOpenSSLCTX = p_SSL_CTX_new(p_SSLv23_method());\r
                g_pOpenSSLCTX = p_SSL_CTX_new(p_SSLv23_method());\r
+               p_SSL_CTX_ctrl(g_pOpenSSLCTX, SSL_CTRL_MODE, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_AUTO_RETRY, NULL);\r
+       }\r
        if(g_pOpenSSLCTX)\r
        {\r
                if(ppSSL = GetUnusedSSLPointer())\r
        if(g_pOpenSSLCTX)\r
        {\r
                if(ppSSL = GetUnusedSSLPointer())\r
@@ -611,6 +620,7 @@ int FTPS_closesocket(SOCKET s)
 // send相当の関数\r
 int FTPS_send(SOCKET s, const char * buf, int len, int flags)\r
 {\r
 // send相当の関数\r
 int FTPS_send(SOCKET s, const char * buf, int len, int flags)\r
 {\r
+       int r;\r
        SSL** ppSSL;\r
        if(!g_bOpenSSLLoaded)\r
                return send(s, buf, len, flags);\r
        SSL** ppSSL;\r
        if(!g_bOpenSSLLoaded)\r
                return send(s, buf, len, flags);\r
@@ -619,12 +629,16 @@ int FTPS_send(SOCKET s, const char * buf, int len, int flags)
        LeaveCriticalSection(&g_OpenSSLLock);\r
        if(!ppSSL)\r
                return send(s, buf, len, flags);\r
        LeaveCriticalSection(&g_OpenSSLLock);\r
        if(!ppSSL)\r
                return send(s, buf, len, flags);\r
-       return p_SSL_write(*ppSSL, buf, len);\r
+       r = p_SSL_write(*ppSSL, buf, len);\r
+       if(r < 0)\r
+               return SOCKET_ERROR;\r
+       return r;\r
 }\r
 \r
 // recv相当の関数\r
 int FTPS_recv(SOCKET s, char * buf, int len, int flags)\r
 {\r
 }\r
 \r
 // recv相当の関数\r
 int FTPS_recv(SOCKET s, char * buf, int len, int flags)\r
 {\r
+       int r;\r
        SSL** ppSSL;\r
        if(!g_bOpenSSLLoaded)\r
                return recv(s, buf, len, flags);\r
        SSL** ppSSL;\r
        if(!g_bOpenSSLLoaded)\r
                return recv(s, buf, len, flags);\r
@@ -634,8 +648,12 @@ int FTPS_recv(SOCKET s, char * buf, int len, int flags)
        if(!ppSSL)\r
                return recv(s, buf, len, flags);\r
        if(flags & MSG_PEEK)\r
        if(!ppSSL)\r
                return recv(s, buf, len, flags);\r
        if(flags & MSG_PEEK)\r
-               return p_SSL_peek(*ppSSL, buf, len);\r
-       return p_SSL_read(*ppSSL, buf, len);\r
+               r = p_SSL_peek(*ppSSL, buf, len);\r
+       else\r
+               r = p_SSL_read(*ppSSL, buf, len);\r
+       if(r < 0)\r
+               return SOCKET_ERROR;\r
+       return r;\r
 }\r
 \r
 // IPv6対応\r
 }\r
 \r
 // IPv6対応\r