2005-04-07 11:27:13 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2009-02-25 07:51:39 -05:00
|
|
|
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2005-04-07 11:27:13 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
***************************************************************************/
|
|
|
|
|
2009-02-25 07:51:39 -05:00
|
|
|
/* This file is for implementing all "generic" SSL functions that all libcurl
|
|
|
|
internals should use. It is then responsible for calling the proper
|
|
|
|
"backend" function.
|
2005-04-07 11:27:13 -04:00
|
|
|
|
|
|
|
SSL-functions in libcurl should call functions in this source file, and not
|
|
|
|
to any specific SSL-layer.
|
|
|
|
|
|
|
|
Curl_ssl_ - prefix for generic ones
|
|
|
|
Curl_ossl_ - prefix for OpenSSL ones
|
|
|
|
Curl_gtls_ - prefix for GnuTLS ones
|
2007-02-12 17:32:37 -05:00
|
|
|
Curl_nss_ - prefix for NSS ones
|
2005-04-07 11:27:13 -04:00
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
Note that this source code uses curlssl_* functions, and they are all
|
|
|
|
defines/macros #defined by the lib-specific header files.
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
"SSL/TLS Strong Encryption: An Introduction"
|
|
|
|
http://httpd.apache.org/docs-2.0/ssl/ssl_intro.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "setup.h"
|
2007-02-25 23:24:26 -05:00
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "urldata.h"
|
|
|
|
#define SSLGEN_C
|
|
|
|
#include "sslgen.h" /* generic SSL protos etc */
|
|
|
|
#include "ssluse.h" /* OpenSSL versions */
|
|
|
|
#include "gtls.h" /* GnuTLS versions */
|
2007-02-12 17:32:37 -05:00
|
|
|
#include "nssg.h" /* NSS versions */
|
2007-07-23 17:46:26 -04:00
|
|
|
#include "qssl.h" /* QSOSSL versions */
|
2005-04-07 11:27:13 -04:00
|
|
|
#include "sendf.h"
|
2008-10-23 07:49:19 -04:00
|
|
|
#include "rawstr.h"
|
2005-04-07 11:27:13 -04:00
|
|
|
#include "url.h"
|
2009-04-21 07:46:16 -04:00
|
|
|
#include "curl_memory.h"
|
2008-07-03 02:56:03 -04:00
|
|
|
#include "progress.h"
|
2005-04-07 11:27:13 -04:00
|
|
|
/* The last #include file should be: */
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
|
|
|
static bool safe_strequal(char* str1, char* str2)
|
|
|
|
{
|
|
|
|
if(str1 && str2)
|
|
|
|
/* both pointers point to something then compare them */
|
2008-10-23 07:49:19 -04:00
|
|
|
return (bool)(0 != Curl_raw_equal(str1, str2));
|
2005-04-07 11:27:13 -04:00
|
|
|
else
|
|
|
|
/* if both pointers are NULL then treat them as equal */
|
2006-09-12 19:51:01 -04:00
|
|
|
return (bool)(!str1 && !str2);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Curl_ssl_config_matches(struct ssl_config_data* data,
|
|
|
|
struct ssl_config_data* needle)
|
|
|
|
{
|
|
|
|
if((data->version == needle->version) &&
|
|
|
|
(data->verifypeer == needle->verifypeer) &&
|
|
|
|
(data->verifyhost == needle->verifyhost) &&
|
|
|
|
safe_strequal(data->CApath, needle->CApath) &&
|
|
|
|
safe_strequal(data->CAfile, needle->CAfile) &&
|
|
|
|
safe_strequal(data->random_file, needle->random_file) &&
|
|
|
|
safe_strequal(data->egdsocket, needle->egdsocket) &&
|
|
|
|
safe_strequal(data->cipher_list, needle->cipher_list))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Curl_clone_ssl_config(struct ssl_config_data *source,
|
|
|
|
struct ssl_config_data *dest)
|
|
|
|
{
|
2007-12-03 06:48:09 -05:00
|
|
|
dest->sessionid = source->sessionid;
|
2005-04-07 11:27:13 -04:00
|
|
|
dest->verifyhost = source->verifyhost;
|
|
|
|
dest->verifypeer = source->verifypeer;
|
|
|
|
dest->version = source->version;
|
|
|
|
|
|
|
|
if(source->CAfile) {
|
|
|
|
dest->CAfile = strdup(source->CAfile);
|
|
|
|
if(!dest->CAfile)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(source->CApath) {
|
|
|
|
dest->CApath = strdup(source->CApath);
|
|
|
|
if(!dest->CApath)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(source->cipher_list) {
|
|
|
|
dest->cipher_list = strdup(source->cipher_list);
|
|
|
|
if(!dest->cipher_list)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(source->egdsocket) {
|
|
|
|
dest->egdsocket = strdup(source->egdsocket);
|
|
|
|
if(!dest->egdsocket)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(source->random_file) {
|
|
|
|
dest->random_file = strdup(source->random_file);
|
|
|
|
if(!dest->random_file)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Curl_free_ssl_config(struct ssl_config_data* sslc)
|
|
|
|
{
|
2007-08-01 17:20:01 -04:00
|
|
|
Curl_safefree(sslc->CAfile);
|
|
|
|
Curl_safefree(sslc->CApath);
|
|
|
|
Curl_safefree(sslc->cipher_list);
|
|
|
|
Curl_safefree(sslc->egdsocket);
|
|
|
|
Curl_safefree(sslc->random_file);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
#ifdef USE_SSL
|
|
|
|
|
|
|
|
/* "global" init done? */
|
|
|
|
static bool init_ssl=FALSE;
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
/**
|
|
|
|
* Global SSL init
|
|
|
|
*
|
|
|
|
* @retval 0 error initializing SSL
|
|
|
|
* @retval 1 SSL initialized successfully
|
|
|
|
*/
|
|
|
|
int Curl_ssl_init(void)
|
|
|
|
{
|
|
|
|
/* make sure this is only done once */
|
|
|
|
if(init_ssl)
|
|
|
|
return 1;
|
|
|
|
init_ssl = TRUE; /* never again */
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_init();
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Global cleanup */
|
|
|
|
void Curl_ssl_cleanup(void)
|
|
|
|
{
|
|
|
|
if(init_ssl) {
|
|
|
|
/* only cleanup if we did a previous init */
|
2008-06-11 13:01:58 -04:00
|
|
|
curlssl_cleanup();
|
2005-04-07 11:27:13 -04:00
|
|
|
init_ssl = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode
|
|
|
|
Curl_ssl_connect(struct connectdata *conn, int sockindex)
|
|
|
|
{
|
2008-07-03 02:56:03 -04:00
|
|
|
CURLcode res;
|
2008-06-11 13:01:58 -04:00
|
|
|
/* mark this is being ssl-enabled from here on. */
|
2005-04-07 11:27:13 -04:00
|
|
|
conn->ssl[sockindex].use = TRUE;
|
2008-02-20 04:56:26 -05:00
|
|
|
conn->ssl[sockindex].state = ssl_connection_negotiating;
|
2005-04-07 11:27:13 -04:00
|
|
|
|
2008-07-03 02:56:03 -04:00
|
|
|
res = curlssl_connect(conn, sockindex);
|
|
|
|
|
|
|
|
if(!res)
|
|
|
|
Curl_pgrsTime(conn->data, TIMER_APPCONNECT); /* SSL is connected */
|
|
|
|
|
|
|
|
return res;
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2006-03-21 16:54:44 -05:00
|
|
|
CURLcode
|
|
|
|
Curl_ssl_connect_nonblocking(struct connectdata *conn, int sockindex,
|
|
|
|
bool *done)
|
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
#ifdef curlssl_connect_nonblocking
|
2009-04-26 07:56:22 -04:00
|
|
|
CURLcode res;
|
2008-06-11 13:01:58 -04:00
|
|
|
/* mark this is being ssl requested from here on. */
|
2006-03-21 16:54:44 -05:00
|
|
|
conn->ssl[sockindex].use = TRUE;
|
2009-04-26 07:56:22 -04:00
|
|
|
res = curlssl_connect_nonblocking(conn, sockindex, done);
|
|
|
|
if(!res && *done == TRUE)
|
|
|
|
Curl_pgrsTime(conn->data, TIMER_APPCONNECT); /* SSL is connected */
|
|
|
|
return res;
|
2007-07-23 17:46:26 -04:00
|
|
|
#else
|
|
|
|
*done = TRUE; /* fallback to BLOCKING */
|
2007-11-19 04:24:24 -05:00
|
|
|
conn->ssl[sockindex].use = TRUE;
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_connect(conn, sockindex);
|
|
|
|
#endif /* non-blocking connect support */
|
2006-03-21 16:54:44 -05:00
|
|
|
}
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
/*
|
|
|
|
* Check if there's a session ID for the given connection in the cache, and if
|
|
|
|
* there's one suitable, it is provided. Returns TRUE when no entry matched.
|
|
|
|
*/
|
|
|
|
int Curl_ssl_getsessionid(struct connectdata *conn,
|
|
|
|
void **ssl_sessionid,
|
|
|
|
size_t *idsize) /* set 0 if unknown */
|
|
|
|
{
|
|
|
|
struct curl_ssl_session *check;
|
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
long i;
|
|
|
|
|
2006-09-11 13:18:18 -04:00
|
|
|
if(!conn->ssl_config.sessionid)
|
|
|
|
/* session ID re-use is disabled */
|
|
|
|
return TRUE;
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
for(i=0; i< data->set.ssl.numsessions; i++) {
|
|
|
|
check = &data->state.session[i];
|
|
|
|
if(!check->sessionid)
|
|
|
|
/* not session ID means blank entry */
|
|
|
|
continue;
|
2008-10-22 21:20:57 -04:00
|
|
|
if(Curl_raw_equal(conn->host.name, check->name) &&
|
2005-04-07 11:27:13 -04:00
|
|
|
(conn->remote_port == check->remote_port) &&
|
|
|
|
Curl_ssl_config_matches(&conn->ssl_config, &check->ssl_config)) {
|
|
|
|
/* yes, we have a session ID! */
|
|
|
|
data->state.sessionage++; /* increase general age */
|
|
|
|
check->age = data->state.sessionage; /* set this as used in this age */
|
|
|
|
*ssl_sessionid = check->sessionid;
|
|
|
|
if(idsize)
|
|
|
|
*idsize = check->idsize;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ssl_sessionid = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kill a single session ID entry in the cache.
|
|
|
|
*/
|
|
|
|
static int kill_session(struct curl_ssl_session *session)
|
|
|
|
{
|
|
|
|
if(session->sessionid) {
|
|
|
|
/* defensive check */
|
|
|
|
|
|
|
|
/* free the ID the SSL-layer specific way */
|
2008-06-11 13:01:58 -04:00
|
|
|
curlssl_session_free(session->sessionid);
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
session->sessionid=NULL;
|
|
|
|
session->age = 0; /* fresh */
|
|
|
|
|
|
|
|
Curl_free_ssl_config(&session->ssl_config);
|
|
|
|
|
|
|
|
Curl_safefree(session->name);
|
|
|
|
session->name = NULL; /* no name */
|
|
|
|
|
|
|
|
return 0; /* ok */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-04 17:57:14 -04:00
|
|
|
/*
|
|
|
|
* Delete the given session ID from the cache.
|
|
|
|
*/
|
|
|
|
void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0; i< conn->data->set.ssl.numsessions; i++) {
|
|
|
|
struct curl_ssl_session *check = &conn->data->state.session[i];
|
|
|
|
|
|
|
|
if (check->sessionid == ssl_sessionid) {
|
|
|
|
kill_session(check);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
/*
|
|
|
|
* Store session id in the session cache. The ID passed on to this function
|
|
|
|
* must already have been extracted and allocated the proper way for the SSL
|
|
|
|
* layer. Curl_XXXX_session_free() will be called to free/kill the session ID
|
|
|
|
* later on.
|
|
|
|
*/
|
|
|
|
CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
|
|
|
|
void *ssl_sessionid,
|
|
|
|
size_t idsize)
|
|
|
|
{
|
2007-08-27 02:31:28 -04:00
|
|
|
long i;
|
2005-04-07 11:27:13 -04:00
|
|
|
struct SessionHandle *data=conn->data; /* the mother of all structs */
|
|
|
|
struct curl_ssl_session *store = &data->state.session[0];
|
|
|
|
long oldest_age=data->state.session[0].age; /* zero if unused */
|
|
|
|
char *clone_host;
|
|
|
|
|
2006-09-11 13:18:18 -04:00
|
|
|
/* Even though session ID re-use might be disabled, that only disables USING
|
|
|
|
IT. We still store it here in case the re-using is again enabled for an
|
|
|
|
upcoming transfer */
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
clone_host = strdup(conn->host.name);
|
|
|
|
if(!clone_host)
|
|
|
|
return CURLE_OUT_OF_MEMORY; /* bail out */
|
|
|
|
|
|
|
|
/* Now we should add the session ID and the host name to the cache, (remove
|
|
|
|
the oldest if necessary) */
|
|
|
|
|
|
|
|
/* find an empty slot for us, or find the oldest */
|
|
|
|
for(i=1; (i<data->set.ssl.numsessions) &&
|
|
|
|
data->state.session[i].sessionid; i++) {
|
|
|
|
if(data->state.session[i].age < oldest_age) {
|
|
|
|
oldest_age = data->state.session[i].age;
|
|
|
|
store = &data->state.session[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(i == data->set.ssl.numsessions)
|
|
|
|
/* cache is full, we must "kill" the oldest entry! */
|
|
|
|
kill_session(store);
|
|
|
|
else
|
|
|
|
store = &data->state.session[i]; /* use this slot */
|
|
|
|
|
|
|
|
/* now init the session struct wisely */
|
|
|
|
store->sessionid = ssl_sessionid;
|
|
|
|
store->idsize = idsize;
|
|
|
|
store->age = data->state.sessionage; /* set current age */
|
2007-12-24 18:45:48 -05:00
|
|
|
if (store->name)
|
|
|
|
/* free it if there's one already present */
|
2007-12-25 08:26:01 -05:00
|
|
|
free(store->name);
|
2005-04-07 11:27:13 -04:00
|
|
|
store->name = clone_host; /* clone host name */
|
|
|
|
store->remote_port = conn->remote_port; /* port number */
|
|
|
|
|
2007-11-07 04:21:35 -05:00
|
|
|
if(!Curl_clone_ssl_config(&conn->ssl_config, &store->ssl_config))
|
2005-04-07 11:27:13 -04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Curl_ssl_close_all(struct SessionHandle *data)
|
|
|
|
{
|
2007-08-27 02:31:28 -04:00
|
|
|
long i;
|
2005-04-07 11:27:13 -04:00
|
|
|
/* kill the session ID cache */
|
|
|
|
if(data->state.session) {
|
|
|
|
for(i=0; i< data->set.ssl.numsessions; i++)
|
|
|
|
/* the single-killer function handles empty table slots */
|
|
|
|
kill_session(&data->state.session[i]);
|
|
|
|
|
|
|
|
/* free the cache data */
|
|
|
|
free(data->state.session);
|
|
|
|
data->state.session = NULL;
|
|
|
|
}
|
2008-06-11 13:01:58 -04:00
|
|
|
|
|
|
|
curlssl_close_all(data);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2007-07-29 08:54:05 -04:00
|
|
|
void Curl_ssl_close(struct connectdata *conn, int sockindex)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2007-07-29 08:54:05 -04:00
|
|
|
DEBUGASSERT((sockindex <= 1) && (sockindex >= -1));
|
2008-06-11 13:01:58 -04:00
|
|
|
curlssl_close(conn, sockindex);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2007-01-05 18:11:14 -05:00
|
|
|
CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex)
|
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
if(curlssl_shutdown(conn, sockindex))
|
2007-07-29 08:54:05 -04:00
|
|
|
return CURLE_SSL_SHUTDOWN_FAILED;
|
|
|
|
|
|
|
|
conn->ssl[sockindex].use = FALSE; /* get back to ordinary socket usage */
|
2008-02-20 04:56:26 -05:00
|
|
|
conn->ssl[sockindex].state = ssl_connection_none;
|
2007-07-29 08:54:05 -04:00
|
|
|
|
2007-01-05 18:11:14 -05:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
/* Selects an SSL crypto engine
|
2005-04-07 11:27:13 -04:00
|
|
|
*/
|
|
|
|
CURLcode Curl_ssl_set_engine(struct SessionHandle *data, const char *engine)
|
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_set_engine(data, engine);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
/* Selects the default SSL crypto engine
|
2005-04-07 11:27:13 -04:00
|
|
|
*/
|
|
|
|
CURLcode Curl_ssl_set_engine_default(struct SessionHandle *data)
|
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_set_engine_default(data);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return list of OpenSSL crypto engine names. */
|
|
|
|
struct curl_slist *Curl_ssl_engines_list(struct SessionHandle *data)
|
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_engines_list(data);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2010-03-19 11:43:11 -04:00
|
|
|
/* return number of sent (non-SSL) bytes; -1 on error */
|
2006-11-11 16:34:43 -05:00
|
|
|
ssize_t Curl_ssl_send(struct connectdata *conn,
|
|
|
|
int sockindex,
|
2008-05-09 07:27:54 -04:00
|
|
|
const void *mem,
|
2006-11-11 16:34:43 -05:00
|
|
|
size_t len)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_send(conn, sockindex, mem, len);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return number of received (decrypted) bytes */
|
|
|
|
|
|
|
|
/*
|
2010-03-19 11:43:11 -04:00
|
|
|
* If the read would block (EWOULDBLOCK) we return -1. If an error occurs during
|
|
|
|
* the read, we return -2. Otherwise we return the count of bytes transfered.
|
2005-04-07 11:27:13 -04:00
|
|
|
*/
|
2006-11-11 16:34:43 -05:00
|
|
|
ssize_t Curl_ssl_recv(struct connectdata *conn, /* connection data */
|
|
|
|
int sockindex, /* socketindex */
|
|
|
|
char *mem, /* store read data here */
|
|
|
|
size_t len) /* max amount to read */
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
|
|
|
ssize_t nread;
|
|
|
|
bool block = FALSE;
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
nread = curlssl_recv(conn, sockindex, mem, len, &block);
|
2005-04-07 11:27:13 -04:00
|
|
|
if(nread == -1) {
|
|
|
|
if(!block)
|
2010-03-19 11:43:11 -04:00
|
|
|
return -2; /* this is a true error, not EWOULDBLOCK */
|
2005-04-07 11:27:13 -04:00
|
|
|
else
|
2010-03-19 11:43:11 -04:00
|
|
|
return -1; /* EWOULDBLOCK */
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2007-08-27 02:31:28 -04:00
|
|
|
return nread;
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This sets up a session ID cache to the specified size. Make sure this code
|
|
|
|
* is agnostic to what underlying SSL technology we use.
|
|
|
|
*/
|
|
|
|
CURLcode Curl_ssl_initsessions(struct SessionHandle *data, long amount)
|
|
|
|
{
|
|
|
|
struct curl_ssl_session *session;
|
|
|
|
|
|
|
|
if(data->state.session)
|
|
|
|
/* this is just a precaution to prevent multiple inits */
|
|
|
|
return CURLE_OK;
|
|
|
|
|
2009-11-18 05:33:54 -05:00
|
|
|
session = calloc(amount, sizeof(struct curl_ssl_session));
|
2005-04-07 11:27:13 -04:00
|
|
|
if(!session)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
/* store the info in the SSL section */
|
|
|
|
data->set.ssl.numsessions = amount;
|
|
|
|
data->state.session = session;
|
|
|
|
data->state.sessionage = 1; /* this is brand new */
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Curl_ssl_version(char *buffer, size_t size)
|
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_version(buffer, size);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2006-05-10 18:17:42 -04:00
|
|
|
/*
|
|
|
|
* This function tries to determine connection status.
|
|
|
|
*
|
|
|
|
* Return codes:
|
|
|
|
* 1 means the connection is still in place
|
|
|
|
* 0 means the connection has been closed
|
|
|
|
* -1 means the connection status is unknown
|
|
|
|
*/
|
|
|
|
int Curl_ssl_check_cxn(struct connectdata *conn)
|
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_check_cxn(conn);
|
2006-05-10 18:17:42 -04:00
|
|
|
}
|
2007-01-24 12:19:08 -05:00
|
|
|
|
2007-08-27 02:31:28 -04:00
|
|
|
bool Curl_ssl_data_pending(const struct connectdata *conn,
|
2007-01-24 12:19:08 -05:00
|
|
|
int connindex)
|
|
|
|
{
|
2008-06-11 13:01:58 -04:00
|
|
|
return curlssl_data_pending(conn, connindex);
|
2007-01-24 12:19:08 -05:00
|
|
|
}
|
2008-06-11 13:01:58 -04:00
|
|
|
|
2008-09-05 10:29:21 -04:00
|
|
|
void Curl_ssl_free_certinfo(struct SessionHandle *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct curl_certinfo *ci = &data->info.certs;
|
|
|
|
if(ci->num_of_certs) {
|
|
|
|
/* free all individual lists used */
|
|
|
|
for(i=0; i<ci->num_of_certs; i++)
|
|
|
|
curl_slist_free_all(ci->certinfo[i]);
|
|
|
|
free(ci->certinfo); /* free the actual array too */
|
|
|
|
ci->num_of_certs = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-09-05 14:35:29 -04:00
|
|
|
#endif /* USE_SSL */
|