Skip to content

Commit fdbecac

Browse files
Added new parameter "ssl_context" as suggested (#259).
1 parent 46f81b0 commit fdbecac

15 files changed

+91
-9
lines changed

Diff for: doc/src/api_manual/connect_param.rst

+10
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ ConnectParams Attributes
277277

278278
This attribute is supported in the python-oracledb Thin and Thick modes.
279279

280+
.. attribute:: ConnectParams.ssl_context
281+
282+
This read-only attribute is an SSLContext object which is used for
283+
connecting to the database using TLS. This SSL context will be modified to
284+
include the private key or any certificates found in a separately supplied
285+
wallet. This parameter should only be specified if the default SSLContext
286+
object cannot be used.
287+
288+
This attribute is only supported in the python-oracledb Thin mode.
289+
280290
.. attribute:: ConnectParams.ssl_server_cert_dn
281291

282292
This read-only attribute is a string that returns the distinguished name

Diff for: doc/src/release_notes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Thin Mode Changes
1515

1616
#) Fixed bug in detecting the current time zone
1717
(`issue 257 <https://github.com/oracle/python-oracledb/issues/257>`__).
18+
#) Added parameter :data:`ConnectParams.ssl_context`
19+
(`issue 259 <https://github.com/oracle/python-oracledb/issues/259>`__).
1820
#) Fixed bug in handling database response in certain unusual circumstances.
1921
#) Fixed bug in handling exceptions raised during connection establishment.
2022
#) Fixed bug in identifying bind variables in SQL statements containing

Diff for: src/oracledb/base_impl.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ cdef class ConnectParamsImpl:
178178
public list supershardingkey
179179
public uint32_t stmtcachesize
180180
public bint disable_oob
181+
public object ssl_context
181182
public DescriptionList description_list
182183
uint64_t _external_handle
183184
public str debug_jdwp

Diff for: src/oracledb/connect_params.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# -----------------------------------------------------------------------------
3535

3636
import functools
37-
from typing import Union, Callable
37+
from typing import Union, Callable, Any
3838

3939
import oracledb
4040

@@ -92,6 +92,7 @@ def __init__(
9292
supershardingkey: list = None,
9393
debug_jdwp: str = None,
9494
connection_id_prefix: str = None,
95+
ssl_context: Any = None,
9596
handle: int = 0,
9697
threaded: bool = True,
9798
encoding: str = None,
@@ -243,6 +244,12 @@ def __init__(
243244
- connection_id_prefix: an application specific prefix that is added to
244245
the connection identifier used for tracing (default: None)
245246
247+
- ssl_context: an SSLContext object used for connecting to the database
248+
using TLS. This SSL context will be modified to include the private
249+
key or any certificates found in a separately supplied wallet. This
250+
parameter should only be specified if the default SSLContext object
251+
cannot be used. (default: None)
252+
246253
- handle: an integer representing a pointer to a valid service context
247254
handle. This value is only used in thick mode. It should be used with
248255
extreme caution (default: 0)
@@ -285,7 +292,8 @@ def __repr__(self):
285292
+ f"shardingkey={self.shardingkey!r}, "
286293
+ f"supershardingkey={self.supershardingkey!r}, "
287294
+ f"debug_jdwp={self.debug_jdwp!r}, "
288-
+ f"connection_id_prefix={self.connection_id_prefix!r}"
295+
+ f"connection_id_prefix={self.connection_id_prefix!r}, "
296+
+ f"ssl_context={self.ssl_context!r}"
289297
+ ")"
290298
)
291299

@@ -532,6 +540,17 @@ def sid(self) -> Union[list, str]:
532540
"""
533541
return self._impl.sid
534542

543+
@property
544+
def ssl_context(self) -> Any:
545+
"""
546+
An SSLContext object used for connecting to the database using TLS.
547+
This SSL context will be modified to include the private key or any
548+
certificates found in a separately supplied wallet. This parameter
549+
should only be specified if the default SSLContext object cannot be
550+
used..
551+
"""
552+
return self._impl.ssl_context
553+
535554
@property
536555
@_description_attr
537556
def ssl_server_cert_dn(self) -> Union[list, str]:
@@ -679,6 +698,7 @@ def set(
679698
supershardingkey: list = None,
680699
debug_jdwp: str = None,
681700
connection_id_prefix: str = None,
701+
ssl_context: Any = None,
682702
handle: int = None,
683703
threaded: bool = None,
684704
encoding: str = None,
@@ -821,6 +841,12 @@ def set(
821841
- connection_id_prefix: an application specific prefix that is added to
822842
the connection identifier used for tracing
823843
844+
- ssl_context: an SSLContext object used for connecting to the database
845+
using TLS. This SSL context will be modified to include the private
846+
key or any certificates found in a separately supplied wallet. This
847+
parameter should only be specified if the default SSLContext object
848+
cannot be used.
849+
824850
- handle: an integer representing a pointer to a valid service context
825851
handle. This value is only used in thick mode. It should be used with
826852
extreme caution

Diff for: src/oracledb/connection.py

+7
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ def connect(
11771177
supershardingkey: list = None,
11781178
debug_jdwp: str = None,
11791179
connection_id_prefix: str = None,
1180+
ssl_context: Any = None,
11801181
handle: int = 0,
11811182
threaded: bool = True,
11821183
encoding: str = None,
@@ -1349,6 +1350,12 @@ def connect(
13491350
- connection_id_prefix: an application specific prefix that is added to the
13501351
connection identifier used for tracing (default: None)
13511352
1353+
- ssl_context: an SSLContext object used for connecting to the database
1354+
using TLS. This SSL context will be modified to include the private key
1355+
or any certificates found in a separately supplied wallet. This parameter
1356+
should only be specified if the default SSLContext object cannot be used.
1357+
(default: None)
1358+
13521359
- handle: an integer representing a pointer to a valid service context
13531360
handle. This value is only used in thick mode. It should be used with
13541361
extreme caution (default: 0)

Diff for: src/oracledb/impl/base/connect_params.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ cdef class ConnectParamsImpl:
158158
_set_bool_param(args, "matchanytag", &self.matchanytag)
159159
_set_uint_param(args, "stmtcachesize", &self.stmtcachesize)
160160
_set_bool_param(args, "disable_oob", &self.disable_oob)
161+
self.ssl_context = args.get("ssl_context")
161162
_set_str_param(args, "debug_jdwp", self)
162163
_set_str_param(args, "config_dir", self)
163164
self.appcontext = args.get("appcontext")
@@ -198,6 +199,7 @@ cdef class ConnectParamsImpl:
198199
self.stmtcachesize = other_params.stmtcachesize
199200
self.disable_oob = other_params.disable_oob
200201
self.debug_jdwp = other_params.debug_jdwp
202+
self.ssl_context = other_params.ssl_context
201203
self.description_list = other_params.description_list
202204
self.access_token_callback = other_params.access_token_callback
203205
self.access_token_expires = other_params.access_token_expires

Diff for: src/oracledb/impl/thin/crypto.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def get_ssl_socket(sock, ConnectParamsImpl params, Description description,
111111
Returns a wrapped SSL socket given a socket and the parameters supplied by
112112
the user.
113113
"""
114-
ssl_context = ssl.create_default_context()
114+
ssl_context = params.ssl_context
115+
if ssl_context is None:
116+
ssl_context = ssl.create_default_context()
115117

116118
# if the platform is macOS, and one-way TLS or mTLS is being used, check
117119
# if the certifi package is installed. If certifi is not installed, load

Diff for: src/oracledb/pool.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# -----------------------------------------------------------------------------
3535

3636
import functools
37-
from typing import Callable, Type, Union
37+
from typing import Callable, Type, Union, Any
3838

3939
import oracledb
4040

@@ -610,6 +610,7 @@ def create_pool(
610610
supershardingkey: list = None,
611611
debug_jdwp: str = None,
612612
connection_id_prefix: str = None,
613+
ssl_context: Any = None,
613614
handle: int = 0,
614615
threaded: bool = True,
615616
encoding: str = None,
@@ -832,6 +833,12 @@ def create_pool(
832833
- connection_id_prefix: an application specific prefix that is added to the
833834
connection identifier used for tracing (default: None)
834835
836+
- ssl_context: an SSLContext object used for connecting to the database
837+
using TLS. This SSL context will be modified to include the private key
838+
or any certificates found in a separately supplied wallet. This parameter
839+
should only be specified if the default SSLContext object cannot be used.
840+
(default: None)
841+
835842
- handle: an integer representing a pointer to a valid service context
836843
handle. This value is only used in thick mode. It should be used with
837844
extreme caution (default: 0)

Diff for: src/oracledb/pool_params.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# more information.
3434
# -----------------------------------------------------------------------------
3535

36-
from typing import Callable, Type, Union
36+
from typing import Callable, Type, Union, Any
3737

3838
import oracledb
3939

@@ -104,6 +104,7 @@ def __init__(
104104
supershardingkey: list = None,
105105
debug_jdwp: str = None,
106106
connection_id_prefix: str = None,
107+
ssl_context: Any = None,
107108
handle: int = 0,
108109
threaded: bool = True,
109110
encoding: str = None,
@@ -310,6 +311,12 @@ def __init__(
310311
- connection_id_prefix: an application specific prefix that is added to
311312
the connection identifier used for tracing (default: None)
312313
314+
- ssl_context: an SSLContext object used for connecting to the database
315+
using TLS. This SSL context will be modified to include the private
316+
key or any certificates found in a separately supplied wallet. This
317+
parameter should only be specified if the default SSLContext object
318+
cannot be used. (default: None)
319+
313320
- handle: an integer representing a pointer to a valid service context
314321
handle. This value is only used in thick mode. It should be used with
315322
extreme caution (default: 0)
@@ -365,7 +372,8 @@ def __repr__(self):
365372
+ f"shardingkey={self.shardingkey!r}, "
366373
+ f"supershardingkey={self.supershardingkey!r}, "
367374
+ f"debug_jdwp={self.debug_jdwp!r}, "
368-
+ f"connection_id_prefix={self.connection_id_prefix!r}"
375+
+ f"connection_id_prefix={self.connection_id_prefix!r}, "
376+
+ f"ssl_context={self.ssl_context!r}"
369377
+ ")"
370378
)
371379

@@ -541,6 +549,7 @@ def set(
541549
supershardingkey: list = None,
542550
debug_jdwp: str = None,
543551
connection_id_prefix: str = None,
552+
ssl_context: Any = None,
544553
handle: int = None,
545554
threaded: bool = None,
546555
encoding: str = None,
@@ -734,6 +743,12 @@ def set(
734743
- connection_id_prefix: an application specific prefix that is added to
735744
the connection identifier used for tracing
736745
746+
- ssl_context: an SSLContext object used for connecting to the database
747+
using TLS. This SSL context will be modified to include the private
748+
key or any certificates found in a separately supplied wallet. This
749+
parameter should only be specified if the default SSLContext object
750+
cannot be used.
751+
737752
- handle: an integer representing a pointer to a valid service context
738753
handle. This value is only used in thick mode. It should be used with
739754
extreme caution

Diff for: tests/test_4500_connect_params.py

+1
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ def test_4564_repr(self):
738738
("supershardingkey", [4]),
739739
("debug_jdwp", "host=host;port=4538"),
740740
("connection_id_prefix", "prefix4564"),
741+
("ssl_context", None),
741742
]
742743
params = oracledb.ConnectParams(**dict(values))
743744
parts = [f"{name}={value!r}" for name, value in values]

Diff for: tests/test_4700_pool_params.py

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def test_4701_repr(self):
112112
("supershardingkey", [4]),
113113
("debug_jdwp", "host=host;port=1523"),
114114
("connection_id_prefix", "prefix4701"),
115+
("ssl_context", None),
115116
]
116117
params = oracledb.PoolParams(**dict(values))
117118
parts = [f"{name}={value!r}" for name, value in values]

Diff for: utils/fields.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,14 @@ description =
403403
an application specific prefix that is added to the connection identifier
404404
used for tracing
405405

406+
[ssl_context]
407+
type = Any
408+
description =
409+
an SSLContext object used for connecting to the database using TLS. This
410+
SSL context will be modified to include the private key or any certificates
411+
found in a separately supplied wallet. This parameter should only be
412+
specified if the default SSLContext object cannot be used.
413+
406414
[handle]
407415
type = int
408416
default = 0

Diff for: utils/templates/connect_params.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# -----------------------------------------------------------------------------
3333

3434
import functools
35-
from typing import Union, Callable
35+
from typing import Union, Callable, Any
3636

3737
import oracledb
3838

Diff for: utils/templates/pool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# -----------------------------------------------------------------------------
3333

3434
import functools
35-
from typing import Callable, Type, Union
35+
from typing import Callable, Type, Union, Any
3636

3737
import oracledb
3838

Diff for: utils/templates/pool_params.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# # {{ generated_notice }}
3232
# -----------------------------------------------------------------------------
3333

34-
from typing import Callable, Type, Union
34+
from typing import Callable, Type, Union, Any
3535

3636
import oracledb
3737

0 commit comments

Comments
 (0)