2007-07-24 05:46:26 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2011-01-05 06:07:58 +08:00
|
|
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2007-07-24 05:46:26 +08: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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
#ifdef USE_QSOSSL
|
2011-07-26 23:23:27 +08:00
|
|
|
|
2007-07-24 05:46:26 +08:00
|
|
|
#include <qsossl.h>
|
2011-07-26 23:23:27 +08:00
|
|
|
|
2009-04-14 21:50:32 +08:00
|
|
|
#ifdef HAVE_LIMITS_H
|
|
|
|
# include <limits.h>
|
|
|
|
#endif
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
#include <curl/curl.h>
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "qssl.h"
|
|
|
|
#include "sslgen.h"
|
|
|
|
#include "connect.h" /* for the connect timeout */
|
|
|
|
#include "select.h"
|
2009-04-21 19:46:16 +08:00
|
|
|
#include "curl_memory.h"
|
2007-07-24 05:46:26 +08:00
|
|
|
/* The last #include file should be: */
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "memdebug.h"
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
int Curl_qsossl_init(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Nothing to do here. We must have connection data to initialize ssl, so
|
|
|
|
* defer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Curl_qsossl_cleanup(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Nothing to do. */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode Curl_qsossl_init_session(struct SessionHandle * data)
|
|
|
|
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
char * certname;
|
|
|
|
SSLInit initstr;
|
|
|
|
SSLInitApp initappstr;
|
|
|
|
|
|
|
|
/* Initialize the job for SSL according to the current parameters.
|
|
|
|
* QsoSSL offers two ways to do it: SSL_Init_Application() that uses an
|
|
|
|
* application identifier to select certificates in the main certificate
|
|
|
|
* store, and SSL_Init() that uses named keyring files and a password.
|
|
|
|
* It is not possible to have different keyrings for the CAs and the
|
|
|
|
* local certificate. We thus use the certificate name to identify the
|
|
|
|
* keyring if given, else the CA file name.
|
|
|
|
* If the key file name is given, it is taken as the password for the
|
|
|
|
* keyring in certificate file.
|
|
|
|
* We first try to SSL_Init_Application(), then SSL_Init() if it failed.
|
|
|
|
*/
|
|
|
|
|
2007-08-02 22:42:16 +08:00
|
|
|
certname = data->set.str[STRING_CERT];
|
2007-07-24 05:46:26 +08:00
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(!certname) {
|
2007-08-02 22:42:16 +08:00
|
|
|
certname = data->set.str[STRING_SSL_CAFILE];
|
2007-07-24 05:46:26 +08:00
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(!certname)
|
2007-07-24 05:46:26 +08:00
|
|
|
return CURLE_OK; /* Use previous setup. */
|
|
|
|
}
|
|
|
|
|
|
|
|
memset((char *) &initappstr, 0, sizeof initappstr);
|
|
|
|
initappstr.applicationID = certname;
|
|
|
|
initappstr.applicationIDLen = strlen(certname);
|
2008-04-07 21:09:17 +08:00
|
|
|
initappstr.protocol = SSL_VERSION_CURRENT; /* TLSV1 compat. SSLV[23]. */
|
2007-07-24 05:46:26 +08:00
|
|
|
initappstr.sessionType = SSL_REGISTERED_AS_CLIENT;
|
|
|
|
rc = SSL_Init_Application(&initappstr);
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(rc == SSL_ERROR_NOT_REGISTERED) {
|
2007-07-24 05:46:26 +08:00
|
|
|
initstr.keyringFileName = certname;
|
2007-08-02 22:42:16 +08:00
|
|
|
initstr.keyringPassword = data->set.str[STRING_KEY];
|
2007-07-24 05:46:26 +08:00
|
|
|
initstr.cipherSuiteList = NULL; /* Use default. */
|
|
|
|
initstr.cipherSuiteListLen = 0;
|
|
|
|
rc = SSL_Init(&initstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (rc) {
|
|
|
|
|
|
|
|
case 0: /* No error. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSL_ERROR_IO:
|
2008-01-16 07:19:02 +08:00
|
|
|
failf(data, "SSL_Init() I/O error: %s", strerror(errno));
|
2007-07-24 05:46:26 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
|
|
|
|
case SSL_ERROR_BAD_CIPHER_SUITE:
|
|
|
|
return CURLE_SSL_CIPHER;
|
|
|
|
|
|
|
|
case SSL_ERROR_KEYPASSWORD_EXPIRED:
|
|
|
|
case SSL_ERROR_NOT_REGISTERED:
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
|
|
|
|
case SSL_ERROR_NO_KEYRING:
|
|
|
|
return CURLE_SSL_CACERT;
|
|
|
|
|
|
|
|
case SSL_ERROR_CERT_EXPIRED:
|
|
|
|
return CURLE_SSL_CERTPROBLEM;
|
|
|
|
|
|
|
|
default:
|
2008-01-16 07:19:02 +08:00
|
|
|
failf(data, "SSL_Init(): %s", SSL_Strerror(rc, NULL));
|
2007-07-24 05:46:26 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode Curl_qsossl_create(struct connectdata * conn, int sockindex)
|
|
|
|
|
|
|
|
{
|
|
|
|
SSLHandle * h;
|
|
|
|
struct ssl_connect_data * connssl = &conn->ssl[sockindex];
|
|
|
|
|
|
|
|
h = SSL_Create(conn->sock[sockindex], SSL_ENCRYPT);
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(!h) {
|
2008-01-16 07:19:02 +08:00
|
|
|
failf(conn->data, "SSL_Create() I/O error: %s", strerror(errno));
|
2007-07-24 05:46:26 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2008-01-16 07:19:02 +08:00
|
|
|
}
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
connssl->handle = h;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int Curl_qsossl_trap_cert(SSLHandle * h)
|
|
|
|
|
|
|
|
{
|
2007-07-24 23:23:16 +08:00
|
|
|
return 1; /* Accept certificate. */
|
2007-07-24 05:46:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode Curl_qsossl_handshake(struct connectdata * conn, int sockindex)
|
|
|
|
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct SessionHandle * data = conn->data;
|
|
|
|
struct ssl_connect_data * connssl = &conn->ssl[sockindex];
|
|
|
|
SSLHandle * h = connssl->handle;
|
|
|
|
long timeout_ms;
|
|
|
|
|
|
|
|
h->exitPgm = NULL;
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(!data->set.ssl.verifyhost)
|
2007-07-24 05:46:26 +08:00
|
|
|
h->exitPgm = Curl_qsossl_trap_cert;
|
|
|
|
|
2008-02-08 06:25:04 +08:00
|
|
|
/* figure out how long time we should wait at maximum */
|
2011-01-05 06:07:58 +08:00
|
|
|
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
2007-07-24 05:46:26 +08:00
|
|
|
|
2008-02-12 06:03:31 +08:00
|
|
|
if(timeout_ms < 0) {
|
|
|
|
/* time-out, bail out, go home */
|
|
|
|
failf(data, "Connection time-out");
|
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
2007-07-24 05:46:26 +08:00
|
|
|
|
2008-02-12 06:03:31 +08:00
|
|
|
/* SSL_Handshake() timeout resolution is second, so round up. */
|
2007-07-24 05:46:26 +08:00
|
|
|
h->timeout = (timeout_ms + 1000 - 1) / 1000;
|
|
|
|
|
|
|
|
/* Set-up protocol. */
|
|
|
|
|
2007-08-02 22:42:16 +08:00
|
|
|
switch (data->set.ssl.version) {
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
case CURL_SSLVERSION_DEFAULT:
|
2008-04-07 21:09:17 +08:00
|
|
|
h->protocol = SSL_VERSION_CURRENT; /* TLSV1 compat. SSLV[23]. */
|
2007-07-24 05:46:26 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CURL_SSLVERSION_TLSv1:
|
|
|
|
h->protocol = TLS_VERSION_1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CURL_SSLVERSION_SSLv2:
|
|
|
|
h->protocol = SSL_VERSION_2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CURL_SSLVERSION_SSLv3:
|
|
|
|
h->protocol = SSL_VERSION_3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = SSL_Handshake(h, SSL_HANDSHAKE_AS_CLIENT);
|
|
|
|
|
|
|
|
switch (rc) {
|
|
|
|
|
|
|
|
case 0: /* No error. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSL_ERROR_BAD_CERTIFICATE:
|
|
|
|
case SSL_ERROR_BAD_CERT_SIG:
|
|
|
|
case SSL_ERROR_NOT_TRUSTED_ROOT:
|
2007-10-03 16:07:50 +08:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
case SSL_ERROR_BAD_CIPHER_SUITE:
|
|
|
|
case SSL_ERROR_NO_CIPHERS:
|
|
|
|
return CURLE_SSL_CIPHER;
|
|
|
|
|
|
|
|
case SSL_ERROR_CERTIFICATE_REJECTED:
|
|
|
|
case SSL_ERROR_CERT_EXPIRED:
|
|
|
|
case SSL_ERROR_NO_CERTIFICATE:
|
|
|
|
return CURLE_SSL_CERTPROBLEM;
|
|
|
|
|
|
|
|
case SSL_ERROR_IO:
|
2008-04-07 21:09:17 +08:00
|
|
|
failf(data, "SSL_Handshake() I/O error: %s", strerror(errno));
|
2007-07-24 05:46:26 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
|
|
|
|
default:
|
2008-04-07 21:09:17 +08:00
|
|
|
failf(data, "SSL_Handshake(): %s", SSL_Strerror(rc, NULL));
|
2007-07-24 05:46:26 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 21:05:34 +08:00
|
|
|
static Curl_recv qsossl_recv;
|
|
|
|
static Curl_send qsossl_send;
|
|
|
|
|
2007-07-24 05:46:26 +08:00
|
|
|
CURLcode Curl_qsossl_connect(struct connectdata * conn, int sockindex)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct SessionHandle * data = conn->data;
|
|
|
|
struct ssl_connect_data * connssl = &conn->ssl[sockindex];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = Curl_qsossl_init_session(data);
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(rc == CURLE_OK) {
|
2007-07-24 05:46:26 +08:00
|
|
|
rc = Curl_qsossl_create(conn, sockindex);
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(rc == CURLE_OK)
|
2007-07-24 05:46:26 +08:00
|
|
|
rc = Curl_qsossl_handshake(conn, sockindex);
|
|
|
|
else {
|
|
|
|
SSL_Destroy(connssl->handle);
|
|
|
|
connssl->handle = NULL;
|
|
|
|
connssl->use = FALSE;
|
2008-02-20 17:56:26 +08:00
|
|
|
connssl->state = ssl_connection_none;
|
2007-07-24 05:46:26 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-20 21:17:42 +08:00
|
|
|
if(rc == CURLE_OK) {
|
2008-02-20 17:56:26 +08:00
|
|
|
connssl->state = ssl_connection_complete;
|
2010-05-12 04:48:38 +08:00
|
|
|
conn->recv[sockindex] = qsossl_recv;
|
|
|
|
conn->send[sockindex] = qsossl_send;
|
2010-05-07 21:05:34 +08:00
|
|
|
}
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int Curl_qsossl_close_one(struct ssl_connect_data * conn,
|
|
|
|
struct SessionHandle * data)
|
|
|
|
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2007-07-29 20:54:05 +08:00
|
|
|
if(!conn->handle)
|
2007-07-24 05:46:26 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
rc = SSL_Destroy(conn->handle);
|
|
|
|
|
|
|
|
if(rc) {
|
2007-11-07 17:21:35 +08:00
|
|
|
if(rc == SSL_ERROR_IO) {
|
2008-01-16 07:19:02 +08:00
|
|
|
failf(data, "SSL_Destroy() I/O error: %s", strerror(errno));
|
2007-07-24 05:46:26 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* An SSL error. */
|
2010-02-05 03:44:31 +08:00
|
|
|
failf(data, "SSL_Destroy() returned error %s", SSL_Strerror(rc, NULL));
|
2007-07-24 05:46:26 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->handle = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-29 20:54:05 +08:00
|
|
|
void Curl_qsossl_close(struct connectdata *conn, int sockindex)
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
{
|
2007-07-29 20:54:05 +08:00
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
if(connssl->use)
|
|
|
|
(void) Curl_qsossl_close_one(connssl, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Curl_qsossl_close_all(struct SessionHandle * data)
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Unimplemented. */
|
|
|
|
(void) data;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Curl_qsossl_shutdown(struct connectdata * conn, int sockindex)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct ssl_connect_data * connssl = &conn->ssl[sockindex];
|
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
ssize_t nread;
|
|
|
|
int what;
|
|
|
|
int rc;
|
|
|
|
char buf[120];
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(!connssl->handle)
|
2007-07-24 05:46:26 +08:00
|
|
|
return 0;
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(data->set.ftp_ccc != CURLFTPSSL_CCC_ACTIVE)
|
2007-07-24 05:46:26 +08:00
|
|
|
return 0;
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(Curl_qsossl_close_one(connssl, data))
|
2007-07-24 05:46:26 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
what = Curl_socket_ready(conn->sock[sockindex],
|
|
|
|
CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
|
|
|
|
|
2011-04-20 21:17:42 +08:00
|
|
|
for(;;) {
|
2007-11-07 17:21:35 +08:00
|
|
|
if(what < 0) {
|
2007-07-24 05:46:26 +08:00
|
|
|
/* anything that gets here is fatally bad */
|
|
|
|
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
|
|
|
rc = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(!what) { /* timeout */
|
2007-07-24 05:46:26 +08:00
|
|
|
failf(data, "SSL shutdown timeout");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Something to read, let's do it and hope that it is the close
|
|
|
|
notify alert from the server. No way to SSL_Read now, so use read(). */
|
|
|
|
|
|
|
|
nread = read(conn->sock[sockindex], buf, sizeof(buf));
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(nread < 0) {
|
2008-01-16 07:19:02 +08:00
|
|
|
failf(data, "read: %s", strerror(errno));
|
2007-07-24 05:46:26 +08:00
|
|
|
rc = -1;
|
|
|
|
}
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(nread <= 0)
|
2007-07-24 05:46:26 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
what = Curl_socket_ready(conn->sock[sockindex], CURL_SOCKET_BAD, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 21:05:34 +08:00
|
|
|
static ssize_t qsossl_send(struct connectdata * conn, int sockindex,
|
|
|
|
const void * mem, size_t len, CURLcode * curlcode)
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
/* SSL_Write() is said to return 'int' while write() and send() returns
|
|
|
|
'size_t' */
|
|
|
|
int rc;
|
|
|
|
|
2008-05-20 18:21:50 +08:00
|
|
|
rc = SSL_Write(conn->ssl[sockindex].handle, (void *) mem, (int) len);
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
if(rc < 0) {
|
|
|
|
switch(rc) {
|
|
|
|
|
|
|
|
case SSL_ERROR_BAD_STATE:
|
|
|
|
/* The operation did not complete; the same SSL I/O function
|
2011-04-19 21:54:13 +08:00
|
|
|
should be called again later. This is basically an EWOULDBLOCK
|
2007-07-24 05:46:26 +08:00
|
|
|
equivalent. */
|
2010-05-07 21:05:34 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
2010-04-07 16:07:29 +08:00
|
|
|
return -1;
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
case SSL_ERROR_IO:
|
|
|
|
switch (errno) {
|
|
|
|
case EWOULDBLOCK:
|
|
|
|
case EINTR:
|
2010-05-07 21:05:34 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
2010-04-07 16:07:29 +08:00
|
|
|
return -1;
|
2007-07-24 05:46:26 +08:00
|
|
|
}
|
|
|
|
|
2008-01-16 07:19:02 +08:00
|
|
|
failf(conn->data, "SSL_Write() I/O error: %s", strerror(errno));
|
2010-04-07 16:07:29 +08:00
|
|
|
*curlcode = CURLE_SEND_ERROR;
|
2007-07-24 05:46:26 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* An SSL error. */
|
2010-02-05 03:44:31 +08:00
|
|
|
failf(conn->data, "SSL_Write() returned error %s",
|
2007-07-24 05:46:26 +08:00
|
|
|
SSL_Strerror(rc, NULL));
|
2010-04-07 16:07:29 +08:00
|
|
|
*curlcode = CURLE_SEND_ERROR;
|
2007-07-24 05:46:26 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ssize_t) rc; /* number of bytes */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 21:05:34 +08:00
|
|
|
static ssize_t qsossl_recv(struct connectdata * conn, int num, char * buf,
|
|
|
|
size_t buffersize, CURLcode * curlcode)
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
char error_buffer[120]; /* OpenSSL documents that this must be at
|
|
|
|
least 120 bytes long. */
|
|
|
|
unsigned long sslerror;
|
2009-04-14 20:53:53 +08:00
|
|
|
int buffsize;
|
2007-07-24 05:46:26 +08:00
|
|
|
int nread;
|
|
|
|
|
2009-04-14 20:53:53 +08:00
|
|
|
buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
|
|
|
|
nread = SSL_Read(conn->ssl[num].handle, buf, buffsize);
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
if(nread < 0) {
|
|
|
|
/* failed SSL_read */
|
|
|
|
|
|
|
|
switch (nread) {
|
|
|
|
|
|
|
|
case SSL_ERROR_BAD_STATE:
|
|
|
|
/* there's data pending, re-invoke SSL_Read(). */
|
2010-05-07 21:05:34 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
2010-04-07 16:07:29 +08:00
|
|
|
return -1;
|
2007-07-24 05:46:26 +08:00
|
|
|
|
|
|
|
case SSL_ERROR_IO:
|
|
|
|
switch (errno) {
|
|
|
|
case EWOULDBLOCK:
|
2010-05-07 21:05:34 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
2007-07-24 05:46:26 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-01-16 07:19:02 +08:00
|
|
|
failf(conn->data, "SSL_Read() I/O error: %s", strerror(errno));
|
2010-04-07 16:07:29 +08:00
|
|
|
*curlcode = CURLE_RECV_ERROR;
|
2007-07-24 05:46:26 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
default:
|
2008-01-16 07:19:02 +08:00
|
|
|
failf(conn->data, "SSL read error: %s", SSL_Strerror(nread, NULL));
|
2010-04-07 16:07:29 +08:00
|
|
|
*curlcode = CURLE_RECV_ERROR;
|
2007-07-24 05:46:26 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ssize_t) nread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t Curl_qsossl_version(char * buffer, size_t size)
|
|
|
|
|
|
|
|
{
|
|
|
|
strncpy(buffer, "IBM OS/400 SSL", size);
|
|
|
|
return strlen(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Curl_qsossl_check_cxn(struct connectdata * cxn)
|
|
|
|
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int errlen;
|
|
|
|
|
|
|
|
/* The only thing that can be tested here is at the socket level. */
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(!cxn->ssl[FIRSTSOCKET].handle)
|
2007-07-24 05:46:26 +08:00
|
|
|
return 0; /* connection has been closed */
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
errlen = sizeof err;
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(getsockopt(cxn->sock[FIRSTSOCKET], SOL_SOCKET, SO_ERROR,
|
2007-07-24 05:46:26 +08:00
|
|
|
(unsigned char *) &err, &errlen) ||
|
|
|
|
errlen != sizeof err || err)
|
|
|
|
return 0; /* connection has been closed */
|
|
|
|
|
|
|
|
return -1; /* connection status unknown */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_QSOSSL */
|