SSL doesn't need to use a different socket to unsecure communications.

This commit is contained in:
Robert Shearman 2005-11-15 12:01:40 +00:00 committed by Alexandre Julliard
parent 17cbf1cbca
commit 5b1fd2e58e
2 changed files with 40 additions and 70 deletions

View File

@ -61,7 +61,6 @@ typedef struct
int socketFD; int socketFD;
#ifdef HAVE_OPENSSL_SSL_H #ifdef HAVE_OPENSSL_SSL_H
SSL *ssl_s; SSL *ssl_s;
int ssl_sock;
char *peek_msg; char *peek_msg;
char *peek_msg_mem; char *peek_msg_mem;
#endif #endif

View File

@ -102,7 +102,6 @@ void NETCON_init(WININET_NETCONNECTION *connection, BOOL useSSL)
{ {
#ifdef HAVE_OPENSSL_SSL_H #ifdef HAVE_OPENSSL_SSL_H
TRACE("using SSL connection\n"); TRACE("using SSL connection\n");
connection->ssl_sock = -1;
if (OpenSSL_ssl_handle) /* already initilzed everything */ if (OpenSSL_ssl_handle) /* already initilzed everything */
return; return;
OpenSSL_ssl_handle = wine_dlopen(SONAME_LIBSSL, RTLD_NOW, NULL, 0); OpenSSL_ssl_handle = wine_dlopen(SONAME_LIBSSL, RTLD_NOW, NULL, 0);
@ -174,22 +173,10 @@ void NETCON_init(WININET_NETCONNECTION *connection, BOOL useSSL)
BOOL NETCON_connected(WININET_NETCONNECTION *connection) BOOL NETCON_connected(WININET_NETCONNECTION *connection)
{ {
if (!connection->useSSL) if (connection->socketFD == -1)
{ return FALSE;
if (connection->socketFD == -1)
return FALSE;
return TRUE;
}
else else
{
#ifdef HAVE_OPENSSL_SSL_H
if (connection->ssl_sock == -1)
return FALSE;
return TRUE; return TRUE;
#else
return FALSE;
#endif
}
} }
/****************************************************************************** /******************************************************************************
@ -200,22 +187,15 @@ BOOL NETCON_connected(WININET_NETCONNECTION *connection)
BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain, BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
int type, int protocol) int type, int protocol)
{ {
if (!connection->useSSL) #ifndef HAVE_OPENSSL_SSL_H
{ if (connection->useSSL)
connection->socketFD = socket(domain, type, protocol); return FALSE;
if (connection->socketFD == -1)
return FALSE;
return TRUE;
}
else
{
#ifdef HAVE_OPENSSL_SSL_H
connection->ssl_sock = socket(domain, type, protocol);
return TRUE;
#else
return FALSE;
#endif #endif
}
connection->socketFD = socket(domain, type, protocol);
if (connection->socketFD == -1)
return FALSE;
return TRUE;
} }
/****************************************************************************** /******************************************************************************
@ -224,31 +204,27 @@ BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
*/ */
BOOL NETCON_close(WININET_NETCONNECTION *connection) BOOL NETCON_close(WININET_NETCONNECTION *connection)
{ {
int result;
if (!NETCON_connected(connection)) return FALSE; if (!NETCON_connected(connection)) return FALSE;
if (!connection->useSSL)
{ result = closesocket(connection->socketFD);
int result; connection->socketFD = -1;
result = closesocket(connection->socketFD);
connection->socketFD = -1;
if (result == -1)
return FALSE;
return TRUE;
}
else
{
#ifdef HAVE_OPENSSL_SSL_H #ifdef HAVE_OPENSSL_SSL_H
closesocket(connection->ssl_sock); if (connection->useSSL)
connection->ssl_sock = -1; {
HeapFree(GetProcessHeap(),0,connection->peek_msg_mem); HeapFree(GetProcessHeap(),0,connection->peek_msg_mem);
connection->peek_msg = NULL; connection->peek_msg = NULL;
connection->peek_msg_mem = NULL; connection->peek_msg_mem = NULL;
/* FIXME should we call SSL_shutdown here?? Probably on whatever is the /* FIXME should we call SSL_shutdown here?? Probably on whatever is the
* opposite of NETCON_init.... */ * opposite of NETCON_init.... */
return TRUE;
#else
return FALSE;
#endif
} }
#endif
if (result == -1)
return FALSE;
return TRUE;
} }
/****************************************************************************** /******************************************************************************
@ -258,42 +234,37 @@ BOOL NETCON_close(WININET_NETCONNECTION *connection)
BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr, BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
unsigned int addrlen) unsigned int addrlen)
{ {
int result;
if (!NETCON_connected(connection)) return FALSE; if (!NETCON_connected(connection)) return FALSE;
if (!connection->useSSL)
result = connect(connection->socketFD, serv_addr, addrlen);
if (result == -1)
{ {
int result; closesocket(connection->socketFD);
result = connect(connection->socketFD, serv_addr, addrlen); connection->socketFD = -1;
if (result == -1) return FALSE;
{
closesocket(connection->socketFD);
connection->socketFD = -1;
return FALSE;
}
return TRUE;
} }
else
{
#ifdef HAVE_OPENSSL_SSL_H #ifdef HAVE_OPENSSL_SSL_H
if (connection->useSSL)
{
BIO *sbio; BIO *sbio;
ctx = pSSL_CTX_new(meth); ctx = pSSL_CTX_new(meth);
connection->ssl_s = pSSL_new(ctx); connection->ssl_s = pSSL_new(ctx);
if (connect(connection->ssl_sock, serv_addr, addrlen) == -1) sbio = pBIO_new_socket(connection->socketFD, BIO_NOCLOSE);
return FALSE;
sbio = pBIO_new_socket(connection->ssl_sock, BIO_NOCLOSE);
pSSL_set_bio(connection->ssl_s, sbio, sbio); pSSL_set_bio(connection->ssl_s, sbio, sbio);
if (pSSL_connect(connection->ssl_s) <= 0) if (pSSL_connect(connection->ssl_s) <= 0)
{ {
ERR("ssl couldn't connect\n"); ERR("ssl couldn't connect\n");
return FALSE; return FALSE;
} }
return TRUE;
#else
return FALSE;
#endif
} }
#endif
return TRUE;
} }
/****************************************************************************** /******************************************************************************