Skip to content

Commit 2f83bd5

Browse files
Add parameter "ssl_version" to allow specification of which TLS version
to use when connecting securely.
1 parent cab0bde commit 2f83bd5

22 files changed

+223
-25
lines changed

doc/src/api_manual/connect_params.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ ConnectParams Methods
5959
edition=None, tag=None, matchanytag=None, config_dir=None, \
6060
appcontext=[], shardingkey=[], supershardingkey=[], debug_jdwp=None, \
6161
connection_id_prefix=None, ssl_context=None, sdu=None, \
62-
pool_boundary=None, use_tcp_fast_open=False, handle=None)
62+
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
63+
handle=None)
6364

6465
Sets the values for one or more of the parameters of a ConnectParams
6566
object.
6667

68+
.. versionchanged:: 2.3.0
69+
70+
The ``ssl_version`` parameter was added.
71+
6772
.. versionchanged:: 2.1.0
6873

6974
The ``pool_boundary`` and ``use_tcp_fast_open`` parameters were added.
@@ -371,6 +376,17 @@ ConnectParams Attributes
371376

372377
This attribute is supported in both python-oracledb Thin and Thick modes.
373378

379+
.. attribute:: ConnectParams.ssl_version
380+
381+
This read-only attribute is one of the constants "ssl.TLSVersion.TLSv1_2"
382+
or "ssl.TLSVersion.TLSv1_3" which identifies the TLS protocol version
383+
used. These constants are defined in the Python `ssl <https://docs.python.
384+
org/3/library/ssl.html>`__ module.
385+
386+
This attribute is supported in both python-oracledb Thin and Thick modes.
387+
388+
.. versionadded:: 2.3.0
389+
374390
.. attribute:: ConnectParams.stmtcachesize
375391

376392
This read-only attribute is an integer that identifies the initial size of

doc/src/api_manual/module.rst

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Oracledb Methods
4949
config_dir=oracledb.defaults.config_dir, appcontext=[], \
5050
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
5151
connection_id_prefix=None, ssl_context=None, sdu=8192, \
52-
pool_boundary=None, use_tcp_fast_open=False, handle=0)
52+
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
53+
handle=0)
5354

5455
Constructor for creating a connection to the database. Returns a
5556
:ref:`Connection Object <connobj>`. All parameters are optional and can be
@@ -339,6 +340,15 @@ Oracledb Methods
339340
available with certain versions of ADB-S. This value is used in both
340341
python-oracledb Thin and Thick modes. The default value is False.
341342

343+
The ``ssl_version`` parameter is expected to be one of the constants
344+
"ssl.TLSVersion.TLSv1_2" or "ssl.TLSVersion.TLSv1_3" and specifies the TLS
345+
protocol version to use. These constants are defined in the Python
346+
`ssl <https://docs.python.org/3/library/ssl.html>`__ module. This
347+
parameter can be specified when establishing connections with the protocol
348+
"tcps". This parameter is used in both python-oracledb Thin and Thick
349+
modes. The value "ssl.TLSVersion.TLSv1_3" requires Oracle Database 23ai
350+
and for Thick mode, Oracle Client 19c (or later) is additionally required.
351+
342352
If the ``handle`` parameter is specified, it must be of type OCISvcCtx\*
343353
and is only of use when embedding Python in an application (like
344354
PowerBuilder) which has already made the connection. The connection thus
@@ -351,7 +361,8 @@ Oracledb Methods
351361

352362
The default value of the ``retry_delay`` parameter was changed from 0
353363
seconds to 1 second. The default value of the ``tcp_connect_timeout``
354-
parameter was changed from 60.0 seconds to 20.0 seconds.
364+
parameter was changed from 60.0 seconds to 20.0 seconds. The
365+
``ssl_version`` parameter was added.
355366

356367
.. versionchanged:: 2.1.0
357368

@@ -379,7 +390,8 @@ Oracledb Methods
379390
config_dir=oracledb.defaults.config_dir, appcontext=[], \
380391
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
381392
connection_id_prefix=None, ssl_context=None, sdu=8192, \
382-
pool_boundary=None, use_tcp_fast_open=False, handle=0)
393+
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
394+
handle=0)
383395

384396
Constructor for creating a connection to the database. Returns an
385397
:ref:`AsyncConnection Object <asyncconnobj>`. All parameters are optional
@@ -601,13 +613,23 @@ Oracledb Methods
601613
available with certain versions of ADB-S. This value is used in both
602614
python-oracledb Thin and Thick modes. The default value is False.
603615

616+
The ``ssl_version`` parameter is expected to be one of the constants
617+
"ssl.TLSVersion.TLSv1_2" or "ssl.TLSVersion.TLSv1_3" and specifies the TLS
618+
protocol version to use. These constants are defined in the Python
619+
`ssl <https://docs.python.org/3/library/ssl.html>`__ module. This
620+
parameter can be specified when establishing connections with the protocol
621+
"tcps". This parameter is used in both python-oracledb Thin and Thick
622+
modes. The value "ssl.TLSVersion.TLSv1_3" requires Oracle Database 23ai
623+
and for Thick mode, Oracle Client 19c (or later) is additionally required.
624+
604625
The ``handle`` parameter is ignored in the python-oracledb Thin mode.
605626

606627
.. versionchanged:: 2.3.0
607628

608629
The default value of the ``retry_delay`` parameter was changed from 0
609630
seconds to 1 second. The default value of the ``tcp_connect_timeout``
610-
parameter was changed from 60.0 seconds to 20.0 seconds.
631+
parameter was changed from 60.0 seconds to 20.0 seconds. The
632+
``ssl_version`` parameter was added.
611633

612634
.. versionchanged:: 2.1.0
613635

@@ -634,7 +656,8 @@ Oracledb Methods
634656
config_dir=oracledb.defaults.config_dir, appcontext=[], \
635657
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
636658
connection_id_prefix=None, ssl_context=None, sdu=8192, \
637-
pool_boundary=None, use_tcp_fast_open=False, handle=0)
659+
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
660+
handle=0)
638661

639662
Contains all the parameters that can be used to establish a connection to
640663
the database.
@@ -888,6 +911,15 @@ Oracledb Methods
888911
available with certain versions of ADB-S. This value is used in both
889912
python-oracledb Thin and Thick modes. The default value is False.
890913

914+
The ``ssl_version`` parameter is expected to be one of the constants
915+
"ssl.TLSVersion.TLSv1_2" or "ssl.TLSVersion.TLSv1_3" and specifies the TLS
916+
protocol version to use. These constants are defined in the Python
917+
`ssl <https://docs.python.org/3/library/ssl.html>`__ module. This
918+
parameter can be specified when establishing connections with the protocol
919+
"tcps". This parameter is used in both python-oracledb Thin and Thick
920+
modes. The value "ssl.TLSVersion.TLSv1_3" requires Oracle Database 23ai
921+
and for Thick mode, Oracle Client 19c (or later) is additionally required.
922+
891923
The ``handle`` parameter is expected to be an integer which represents a
892924
pointer to a valid service context handle. This value is only used in the
893925
python-oracledb Thick mode. It should be used with extreme caution. The
@@ -897,7 +929,8 @@ Oracledb Methods
897929

898930
The default value of the ``retry_delay`` parameter was changed from 0
899931
seconds to 1 second. The default value of the ``tcp_connect_timeout``
900-
parameter was changed from 60.0 seconds to 20.0 seconds.
932+
parameter was changed from 60.0 seconds to 20.0 seconds. The
933+
``ssl_version`` parameter was added.
901934

902935
.. versionchanged:: 2.1.0
903936

@@ -930,7 +963,8 @@ Oracledb Methods
930963
config_dir=oracledb.defaults.config_dir, appcontext=[], \
931964
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
932965
connection_id_prefix=None, ssl_context=None, sdu=8192, \
933-
pool_boundary=None, use_tcp_fast_open=False, handle=0)
966+
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
967+
handle=0)
934968

935969
Creates a connection pool with the supplied parameters and returns the
936970
:ref:`ConnectionPool object <connpool>` for the pool. See :ref:`Connection
@@ -1277,6 +1311,15 @@ Oracledb Methods
12771311
with certain versions of ADB-S. This value is used in both python-oracledb
12781312
Thin and Thick modes. The default value is False.
12791313

1314+
The ``ssl_version`` parameter is expected to be one of the constants
1315+
"ssl.TLSVersion.TLSv1_2" or "ssl.TLSVersion.TLSv1_3" and specifies the TLS
1316+
protocol version to use. These constants are defined in the Python
1317+
`ssl <https://docs.python.org/3/library/ssl.html>`__ module. This
1318+
parameter can be specified when establishing connections with the protocol
1319+
"tcps". This parameter is used in both python-oracledb Thin and Thick
1320+
modes. The value "ssl.TLSVersion.TLSv1_3" requires Oracle Database 23ai
1321+
and for Thick mode, Oracle Client 19c (or later) is additionally required.
1322+
12801323
If the ``handle`` parameter is specified, it must be of type OCISvcCtx\*
12811324
and is only of use when embedding Python in an application (like
12821325
PowerBuilder) which has already made the connection. The connection thus
@@ -1297,7 +1340,7 @@ Oracledb Methods
12971340
The default value of the ``retry_delay`` parameter was changed from 0
12981341
seconds to 1 second. The default value of the ``tcp_connect_timeout``
12991342
parameter was changed from 60.0 seconds to 20.0 seconds. The
1300-
``ping_timeout`` parameter was added.
1343+
``ping_timeout`` and ``ssl_version`` parameters were added.
13011344

13021345
.. versionchanged:: 2.1.0
13031346

@@ -1330,7 +1373,8 @@ Oracledb Methods
13301373
config_dir=oracledb.defaults.config_dir, appcontext=[], \
13311374
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
13321375
connection_id_prefix=None, ssl_context=None, sdu=8192, \
1333-
pool_boundary=None, use_tcp_fast_open=False, handle=0)
1376+
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
1377+
handle=0)
13341378

13351379
Creates a connection pool with the supplied parameters and returns the
13361380
:ref:`AsyncConnectionPool object <asyncconnpoolobj>` for the pool.
@@ -1607,14 +1651,23 @@ Oracledb Methods
16071651
with certain versions of ADB-S. This value is used in both python-oracledb
16081652
Thin and Thick modes. The default value is False.
16091653

1654+
The ``ssl_version`` parameter is expected to be one of the constants
1655+
"ssl.TLSVersion.TLSv1_2" or "ssl.TLSVersion.TLSv1_3" and specifies the TLS
1656+
protocol version to use. These constants are defined in the Python
1657+
`ssl <https://docs.python.org/3/library/ssl.html>`__ module. This
1658+
parameter can be specified when establishing connections with the protocol
1659+
"tcps". This parameter is used in both python-oracledb Thin and Thick
1660+
modes. The value "ssl.TLSVersion.TLSv1_3" requires Oracle Database 23ai
1661+
and for Thick mode, Oracle Client 19c (or later) is additionally required.
1662+
16101663
The ``handle`` parameter is ignored in the python-oracledb Thin mode.
16111664

16121665
.. versionchanged:: 2.3.0
16131666

16141667
The default value of the ``retry_delay`` parameter was changed from 0
16151668
seconds to 1 second. The default value of the ``tcp_connect_timeout``
16161669
parameter was changed from 60.0 seconds to 20.0 seconds. The
1617-
``ping_timeout`` parameter was added.
1670+
``ping_timeout`` and ``ssl_version`` parameters were added.
16181671

16191672
.. versionchanged:: 2.1.0
16201673

@@ -1750,7 +1803,8 @@ Oracledb Methods
17501803
config_dir=oracledb.defaults.config_dir, appcontext=[], \
17511804
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
17521805
connection_id_prefix=None, ssl_context=None, sdu=8192, \
1753-
pool_boundary=None, use_tcp_fast_open=False, handle=0)
1806+
pool_boundary=None, use_tcp_fast_open=False, ssl_version=None, \
1807+
handle=0)
17541808

17551809
Creates and returns a :ref:`PoolParams Object <poolparam>`. The object
17561810
can be passed to :meth:`oracledb.create_pool()`.
@@ -2064,6 +2118,15 @@ Oracledb Methods
20642118
with certain versions of ADB-S. This value is used in both python-oracledb
20652119
Thin and Thick modes. The default value is False.
20662120

2121+
The ``ssl_version`` parameter is expected to be one of the constants
2122+
"ssl.TLSVersion.TLSv1_2" or "ssl.TLSVersion.TLSv1_3" and specifies the TLS
2123+
protocol version to use. These constants are defined in the Python
2124+
`ssl <https://docs.python.org/3/library/ssl.html>`__ module. This
2125+
parameter can be specified when establishing connections with the protocol
2126+
"tcps". This parameter is used in both python-oracledb Thin and Thick
2127+
modes. The value "ssl.TLSVersion.TLSv1_3" requires Oracle Database 23ai
2128+
and for Thick mode, Oracle Client 19c (or later) is additionally required.
2129+
20672130
The ``handle`` parameter is expected to be an integer which represents a
20682131
pointer to a valid service context handle. This value is only used in the
20692132
python-oracledb Thick mode. It should be used with extreme caution. The
@@ -2074,7 +2137,7 @@ Oracledb Methods
20742137
The default value of the ``retry_delay`` parameter was changed from 0
20752138
seconds to 1 second. The default value of the ``tcp_connect_timeout``
20762139
parameter was changed from 60.0 seconds to 20.0 seconds. The
2077-
``ping_timeout`` parameter was added.
2140+
``ping_timeout`` and ``ssl_version`` parameters were added.
20782141

20792142
.. versionchanged:: 2.1.0
20802143

doc/src/api_manual/pool_params.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ PoolParams Methods
4848
matchanytag=None, config_dir=None, appcontext=[], shardingkey=[], \
4949
supershardingkey=[], debug_jdwp=None, connection_id_prefix=None, \
5050
ssl_context=None, sdu=None, pool_boundary=None, \
51-
use_tcp_fast_open=False, handle=None)
51+
use_tcp_fast_open=False, ssl_version=None, handle=None)
5252

5353
Sets one or more of the parameters.
5454

5555
.. versionchanged:: 2.3.0
5656

57-
The ``ping_timeout`` parameter was added.
57+
The ``ping_timeout`` and ``ssl_version`` parameters were added.
5858

5959
.. versionchanged:: 2.1.0
6060

doc/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Common Changes
4848
#) The default value of the ``tcp_connect_timeout`` parameter was changed
4949
from 60 seconds to 20 seconds. The default value of the
5050
``retry_delay`` parameter was changed from 0 seconds to 1 second.
51+
#) Added parameter ``ssl_version`` to :meth:`oracledb.connect()`
52+
:meth:`oracledb.connect_async()`, :meth:`oracledb.create_pool()`, and
53+
:meth:`oracledb.create_pool_async()` methods in order to specify which TLS
54+
version to use when establishing connections with the protocol "tcps".
5155
#) Added parameter ``ping_timeout`` to methods :meth:`oracledb.create_pool()`
5256
and :meth:`oracledb.create_pool_async()` with a default value of 5000
5357
milliseconds. This limits the amount of time that a call to

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ cdef class Description(ConnectParamsNode):
422422
public bint ssl_server_dn_match
423423
public bint use_tcp_fast_open
424424
public str ssl_server_cert_dn
425+
public object ssl_version
425426
public str wallet_location
426427
str connection_id
427428

src/oracledb/base_impl.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import os
5252
import random
5353
import re
5454
import secrets
55+
import ssl
5556
import sys
5657

5758
cydatetime.import_datetime()

src/oracledb/connect_params.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# -----------------------------------------------------------------------------
3535

3636
import functools
37+
import ssl
3738
from typing import Union, Callable, Any
3839

3940
import oracledb
@@ -96,6 +97,7 @@ def __init__(
9697
sdu: int = 8192,
9798
pool_boundary: str = None,
9899
use_tcp_fast_open: bool = False,
100+
ssl_version: ssl.TLSVersion = None,
99101
handle: int = 0,
100102
):
101103
"""
@@ -268,6 +270,10 @@ def __init__(
268270
refer to the ADB-S documentation for more information (default:
269271
False)
270272
273+
- ssl_version: one of the values ssl.TLSVersion.TLSv1_2 or
274+
ssl.TLSVersion.TLSv1_3 indicating which TLS version to use (default:
275+
None)
276+
271277
- handle: an integer representing a pointer to a valid service context
272278
handle. This value is only used in thick mode. It should be used with
273279
extreme caution (default: 0)
@@ -314,7 +320,8 @@ def __repr__(self):
314320
+ f"ssl_context={self.ssl_context!r}, "
315321
+ f"sdu={self.sdu!r}, "
316322
+ f"pool_boundary={self.pool_boundary!r}, "
317-
+ f"use_tcp_fast_open={self.use_tcp_fast_open!r}"
323+
+ f"use_tcp_fast_open={self.use_tcp_fast_open!r}, "
324+
+ f"ssl_version={self.ssl_version!r}"
318325
+ ")"
319326
)
320327

@@ -611,6 +618,15 @@ def ssl_server_dn_match(self) -> Union[list, bool]:
611618
d.ssl_server_dn_match for d in self._impl.description_list.children
612619
]
613620

621+
@property
622+
@_flatten_value
623+
def ssl_version(self) -> Union[list, ssl.TLSVersion]:
624+
"""
625+
One of the values ssl.TLSVersion.TLSv1_2 or ssl.TLSVersion.TLSv1_3
626+
indicating which TLS version to use.
627+
"""
628+
return [d.ssl_version for d in self._impl.description_list.children]
629+
614630
@property
615631
def stmtcachesize(self) -> int:
616632
"""
@@ -765,6 +781,7 @@ def set(
765781
sdu: int = None,
766782
pool_boundary: str = None,
767783
use_tcp_fast_open: bool = None,
784+
ssl_version: ssl.TLSVersion = None,
768785
handle: int = None,
769786
):
770787
"""
@@ -926,6 +943,9 @@ def set(
926943
property for clients connecting from within OCI Cloud network. Please
927944
refer to the ADB-S documentation for more information
928945
946+
- ssl_version: one of the values ssl.TLSVersion.TLSv1_2 or
947+
ssl.TLSVersion.TLSv1_3 indicating which TLS version to use
948+
929949
- handle: an integer representing a pointer to a valid service context
930950
handle. This value is only used in thick mode. It should be used with
931951
extreme caution

0 commit comments

Comments
 (0)