Skip to content

Commit ccdd41d

Browse files
committed
Use certifi also for check-update and HTTP up/downloads
1 parent 15cebe5 commit ccdd41d

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

syncrypt/pipes/http.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1+
import asyncio
12
import logging
2-
import sys
33
import os.path
44
import shutil
5-
import aiohttp
5+
import ssl
6+
import sys
67

78
import aiofiles
8-
import asyncio
9+
import aiohttp
10+
import certifi
911

10-
from .base import Pipe, Sink, Source, Limit, BufferedFree
12+
from .base import BufferedFree, Limit, Pipe, Sink, Source
1113

1214
logger = logging.getLogger(__name__)
1315

1416
class AiohttpClientSessionMixin():
1517
def init_client(self, client, headers={}):
18+
sslcontext = ssl.create_default_context(cafile=certifi.where())
19+
conn = aiohttp.TCPConnector(ssl_context=sslcontext)
1620
if client:
1721
self.client_owned, self.client = False, client
1822
else:
19-
self.client_owned, self.client = True, aiohttp.ClientSession(headers=headers, skip_auto_headers=["Content-Type", "User-Agent"])
23+
self.client_owned, self.client = True, aiohttp.ClientSession(
24+
connector=conn,
25+
headers=headers,
26+
skip_auto_headers=["Content-Type", "User-Agent"]
27+
)
2028

2129
@asyncio.coroutine
2230
def close_client(self):

syncrypt/utils/updates.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import asyncio
2+
import ssl
3+
from distutils.version import LooseVersion
4+
25
import aiohttp
6+
import certifi
7+
38
import syncrypt
4-
from distutils.version import LooseVersion
59

610
# The endpoint should return something along the lines of:
711
# { "darwin": "x.y.z", "linux": "x.y.z", "win": "x.y.z" }
812
CURRENT_ENDPOINT = 'https://alpha.syncrypt.space/releases/current.json'
913

1014
@asyncio.coroutine
1115
def retrieve_available_version(platform_id):
12-
with aiohttp.ClientSession() as c:
16+
sslcontext = ssl.create_default_context(cafile=certifi.where())
17+
conn = aiohttp.TCPConnector(ssl_context=sslcontext)
18+
with aiohttp.ClientSession(connector=conn) as c:
1319
r = yield from c.get(CURRENT_ENDPOINT)
1420
content = yield from r.json()
1521
return content[platform_id]

0 commit comments

Comments
 (0)