Skip to content

Commit fcea080

Browse files
bpo-40163: Fix multissltest download of old OpenSSL (GH-19329)
(cherry picked from commit 938717f) Co-authored-by: Christian Heimes <[email protected]>
1 parent 387c744 commit fcea080

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix multissltest tool. OpenSSL has changed download URL for old releases.
2+
The multissltest tool now tries to download from current and old download
3+
URLs.

Tools/ssl/multissltests.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
import os
3131
try:
3232
from urllib.request import urlopen
33+
from urllib.error import HTTPError
3334
except ImportError:
34-
from urllib2 import urlopen
35-
import subprocess
35+
from urllib2 import urlopen, HTTPError
3636
import shutil
37+
import string
38+
import subprocess
3739
import sys
3840
import tarfile
3941

@@ -163,7 +165,7 @@
163165

164166
class AbstractBuilder(object):
165167
library = None
166-
url_template = None
168+
url_templates = None
167169
src_template = None
168170
build_template = None
169171
install_target = 'install'
@@ -202,6 +204,11 @@ def __eq__(self, other):
202204
def __hash__(self):
203205
return hash((self.library, self.version))
204206

207+
@property
208+
def short_version(self):
209+
"""Short version for OpenSSL download URL"""
210+
return None
211+
205212
@property
206213
def openssl_cli(self):
207214
"""openssl CLI binary"""
@@ -255,11 +262,23 @@ def _download_src(self):
255262
src_dir = os.path.dirname(self.src_file)
256263
if not os.path.isdir(src_dir):
257264
os.makedirs(src_dir)
258-
url = self.url_template.format(self.version)
259-
log.info("Downloading from {}".format(url))
260-
req = urlopen(url)
261-
# KISS, read all, write all
262-
data = req.read()
265+
data = None
266+
for url_template in self.url_templates:
267+
url = url_template.format(v=self.version, s=self.short_version)
268+
log.info("Downloading from {}".format(url))
269+
try:
270+
req = urlopen(url)
271+
# KISS, read all, write all
272+
data = req.read()
273+
except HTTPError as e:
274+
log.error(
275+
"Download from {} has from failed: {}".format(url, e)
276+
)
277+
else:
278+
log.info("Successfully downloaded from {}".format(url))
279+
break
280+
if data is None:
281+
raise ValueError("All download URLs have failed")
263282
log.info("Storing {}".format(self.src_file))
264283
with open(self.src_file, "wb") as f:
265284
f.write(data)
@@ -380,7 +399,10 @@ def run_python_tests(self, tests, network=True):
380399

381400
class BuildOpenSSL(AbstractBuilder):
382401
library = "OpenSSL"
383-
url_template = "https://www.openssl.org/source/openssl-{}.tar.gz"
402+
url_templates = (
403+
"https://www.openssl.org/source/openssl-{v}.tar.gz",
404+
"https://www.openssl.org/source/old/{s}/openssl-{v}.tar.gz"
405+
)
384406
src_template = "openssl-{}.tar.gz"
385407
build_template = "openssl-{}"
386408
# only install software, skip docs
@@ -419,12 +441,20 @@ def _post_install_300(self):
419441
)
420442
with open(openssl_fips_cnf, "w") as f:
421443
f.write(OPENSSL_FIPS_CNF.format(self=self))
444+
@property
445+
def short_version(self):
446+
"""Short version for OpenSSL download URL"""
447+
short_version = self.version.rstrip(string.ascii_letters)
448+
if short_version.startswith("0.9"):
449+
short_version = "0.9.x"
450+
return short_version
422451

423452

424453
class BuildLibreSSL(AbstractBuilder):
425454
library = "LibreSSL"
426-
url_template = (
427-
"https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-{}.tar.gz")
455+
url_templates = (
456+
"https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-{v}.tar.gz",
457+
)
428458
src_template = "libressl-{}.tar.gz"
429459
build_template = "libressl-{}"
430460

0 commit comments

Comments
 (0)