Skip to content

Commit d58096a

Browse files
jeeftorMasterOdin
andauthored
Disable SSL Inspection (#39)
Co-authored-by: Matthew Peveler <[email protected]>
1 parent 56ab4cc commit d58096a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ In order of precedence:
5757

5858
If you are experiencing issues with *tldr*, consider deleting the cache files before trying other measures.
5959

60+
### SSL Inspection
61+
62+
For networks that sit behind a proxy, it may be necessary to disable SSL verification for the client to function. Setting the following:
63+
64+
* `TLDR_ALLOW_INSECURE=1`
65+
66+
will disable SSL certificate inspection. This __should be avoided__ unless absolutely necessary.
67+
6068
### Colors
6169

6270
Values of the `TLDR_COLOR_x` variables may consist of three parts:
@@ -83,4 +91,4 @@ can either use the `--source` flag when using tldr or by specifying the followin
8391
* defaults to `https://raw.githubusercontent.com/tldr-pages/tldr/master/pages`
8492
* it can also point to local directory using `file:///path/to/directory`
8593
* `TLDR_DOWNLOAD_CACHE_LOCATION` to control where to pull a zip of all pages from
86-
* defaults to `https://tldr-pages.github.io/assets/tldr.zip`
94+
* defaults to `https://tldr-pages.github.io/assets/tldr.zip`

tldr.py

100755100644
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from zipfile import ZipFile
88
from datetime import datetime
99
from io import BytesIO
10+
import ssl
1011
from urllib.parse import quote
1112
from urllib.request import urlopen, Request
1213
from urllib.error import HTTPError, URLError
@@ -25,6 +26,11 @@
2526
)
2627
USE_CACHE = int(os.environ.get('TLDR_CACHE_ENABLED', '1')) > 0
2728
MAX_CACHE_AGE = int(os.environ.get('TLDR_CACHE_MAX_AGE', 24))
29+
URLOPEN_CONTEXT = None
30+
if int(os.environ.get('TLDR_ALLOW_INSECURE', '0')) == 1:
31+
URLOPEN_CONTEXT = ssl.create_default_context()
32+
URLOPEN_CONTEXT.check_hostname = False
33+
URLOPEN_CONTEXT.verify_mode = ssl.CERT_NONE
2834

2935
OS_DIRECTORIES = {
3036
"linux": "linux",
@@ -88,7 +94,7 @@ def get_page_for_platform(command, platform, remote=None):
8894
else:
8995
page_url = get_page_url(platform, command, remote)
9096
try:
91-
data = urlopen(Request(page_url, headers=REQUEST_HEADERS)).read()
97+
data = urlopen(Request(page_url, headers=REQUEST_HEADERS), context=URLOPEN_CONTEXT).read()
9298
data_downloaded = True
9399
except Exception:
94100
data = load_page_from_cache(command, platform)
@@ -101,7 +107,7 @@ def get_page_for_platform(command, platform, remote=None):
101107

102108
def update_page_for_platform(command, platform, remote=None):
103109
page_url = get_page_url(platform, command, remote)
104-
data = urlopen(Request(page_url, headers=REQUEST_HEADERS)).read()
110+
data = urlopen(Request(page_url, headers=REQUEST_HEADERS), context=URLOPEN_CONTEXT).read()
105111
store_page_to_cache(data, command, platform)
106112

107113

@@ -222,7 +228,7 @@ def update_cache():
222228
req = urlopen(Request(
223229
DOWNLOAD_CACHE_LOCATION,
224230
headers=REQUEST_HEADERS
225-
))
231+
), context=URLOPEN_CONTEXT)
226232
zipfile = ZipFile(BytesIO(req.read()))
227233
pattern = re.compile(r'pages/(.+)/(.+)\.md')
228234
cached = 0

0 commit comments

Comments
 (0)