Index: lib/http_client.c
===================================================================
--- lib/http_client.c	(revision 78b840187cc1e2d370dd758e6a73c21e510107b5)
+++ lib/http_client.c	(revision a72dc2bb447e754295f8efc6f44fc6572f0f8511)
@@ -47,5 +47,5 @@
 	if( ssl )
 	{
-		req->ssl = ssl_connect( host, port, http_ssl_connected, req );
+		req->ssl = ssl_connect( host, port, TRUE, http_ssl_connected, req );
 		if( req->ssl == NULL )
 			error = 1;
@@ -163,5 +163,6 @@
 	
 error:
-	req->status_string = g_strdup( "Error while writing HTTP request" );
+	if( req->status_string == NULL )
+		req->status_string = g_strdup( "Error while writing HTTP request" );
 	
 	req->func( req );
@@ -176,5 +177,15 @@
 	
 	if( source == NULL )
+	{
+		if( returncode != 0 )
+		{
+			char *err = ssl_verify_strerror( returncode );
+			req->status_string = g_strdup_printf(
+				"Certificate verification problem 0x%x: %s",
+				returncode, err ? err : "Unknown" );
+			g_free( err );
+		}
 		return http_connected( data, -1, cond );
+	}
 	
 	req->fd = ssl_getfd( source );
@@ -440,5 +451,5 @@
 		if( new_proto == PROTO_HTTPS )
 		{
-			req->ssl = ssl_connect( new_host, new_port, http_ssl_connected, req );
+			req->ssl = ssl_connect( new_host, new_port, TRUE, http_ssl_connected, req );
 			if( req->ssl == NULL )
 				error = 1;
Index: lib/ssl_bogus.c
===================================================================
--- lib/ssl_bogus.c	(revision 78b840187cc1e2d370dd758e6a73c21e510107b5)
+++ lib/ssl_bogus.c	(revision a72dc2bb447e754295f8efc6f44fc6572f0f8511)
@@ -32,5 +32,5 @@
 }
 
-void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
+void *ssl_connect( char *host, int port, gboolean verify, ssl_input_function func, gpointer data )
 {
 	return( NULL );
Index: lib/ssl_client.h
===================================================================
--- lib/ssl_client.h	(revision 78b840187cc1e2d370dd758e6a73c21e510107b5)
+++ lib/ssl_client.h	(revision a72dc2bb447e754295f8efc6f44fc6572f0f8511)
@@ -64,5 +64,5 @@
    ready to be used for SSL traffic. This is all done asynchronously, no
    blocking I/O! (Except for the DNS lookups, for now...) */
-G_MODULE_EXPORT void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data );
+G_MODULE_EXPORT void *ssl_connect( char *host, int port, gboolean verify, ssl_input_function func, gpointer data );
 
 /* Start an SSL session on an existing fd. Useful for STARTTLS functionality,
Index: lib/ssl_gnutls.c
===================================================================
--- lib/ssl_gnutls.c	(revision 78b840187cc1e2d370dd758e6a73c21e510107b5)
+++ lib/ssl_gnutls.c	(revision a72dc2bb447e754295f8efc6f44fc6572f0f8511)
@@ -78,5 +78,5 @@
 }
 
-void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
+void *ssl_connect( char *host, int port, gboolean verify, ssl_input_function func, gpointer data )
 {
 	struct scd *conn = g_new0( struct scd, 1 );
@@ -86,4 +86,6 @@
 	conn->data = data;
 	conn->inpa = -1;
+	conn->hostname = g_strdup( host );
+	conn->verify = verify && global.conf->cafile;
 	
 	if( conn->fd < 0 )
Index: lib/ssl_nss.c
===================================================================
--- lib/ssl_nss.c	(revision 78b840187cc1e2d370dd758e6a73c21e510107b5)
+++ lib/ssl_nss.c	(revision a72dc2bb447e754295f8efc6f44fc6572f0f8511)
@@ -103,5 +103,5 @@
 }
 
-void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
+void *ssl_connect( char *host, int port, gboolean verify, ssl_input_function func, gpointer data )
 {
 	struct scd *conn = g_new0( struct scd, 1 );
Index: lib/ssl_openssl.c
===================================================================
--- lib/ssl_openssl.c	(revision 78b840187cc1e2d370dd758e6a73c21e510107b5)
+++ lib/ssl_openssl.c	(revision a72dc2bb447e754295f8efc6f44fc6572f0f8511)
@@ -65,5 +65,5 @@
 }
 
-void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
+void *ssl_connect( char *host, int port, gboolean verify, ssl_input_function func, gpointer data )
 {
 	struct scd *conn = g_new0( struct scd, 1 );
