src/lib/tls.c
TLS_CONNECTION *new_tls_connection(TLS_CONTEXT *ctx, int fd)
{
   BIO *bio;

   /*
    * Create a new BIO and assign the fd.
    * The caller will remain responsible for closing the associated fd
    */
   bio = BIO_new(BIO_s_socket());
   if (!bio) {
      /* Not likely, but never say never */
      openssl_post_errors(M_FATAL, _("Error creating file descriptor-based BIO"));
      return NULL; /* Nothing allocated, nothing to clean up */
   }
   BIO_set_fd(bio, fd, BIO_NOCLOSE);

   /* Allocate our new tls connection */
   TLS_CONNECTION *tls = (TLS_CONNECTION *)malloc(sizeof(TLS_CONNECTION));

   /* Create the SSL object and attach the socket BIO */
   if ((tls->openssl = SSL_new(ctx->openssl)) == NULL) {
      /* Not likely, but never say never */
      openssl_post_errors(M_FATAL, _("Error creating new SSL object"));
      goto err;
   }

   SSL_set_bio(tls->openssl, bio, bio);

   /* Non-blocking partial writes */
   SSL_set_mode(tls->openssl, SSL_MODE_ENABLE_PARTIAL_WRITE|SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);

   pthread_mutex_init(&tls->wlock, NULL);
   pthread_mutex_init(&tls->rwlock, NULL);

   return tls;

err:
   /* Clean up */
   BIO_free(bio);
   SSL_free(tls->openssl);
   free(tls);
   return NULL;
}
/*
 * Create a new TLS_CONNECTION instance.
 *
 * Returns: Pointer to TLS_CONNECTION instance on success
 *          NULL on failure;
 */
Create a new TLS_CONNECTION instance.
Returns: Pointer to TLS_CONNECTION instance on success
NULL on failure.
Create a new TLS_CONNECTION instance . Returns : Pointer to TLS_CONNECTION instance on success NULL on failure .
TLS_CONNECTION *new_tls_connection(TLS_CONTEXT *ctx, int fd)
{
   BIO *bio;
   bio = BIO_new(BIO_s_socket());
   if (!bio) {
      openssl_post_errors(M_FATAL, _("Error creating file descriptor-based BIO"));
      return NULL; 
   }
   BIO_set_fd(bio, fd, BIO_NOCLOSE);
   TLS_CONNECTION *tls = (TLS_CONNECTION *)malloc(sizeof(TLS_CONNECTION));
   if ((tls->openssl = SSL_new(ctx->openssl)) == NULL) {
      openssl_post_errors(M_FATAL, _("Error creating new SSL object"));
      goto err;
   }
   SSL_set_bio(tls->openssl, bio, bio);
   SSL_set_mode(tls->openssl, SSL_MODE_ENABLE_PARTIAL_WRITE|SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
   pthread_mutex_init(&tls->wlock, NULL);
   pthread_mutex_init(&tls->rwlock, NULL);
   return tls;
err:
   BIO_free(bio);
   SSL_free(tls->openssl);
   free(tls);
   return NULL;
}
TLS_CONNECTION * new_tls_connection ( TLS_CONTEXT * ctx , int fd ) { BIO * bio ; bio = BIO_new ( BIO_s_socket ( ) ) ; if ( ! bio ) { openssl_post_errors ( M_FATAL , _ ( " " ) ) ; return NULL ; } BIO_set_fd ( bio , fd , BIO_NOCLOSE ) ; TLS_CONNECTION * tls = ( TLS_CONNECTION * ) malloc ( sizeof ( TLS_CONNECTION ) ) ; if ( ( tls -> openssl = SSL_new ( ctx -> openssl ) ) == NULL ) { openssl_post_errors ( M_FATAL , _ ( " " ) ) ; goto err ; } SSL_set_bio ( tls -> openssl , bio , bio ) ; SSL_set_mode ( tls -> openssl , SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER ) ; pthread_mutex_init ( & tls -> wlock , NULL ) ; pthread_mutex_init ( & tls -> rwlock , NULL ) ; return tls ; err : BIO_free ( bio ) ; SSL_free ( tls -> openssl ) ; free ( tls ) ; return NULL ; }
Create a new TLS_CONNECTION instance.
Create a new TLS_CONNECTION instance .
/*
    * Create a new BIO and assign the fd.
    * The caller will remain responsible for closing the associated fd
    */ /* Not likely, but never say never */ /* Nothing allocated, nothing to clean up */ /* Allocate our new tls connection */ /* Create the SSL object and attach the socket BIO */ /* Not likely, but never say never */ /* Non-blocking partial writes */ /* Clean up */