Skip to content

Commit 48d6b2c

Browse files
authored
enable server cert verification by default (#75)
* enable server cert verification by default * update change log
1 parent 69c7f92 commit 48d6b2c

File tree

12 files changed

+60
-65
lines changed

12 files changed

+60
-65
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99
- add TLS support
10+
- enable server certificate verification by default
1011

1112
## [v0.2.0](https://github.com/Mapepire-IBMi/mapepire-python/releases/tag/v0.2.0) - 2024-11-26
1213
- replace `websocket-client` with `websockets`

README.md

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
- [Setup](#setup)
2121
- [Install with `pip`](#install-with-pip)
2222
- [Server Component Setup](#server-component-setup)
23-
- [Connection options](#connection-options)
23+
- [Quick Start](#quick-start)
24+
- [Other Connection options](#other-connection-options)
2425
- [1. Using the `DaemonServer` object](#1-using-the-daemonserver-object)
2526
- [2. Passing the connection details as a dictionary](#2-passing-the-connection-details-as-a-dictionary)
2627
- [3. Using a config file (`.ini`) to store the connection details](#3-using-a-config-file-ini-to-store-the-connection-details)
28+
- [TLS Configuration](#tls-configuration)
2729
- [Usage](#usage)
2830
- [1. Using the `SQLJob` object to run queries synchronously](#1-using-the-sqljob-object-to-run-queries-synchronously)
2931
- [Query and run](#query-and-run)
@@ -87,8 +89,34 @@ pip install mapepire-python
8789
### Server Component Setup
8890
To use mapire-python, you will need to have the Mapepire Server Component running on your IBM i server. Follow these instructions to set up the server component: [Mapepire Server Installation](https://mapepire-ibmi.github.io/guides/sysadmin/)
8991

90-
91-
# Connection options
92+
# Quick Start
93+
94+
To get started with `mapepire-python`, you will need to setup a connection credentials for the Mapepire server. You can use a dictionary to store the connection details:
95+
96+
```python
97+
from mapepire_python import connect
98+
99+
creds = {
100+
"host": "SERVER",
101+
"port": 8076,
102+
"user": "USER",
103+
"password": "PASSWORD",
104+
}
105+
106+
with connect(creds) as conn:
107+
with conn.execute("select * from sample.employee") as cursor:
108+
result = cursor.fetchone()
109+
print(result)
110+
111+
```
112+
113+
# Other Connection options
114+
115+
> [!NOTE]
116+
> TLS support as of version 0.3.0 is now available. Server certificate verification is enabled by default. To disable certificate verification, set the `ignoreUnauthorized` field to `True` in the connection details.
117+
> - To update run `pip install -U mapepire-python`
118+
>
119+
> - More info TLS Configuration [here](#tls-configuration)
92120
93121
There are three ways to configure mapepire server connection details using `mapepire-python`:
94122

@@ -107,8 +135,7 @@ creds = DaemonServer(
107135
host="SERVER",
108136
port="PORT",
109137
user="USER",
110-
password="PASSWORD",
111-
ignoreUnauthorized=True
138+
password="PASSWORD"
112139
)
113140
```
114141

@@ -122,8 +149,7 @@ creds = DaemonServer(
122149
host="SERVER",
123150
port="PORT",
124151
user="USER",
125-
password="PASSWORD",
126-
ignoreUnauthorized=True
152+
password="PASSWORD"
127153
)
128154

129155
job = SQLJob(creds)
@@ -174,6 +200,22 @@ job = SQLJob("./mapepire.ini", section="mapepire")
174200

175201
The `section` argument is optional and allows you to specify a specific section in the `.ini` file where the connection details are stored. This allows you to store multiple connection details to different systems in the same file. If you do not specify a `section`, the first section in the file will be used.
176202

203+
## TLS Configuration
204+
205+
Server certificate verification (`ssl.CERT_REQUIRED`) is enabled by default. To disable certificate verification, set the `ignoreUnauthorized` field to `True` in the connection details.
206+
207+
get the server certificate:
208+
209+
```python
210+
from mapepire_python.data_types import DaemonServer
211+
from mapepire_python.ssl import get_certificate
212+
213+
creds = DaemonServer(host=server, port=port, user=user, password=password)
214+
cert = get_certificate(creds)
215+
print(cert)
216+
```
217+
218+
177219

178220
# Usage
179221

mapepire_python/data_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DaemonServer:
4646
user: str
4747
password: str
4848
port: Optional[Union[str, int]]
49-
ignoreUnauthorized: Optional[bool] = True
49+
ignoreUnauthorized: Optional[bool] = False
5050
ca: Optional[Union[str, bytes]] = None
5151

5252

tests/async_pool_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@
1818
raise ValueError("One or more environment variables are missing.")
1919

2020

21-
creds = DaemonServer(
22-
host=server,
23-
port=port,
24-
user=user,
25-
password=password,
26-
ignoreUnauthorized=True,
27-
)
21+
creds = DaemonServer(host=server, port=port, user=user, password=password)
2822

2923

3024
@pytest.mark.asyncio

tests/cl_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@
1414
raise ValueError("One or more environment variables are missing.")
1515

1616

17-
creds = DaemonServer(
18-
host=server,
19-
port=port,
20-
user=user,
21-
password=password,
22-
ignoreUnauthorized=True,
23-
)
17+
creds = DaemonServer(host=server, port=port, user=user, password=password)
2418

2519

2620
def test_simple():

tests/pep249_async_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@
1919
raise ValueError("One or more environment variables are missing.")
2020

2121

22-
creds = DaemonServer(
23-
host=server,
24-
port=port,
25-
user=user,
26-
password=password,
27-
ignoreUnauthorized=True,
28-
)
22+
creds = DaemonServer(host=server, port=port, user=user, password=password)
2923

3024

3125
@pytest.mark.asyncio

tests/pep249_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
if not server or not user or not password:
1414
raise ValueError("One or more environment variables are missing.")
1515

16-
creds = DaemonServer(
17-
host=server,
18-
port=port,
19-
user=user,
20-
password=password,
21-
ignoreUnauthorized=True,
22-
)
16+
creds = DaemonServer(host=server, port=port, user=user, password=password)
2317

2418

2519
def test_pep249():

tests/pooling_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@
1717
raise ValueError("One or more environment variables are missing.")
1818

1919

20-
creds = DaemonServer(
21-
host=server,
22-
port=port,
23-
user=user,
24-
password=password,
25-
ignoreUnauthorized=True,
26-
)
20+
creds = DaemonServer(host=server, port=port, user=user, password=password)
2721

2822

2923
@pytest.mark.asyncio

tests/query_manager_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
raise ValueError("One or more environment variables are missing.")
1616

1717

18-
creds = DaemonServer(
19-
host=server,
20-
port=port,
21-
user=user,
22-
password=password,
23-
ignoreUnauthorized=True,
24-
)
18+
creds = DaemonServer(host=server, port=port, user=user, password=password)
2519

2620

2721
def test_query_manager():

tests/simple_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@
1414
if not server or not user or not password:
1515
raise ValueError("One or more environment variables are missing.")
1616

17-
creds = DaemonServer(
18-
host=server,
19-
port=port,
20-
user=user,
21-
password=password,
22-
ignoreUnauthorized=True,
23-
)
17+
creds = DaemonServer(host=server, port=port, user=user, password=password)
2418

2519

2620
def parse_sql_rc(message):

0 commit comments

Comments
 (0)