1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

DarwinSSL: several adjustments

- Renamed st_ function prefix to darwinssl_
- Renamed Curl_st_ function prefix to Curl_darwinssl_
- Moved the duplicated ssl_connect_done out of the #ifdef in lib/urldata.h
- Fixed a teensy little bug that made non-blocking connection attempts block
- Made it so that it builds cleanly against the iOS 5.1 SDK
This commit is contained in:
Nick Zitzmann 2012-06-26 21:39:48 +02:00 committed by Yang Tse
parent f1474db360
commit 3a4b28d473
4 changed files with 71 additions and 65 deletions

View File

@ -36,6 +36,8 @@
#ifdef USE_DARWINSSL #ifdef USE_DARWINSSL
#include <Security/Security.h> #include <Security/Security.h>
#include <Security/SecureTransport.h>
#include <CoreFoundation/CoreFoundation.h>
#include "urldata.h" #include "urldata.h"
#include "sendf.h" #include "sendf.h"
#include "inet_pton.h" #include "inet_pton.h"
@ -147,8 +149,8 @@ static OSStatus SocketWrite(SSLConnectionRef connection,
return ortn; return ortn;
} }
static CURLcode st_connect_step1(struct connectdata *conn, static CURLcode darwinssl_connect_step1(struct connectdata *conn,
int sockindex) int sockindex)
{ {
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
curl_socket_t sockfd = conn->sock[sockindex]; curl_socket_t sockfd = conn->sock[sockindex];
@ -252,7 +254,7 @@ static CURLcode st_connect_step1(struct connectdata *conn,
} }
static CURLcode static CURLcode
st_connect_step2(struct connectdata *conn, int sockindex) darwinssl_connect_step2(struct connectdata *conn, int sockindex)
{ {
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex]; struct ssl_connect_data *connssl = &conn->ssl[sockindex];
@ -276,7 +278,7 @@ st_connect_step2(struct connectdata *conn, int sockindex)
case errSSLServerAuthCompleted: case errSSLServerAuthCompleted:
/* the documentation says we need to call SSLHandshake() again */ /* the documentation says we need to call SSLHandshake() again */
return st_connect_step2(conn, sockindex); return darwinssl_connect_step2(conn, sockindex);
case errSSLXCertChainInvalid: case errSSLXCertChainInvalid:
case errSSLUnknownRootCert: case errSSLUnknownRootCert:
@ -306,8 +308,8 @@ st_connect_step2(struct connectdata *conn, int sockindex)
} }
static CURLcode static CURLcode
st_connect_step3(struct connectdata *conn, darwinssl_connect_step3(struct connectdata *conn,
int sockindex) int sockindex)
{ {
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex]; struct ssl_connect_data *connssl = &conn->ssl[sockindex];
@ -344,14 +346,14 @@ st_connect_step3(struct connectdata *conn,
return CURLE_OK; return CURLE_OK;
} }
static Curl_recv st_recv; static Curl_recv darwinssl_recv;
static Curl_send st_send; static Curl_send darwinssl_send;
static CURLcode static CURLcode
st_connect_common(struct connectdata *conn, darwinssl_connect_common(struct connectdata *conn,
int sockindex, int sockindex,
bool nonblocking, bool nonblocking,
bool *done) bool *done)
{ {
CURLcode retcode; CURLcode retcode;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
@ -375,7 +377,7 @@ st_connect_common(struct connectdata *conn,
failf(data, "SSL connection timeout"); failf(data, "SSL connection timeout");
return CURLE_OPERATION_TIMEDOUT; return CURLE_OPERATION_TIMEDOUT;
} }
retcode = st_connect_step1(conn, sockindex); retcode = darwinssl_connect_step1(conn, sockindex);
if(retcode) if(retcode)
return retcode; return retcode;
} }
@ -432,26 +434,27 @@ st_connect_common(struct connectdata *conn,
* before step2 has completed while ensuring that a client using select() * before step2 has completed while ensuring that a client using select()
* or epoll() will always have a valid fdset to wait on. * or epoll() will always have a valid fdset to wait on.
*/ */
retcode = st_connect_step2(conn, sockindex); retcode = darwinssl_connect_step2(conn, sockindex);
if(retcode || (nonblocking && if(retcode || (nonblocking &&
(ssl_connect_2 == connssl->connecting_state || (ssl_connect_2 == connssl->connecting_state ||
ssl_connect_2_reading == connssl->connecting_state || ssl_connect_2_reading == connssl->connecting_state ||
ssl_connect_2_writing == connssl->connecting_state))) ssl_connect_2_writing == connssl->connecting_state ||
ssl_connect_2_wouldblock == connssl->connecting_state)))
return retcode; return retcode;
} /* repeat step2 until all transactions are done. */ } /* repeat step2 until all transactions are done. */
if(ssl_connect_3==connssl->connecting_state) { if(ssl_connect_3==connssl->connecting_state) {
retcode = st_connect_step3(conn, sockindex); retcode = darwinssl_connect_step3(conn, sockindex);
if(retcode) if(retcode)
return retcode; return retcode;
} }
if(ssl_connect_done==connssl->connecting_state) { if(ssl_connect_done==connssl->connecting_state) {
connssl->state = ssl_connection_complete; connssl->state = ssl_connection_complete;
conn->recv[sockindex] = st_recv; conn->recv[sockindex] = darwinssl_recv;
conn->send[sockindex] = st_send; conn->send[sockindex] = darwinssl_send;
*done = TRUE; *done = TRUE;
} }
else else
@ -464,21 +467,21 @@ st_connect_common(struct connectdata *conn,
} }
CURLcode CURLcode
Curl_st_connect_nonblocking(struct connectdata *conn, Curl_darwinssl_connect_nonblocking(struct connectdata *conn,
int sockindex, int sockindex,
bool *done) bool *done)
{ {
return st_connect_common(conn, sockindex, TRUE, done); return darwinssl_connect_common(conn, sockindex, TRUE, done);
} }
CURLcode CURLcode
Curl_st_connect(struct connectdata *conn, Curl_darwinssl_connect(struct connectdata *conn,
int sockindex) int sockindex)
{ {
CURLcode retcode; CURLcode retcode;
bool done = FALSE; bool done = FALSE;
retcode = st_connect_common(conn, sockindex, FALSE, &done); retcode = darwinssl_connect_common(conn, sockindex, FALSE, &done);
if(retcode) if(retcode)
return retcode; return retcode;
@ -488,7 +491,7 @@ Curl_st_connect(struct connectdata *conn,
return CURLE_OK; return CURLE_OK;
} }
void Curl_st_close(struct connectdata *conn, int sockindex) void Curl_darwinssl_close(struct connectdata *conn, int sockindex)
{ {
struct ssl_connect_data *connssl = &conn->ssl[sockindex]; struct ssl_connect_data *connssl = &conn->ssl[sockindex];
@ -498,13 +501,13 @@ void Curl_st_close(struct connectdata *conn, int sockindex)
connssl->ssl_sockfd = 0; connssl->ssl_sockfd = 0;
} }
void Curl_st_close_all(struct SessionHandle *data) void Curl_darwinssl_close_all(struct SessionHandle *data)
{ {
/* SecureTransport doesn't separate sessions from contexts, so... */ /* SecureTransport doesn't separate sessions from contexts, so... */
(void)data; (void)data;
} }
int Curl_st_shutdown(struct connectdata *conn, int sockindex) int Curl_darwinssl_shutdown(struct connectdata *conn, int sockindex)
{ {
struct ssl_connect_data *connssl = &conn->ssl[sockindex]; struct ssl_connect_data *connssl = &conn->ssl[sockindex];
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
@ -519,7 +522,7 @@ int Curl_st_shutdown(struct connectdata *conn, int sockindex)
if(data->set.ftp_ccc != CURLFTPSSL_CCC_ACTIVE) if(data->set.ftp_ccc != CURLFTPSSL_CCC_ACTIVE)
return 0; return 0;
Curl_st_close(conn, sockindex); Curl_darwinssl_close(conn, sockindex);
rc = 0; rc = 0;
@ -558,7 +561,7 @@ int Curl_st_shutdown(struct connectdata *conn, int sockindex)
return rc; return rc;
} }
size_t Curl_st_version(char *buffer, size_t size) size_t Curl_darwinssl_version(char *buffer, size_t size)
{ {
return snprintf(buffer, size, "SecureTransport"); return snprintf(buffer, size, "SecureTransport");
} }
@ -571,7 +574,7 @@ size_t Curl_st_version(char *buffer, size_t size)
* 0 means the connection has been closed * 0 means the connection has been closed
* -1 means the connection status is unknown * -1 means the connection status is unknown
*/ */
int Curl_st_check_cxn(struct connectdata *conn) int Curl_darwinssl_check_cxn(struct connectdata *conn)
{ {
struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET]; struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET];
OSStatus err; OSStatus err;
@ -586,7 +589,8 @@ int Curl_st_check_cxn(struct connectdata *conn)
return 0; return 0;
} }
bool Curl_st_data_pending(const struct connectdata *conn, int connindex) bool Curl_darwinssl_data_pending(const struct connectdata *conn,
int connindex)
{ {
const struct ssl_connect_data *connssl = &conn->ssl[connindex]; const struct ssl_connect_data *connssl = &conn->ssl[connindex];
OSStatus err; OSStatus err;
@ -602,11 +606,11 @@ bool Curl_st_data_pending(const struct connectdata *conn, int connindex)
return false; return false;
} }
static ssize_t st_send(struct connectdata *conn, static ssize_t darwinssl_send(struct connectdata *conn,
int sockindex, int sockindex,
const void *mem, const void *mem,
size_t len, size_t len,
CURLcode *curlcode) CURLcode *curlcode)
{ {
/*struct SessionHandle *data = conn->data;*/ /*struct SessionHandle *data = conn->data;*/
struct ssl_connect_data *connssl = &conn->ssl[sockindex]; struct ssl_connect_data *connssl = &conn->ssl[sockindex];
@ -630,11 +634,11 @@ static ssize_t st_send(struct connectdata *conn,
return (ssize_t)processed; return (ssize_t)processed;
} }
static ssize_t st_recv(struct connectdata *conn, /* connection data */ static ssize_t darwinssl_recv(struct connectdata *conn,
int num, /* socketindex */ int num,
char *buf, /* store read data here */ char *buf,
size_t buffersize, /* max amount to read */ size_t buffersize,
CURLcode *curlcode) CURLcode *curlcode)
{ {
/*struct SessionHandle *data = conn->data;*/ /*struct SessionHandle *data = conn->data;*/
struct ssl_connect_data *connssl = &conn->ssl[num]; struct ssl_connect_data *connssl = &conn->ssl[num];

View File

@ -25,38 +25,39 @@
#ifdef USE_DARWINSSL #ifdef USE_DARWINSSL
CURLcode Curl_st_connect(struct connectdata *conn, int sockindex); CURLcode Curl_darwinssl_connect(struct connectdata *conn, int sockindex);
CURLcode Curl_st_connect_nonblocking(struct connectdata *conn, CURLcode Curl_darwinssl_connect_nonblocking(struct connectdata *conn,
int sockindex, int sockindex,
bool *done); bool *done);
/* this function doesn't actually do anything */ /* this function doesn't actually do anything */
void Curl_st_close_all(struct SessionHandle *data); void Curl_darwinssl_close_all(struct SessionHandle *data);
/* close a SSL connection */ /* close a SSL connection */
void Curl_st_close(struct connectdata *conn, int sockindex); void Curl_darwinssl_close(struct connectdata *conn, int sockindex);
size_t Curl_st_version(char *buffer, size_t size); size_t Curl_darwinssl_version(char *buffer, size_t size);
int Curl_st_shutdown(struct connectdata *conn, int sockindex); int Curl_darwinssl_shutdown(struct connectdata *conn, int sockindex);
int Curl_st_check_cxn(struct connectdata *conn); int Curl_darwinssl_check_cxn(struct connectdata *conn);
bool Curl_st_data_pending(const struct connectdata *conn, int connindex); bool Curl_darwinssl_data_pending(const struct connectdata *conn,
int connindex);
/* API setup for SecureTransport */ /* API setup for SecureTransport */
#define curlssl_init() (1) #define curlssl_init() (1)
#define curlssl_cleanup() Curl_nop_stmt #define curlssl_cleanup() Curl_nop_stmt
#define curlssl_connect Curl_st_connect #define curlssl_connect Curl_darwinssl_connect
#define curlssl_connect_nonblocking Curl_st_connect_nonblocking #define curlssl_connect_nonblocking Curl_darwinssl_connect_nonblocking
#define curlssl_session_free(x) Curl_nop_stmt #define curlssl_session_free(x) Curl_nop_stmt
#define curlssl_close_all Curl_st_close_all #define curlssl_close_all Curl_darwinssl_close_all
#define curlssl_close Curl_st_close #define curlssl_close Curl_darwinssl_close
#define curlssl_shutdown(x,y) 0 #define curlssl_shutdown(x,y) 0
#define curlssl_set_engine(x,y) (x=x, y=y, CURLE_NOT_BUILT_IN) #define curlssl_set_engine(x,y) (x=x, y=y, CURLE_NOT_BUILT_IN)
#define curlssl_set_engine_default(x) (x=x, CURLE_NOT_BUILT_IN) #define curlssl_set_engine_default(x) (x=x, CURLE_NOT_BUILT_IN)
#define curlssl_engines_list(x) (x=x, (struct curl_slist *)NULL) #define curlssl_engines_list(x) (x=x, (struct curl_slist *)NULL)
#define curlssl_version Curl_st_version #define curlssl_version Curl_darwinssl_version
#define curlssl_check_cxn Curl_st_check_cxn #define curlssl_check_cxn Curl_darwinssl_check_cxn
#define curlssl_data_pending(x,y) Curl_st_data_pending(x, y) #define curlssl_data_pending(x,y) Curl_darwinssl_data_pending(x, y)
#endif /* USE_DARWINSSL */ #endif /* USE_DARWINSSL */
#endif /* HEADER_CURL_DARWINSSL_H */ #endif /* HEADER_CURL_DARWINSSL_H */

View File

@ -34,7 +34,7 @@
Curl_polarssl_ - prefix for PolarSSL ones Curl_polarssl_ - prefix for PolarSSL ones
Curl_cyassl_ - prefix for CyaSSL ones Curl_cyassl_ - prefix for CyaSSL ones
Curl_schannel_ - prefix for Schannel SSPI ones Curl_schannel_ - prefix for Schannel SSPI ones
Curl_st_ - prefix for SecureTransport (Darwin) ones Curl_darwinssl_ - prefix for SecureTransport (Darwin) ones
Note that this source code uses curlssl_* functions, and they are all Note that this source code uses curlssl_* functions, and they are all
defines/macros #defined by the lib-specific header files. defines/macros #defined by the lib-specific header files.

View File

@ -141,6 +141,9 @@
#ifdef USE_DARWINSSL #ifdef USE_DARWINSSL
#include <Security/Security.h> #include <Security/Security.h>
/* For some reason, when building for iOS, the omnibus header above does
* not include SecureTransport.h as of iOS SDK 5.1. */
#include <Security/SecureTransport.h>
#endif #endif
#ifdef HAVE_NETINET_IN_H #ifdef HAVE_NETINET_IN_H
@ -245,13 +248,11 @@ typedef enum {
ssl_connect_2, ssl_connect_2,
ssl_connect_2_reading, ssl_connect_2_reading,
ssl_connect_2_writing, ssl_connect_2_writing,
ssl_connect_3,
#ifdef USE_DARWINSSL #ifdef USE_DARWINSSL
ssl_connect_done, ssl_connect_2_wouldblock,
ssl_connect_2_wouldblock
#else
ssl_connect_done
#endif /* USE_DARWINSSL */ #endif /* USE_DARWINSSL */
ssl_connect_3,
ssl_connect_done
} ssl_connect_state; } ssl_connect_state;
typedef enum { typedef enum {