/* SSL support via OpenSSL library.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
- 2009, 2010, 2011 Free Software Foundation, Inc.
+ 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
Originally contributed by Christian Fraenkel.
This file is part of GNU Wget.
Returns true on success, false otherwise. */
bool
-ssl_init ()
+ssl_init (void)
{
- SSL_METHOD *meth;
+ SSL_METHOD const *meth;
if (ssl_ctx)
/* The SSL has already been initialized. */
abort ();
}
- ssl_ctx = SSL_CTX_new (meth);
+ /* The type cast below accommodates older OpenSSL versions (0.9.8)
+ where SSL_CTX_new() is declared without a "const" argument. */
+ ssl_ctx = SSL_CTX_new ((SSL_METHOD *)meth);
if (!ssl_ctx)
goto error;
do
ret = SSL_read (conn, buf, bufsize);
while (ret == -1
- && (SSL_get_error (conn, ret) == SSL_ERROR_WANT_READ
- || (SSL_get_error (conn, ret) == SSL_ERROR_SYSCALL
- && errno == EINTR)));
+ && SSL_get_error (conn, ret) == SSL_ERROR_SYSCALL
+ && errno == EINTR);
return ret;
}
{
struct openssl_transport_context *ctx = arg;
SSL *conn = ctx->conn;
- if (timeout == 0)
- return 1;
if (SSL_pending (conn))
return 1;
+ if (timeout == 0)
+ return 1;
return select_fd (fd, timeout, wait_for);
}
int ret;
struct openssl_transport_context *ctx = arg;
SSL *conn = ctx->conn;
+ if (! openssl_poll (fd, 0.0, WAIT_FOR_READ, arg))
+ return 0;
do
ret = SSL_peek (conn, buf, bufsize);
while (ret == -1
Returns true on success, false on failure. */
bool
-ssl_connect_wget (int fd)
+ssl_connect_wget (int fd, const char *hostname)
{
SSL *conn;
struct openssl_transport_context *ctx;
conn = SSL_new (ssl_ctx);
if (!conn)
goto error;
+#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
+ /* If the SSL library was build with support for ServerNameIndication
+ then use it whenever we have a hostname. If not, don't, ever. */
+ if (! is_valid_ip_address (hostname))
+ {
+ if (! SSL_set_tlsext_host_name (conn, hostname))
+ {
+ DEBUGP (("Failed to set TLS server-name indication."));
+ goto error;
+ }
+ }
+#endif
+
#ifndef FD_TO_SOCKET
# define FD_TO_SOCKET(X) (X)
#endif