Skip to content

Commit 8f498c6

Browse files
Fixed bug validating the database host during connection.
1 parent 98a9db4 commit 8f498c6

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

doc/src/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Thin Mode Changes
2323
types :attr:`oracledb.DB_TYPE_TIMESTAMP`,
2424
:attr:`oracledb.DB_TYPE_TIMESTAMP_TZ` and
2525
:attr:`oracledb.DB_TYPE_TIMESTAMP_LTZ`.
26+
#) Fixed bug validating the database host during connection.
2627
#) Internal change: refactor encoding of Oracle data types.
2728
#) Internal change: small performance improvement sending bytes on the
2829
network transport.

src/oracledb/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def _raise_not_supported(feature: str) -> None:
363363
ERR_INVALID_SSL_VERSION = 4032
364364
ERR_EXCEEDED_IDLE_TIME = 4033
365365
ERR_INVALID_PASSWORD_TYPE = 4034
366+
ERR_INVALID_SERVER_RESPONSE = 4035
366367

367368
# error numbers that result in InternalError
368369
ERR_MESSAGE_TYPE_UNKNOWN = 5000
@@ -674,6 +675,9 @@ def _raise_not_supported(feature: str) -> None:
674675
"The name on the server certificate does not match the expected "
675676
'value: "{expected_name}"'
676677
),
678+
ERR_INVALID_SERVER_RESPONSE: (
679+
"invalid server response to connection request"
680+
),
677681
ERR_INVALID_SERVER_TYPE: "invalid server_type: {server_type}",
678682
ERR_INVALID_SERVICE_NAME: (
679683
'Service "{service_name}" is not registered with the listener at '

src/oracledb/impl/thin/capabilities.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ cdef class Capabilities:
106106
TNS_CCAP_O7LOGON | TNS_CCAP_O8LOGON_LONG_IDENTIFIER | \
107107
TNS_CCAP_O9LOGON_LONG_PASSWORD
108108
self.compile_caps[TNS_CCAP_FEATURE_BACKPORT] = \
109-
TNS_CCAP_CTB_IMPLICIT_POOL
109+
TNS_CCAP_CTB_IMPLICIT_POOL | \
110+
TNS_CCAP_CTB_OAUTH_MSG_ON_ERR
110111
self.compile_caps[TNS_CCAP_FIELD_VERSION] = self.ttc_field_version
111112
self.compile_caps[TNS_CCAP_SERVER_DEFINE_CONV] = 1
112113
self.compile_caps[TNS_CCAP_DEQUEUE_WITH_SELECTOR] = 1

src/oracledb/impl/thin/constants.pxi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ cdef enum:
455455
TNS_CCAP_O8LOGON_LONG_IDENTIFIER = 64
456456
TNS_CCAP_O9LOGON_LONG_PASSWORD = 0x80
457457
TNS_CCAP_CTB_IMPLICIT_POOL = 0x08
458+
TNS_CCAP_CTB_OAUTH_MSG_ON_ERR = 0x10
458459
TNS_CCAP_END_OF_CALL_STATUS = 0x01
459460
TNS_CCAP_IND_RCD = 0x08
460461
TNS_CCAP_FAST_BVEC = 0x20

src/oracledb/impl/thin/messages/auth.pyx

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ cdef class AuthMessage(Message):
206206

207207
cdef int _process_return_parameters(self, ReadBuffer buf) except -1:
208208
cdef:
209+
bytes encoded_response, response
209210
uint16_t num_params, i
210211
str key, value
211212
buf.read_ub2(&num_params)
@@ -222,26 +223,15 @@ cdef class AuthMessage(Message):
222223
if self.function_code == TNS_FUNC_AUTH_PHASE_ONE:
223224
self.function_code = TNS_FUNC_AUTH_PHASE_TWO
224225
elif not self.change_password:
225-
self.conn_impl._session_id = \
226-
<uint32_t> int(self.session_data["AUTH_SESSION_ID"])
227-
self.conn_impl._serial_num = \
228-
<uint16_t> int(self.session_data["AUTH_SERIAL_NUM"])
229-
self.conn_impl._db_domain = \
230-
self.session_data.get("AUTH_SC_DB_DOMAIN")
231-
self.conn_impl._db_name = \
232-
self.session_data.get("AUTH_SC_DBUNIQUE_NAME")
233-
self.conn_impl._max_open_cursors = \
234-
int(self.session_data.get("AUTH_MAX_OPEN_CURSORS", 0))
235-
self.conn_impl._service_name = \
236-
self.session_data.get("AUTH_SC_SERVICE_NAME")
237-
self.conn_impl._instance_name = \
238-
self.session_data.get("AUTH_INSTANCENAME")
239-
self.conn_impl._max_identifier_length = \
240-
int(self.session_data.get("AUTH_MAX_IDEN_LENGTH", 30))
241-
self.conn_impl.server_version = self._get_version_tuple(buf)
242-
self.conn_impl.supports_bool = \
243-
buf._caps.ttc_field_version >= TNS_CCAP_FIELD_VERSION_23_1
244-
self.conn_impl._edition = self.edition
226+
response = None
227+
value = self.session_data.get("AUTH_SVR_RESPONSE")
228+
if value is not None:
229+
encoded_response = bytes.fromhex(value)
230+
response = decrypt_cbc(
231+
self.conn_impl._combo_key, encoded_response
232+
)
233+
if response is None or response[16:32] != b"SERVER_TO_CLIENT":
234+
errors._raise_err(errors.ERR_INVALID_SERVER_RESPONSE)
245235

246236
cdef int _set_params(self, ConnectParamsImpl params,
247237
Description description) except -1:

src/oracledb/impl/thin/protocol.pyx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,27 @@ cdef class BaseProtocol:
176176
the packet may indicate EOF for the initial connection that is
177177
established.
178178
"""
179+
cdef:
180+
dict session_data = auth_message.session_data
181+
ReadBuffer buf = self._read_buf
182+
conn_impl._session_id = \
183+
<uint32_t> int(session_data["AUTH_SESSION_ID"])
184+
conn_impl._serial_num = \
185+
<uint16_t> int(session_data["AUTH_SERIAL_NUM"])
186+
conn_impl._db_domain = session_data.get("AUTH_SC_DB_DOMAIN")
187+
conn_impl._db_name = session_data.get("AUTH_SC_DBUNIQUE_NAME")
188+
conn_impl._max_open_cursors = \
189+
int(session_data.get("AUTH_MAX_OPEN_CURSORS", 0))
190+
conn_impl._service_name = session_data.get("AUTH_SC_SERVICE_NAME")
191+
conn_impl._instance_name = session_data.get("AUTH_INSTANCENAME")
192+
conn_impl._max_identifier_length = \
193+
int(session_data.get("AUTH_MAX_IDEN_LENGTH", 30))
194+
conn_impl.server_version = auth_message._get_version_tuple(buf)
195+
conn_impl.supports_bool = \
196+
buf._caps.ttc_field_version >= TNS_CCAP_FIELD_VERSION_23_1
197+
conn_impl._edition = auth_message.edition
179198
conn_impl.warning = auth_message.warning
180-
self._read_buf._pending_error_num = 0
199+
buf._pending_error_num = 0
181200
self._in_connect = False
182201

183202
cdef int _send_marker(self, WriteBuffer buf, uint8_t marker_type):

0 commit comments

Comments
 (0)