|
|
226bdc |
diff -up wget-1.14/src/openssl.c.ssltimeout wget-1.14/src/openssl.c
|
|
|
226bdc |
--- wget-1.14/src/openssl.c.ssltimeout 2012-08-09 14:30:14.987964706 +0200
|
|
|
226bdc |
+++ wget-1.14/src/openssl.c 2012-08-09 14:44:05.467660741 +0200
|
|
|
226bdc |
@@ -256,19 +256,42 @@ struct openssl_transport_context {
|
|
|
226bdc |
char *last_error; /* last error printed with openssl_errstr */
|
|
|
226bdc |
};
|
|
|
226bdc |
|
|
|
226bdc |
-static int
|
|
|
226bdc |
-openssl_read (int fd, char *buf, int bufsize, void *arg)
|
|
|
226bdc |
-{
|
|
|
226bdc |
- int ret;
|
|
|
226bdc |
- struct openssl_transport_context *ctx = arg;
|
|
|
226bdc |
+struct openssl_read_args {
|
|
|
226bdc |
+ int fd;
|
|
|
226bdc |
+ struct openssl_transport_context *ctx;
|
|
|
226bdc |
+ char *buf;
|
|
|
226bdc |
+ int bufsize;
|
|
|
226bdc |
+ int retval;
|
|
|
226bdc |
+};
|
|
|
226bdc |
+
|
|
|
226bdc |
+static void openssl_read_callback(void *arg) {
|
|
|
226bdc |
+ struct openssl_read_args *args = (struct openssl_read_args *) arg;
|
|
|
226bdc |
+ struct openssl_transport_context *ctx = args->ctx;
|
|
|
226bdc |
SSL *conn = ctx->conn;
|
|
|
226bdc |
+ char *buf = args->buf;
|
|
|
226bdc |
+ int bufsize = args->bufsize;
|
|
|
226bdc |
+ int ret;
|
|
|
226bdc |
+
|
|
|
226bdc |
do
|
|
|
226bdc |
ret = SSL_read (conn, buf, bufsize);
|
|
|
226bdc |
- while (ret == -1
|
|
|
226bdc |
- && SSL_get_error (conn, ret) == SSL_ERROR_SYSCALL
|
|
|
226bdc |
+ while (ret == -1 && SSL_get_error (conn, ret) == SSL_ERROR_SYSCALL
|
|
|
226bdc |
&& errno == EINTR);
|
|
|
226bdc |
+ args->retval = ret;
|
|
|
226bdc |
+}
|
|
|
226bdc |
|
|
|
226bdc |
- return ret;
|
|
|
226bdc |
+static int
|
|
|
226bdc |
+openssl_read (int fd, char *buf, int bufsize, void *arg)
|
|
|
226bdc |
+{
|
|
|
226bdc |
+ struct openssl_read_args args;
|
|
|
226bdc |
+ args.fd = fd;
|
|
|
226bdc |
+ args.buf = buf;
|
|
|
226bdc |
+ args.bufsize = bufsize;
|
|
|
226bdc |
+ args.ctx = (struct openssl_transport_context*) arg;
|
|
|
226bdc |
+
|
|
|
226bdc |
+ if (run_with_timeout(opt.read_timeout, openssl_read_callback, &args)) {
|
|
|
226bdc |
+ return -1;
|
|
|
226bdc |
+ }
|
|
|
226bdc |
+ return args.retval;
|
|
|
226bdc |
}
|
|
|
226bdc |
|
|
|
226bdc |
static int
|
|
|
226bdc |
@@ -386,6 +409,18 @@ static struct transport_implementation o
|
|
|
226bdc |
openssl_peek, openssl_errstr, openssl_close
|
|
|
226bdc |
};
|
|
|
226bdc |
|
|
|
226bdc |
+struct scwt_context {
|
|
|
226bdc |
+ SSL *ssl;
|
|
|
226bdc |
+ int result;
|
|
|
226bdc |
+};
|
|
|
226bdc |
+
|
|
|
226bdc |
+static void
|
|
|
226bdc |
+ssl_connect_with_timeout_callback(void *arg)
|
|
|
226bdc |
+{
|
|
|
226bdc |
+ struct scwt_context *ctx = (struct scwt_context *)arg;
|
|
|
226bdc |
+ ctx->result = SSL_connect(ctx->ssl);
|
|
|
226bdc |
+}
|
|
|
226bdc |
+
|
|
|
226bdc |
/* Perform the SSL handshake on file descriptor FD, which is assumed
|
|
|
226bdc |
to be connected to an SSL server. The SSL handle provided by
|
|
|
226bdc |
OpenSSL is registered with the file descriptor FD using
|
|
|
226bdc |
@@ -398,6 +433,7 @@ bool
|
|
|
226bdc |
ssl_connect_wget (int fd, const char *hostname)
|
|
|
226bdc |
{
|
|
|
226bdc |
SSL *conn;
|
|
|
226bdc |
+ struct scwt_context scwt_ctx;
|
|
|
226bdc |
struct openssl_transport_context *ctx;
|
|
|
226bdc |
|
|
|
226bdc |
DEBUGP (("Initiating SSL handshake.\n"));
|
|
|
226bdc |
@@ -425,7 +461,14 @@ ssl_connect_wget (int fd, const char *ho
|
|
|
226bdc |
if (!SSL_set_fd (conn, FD_TO_SOCKET (fd)))
|
|
|
226bdc |
goto error;
|
|
|
226bdc |
SSL_set_connect_state (conn);
|
|
|
226bdc |
- if (SSL_connect (conn) <= 0 || conn->state != SSL_ST_OK)
|
|
|
226bdc |
+
|
|
|
226bdc |
+ scwt_ctx.ssl = conn;
|
|
|
226bdc |
+ if (run_with_timeout(opt.read_timeout, ssl_connect_with_timeout_callback,
|
|
|
226bdc |
+ &scwt_ctx)) {
|
|
|
226bdc |
+ DEBUGP (("SSL handshake timed out.\n"));
|
|
|
226bdc |
+ goto timeout;
|
|
|
226bdc |
+ }
|
|
|
226bdc |
+ if (scwt_ctx.result <= 0 || conn->state != SSL_ST_OK)
|
|
|
226bdc |
goto error;
|
|
|
226bdc |
|
|
|
226bdc |
ctx = xnew0 (struct openssl_transport_context);
|
|
|
226bdc |
@@ -441,6 +484,7 @@ ssl_connect_wget (int fd, const char *ho
|
|
|
226bdc |
error:
|
|
|
226bdc |
DEBUGP (("SSL handshake failed.\n"));
|
|
|
226bdc |
print_errors ();
|
|
|
226bdc |
+ timeout:
|
|
|
226bdc |
if (conn)
|
|
|
226bdc |
SSL_free (conn);
|
|
|
226bdc |
return false;
|