Skip to content

Commit 097ba01

Browse files
authored
Merge pull request #306 from MerginMaps/fix-ssl-certificates
Fix issues with SSL certificates
2 parents 5718237 + 4e7a29f commit 097ba01

7 files changed

Lines changed: 23 additions & 4560 deletions

File tree

.github/workflows/autotests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515

1616
- uses: actions/setup-python@v2
1717
with:
18-
python-version: "3.8"
18+
python-version: "3.10"
1919

2020
- name: Install python package dependencies
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install python-dateutil pytz pytest pytest-cov pygeodiff coveralls
23+
pip install python-dateutil pytz pytest pytest-cov pygeodiff truststore coveralls
2424
2525
- name: Run tests
2626
run: |

.github/workflows/security_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Set up Python
1414
uses: actions/setup-python@v4
1515
with:
16-
python-version: '3.9'
16+
python-version: '3.10'
1717

1818
- name: Install dependencies
1919
run: |

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ it is possible to run other commands without specifying username/password.
160160

161161
### Installing deps
162162

163-
Python 3.7+ required. Create `mergin/deps` folder where [geodiff](https://github.com/MerginMaps/geodiff) lib is supposed to be and install dependencies:
163+
Python 3.10+ required. Create `mergin/deps` folder where [geodiff](https://github.com/MerginMaps/geodiff) lib is supposed to be and install dependencies:
164164
```bash
165165
rm -r mergin/deps
166166
mkdir mergin/deps
167-
pip install python-dateutil pytz
167+
pip install python-dateutil pytz truststore
168168
pip install pygeodiff --target=mergin/deps
169169
```
170170

mergin/cert.pem

Lines changed: 0 additions & 4523 deletions
This file was deleted.

mergin/client.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import platform
1212
from datetime import datetime, timezone
1313
import dateutil.parser
14-
import ssl
14+
import truststore
1515
from enum import Enum, auto
1616
import re
1717
import typing
@@ -71,7 +71,8 @@
7171
)
7272
from .version import __version__
7373

74-
this_dir = os.path.dirname(os.path.realpath(__file__))
74+
truststore.inject_into_ssl()
75+
7576
json_headers = {"Content-Type": "application/json"}
7677

7778

@@ -180,21 +181,7 @@ def __init__(
180181
else:
181182
handlers.append(urllib.request.ProxyHandler({"https": f"{proxy_url}:{proxy_config['port']}"}))
182183

183-
# fix for wrong macos installation of python certificates,
184-
# see https://github.com/lutraconsulting/qgis-mergin-plugin/issues/70
185-
# remove when https://github.com/qgis/QGIS-Mac-Packager/issues/32
186-
# is fixed.
187-
default_capath = ssl.get_default_verify_paths().openssl_capath
188-
if os.path.exists(default_capath):
189-
self.opener = urllib.request.build_opener(*handlers, urllib.request.HTTPSHandler())
190-
else:
191-
cafile = os.path.join(this_dir, "cert.pem")
192-
if not os.path.exists(cafile):
193-
raise Exception("missing " + cafile)
194-
ctx = ssl.SSLContext()
195-
ctx.load_verify_locations(cafile)
196-
https_handler = urllib.request.HTTPSHandler(context=ctx)
197-
self.opener = urllib.request.build_opener(*handlers, https_handler)
184+
self.opener = urllib.request.build_opener(*handlers, urllib.request.HTTPSHandler())
198185
urllib.request.install_opener(self.opener)
199186

200187
if login and not password:

mergin/common.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,18 @@ class InvalidProject(Exception):
114114
pass
115115

116116

117-
try:
118-
import dateutil.parser
119-
from dateutil.tz import tzlocal
120-
except ImportError:
121-
# this is to import all dependencies shipped with package (e.g. to use in qgis-plugin)
122-
deps_dir = os.path.join(this_dir, "deps")
123-
if os.path.exists(deps_dir):
124-
import sys
125-
126-
for f in os.listdir(os.path.join(deps_dir)):
127-
sys.path.append(os.path.join(deps_dir, f))
128-
129-
import dateutil.parser
130-
from dateutil.tz import tzlocal
117+
# add dependencies shipped in deps/ on sys.path
118+
deps_dir = os.path.join(this_dir, "deps")
119+
if os.path.exists(deps_dir):
120+
import sys
121+
122+
for f in os.listdir(deps_dir):
123+
dep_path = os.path.join(deps_dir, f)
124+
if dep_path not in sys.path:
125+
sys.path.append(dep_path)
126+
127+
import dateutil.parser
128+
from dateutil.tz import tzlocal
131129

132130

133131
class WorkspaceRole(Enum):

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
long_description="Mergin Maps utils and client",
1515
packages=find_packages(),
1616
platforms="any",
17+
python_requires=">=3.10",
1718
install_requires=[
1819
"python-dateutil==2.8.2",
1920
"pygeodiff==2.3.0",
2021
"pytz==2022.1",
2122
"click==8.1.3",
23+
"truststore==0.10.4",
2224
],
2325
entry_points={
2426
"console_scripts": ["mergin=mergin.cli:cli"],
@@ -30,5 +32,4 @@
3032
"Operating System :: OS Independent",
3133
"Programming Language :: Python :: 3",
3234
],
33-
package_data={"mergin": ["cert.pem"]},
3435
)

0 commit comments

Comments
 (0)