]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Get builds going again with GNU TLS.
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 6 Nov 2013 01:57:02 +0000 (01:57 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 6 Nov 2013 01:57:02 +0000 (01:57 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11393 a1ca3aef-8c08-0410-bb20-df032aa958be

cups/http-private.h
cups/tls-gnutls.c

index 006e390655b65a50b514c11384d1f2d5ee20a4bc..c0b6d340b9a642bd7b718ac47ba4dbeb6516b709 100644 (file)
@@ -169,14 +169,9 @@ typedef void *http_tls_credentials_t;
  * The GNU TLS library is more of a "bare metal" SSL/TLS library...
  */
 
-typedef gnutls_session http_tls_t;
+typedef gnutls_session_t http_tls_t;
 typedef void *http_tls_credentials_t;
 
-//extern ssize_t       _httpReadGNUTLS(gnutls_transport_ptr ptr, void *data,
-//                             size_t length);
-//extern ssize_t       _httpWriteGNUTLS(gnutls_transport_ptr ptr, const void *data,
-//                              size_t length);
-
 #  elif defined(HAVE_CDSASSL)
 /*
  * Darwin's Security framework provides its own SSL/TLS context structure
index 6ef10c66a1c84282b1771d67a36da6240300b706..0f5b11881654c04d2478cbb871d32b4377f824a9 100644 (file)
  * Local functions...
  */
 
-static int             make_certificate(cupsd_client_t *con);
+//static int           make_certificate(cupsd_client_t *con);
+static ssize_t http_gnutls_read(gnutls_transport_ptr_t ptr, void *data, size_t length);
+static ssize_t http_gnutls_write(gnutls_transport_ptr_t ptr, const void *data, size_t length);
+
+
+/*
+ * 'httpCopyCredentials()' - Copy the credentials associated with the peer in
+ *                           an encrypted connection.
+ *
+ * @since CUPS 1.5/OS X 10.7@
+ */
+
+int                                    /* O - Status of call (0 = success) */
+httpCopyCredentials(
+    http_t      *http,                 /* I - Connection to server */
+    cups_array_t **credentials)                /* O - Array of credentials */
+{
+  if (credentials)
+    *credentials = NULL;
+
+  if (!http || !http->tls || !credentials)
+    return (-1);
+
+  return (0);
+}
+
+
+/*
+ * '_httpCreateCredentials()' - Create credentials in the internal format.
+ */
+
+http_tls_credentials_t                 /* O - Internal credentials */
+_httpCreateCredentials(
+    cups_array_t *credentials)         /* I - Array of credentials */
+{
+  (void)credentials;
+
+  return (NULL);
+}
+
+
+/*
+ * '_httpFreeCredentials()' - Free internal credentials.
+ */
+
+void
+_httpFreeCredentials(
+    http_tls_credentials_t credentials)        /* I - Internal credentials */
+{
+  (void)credentials;
+}
+
+
+/*
+ * 'http_gnutls_read()' - Read function for the GNU TLS library.
+ */
+
+static ssize_t                         /* O - Number of bytes read or -1 on error */
+http_gnutls_read(
+    gnutls_transport_ptr_t ptr,                /* I - Connection to server */
+    void                   *data,      /* I - Buffer */
+    size_t                 length)     /* I - Number of bytes to read */
+{
+  http_t       *http;                  /* HTTP connection */
+  ssize_t      bytes;                  /* Bytes read */
+
+
+  DEBUG_printf(("6http_gnutls_read(ptr=%p, data=%p, length=%d)", ptr, data, (int)length));
+
+  http = (http_t *)ptr;
+
+  if (!http->blocking)
+  {
+   /*
+    * Make sure we have data before we read...
+    */
+
+    while (!_httpWait(http, http->wait_value, 0))
+    {
+      if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data))
+       continue;
+
+      http->error = ETIMEDOUT;
+      return (-1);
+    }
+  }
+
+  bytes = recv(http->fd, data, length, 0);
+  DEBUG_printf(("6http_gnutls_read: bytes=%d", (int)bytes));
+  return (bytes);
+}
+
+
+/*
+ * 'http_gnutls_write()' - Write function for the GNU TLS library.
+ */
+
+static ssize_t                         /* O - Number of bytes written or -1 on error */
+http_gnutls_write(
+    gnutls_transport_ptr_t ptr,                /* I - Connection to server */
+    const void             *data,      /* I - Data buffer */
+    size_t                 length)     /* I - Number of bytes to write */
+{
+  ssize_t bytes;                       /* Bytes written */
+
+
+  DEBUG_printf(("6http_gnutls_write(ptr=%p, data=%p, length=%d)", ptr, data,
+                (int)length));
+#ifdef DEBUG
+  http_debug_hex("http_gnutls_write", data, (int)length);
+#endif /* DEBUG */
+
+  bytes = send(((http_t *)ptr)->fd, data, length, 0);
+  DEBUG_printf(("http_gnutls_write: bytes=%d", (int)bytes));
+
+  return (bytes);
+}
 
 
 /*
@@ -30,37 +146,25 @@ static int         make_certificate(cupsd_client_t *con);
 static void
 http_tls_initialize(void)
 {
-#ifdef HAVE_GNUTLS
  /*
   * Initialize GNU TLS...
   */
 
   gnutls_global_init();
+}
 
-#elif defined(HAVE_LIBSSL)
- /*
-  * Initialize OpenSSL...
-  */
-
-  SSL_load_error_strings();
-  SSL_library_init();
-
- /*
-  * Using the current time is a dubious random seed, but on some systems
-  * it is the best we can do (on others, this seed isn't even used...)
-  */
-
-  CUPS_SRAND(time(NULL));
 
-  for (i = 0; i < sizeof(data); i ++)
-    data[i] = CUPS_RAND();
+/*
+ * 'http_tls_pending()' - Return the number of pending TLS-encrypted bytes.
+ */
 
-  RAND_seed(data, sizeof(data));
-#endif /* HAVE_GNUTLS */
+static size_t
+http_tls_pending(http_t *http)         /* I - HTTP connection */
+{
+  return (gnutls_record_check_pending(http->tls));
 }
 
 
-#ifdef HAVE_SSL
 /*
  * 'http_tls_read()' - Read from a SSL/TLS connection.
  */
@@ -70,10 +174,6 @@ http_tls_read(http_t *http,         /* I - Connection to server */
              char   *buf,              /* I - Buffer to store data */
              int    len)               /* I - Length of buffer */
 {
-#  if defined(HAVE_LIBSSL)
-  return (SSL_read((SSL *)(http->tls), buf, len));
-
-#  elif defined(HAVE_GNUTLS)
   ssize_t      result;                 /* Return value */
 
 
@@ -104,89 +204,34 @@ http_tls_read(http_t *http,               /* I - Connection to server */
   }
 
   return ((int)result);
-
-#  elif defined(HAVE_CDSASSL)
-  int          result;                 /* Return value */
-  OSStatus     error;                  /* Error info */
-  size_t       processed;              /* Number of bytes processed */
+}
 
 
-  error = SSLRead(http->tls, buf, len, &processed);
-  DEBUG_printf(("6http_tls_read: error=%d, processed=%d", (int)error,
-                (int)processed));
-  switch (error)
-  {
-    case 0 :
-       result = (int)processed;
-       break;
-
-    case errSSLWouldBlock :
-       if (processed)
-         result = (int)processed;
-       else
-       {
-         result = -1;
-         errno  = EINTR;
-       }
-       break;
-
-    case errSSLClosedGraceful :
-    default :
-       if (processed)
-         result = (int)processed;
-       else
-       {
-         result = -1;
-         errno  = EPIPE;
-       }
-       break;
-  }
+/*
+ * 'http_tls_set_credentials()' - Set the TLS credentials.
+ */
 
-  return (result);
+static int                             /* O - Status of connection */
+http_tls_set_credentials(http_t *http) /* I - Connection to server */
+{
+  (void)http;
 
-#  elif defined(HAVE_SSPISSL)
-  return _sspiRead((_sspi_struct_t*) http->tls, buf, len);
-#  endif /* HAVE_LIBSSL */
+  return (0);
 }
-#endif /* HAVE_SSL */
 
 
-#ifdef HAVE_SSL
 /*
- * 'http_setup_ssl()' - Set up SSL/TLS support on a connection.
+ * 'http_tls_start()' - Set up SSL/TLS support on a connection.
  */
 
 static int                             /* O - 0 on success, -1 on failure */
-http_setup_ssl(http_t *http)           /* I - Connection to server */
+http_tls_start(http_t *http)           /* I - Connection to server */
 {
   char                 hostname[256],  /* Hostname */
                        *hostptr;       /* Pointer into hostname */
-
-#  ifdef HAVE_LIBSSL
-  SSL_CTX              *context;       /* Context for encryption */
-  BIO                  *bio;           /* BIO data */
-  const char           *message = NULL;/* Error message */
-#  elif defined(HAVE_GNUTLS)
   int                  status;         /* Status of handshake */
   gnutls_certificate_client_credentials *credentials;
                                        /* TLS credentials */
-#  elif defined(HAVE_CDSASSL)
-  _cups_globals_t      *cg = _cupsGlobals();
-                                       /* Pointer to library globals */
-  OSStatus             error;          /* Error code */
-  const char           *message = NULL;/* Error message */
-  cups_array_t         *credentials;   /* Credentials array */
-  cups_array_t         *names;         /* CUPS distinguished names */
-  CFArrayRef           dn_array;       /* CF distinguished names array */
-  CFIndex              count;          /* Number of credentials */
-  CFDataRef            data;           /* Certificate data */
-  int                  i;              /* Looping var */
-  http_credential_t    *credential;    /* Credential data */
-#  elif defined(HAVE_SSPISSL)
-  TCHAR                        username[256];  /* Username returned from GetUserName() */
-  TCHAR                        commonName[256];/* Common name for certificate */
-  DWORD                        dwSize;         /* 32 bit size */
-#  endif /* HAVE_LIBSSL */
 
 
   DEBUG_printf(("7http_setup_ssl(http=%p)", http));
@@ -211,51 +256,6 @@ http_setup_ssl(http_t *http)               /* I - Connection to server */
       *hostptr = '\0';
   }
 
-#  ifdef HAVE_LIBSSL
-  context = SSL_CTX_new(SSLv23_client_method());
-
-  SSL_CTX_set_options(context, SSL_OP_NO_SSLv2); /* Only use SSLv3 or TLS */
-
-  bio = BIO_new(_httpBIOMethods());
-  BIO_ctrl(bio, BIO_C_SET_FILE_PTR, 0, (char *)http);
-
-  http->tls = SSL_new(context);
-  SSL_set_bio(http->tls, bio, bio);
-
-#   ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
-  SSL_set_tlsext_host_name(http->tls, hostname);
-#   endif /* HAVE_SSL_SET_TLSEXT_HOST_NAME */
-
-  if (SSL_connect(http->tls) != 1)
-  {
-    unsigned long      error;  /* Error code */
-
-    while ((error = ERR_get_error()) != 0)
-    {
-      message = ERR_error_string(error, NULL);
-      DEBUG_printf(("8http_setup_ssl: %s", message));
-    }
-
-    SSL_CTX_free(context);
-    SSL_free(http->tls);
-    http->tls = NULL;
-
-#    ifdef WIN32
-    http->error  = WSAGetLastError();
-#    else
-    http->error  = errno;
-#    endif /* WIN32 */
-    http->status = HTTP_STATUS_ERROR;
-
-    if (!message)
-      message = _("Unable to establish a secure connection to host.");
-
-    _cupsSetError(IPP_STATUS_ERROR_CUPS_PKI, message, 1);
-
-    return (-1);
-  }
-
-#  elif defined(HAVE_GNUTLS)
   credentials = (gnutls_certificate_client_credentials *)
                     malloc(sizeof(gnutls_certificate_client_credentials));
   if (credentials == NULL)
@@ -276,9 +276,9 @@ http_setup_ssl(http_t *http)                /* I - Connection to server */
   gnutls_server_name_set(http->tls, GNUTLS_NAME_DNS, hostname,
                          strlen(hostname));
   gnutls_credentials_set(http->tls, GNUTLS_CRD_CERTIFICATE, *credentials);
-  gnutls_transport_set_ptr(http->tls, (gnutls_transport_ptr)http);
-  gnutls_transport_set_pull_function(http->tls, _httpReadGNUTLS);
-  gnutls_transport_set_push_function(http->tls, _httpWriteGNUTLS);
+  gnutls_transport_set_ptr(http->tls, (gnutls_transport_ptr_t)http);
+  gnutls_transport_set_pull_function(http->tls, http_gnutls_read);
+  gnutls_transport_set_push_function(http->tls, http_gnutls_write);
 
   while ((status = gnutls_handshake(http->tls)) != GNUTLS_E_SUCCESS)
   {
@@ -303,284 +303,20 @@ http_setup_ssl(http_t *http)             /* I - Connection to server */
 
   http->tls_credentials = credentials;
 
-#  elif defined(HAVE_CDSASSL)
-  if ((http->tls = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide,
-                                    kSSLStreamType)) == NULL)
-  {
-    DEBUG_puts("4http_setup_ssl: SSLCreateContext failed.");
-    http->error  = errno = ENOMEM;
-    http->status = HTTP_STATUS_ERROR;
-    _cupsSetHTTPError(HTTP_STATUS_ERROR);
-
-    return (-1);
-  }
-
-  error = SSLSetConnection(http->tls, http);
-  DEBUG_printf(("4http_setup_ssl: SSLSetConnection, error=%d", (int)error));
-
-  if (!error)
-  {
-    error = SSLSetIOFuncs(http->tls, _httpReadCDSA, _httpWriteCDSA);
-    DEBUG_printf(("4http_setup_ssl: SSLSetIOFuncs, error=%d", (int)error));
-  }
-
-  if (!error)
-  {
-    error = SSLSetSessionOption(http->tls, kSSLSessionOptionBreakOnServerAuth,
-                                true);
-    DEBUG_printf(("4http_setup_ssl: SSLSetSessionOption, error=%d",
-                  (int)error));
-  }
-
-  if (!error)
-  {
-    if (cg->client_cert_cb)
-    {
-      error = SSLSetSessionOption(http->tls,
-                                 kSSLSessionOptionBreakOnCertRequested, true);
-      DEBUG_printf(("4http_setup_ssl: kSSLSessionOptionBreakOnCertRequested, "
-                    "error=%d", (int)error));
-    }
-    else
-    {
-      error = http_set_credentials(http);
-      DEBUG_printf(("4http_setup_ssl: http_set_credentials, error=%d",
-                    (int)error));
-    }
-  }
-
- /*
-  * Let the server know which hostname/domain we are trying to connect to
-  * in case it wants to serve up a certificate with a matching common name.
-  */
-
-  if (!error)
-  {
-    error = SSLSetPeerDomainName(http->tls, hostname, strlen(hostname));
-
-    DEBUG_printf(("4http_setup_ssl: SSLSetPeerDomainName, error=%d",
-                  (int)error));
-  }
-
-  if (!error)
-  {
-    int done = 0;                      /* Are we done yet? */
-
-    while (!error && !done)
-    {
-      error = SSLHandshake(http->tls);
-
-      DEBUG_printf(("4http_setup_ssl: SSLHandshake returned %d.", (int)error));
-
-      switch (error)
-      {
-       case noErr :
-           done = 1;
-           break;
-
-       case errSSLWouldBlock :
-           error = noErr;              /* Force a retry */
-           usleep(1000);               /* in 1 millisecond */
-           break;
-
-       case errSSLServerAuthCompleted :
-           error = 0;
-           if (cg->server_cert_cb)
-           {
-             error = httpCopyCredentials(http, &credentials);
-             if (!error)
-             {
-               error = (cg->server_cert_cb)(http, http->tls, credentials,
-                                            cg->server_cert_data);
-               httpFreeCredentials(credentials);
-             }
-
-             DEBUG_printf(("4http_setup_ssl: Server certificate callback "
-                           "returned %d.", (int)error));
-           }
-           break;
-
-       case errSSLClientCertRequested :
-           error = 0;
-
-           if (cg->client_cert_cb)
-           {
-             names = NULL;
-             if (!(error = SSLCopyDistinguishedNames(http->tls, &dn_array)) &&
-                 dn_array)
-             {
-               if ((names = cupsArrayNew(NULL, NULL)) != NULL)
-               {
-                 for (i = 0, count = CFArrayGetCount(dn_array); i < count; i++)
-                 {
-                   data = (CFDataRef)CFArrayGetValueAtIndex(dn_array, i);
-
-                   if ((credential = malloc(sizeof(*credential))) != NULL)
-                   {
-                     credential->datalen = CFDataGetLength(data);
-                     if ((credential->data = malloc(credential->datalen)))
-                     {
-                       memcpy((void *)credential->data, CFDataGetBytePtr(data),
-                              credential->datalen);
-                       cupsArrayAdd(names, credential);
-                     }
-                     else
-                       free(credential);
-                   }
-                 }
-               }
-
-               CFRelease(dn_array);
-             }
-
-             if (!error)
-             {
-               error = (cg->client_cert_cb)(http, http->tls, names,
-                                            cg->client_cert_data);
-
-               DEBUG_printf(("4http_setup_ssl: Client certificate callback "
-                             "returned %d.", (int)error));
-             }
-
-             httpFreeCredentials(names);
-           }
-           break;
-
-       case errSSLUnknownRootCert :
-           message = _("Unable to establish a secure connection to host "
-                       "(untrusted certificate).");
-           break;
-
-       case errSSLNoRootCert :
-           message = _("Unable to establish a secure connection to host "
-                       "(self-signed certificate).");
-           break;
-
-       case errSSLCertExpired :
-           message = _("Unable to establish a secure connection to host "
-                       "(expired certificate).");
-           break;
-
-       case errSSLCertNotYetValid :
-           message = _("Unable to establish a secure connection to host "
-                       "(certificate not yet valid).");
-           break;
-
-       case errSSLHostNameMismatch :
-           message = _("Unable to establish a secure connection to host "
-                       "(host name mismatch).");
-           break;
-
-       case errSSLXCertChainInvalid :
-           message = _("Unable to establish a secure connection to host "
-                       "(certificate chain invalid).");
-           break;
-
-       case errSSLConnectionRefused :
-           message = _("Unable to establish a secure connection to host "
-                       "(peer dropped connection before responding).");
-           break;
-
-       default :
-           break;
-      }
-    }
-  }
-
-  if (error)
-  {
-    http->error  = error;
-    http->status = HTTP_STATUS_ERROR;
-    errno        = ECONNREFUSED;
-
-    CFRelease(http->tls);
-    http->tls = NULL;
-
-   /*
-    * If an error string wasn't set by the callbacks use a generic one...
-    */
-
-    if (!message)
-#ifdef HAVE_CSSMERRORSTRING
-      message = cssmErrorString(error);
-#else
-      message = _("Unable to establish a secure connection to host.");
-#endif /* HAVE_CSSMERRORSTRING */
-
-    _cupsSetError(IPP_STATUS_ERROR_CUPS_PKI, message, 1);
-
-    return (-1);
-  }
-
-#  elif defined(HAVE_SSPISSL)
-  http->tls = _sspiAlloc();
-
-  if (!http->tls)
-  {
-    _cupsSetHTTPError(HTTP_STATUS_ERROR);
-    return (-1);
-  }
-
-  http->tls->sock = http->fd;
-  dwSize          = sizeof(username) / sizeof(TCHAR);
-  GetUserName(username, &dwSize);
-  _sntprintf_s(commonName, sizeof(commonName) / sizeof(TCHAR),
-               sizeof(commonName) / sizeof(TCHAR), TEXT("CN=%s"), username);
-
-  if (!_sspiGetCredentials(http->tls_credentials, L"ClientContainer",
-                           commonName, FALSE))
-  {
-    _sspiFree(http->tls_credentials);
-    http->tls_credentials = NULL;
-
-    http->error  = EIO;
-    http->status = HTTP_STATUS_ERROR;
-
-    _cupsSetError(IPP_STATUS_ERROR_CUPS_PKI,
-                  _("Unable to establish a secure connection to host."), 1);
-
-    return (-1);
-  }
-
-  _sspiSetAllowsAnyRoot(http->tls_credentials, TRUE);
-  _sspiSetAllowsExpiredCerts(http->tls_credentials, TRUE);
-
-  if (!_sspiConnect(http->tls_credentials, hostname))
-  {
-    _sspiFree(http->tls_credentials);
-    http->tls_credentials = NULL;
-
-    http->error  = EIO;
-    http->status = HTTP_STATUS_ERROR;
-
-    _cupsSetError(IPP_STATUS_ERROR_CUPS_PKI,
-                  _("Unable to establish a secure connection to host."), 1);
-
-    return (-1);
-  }
-#  endif /* HAVE_CDSASSL */
+  // TODO: Put this in the right place; no-op for now, this to get things to compile
+  http_tls_set_credentials(http);
 
   return (0);
 }
 
 
 /*
- * 'http_shutdown_ssl()' - Shut down SSL/TLS on a connection.
+ * 'http_tls_stop()' - Shut down SSL/TLS on a connection.
  */
 
 static void
-http_shutdown_ssl(http_t *http)                /* I - Connection to server */
+http_tls_stop(http_t *http)            /* I - Connection to server */
 {
-#  ifdef HAVE_LIBSSL
-  SSL_CTX      *context;               /* Context for encryption */
-
-  context = SSL_get_SSL_CTX(http->tls);
-
-  SSL_shutdown(http->tls);
-  SSL_CTX_free(context);
-  SSL_free(http->tls);
-
-#  elif defined(HAVE_GNUTLS)
   gnutls_certificate_client_credentials *credentials;
                                        /* TLS credentials */
 
@@ -590,33 +326,15 @@ http_shutdown_ssl(http_t *http)           /* I - Connection to server */
   gnutls_deinit(http->tls);
   gnutls_certificate_free_credentials(*credentials);
   free(credentials);
-
-#  elif defined(HAVE_CDSASSL)
-  while (SSLClose(http->tls) == errSSLWouldBlock)
-    usleep(1000);
-
-  CFRelease(http->tls);
-
-  if (http->tls_credentials)
-    CFRelease(http->tls_credentials);
-
-#  elif defined(HAVE_SSPISSL)
-  _sspiFree(http->tls_credentials);
-#  endif /* HAVE_LIBSSL */
-
-  http->tls             = NULL;
-  http->tls_credentials = NULL;
 }
-#endif /* HAVE_SSL */
 
 
-#ifdef HAVE_SSL
 /*
- * 'http_write_ssl()' - Write to a SSL/TLS connection.
+ * 'http_tls_write()' - Write to a SSL/TLS connection.
  */
 
 static int                             /* O - Bytes written */
-http_write_ssl(http_t     *http,       /* I - Connection to server */
+http_tls_write(http_t     *http,       /* I - Connection to server */
               const char *buf,         /* I - Buffer holding data */
               int        len)          /* I - Length of buffer */
 {
@@ -625,10 +343,6 @@ http_write_ssl(http_t     *http,   /* I - Connection to server */
 
   DEBUG_printf(("2http_write_ssl(http=%p, buf=%p, len=%d)", http, buf, len));
 
-#  if defined(HAVE_LIBSSL)
-  result = SSL_write((SSL *)(http->tls), buf, len);
-
-#  elif defined(HAVE_GNUTLS)
   result = gnutls_record_send(http->tls, buf, len);
 
   if (result < 0 && !errno)
@@ -655,157 +369,13 @@ http_write_ssl(http_t     *http, /* I - Connection to server */
     result = -1;
   }
 
-#  elif defined(HAVE_CDSASSL)
-  OSStatus     error;                  /* Error info */
-  size_t       processed;              /* Number of bytes processed */
-
-
-  error = SSLWrite(http->tls, buf, len, &processed);
-
-  switch (error)
-  {
-    case 0 :
-       result = (int)processed;
-       break;
-
-    case errSSLWouldBlock :
-       if (processed)
-         result = (int)processed;
-       else
-       {
-         result = -1;
-         errno  = EINTR;
-       }
-       break;
-
-    case errSSLClosedGraceful :
-    default :
-       if (processed)
-         result = (int)processed;
-       else
-       {
-         result = -1;
-         errno  = EPIPE;
-       }
-       break;
-  }
-#  elif defined(HAVE_SSPISSL)
-  return _sspiWrite((_sspi_struct_t *)http->tls, (void *)buf, len);
-#  endif /* HAVE_LIBSSL */
-
   DEBUG_printf(("3http_write_ssl: Returning %d.", (int)result));
 
   return ((int)result);
 }
-#endif /* HAVE_SSL */
-
-
-/*
- * 'http_tls_pending()' - Return the number of pending TLS-encrypted bytes.
- */
-
-static size_t
-http_tls_pending(http_t *http)         /* I - HTTP connection */
-{
-  if (http->tls && usessl)
-  {
-#  ifdef HAVE_LIBSSL
-    if (SSL_pending(http->tls))
-    {
-      DEBUG_puts("5_httpWait: Return 1 since there is pending SSL data.");
-      return (1);
-    }
-
-#  elif defined(HAVE_GNUTLS)
-    if (gnutls_record_check_pending(http->tls))
-    {
-      DEBUG_puts("5_httpWait: Return 1 since there is pending SSL data.");
-      return (1);
-    }
-
-#  elif defined(HAVE_CDSASSL)
-    size_t bytes;                      /* Bytes that are available */
-
-    if (!SSLGetBufferedReadSize(http->tls, &bytes) &&
-        bytes > 0)
-    {
-      DEBUG_puts("5_httpWait: Return 1 since there is pending SSL data.");
-      return (1);
-    }
-#  endif /* HAVE_LIBSSL */
-}
-
-
-#if defined(HAVE_SSL) && defined(HAVE_GNUTLS)
-/*
- * '_httpReadGNUTLS()' - Read function for the GNU TLS library.
- */
-
-ssize_t                                        /* O - Number of bytes read or -1 on error */
-_httpReadGNUTLS(
-    gnutls_transport_ptr ptr,          /* I - Connection to server */
-    void                 *data,                /* I - Buffer */
-    size_t               length)       /* I - Number of bytes to read */
-{
-  http_t       *http;                  /* HTTP connection */
-  ssize_t      bytes;                  /* Bytes read */
-
-
-  DEBUG_printf(("6_httpReadGNUTLS(ptr=%p, data=%p, length=%d)", ptr, data, (int)length));
-
-  http = (http_t *)ptr;
-
-  if (!http->blocking)
-  {
-   /*
-    * Make sure we have data before we read...
-    */
-
-    while (!_httpWait(http, http->wait_value, 0))
-    {
-      if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data))
-       continue;
-
-      http->error = ETIMEDOUT;
-      return (-1);
-    }
-  }
-
-  bytes = recv(http->fd, data, length, 0);
-  DEBUG_printf(("6_httpReadGNUTLS: bytes=%d", (int)bytes));
-  return (bytes);
-}
-#endif /* HAVE_SSL && HAVE_GNUTLS */
-
-
-#if defined(HAVE_SSL) && defined(HAVE_GNUTLS)
-/*
- * '_httpWriteGNUTLS()' - Write function for the GNU TLS library.
- */
-
-ssize_t                                        /* O - Number of bytes written or -1 on error */
-_httpWriteGNUTLS(
-    gnutls_transport_ptr ptr,          /* I - Connection to server */
-    const void           *data,                /* I - Data buffer */
-    size_t               length)       /* I - Number of bytes to write */
-{
-  ssize_t bytes;                       /* Bytes written */
-
-
-  DEBUG_printf(("6_httpWriteGNUTLS(ptr=%p, data=%p, length=%d)", ptr, data,
-                (int)length));
-#ifdef DEBUG
-  http_debug_hex("_httpWriteGNUTLS", data, (int)length);
-#endif /* DEBUG */
-
-  bytes = send(((http_t *)ptr)->fd, data, length, 0);
-  DEBUG_printf(("_httpWriteGNUTLS: bytes=%d", (int)bytes));
-
-  return (bytes);
-}
-#endif /* HAVE_SSL && HAVE_GNUTLS */
 
 
+#if 0
 /*
  * 'cupsdEndTLS()' - Shutdown a secure session with the client.
  */
@@ -896,9 +466,9 @@ cupsdStartTLS(cupsd_client_t *con)  /* I - Client connection */
   gnutls_set_default_priority(con->http.tls);
 
   gnutls_credentials_set(con->http.tls, GNUTLS_CRD_CERTIFICATE, *credentials);
-  gnutls_transport_set_ptr(con->http.tls, (gnutls_transport_ptr)HTTP(con));
-  gnutls_transport_set_pull_function(con->http.tls, _httpReadGNUTLS);
-  gnutls_transport_set_push_function(con->http.tls, _httpWriteGNUTLS);
+  gnutls_transport_set_ptr(con->http.tls, (gnutls_transport_ptr_t)HTTP(con));
+  gnutls_transport_set_pull_function(con->http.tls, http_gnutls_read);
+  gnutls_transport_set_push_function(con->http.tls, http_gnutls_write);
 
   while ((status = gnutls_handshake(con->http.tls)) != GNUTLS_E_SUCCESS)
   {
@@ -1064,6 +634,7 @@ make_certificate(cupsd_client_t *con)      /* I - Client connection */
 
   return (1);
 }
+#endif /* 0 */
 
 
 /*