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

ODBC SSL Compliance Fix #75

Merged
merged 10 commits into from
Jun 22, 2022
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
156 changes: 108 additions & 48 deletions sql-odbc/src/IntegrationTests/ITODBCConnection/test_odbc_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ TEST_F(TestSQLDriverConnect, InvalidDriver) {
std::wstring invalid_driver_conn_string =
use_ssl ? L"Driver=xxxx;"
L"host=https://localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver=xxxx;"
L"host=localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret = SQLDriverConnect(
Expand All @@ -164,13 +164,13 @@ TEST_F(TestSQLDriverConnect, InvalidHost) {
std::wstring invalid_host_conn_string =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=1;"
: L"Driver={OpenSearch ODBC};"
L"host=8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=1;";

SQLRETURN ret = SQLDriverConnect(
Expand All @@ -184,13 +184,13 @@ TEST_F(TestSQLDriverConnect, InvalidPort) {
std::wstring invalid_port_conn_string =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"host=localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret = SQLDriverConnect(
Expand All @@ -207,13 +207,13 @@ TEST_F(TestSQLDriverConnect, UnsupportedKeyword) {
std::wstring unsupported_keyword_conn_string =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;extra=1"
: L"Driver={OpenSearch ODBC};"
L"host=localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;extra=1";

SQLRETURN ret = SQLDriverConnect(
Expand All @@ -227,13 +227,13 @@ TEST_F(TestSQLDriverConnect, ConnStringAbbrevsUID) {
std::wstring abbrev_str =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://localhost;port=9200;"
L"UID=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"UID=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"host=localhost;port=9200;"
L"UID=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"UID=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret =
Expand All @@ -247,13 +247,13 @@ TEST_F(TestSQLDriverConnect, ConnStringAbbrevsPWD) {
std::wstring abbrev_str =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://localhost;port=9200;"
L"user=admin;PWD=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;PWD=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"host=localhost;port=9200;"
L"user=admin;PWD=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;PWD=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret =
Expand All @@ -267,13 +267,73 @@ TEST_F(TestSQLDriverConnect, ConnStringAbbrevsUIDPWD) {
std::wstring abbrev_str =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"host=localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret =
SQLDriverConnect(m_conn, NULL, (SQLTCHAR*)abbrev_str.c_str(), SQL_NTS,
m_out_conn_string, IT_SIZEOF(m_out_conn_string),
&m_out_conn_string_length, SQL_DRIVER_NOPROMPT);
EXPECT_EQ(SQL_SUCCESS, ret);
}

TEST_F(TestSQLDriverConnect, ConnStringAbbrevsHostMixedProtocol) {
std::wstring abbrev_str =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=http://localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"host=https://localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret =
SQLDriverConnect(m_conn, NULL, (SQLTCHAR*)abbrev_str.c_str(), SQL_NTS,
m_out_conn_string, IT_SIZEOF(m_out_conn_string),
&m_out_conn_string_length, SQL_DRIVER_NOPROMPT);
EXPECT_EQ(SQL_ERROR, ret);
}

TEST_F(TestSQLDriverConnect, ConnStringAbbrevsHost) {
std::wstring abbrev_str =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"host=localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret =
SQLDriverConnect(m_conn, NULL, (SQLTCHAR*)abbrev_str.c_str(), SQL_NTS,
m_out_conn_string, IT_SIZEOF(m_out_conn_string),
&m_out_conn_string_length, SQL_DRIVER_NOPROMPT);
EXPECT_EQ(SQL_SUCCESS, ret);
}

TEST_F(TestSQLDriverConnect, ConnStringAbbrevsHostProtocol) {
std::wstring abbrev_str =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"host=http://localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret =
Expand All @@ -287,13 +347,13 @@ TEST_F(TestSQLDriverConnect, ConnStringAbbrevsServer) {
std::wstring abbrev_str =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"server=https://localhost;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"server=localhost;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret =
Expand All @@ -307,13 +367,13 @@ TEST_F(TestSQLDriverConnect, ConnStringAbbrevsServerUIDPWD) {
std::wstring abbrev_str =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"server=https://localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={OpenSearch ODBC};"
L"server=localhost;port=9200;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"UID=admin;PWD=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret =
Expand All @@ -327,13 +387,13 @@ TEST_F(TestSQLDriverConnect, Timeout1Second) {
std::wstring one_second_timeout =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=1;"
: L"Driver={OpenSearch ODBC};"
L"host=8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=1;";

auto start = std::chrono::steady_clock::now();
Expand Down Expand Up @@ -363,13 +423,13 @@ TEST_F(TestSQLDriverConnect, Timeout3Second) {
std::wstring one_second_timeout =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=3;"
: L"Driver={OpenSearch ODBC};"
L"host=8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=3;";

auto start = std::chrono::steady_clock::now();
Expand Down Expand Up @@ -399,13 +459,13 @@ TEST_F(TestSQLDriverConnect, Timeout7Second) {
std::wstring seven_second_timeout =
use_ssl ? L"Driver={OpenSearch ODBC};"
L"host=https://8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=1;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=7;"
: L"Driver={OpenSearch ODBC};"
L"host=8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"user=admin;password=admin;auth=BASIC;useSSL=0;"
L"hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=7;";

auto start = std::chrono::steady_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion sql-odbc/src/sqlodbc/dlg_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ extern "C" {
#define DEFAULT_BOOLSASCHAR 0
#define DEFAULT_UNIQUEINDEX 1 /* dont recognize */
#define DEFAULT_LOGLEVEL OPENSEARCH_WARNING
#define DEFAULT_USE_SSL 0
#define DEFAULT_USE_SSL 1
#define DEFAULT_TRUST_SELF_SIGNED 0
#define DEFAULT_AUTH_MODE "NONE"
#define DEFAULT_REGION ""
Expand Down
30 changes: 28 additions & 2 deletions sql-odbc/src/sqlodbc/dlg_wingui.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "xalibname.h"
#endif /* _HANDLE_ENLIST_IN_DTC_ */

#define HTTP_PREFIX "http://"
#define HTTPS_PREFIX "https://"

#define AUTHMODE_CNT 3
#define LOGLEVEL_CNT 8
extern HINSTANCE s_hModule;
Expand Down Expand Up @@ -137,14 +140,37 @@ static void getDriversDefaultsOfCi(const ConnInfo *ci, GLOBAL_VALUES *glbv) {
getDriversDefaults(INVALID_DRIVER, glbv);
}

/**
* @brief Initializes and closes the advanced dialog box.
*
* @param hdlg : Handle to dialog box
* @param wMsg : Dialog box command message
* @param wParam : Handle to the control to receive keyboard focus
* @param lParam : Dialog connection data
* @return INT_PTR : Returns true on successful command of advanced dialog box
*/
INT_PTR CALLBACK advancedOptionsProc(HWND hdlg, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
switch (wMsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hdlg, DWLP_USER, lParam);
ConnInfo *ci = (ConnInfo *)lParam;
CheckDlgButton(hdlg, IDC_USESSL, ci->use_ssl);
CheckDlgButton(hdlg, IDC_HOST_VER, ci->verify_server);

// To avoid cases in which the "UseSSL" flag is different from a specified server protocol
if (strncmp(HTTP_PREFIX, ci->server, strlen(HTTP_PREFIX)) == 0) {
CheckDlgButton(hdlg, IDC_USESSL, FALSE);
CheckDlgButton(hdlg, IDC_HOST_VER, FALSE);
EnableWindow(GetDlgItem(hdlg, IDC_USESSL), FALSE);
EnableWindow(GetDlgItem(hdlg, IDC_HOST_VER), FALSE);
} else if (strncmp(HTTPS_PREFIX, ci->server, strlen(HTTPS_PREFIX)) == 0) {
CheckDlgButton(hdlg, IDC_USESSL, TRUE);
CheckDlgButton(hdlg, IDC_HOST_VER, ci->verify_server);
EnableWindow(GetDlgItem(hdlg, IDC_USESSL), FALSE);
} else {
CheckDlgButton(hdlg, IDC_USESSL, ci->use_ssl);
CheckDlgButton(hdlg, IDC_HOST_VER, ci->verify_server);
}

SetDlgItemText(hdlg, IDC_CONNTIMEOUT, ci->response_timeout);
SetDlgItemText(hdlg, IDC_FETCH_SIZE, ci->fetch_size);
break;
Expand Down
Loading