Skip to content

Commit 28df389

Browse files
Added support for using the TLS SNI extension to reduce the number of
TLS renegotiations that are needed to connect to the database.
1 parent 8392f23 commit 28df389

15 files changed

+205
-18
lines changed

doc/src/api_manual/connect_params.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ ConnectParams Methods
6262
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
6363
program=oracledb.defaults.program, machine=oracledb.defaults.machine, \
6464
terminal=oracledb.defaults.terminal, osuser=oracledb.defaults.osuser, \
65-
driver_name=oracledb.defaults.driver_name, handle=None)
65+
driver_name=oracledb.defaults.driver_name, use_sni=None, handle=None)
6666

6767
Sets the values for one or more of the parameters of a ConnectParams
6868
object.
6969

70+
.. versionchanged:: 3.0.0
71+
72+
The ``use_sni`` parameter was added.
73+
7074
.. versionchanged:: 2.5.0
7175

7276
The ``program``, ``machine``, ``terminal``, ``osuser``, and
@@ -509,6 +513,16 @@ ConnectParams Attributes
509513
The default value of this attribute was changed from *60.0* seconds to
510514
*20.0* seconds.
511515

516+
.. attribute:: ConnectParams.use_sni
517+
518+
This read-only attribute is a boolean which indicates whether to use the
519+
TLS Server Name Indicator (SNI) extension to bypass the second TLS
520+
negotiation that would otherwise be required.
521+
522+
This attribute is supported in both python-oracledb Thin and Thick modes.
523+
524+
.. versionadded:: 3.0.0
525+
512526
.. attribute:: ConnectParams.terminal
513527

514528
This read-only attribute is a string that specifies the terminal

doc/src/api_manual/module.rst

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Oracledb Methods
5252
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
5353
program=oracledb.defaults.program, machine=oracledb.defaults.machine, \
5454
terminal=oracledb.defaults.terminal, osuser=oracledb.defaults.osuser, \
55-
driver_name=oracledb.defaults.driver_name, handle=0)
55+
driver_name=oracledb.defaults.driver_name, use_sni=False, handle=0)
5656

5757
Constructor for creating a connection to the database. Returns a
5858
:ref:`Connection Object <connobj>`. All parameters are optional and can be
@@ -362,6 +362,12 @@ Oracledb Methods
362362
are using python-oracledb Thick mode, Oracle Client 23ai is additionally
363363
required.
364364

365+
The ``use_sni`` parameter is expected to be a boolean which indicates
366+
whether to use the TLS Server Name Indicator (SNI) extension to bypass the
367+
second TLS neogiation that would otherwise be required. This parameter is
368+
used in both python-oracledb Thin and Thick modes. The default value is
369+
False.
370+
365371
The ``program`` parameter is expected to be a string which specifies the
366372
name of the executable program or application connected to Oracle
367373
Database. This value is only used in the python-oracledb Thin mode. The
@@ -397,8 +403,8 @@ Oracledb Methods
397403

398404
.. versionchanged:: 3.0.0
399405

400-
The ``pool_alias`` parameter was added. The ``pool`` parameter was
401-
deprecated. Use :meth:`ConnectionPool.acquire()` instead.
406+
The ``pool_alias`` and ``use_sni`` parameters were added. The ``pool``
407+
parameter was deprecated. Use :meth:`ConnectionPool.acquire()` instead.
402408

403409
.. versionchanged:: 2.5.0
404410

@@ -443,7 +449,7 @@ Oracledb Methods
443449
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
444450
program=oracledb.defaults.program, machine=oracledb.defaults.machine, \
445451
terminal=oracledb.defaults.terminal, osuser=oracledb.defaults.osuser, \
446-
driver_name=oracledb.defaults.driver_name, handle=0)
452+
driver_name=oracledb.defaults.driver_name, use_sni=False, handle=0)
447453

448454
Constructor for creating a connection to the database. Returns an
449455
:ref:`AsyncConnection Object <asyncconnobj>`. All parameters are optional
@@ -689,6 +695,12 @@ Oracledb Methods
689695
are using python-oracledb Thick mode, Oracle Client 23ai is additionally
690696
required.
691697

698+
The ``use_sni`` parameter is expected to be a boolean which indicates
699+
whether to use the TLS Server Name Indicator (SNI) extension to bypass the
700+
second TLS neogiation that would otherwise be required. This parameter is
701+
used in both python-oracledb Thin and Thick modes. The default value is
702+
False.
703+
692704
The ``program`` parameter is expected to be a string which specifies the
693705
name of the executable program or application connected to Oracle
694706
Database. This value is only used in the python-oracledb Thin mode. The
@@ -718,8 +730,9 @@ Oracledb Methods
718730

719731
.. versionchanged:: 3.0.0
720732

721-
The ``pool_alias`` parameter was added. The ``pool`` parameter was
722-
deprecated. Use :meth:`AsyncConnectionPool.acquire()` instead.
733+
The ``pool_alias`` and ``use_sni`` parameters were added. The ``pool``
734+
parameter was deprecated. Use :meth:`AsyncConnectionPool.acquire()`
735+
instead.
723736

724737
.. versionchanged:: 2.5.0
725738

@@ -762,7 +775,7 @@ Oracledb Methods
762775
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
763776
program=oracledb.defaults.program, machine=oracledb.defaults.machine, \
764777
terminal=oracledb.defaults.terminal, osuser=oracledb.defaults.osuser, \
765-
driver_name=oracledb.defaults.driver_name, handle=0)
778+
driver_name=oracledb.defaults.driver_name, use_sni=False, handle=0)
766779

767780
Contains all the parameters that can be used to establish a connection to
768781
the database.
@@ -1026,6 +1039,12 @@ Oracledb Methods
10261039
are using python-oracledb Thick mode, Oracle Client 23ai is additionally
10271040
required.
10281041

1042+
The ``use_sni`` parameter is expected to be a boolean which indicates
1043+
whether to use the TLS Server Name Indicator (SNI) extension to bypass the
1044+
second TLS neogiation that would otherwise be required. This parameter is
1045+
used in both python-oracledb Thin and Thick modes. The default value is
1046+
False.
1047+
10291048
The ``program`` parameter is expected to be a string which specifies the
10301049
name of the executable program or application connected to Oracle
10311050
Database. This value is only used in the python-oracledb Thin mode. The
@@ -1056,6 +1075,10 @@ Oracledb Methods
10561075
python-oracledb Thick mode. It should be used with extreme caution. The
10571076
default value is *0*.
10581077

1078+
.. versionchanged:: 3.0.0
1079+
1080+
The ``use_sni`` parameter was added.
1081+
10591082
.. versionchanged:: 2.5.0
10601083

10611084
The ``program``, ``machine``, ``terminal``, ``osuser``, and
@@ -1115,7 +1138,7 @@ Oracledb Methods
11151138
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
11161139
program=oracledb.defaults.program, machine=oracledb.defaults.machine, \
11171140
terminal=oracledb.defaults.terminal, osuser=oracledb.defaults.osuser, \
1118-
driver_name=oracledb.defaults.driver_name, handle=0)
1141+
driver_name=oracledb.defaults.driver_name, use_sni=False, handle=0)
11191142

11201143
Creates a connection pool with the supplied parameters and returns the
11211144
:ref:`ConnectionPool object <connpool>` for the pool. See :ref:`Connection
@@ -1497,6 +1520,12 @@ Oracledb Methods
14971520
are using python-oracledb Thick mode, Oracle Client 23ai is additionally
14981521
required.
14991522

1523+
The ``use_sni`` parameter is expected to be a boolean which indicates
1524+
whether to use the TLS Server Name Indicator (SNI) extension to bypass the
1525+
second TLS neogiation that would otherwise be required. This parameter is
1526+
used in both python-oracledb Thin and Thick modes. The default value is
1527+
False.
1528+
15001529
The ``program`` parameter is expected to be a string which specifies the
15011530
name of the executable program or application connected to Oracle
15021531
Database. This value is only used in the python-oracledb Thin mode. The
@@ -1540,6 +1569,10 @@ Oracledb Methods
15401569
``driver_name`` parameters were added. Support for ``edition`` and
15411570
``appcontext`` was added to python-oracledb Thin mode.
15421571

1572+
.. versionchanged:: 2.5.0
1573+
1574+
The ``use_sni`` parameter was added.
1575+
15431576
.. versionchanged:: 2.3.0
15441577

15451578
The default value of the ``retry_delay`` parameter was changed from *0*
@@ -1582,7 +1615,7 @@ Oracledb Methods
15821615
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
15831616
program=oracledb.defaults.program, machine=oracledb.defaults.machine, \
15841617
terminal=oracledb.defaults.terminal, osuser=oracledb.defaults.osuser, \
1585-
driver_name=oracledb.defaults.driver_name, handle=0)
1618+
driver_name=oracledb.defaults.driver_name, use_sni=False, handle=0)
15861619

15871620
Creates a connection pool with the supplied parameters and returns the
15881621
:ref:`AsyncConnectionPool object <asyncconnpoolobj>` for the pool.
@@ -1884,6 +1917,12 @@ Oracledb Methods
18841917
are using python-oracledb Thick mode, Oracle Client 23ai is additionally
18851918
required.
18861919

1920+
The ``use_sni`` parameter is expected to be a boolean which indicates
1921+
whether to use the TLS Server Name Indicator (SNI) extension to bypass the
1922+
second TLS neogiation that would otherwise be required. This parameter is
1923+
used in both python-oracledb Thin and Thick modes. The default value is
1924+
False.
1925+
18871926
The ``program`` parameter is expected to be a string which specifies the
18881927
name of the executable program or application connected to Oracle
18891928
Database. This value is only used in the python-oracledb Thin mode. The
@@ -1913,7 +1952,7 @@ Oracledb Methods
19131952

19141953
.. versionchanged:: 3.0.0
19151954

1916-
The ``pool_alias`` parameter was added.
1955+
The ``pool_alias`` and ``use_sni`` parameters were added.
19171956

19181957
.. versionchanged:: 2.5.0
19191958

@@ -2129,7 +2168,7 @@ Oracledb Methods
21292168
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
21302169
program=oracledb.defaults.program, machine=oracledb.defaults.machine, \
21312170
terminal=oracledb.defaults.terminal, osuser=oracledb.defaults.osuser, \
2132-
driver_name=oracledb.defaults.driver_name, handle=0)
2171+
driver_name=oracledb.defaults.driver_name, use_sni=False, handle=0)
21332172

21342173
Creates and returns a :ref:`PoolParams Object <poolparam>`. The object
21352174
can be passed to :meth:`oracledb.create_pool()`.
@@ -2454,6 +2493,12 @@ Oracledb Methods
24542493
are using python-oracledb Thick mode, Oracle Client 23ai is additionally
24552494
required.
24562495

2496+
The ``use_sni`` parameter is expected to be a boolean which indicates
2497+
whether to use the TLS Server Name Indicator (SNI) extension to bypass the
2498+
second TLS neogiation that would otherwise be required. This parameter is
2499+
used in both python-oracledb Thin and Thick modes. The default value is
2500+
False.
2501+
24572502
The ``program`` parameter is expected to be a string which specifies the
24582503
name of the executable program or application connected to Oracle
24592504
Database. This value is only used in the python-oracledb Thin mode. The
@@ -2484,6 +2529,10 @@ Oracledb Methods
24842529
python-oracledb Thick mode. It should be used with extreme caution. The
24852530
default value is *0*.
24862531

2532+
.. versionchanged:: 3.0.0
2533+
2534+
The ``use_sni`` parameter was added.
2535+
24872536
.. versionchanged:: 2.5.0
24882537

24892538
The ``program``, ``machine``, ``terminal``, ``osuser``, and

doc/src/api_manual/pool_params.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ PoolParams Methods
5151
use_tcp_fast_open=False, ssl_version=None, \
5252
program=oracledb.defaults.program, machine=oracledb.defaults.machine, \
5353
terminal=oracledb.defaults.terminal, osuser=oracledb.defaults.osuser, \
54-
driver_name=oracledb.defaults.driver_name, handle=None)
54+
driver_name=oracledb.defaults.driver_name, use_sni=None, handle=None)
5555

5656
Sets one or more of the parameters.
5757

58+
.. versionchanged:: 3.0.0
59+
60+
The ``use_sni`` parameter was added.
61+
5862
.. versionchanged:: 2.5.0
5963

6064
The ``program``, ``machine``, ``terminal``, ``osuser``, and

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Thin Mode Changes
2222
#) Perform TLS server matching in python-oracledb instead of the Python SSL
2323
library to allow alternate names to be checked
2424
(`issue 415 <https://github.com/oracle/python-oracledb/issues/415>`__).
25+
#) Added parameter :data:`ConnectParams.use_sni` to specify that the TLS SNI
26+
extension should be used to reduce the number of TLS neegotiations that are
27+
needed to connect to the database.
2528
#) Host names are now resolved to IP addresses in python-oracledb instead of
2629
the Python libraries. Address list load balancing and failover settings
2730
will be used when establishing connections.

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ cdef class Description(ConnectParamsNode):
496496
public uint32_t purity
497497
public bint ssl_server_dn_match
498498
public bint use_tcp_fast_open
499+
public bint use_sni
499500
public str ssl_server_cert_dn
500501
public object ssl_version
501502
public str wallet_location

src/oracledb/connect_params.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(
103103
terminal: str = oracledb.defaults.terminal,
104104
osuser: str = oracledb.defaults.osuser,
105105
driver_name: str = oracledb.defaults.driver_name,
106+
use_sni: bool = False,
106107
handle: int = 0,
107108
):
108109
"""
@@ -294,6 +295,10 @@ def __init__(
294295
- driver_name: the driver name used by the client to connect to the
295296
Oracle Database (default: oracledb.defaults.driver_name)
296297
298+
- use_sni: boolean indicating whether to use the TLS SNI extension to
299+
bypass the second TLS neogiation that would otherwise be required
300+
(default: False)
301+
297302
- handle: an integer representing a pointer to a valid service context
298303
handle. This value is only used in thick mode. It should be used with
299304
extreme caution (default: 0)
@@ -346,7 +351,8 @@ def __repr__(self):
346351
+ f"machine={self.machine!r}, "
347352
+ f"terminal={self.terminal!r}, "
348353
+ f"osuser={self.osuser!r}, "
349-
+ f"driver_name={self.driver_name!r}"
354+
+ f"driver_name={self.driver_name!r}, "
355+
+ f"use_sni={self.use_sni!r}"
350356
+ ")"
351357
)
352358

@@ -729,6 +735,15 @@ def user(self) -> str:
729735
"""
730736
return self._impl.user
731737

738+
@property
739+
@_flatten_value
740+
def use_sni(self) -> Union[list, bool]:
741+
"""
742+
Boolean indicating whether to use the TLS SNI extension to bypass the
743+
second TLS neogiation that would otherwise be required.
744+
"""
745+
return [d.use_sni for d in self._impl.description_list.children]
746+
732747
@property
733748
@_flatten_value
734749
def use_tcp_fast_open(self) -> Union[list, bool]:
@@ -848,6 +863,7 @@ def set(
848863
terminal: str = None,
849864
osuser: str = None,
850865
driver_name: str = None,
866+
use_sni: bool = None,
851867
handle: int = None,
852868
):
853869
"""
@@ -1027,6 +1043,9 @@ def set(
10271043
- driver_name: the driver name used by the client to connect to the
10281044
Oracle Database
10291045
1046+
- use_sni: boolean indicating whether to use the TLS SNI extension to
1047+
bypass the second TLS neogiation that would otherwise be required
1048+
10301049
- handle: an integer representing a pointer to a valid service context
10311050
handle. This value is only used in thick mode. It should be used with
10321051
extreme caution

src/oracledb/connection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ def connect(
12711271
terminal: str = oracledb.defaults.terminal,
12721272
osuser: str = oracledb.defaults.osuser,
12731273
driver_name: str = oracledb.defaults.driver_name,
1274+
use_sni: bool = False,
12741275
handle: int = 0,
12751276
) -> Connection:
12761277
"""
@@ -1481,6 +1482,10 @@ def connect(
14811482
- driver_name: the driver name used by the client to connect to the Oracle
14821483
Database (default: oracledb.defaults.driver_name)
14831484
1485+
- use_sni: boolean indicating whether to use the TLS SNI extension to
1486+
bypass the second TLS neogiation that would otherwise be required
1487+
(default: False)
1488+
14841489
- handle: an integer representing a pointer to a valid service context
14851490
handle. This value is only used in thick mode. It should be used with
14861491
extreme caution (default: 0)
@@ -2036,6 +2041,7 @@ def connect_async(
20362041
terminal: str = oracledb.defaults.terminal,
20372042
osuser: str = oracledb.defaults.osuser,
20382043
driver_name: str = oracledb.defaults.driver_name,
2044+
use_sni: bool = False,
20392045
handle: int = 0,
20402046
) -> AsyncConnection:
20412047
"""
@@ -2246,6 +2252,10 @@ def connect_async(
22462252
- driver_name: the driver name used by the client to connect to the Oracle
22472253
Database (default: oracledb.defaults.driver_name)
22482254
2255+
- use_sni: boolean indicating whether to use the TLS SNI extension to
2256+
bypass the second TLS neogiation that would otherwise be required
2257+
(default: False)
2258+
22492259
- handle: an integer representing a pointer to a valid service context
22502260
handle. This value is only used in thick mode. It should be used with
22512261
extreme caution (default: 0)

src/oracledb/impl/base/connect_params.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ cdef class Description(ConnectParamsNode):
792792
if self.tcp_connect_timeout != DEFAULT_TCP_CONNECT_TIMEOUT:
793793
temp = self._build_duration_str(self.tcp_connect_timeout)
794794
parts.append(f"(TRANSPORT_CONNECT_TIMEOUT={temp})")
795+
if self.use_sni:
796+
parts.append("(USE_SNI=ON)")
795797
if self.sdu != DEFAULT_SDU:
796798
parts.append(f"(SDU={self.sdu})")
797799

@@ -875,6 +877,7 @@ cdef class Description(ConnectParamsNode):
875877
description.use_tcp_fast_open = self.use_tcp_fast_open
876878
description.ssl_server_cert_dn = self.ssl_server_cert_dn
877879
description.ssl_version = self.ssl_version
880+
description.use_sni = self.use_sni
878881
description.wallet_location = self.wallet_location
879882
return description
880883

@@ -914,6 +917,7 @@ cdef class Description(ConnectParamsNode):
914917
_set_bool_param(args, "source_route", &self.source_route)
915918
_set_uint_param(args, "retry_count", &self.retry_count)
916919
_set_uint_param(args, "retry_delay", &self.retry_delay)
920+
_set_bool_param(args, "use_sni", &self.use_sni)
917921
_set_uint_param(args, "sdu", &self.sdu)
918922
self.sdu = min(max(self.sdu, 512), 2097152) # sanitize SDU
919923
_set_duration_param(args, "tcp_connect_timeout",

0 commit comments

Comments
 (0)