Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-23639] CAS change for SSL #2279

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions cubrid_broker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#
# Copyright (C) 2008 Search Solution Corporation. All rights reserved by Search Solution.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#

[broker]
MASTER_SHM_ID =30001
ADMIN_LOG_FILE =log/broker/cubrid_broker.log

[%query_editor]
SERVICE =ON
SSL =ON
BROKER_PORT =30000
MIN_NUM_APPL_SERVER =5
MAX_NUM_APPL_SERVER =40
APPL_SERVER_SHM_ID =30000
LOG_DIR =log/broker/sql_log
ERROR_LOG_DIR =log/broker/error_log
SQL_LOG =ON
TIME_TO_KILL =120
SESSION_TIMEOUT =300
KEEP_CONNECTION =AUTO
CCI_DEFAULT_AUTOCOMMIT =ON

[%BROKER1]
SERVICE =ON
SSL =ON
BROKER_PORT =33000
MIN_NUM_APPL_SERVER =5
MAX_NUM_APPL_SERVER =40
APPL_SERVER_SHM_ID =33000
LOG_DIR =log/broker/sql_log
ERROR_LOG_DIR =log/broker/error_log
SQL_LOG =ON
TIME_TO_KILL =120
SESSION_TIMEOUT =300
KEEP_CONNECTION =AUTO
CCI_DEFAULT_AUTOCOMMIT =ON
25 changes: 25 additions & 0 deletions src/broker/cas.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ static void set_db_connection_info (void);
static void clear_db_connection_info (void);
static bool need_database_reconnect (void);

extern int initSSL (int);
extern bool ssl_client;
extern void cas_ssl_close (int client_sock_fd);

#else /* !LIBCAS_FOR_JSP */
extern int libcas_main (SOCKET jsp_sock_fd);
extern void *libcas_get_db_result_set (int h_id);
Expand Down Expand Up @@ -880,6 +884,7 @@ cas_main (void)
#endif /* WINDOWS */
for (;;)
{
ssl_client = false;
error_info_clear ();
cas_info[CAS_INFO_STATUS] = CAS_INFO_STATUS_INACTIVE;

Expand Down Expand Up @@ -1009,6 +1014,17 @@ cas_main (void)
db_info_size = SRV_CON_DB_INFO_SIZE;
}

if (IS_SSL_CLIENT (req_info.driver_info))
{
err_code = initSSL (client_sock_fd);
if (err_code < 0)
{
net_write_error (client_sock_fd, req_info.client_version, req_info.driver_info, cas_info, cas_info_size,
CAS_ERROR_INDICATOR, CAS_ER_COMMUNICATION, NULL);
goto finish_cas;
}
}

if (net_read_stream (client_sock_fd, read_buf, db_info_size) < 0)
{
cas_info[CAS_INFO_STATUS] = CAS_INFO_STATUS_INACTIVE;
Expand Down Expand Up @@ -1183,6 +1199,10 @@ cas_main (void)
cas_log_write_and_end (0, false, msg_buf);
cas_slow_log_write_and_end (NULL, 0, msg_buf);

if (ssl_client)
{
cas_ssl_close (client_sock_fd);
}
CLOSE_SOCKET (client_sock_fd);
FREE_MEM (db_err_msg);

Expand Down Expand Up @@ -1309,6 +1329,11 @@ cas_main (void)
#endif /* !CAS_FOR_ORACLE && !CAS_FOR_MYSQL */
}

if (ssl_client)
{
cas_ssl_close (client_sock_fd);
}

CLOSE_SOCKET (client_sock_fd);

finish_cas:
Expand Down
40 changes: 34 additions & 6 deletions src/broker/cas_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ static bool net_timeout_flag = false;
static char net_error_flag;
static int net_timeout = NET_DEFAULT_TIMEOUT;

extern bool ssl_client;
extern int cas_ssl_write (int sock_fd, const char *buf, int size);
extern int cas_ssl_read (int sock_fd, char *buf, int size);

SOCKET
#if defined(WINDOWS)
net_init_env (int *new_port)
Expand Down Expand Up @@ -277,7 +281,7 @@ net_write_stream (SOCKET sock_fd, const char *buf, int size)
{
int write_len;

write_len = write_buffer (sock_fd, buf, size);
write_len = ssl_client ? cas_ssl_write (sock_fd, buf, size) : write_buffer (sock_fd, buf, size);

if (write_len <= 0)
{
Expand All @@ -299,7 +303,7 @@ net_read_stream (SOCKET sock_fd, char *buf, int size)
{
int read_len;

read_len = read_buffer (sock_fd, buf, size);
read_len = ssl_client ? cas_ssl_read (sock_fd, buf, size) : read_buffer (sock_fd, buf, size);

if (read_len <= 0)
{
Expand All @@ -316,19 +320,43 @@ net_read_stream (SOCKET sock_fd, char *buf, int size)
return 0;
}

int
net_read_stream_plain (SOCKET sock_fd, char *buf, int size)
{
while (size > 0)
{
int read_len;

read_len = read_buffer (sock_fd, buf, size);

if (read_len < 0)
{
#ifdef _DEBUG
if (!is_net_timed_out ())
printf ("read error %d\n", read_len);
#endif
return -1;
}
buf += read_len;
size -= read_len;
}

return 0;
}

int
net_read_header (SOCKET sock_fd, MSG_HEADER * header)
{
int retval = 0;

if (cas_info_size > 0)
{
retval = net_read_stream (sock_fd, header->buf, MSG_HEADER_SIZE);
retval = net_read_stream_plain (sock_fd, header->buf, MSG_HEADER_SIZE);
*(header->msg_body_size_ptr) = ntohl (*(header->msg_body_size_ptr));
}
else
{
retval = net_read_int (sock_fd, header->msg_body_size_ptr);
retval = net_read_stream_plain (sock_fd, (char *) header->msg_body_size_ptr, 4);
}

return retval;
Expand Down Expand Up @@ -581,7 +609,7 @@ read_buffer (SOCKET sock_fd, char *buf, int size)
{
#endif /* ASYNC_MODE */
/* RECEIVE NEW REQUEST */
read_len = READ_FROM_SOCKET (sock_fd, buf, size);
read_len = ssl_client ? cas_ssl_read (sock_fd, buf, size) : READ_FROM_SOCKET (sock_fd, buf, size);
#if defined(ASYNC_MODE)
}
}
Expand Down Expand Up @@ -643,7 +671,7 @@ write_buffer (SOCKET sock_fd, const char *buf, int size)
else if (po[0].revents & POLLOUT)
{
#endif /* ASYNC_MODE */
write_len = WRITE_TO_SOCKET (sock_fd, buf, size);
write_len = ssl_client ? cas_ssl_write (sock_fd, buf, size) : WRITE_TO_SOCKET (sock_fd, buf, size);
#if defined(ASYNC_MODE)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/broker/cas_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ cas_ssl_close (int client_sock_fd)
SSL_free (ssl);
ssl = NULL;
}
}
}