Skip to content

Commit

Permalink
GH-19: Replaced _acquire_curl-ca-bundle.bat with _get_curl-ca-bundle.py
Browse files Browse the repository at this point in the history
  • Loading branch information
negrutiu committed Jun 1, 2024
1 parent 6216faa commit 6c2f8d1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/nscurl/Makefile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ nsis-sdk:

curl-ca-bundle:
REM ----- curl-ca-bundle.crt --------------------------------------------------
call _acquire_curl-ca-bundle.bat
py -3 _get_curl-ca-bundle.py

update-file-version:
REM ----- Resource.rc ---------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/nscurl/NScurl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<AdditionalDependencies>version.lib;libcurl-d.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlibd.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; call _acquire_curl-ca-bundle.bat &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -105,7 +105,7 @@
<AdditionalDependencies>version.lib;libcurl-d.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlibd.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; call _acquire_curl-ca-bundle.bat &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -125,7 +125,7 @@
<AdditionalDependencies>version.lib;libcurl.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlib.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; call _acquire_curl-ca-bundle.bat &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -144,7 +144,7 @@
<AdditionalDependencies>version.lib;libcurl.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlib.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; call _acquire_curl-ca-bundle.bat &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand Down
7 changes: 0 additions & 7 deletions src/nscurl/_acquire_curl-ca-bundle.bat

This file was deleted.

31 changes: 31 additions & 0 deletions src/nscurl/_get_curl-ca-bundle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Download curl-ca-bundle.crt from Curl website

from pathlib import Path
from urllib import request
import ssl
from pip._vendor import certifi # use pip certifi to fix "Let's Encrypt" issues (urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1006)>)
import datetime

url = 'https://curl.se/ca/cacert.pem'
file = Path(__file__).parent.joinpath('curl-ca-bundle.crt')

print(f"Download {url} ...")

headers = {}
if file.exists():
dt = datetime.datetime.fromtimestamp(file.stat().st_mtime, tz=datetime.timezone.utc)
headers['If-Modified-Since'] = dt.strftime('%a, %d %b %Y %H:%M:%S GMT')
print(f" If-Modified-Since: {headers['If-Modified-Since']}")

sslctx = ssl.create_default_context(cafile=certifi.where())
try:
with request.urlopen(request.Request(url, headers=headers), context=sslctx) as http:
file.parent.mkdir(parents=True, exist_ok=True)
with open(file, 'wb') as outfile:
outfile.write(http.read())
print(f" {http.status} {http.reason}, {http.getheader('Content-Length')} bytes")
except request.HTTPError as ex:
if ex.code == 304:
print(f" {ex.code} {ex.reason}, {file.stat().st_size} bytes, the file is already up-to-date")
else:
raise

0 comments on commit 6c2f8d1

Please sign in to comment.