src/ssl_sock.c
static int ssl_sock_init(struct connection *conn)
{
	/* already initialized */
	if (conn->xprt_ctx)
		return 0;

	if (global.maxsslconn && sslconns >= global.maxsslconn) {
		conn->err_code = CO_ER_SSL_TOO_MANY;
		return -1;
	}

	/* If it is in client mode initiate SSL session
	   in connect state otherwise accept state */
	if (objt_server(conn->target)) {
		/* Alloc a new SSL session ctx */
		conn->xprt_ctx = SSL_new(objt_server(conn->target)->ssl_ctx.ctx);
		if (!conn->xprt_ctx) {
			conn->err_code = CO_ER_SSL_NO_MEM;
			return -1;
		}

		SSL_set_connect_state(conn->xprt_ctx);
		if (objt_server(conn->target)->ssl_ctx.reused_sess)
			SSL_set_session(conn->xprt_ctx, objt_server(conn->target)->ssl_ctx.reused_sess);

		/* set fd on SSL session context */
		SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);

		/* leave init state and start handshake */
		conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN;

		sslconns++;
		return 0;
	}
	else if (objt_listener(conn->target)) {
		/* Alloc a new SSL session ctx */
		conn->xprt_ctx = SSL_new(objt_listener(conn->target)->bind_conf->default_ctx);
		if (!conn->xprt_ctx) {
			conn->err_code = CO_ER_SSL_NO_MEM;
			return -1;
		}

		SSL_set_accept_state(conn->xprt_ctx);

		/* set fd on SSL session context */
		SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);

		/* set connection pointer */
		SSL_set_app_data(conn->xprt_ctx, conn);

		/* leave init state and start handshake */
		conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN;

		sslconns++;
		return 0;
	}
	/* don't know how to handle such a target */
	conn->err_code = CO_ER_SSL_NO_TARGET;
	return -1;
}
/*
 * This function is called if SSL * context is not yet allocated. The function
 * is designed to be called before any other data-layer operation and sets the
 * handshake flag on the connection. It is safe to call it multiple times.
 * It returns 0 on success and -1 in error case.
 */
This function is called if SSL * context is not yet allocated. The function
is designed to be called before any other data-layer operation and sets the
handshake flag on the connection. It is safe to call it multiple times.
It returns 0 on success and -1 in error case.
This function is called if SSL * context is not yet allocated . The function is designed to be called before any other data - layer operation and sets the handshake flag on the connection . It is safe to call it multiple times . It returns 0 on success and - 1 in error case .
static int ssl_sock_init(struct connection *conn)
{
	if (conn->xprt_ctx)
		return 0;
	if (global.maxsslconn && sslconns >= global.maxsslconn) {
		conn->err_code = CO_ER_SSL_TOO_MANY;
		return -1;
	}
	if (objt_server(conn->target)) {
		conn->xprt_ctx = SSL_new(objt_server(conn->target)->ssl_ctx.ctx);
		if (!conn->xprt_ctx) {
			conn->err_code = CO_ER_SSL_NO_MEM;
			return -1;
		}
		SSL_set_connect_state(conn->xprt_ctx);
		if (objt_server(conn->target)->ssl_ctx.reused_sess)
			SSL_set_session(conn->xprt_ctx, objt_server(conn->target)->ssl_ctx.reused_sess);
		SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);
		conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN;
		sslconns++;
		return 0;
	}
	else if (objt_listener(conn->target)) {
		conn->xprt_ctx = SSL_new(objt_listener(conn->target)->bind_conf->default_ctx);
		if (!conn->xprt_ctx) {
			conn->err_code = CO_ER_SSL_NO_MEM;
			return -1;
		}
		SSL_set_accept_state(conn->xprt_ctx);
		SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);
		SSL_set_app_data(conn->xprt_ctx, conn);
		conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN;
		sslconns++;
		return 0;
	}
	conn->err_code = CO_ER_SSL_NO_TARGET;
	return -1;
}
static int ssl_sock_init ( struct connection * conn ) { if ( conn -> xprt_ctx ) return 0 ; if ( global . maxsslconn && sslconns >= global . maxsslconn ) { conn -> err_code = CO_ER_SSL_TOO_MANY ; return -1 ; } if ( objt_server ( conn -> target ) ) { conn -> xprt_ctx = SSL_new ( objt_server ( conn -> target ) -> ssl_ctx . ctx ) ; if ( ! conn -> xprt_ctx ) { conn -> err_code = CO_ER_SSL_NO_MEM ; return -1 ; } SSL_set_connect_state ( conn -> xprt_ctx ) ; if ( objt_server ( conn -> target ) -> ssl_ctx . reused_sess ) SSL_set_session ( conn -> xprt_ctx , objt_server ( conn -> target ) -> ssl_ctx . reused_sess ) ; SSL_set_fd ( conn -> xprt_ctx , conn -> t . sock . fd ) ; conn -> flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN ; sslconns ++ ; return 0 ; } else if ( objt_listener ( conn -> target ) ) { conn -> xprt_ctx = SSL_new ( objt_listener ( conn -> target ) -> bind_conf -> default_ctx ) ; if ( ! conn -> xprt_ctx ) { conn -> err_code = CO_ER_SSL_NO_MEM ; return -1 ; } SSL_set_accept_state ( conn -> xprt_ctx ) ; SSL_set_fd ( conn -> xprt_ctx , conn -> t . sock . fd ) ; SSL_set_app_data ( conn -> xprt_ctx , conn ) ; conn -> flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN ; sslconns ++ ; return 0 ; } conn -> err_code = CO_ER_SSL_NO_TARGET ; return -1 ; }
This function is called if SSL * context is not yet allocated.
This function is called if SSL * context is not yet allocated .
/* already initialized */ /* If it is in client mode initiate SSL session
	   in connect state otherwise accept state */ /* Alloc a new SSL session ctx */ /* set fd on SSL session context */ /* leave init state and start handshake */ /* Alloc a new SSL session ctx */ /* set fd on SSL session context */ /* set connection pointer */ /* leave init state and start handshake */ /* don't know how to handle such a target */