diff --git a/emscr/builds/openssl/build.sh b/emscr/builds/openssl/build.sh index f2572f2..e278db2 100755 --- a/emscr/builds/openssl/build.sh +++ b/emscr/builds/openssl/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -OPENSSL_VERSION="openssl-3.1.0" +OPENSSL_VERSION="openssl-3.4.0" OPENSSL_DIR="src" if [ -d ${OPENSSL_DIR} ]; then @@ -8,7 +8,7 @@ if [ -d ${OPENSSL_DIR} ]; then fi if [ ! -f ${OPENSSL_VERSION}.tar.gz ]; then - curl -O https://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz + curl -O https://www.openssl.org/source/${OPENSSL_VERSION}/${OPENSSL_VERSION}.tar.gz fi mkdir ${OPENSSL_DIR} diff --git a/emscr/tools/upgrade-ssl.js b/emscr/tools/upgrade-ssl.js new file mode 100644 index 0000000..a52961e --- /dev/null +++ b/emscr/tools/upgrade-ssl.js @@ -0,0 +1,51 @@ +const fs = require("fs"); +const path = require("path"); + +async function fetchLatestOpenSSLTag() { + const response = await fetch( + "https://api.github.com/repos/openssl/openssl/tags", + ); + const data = await response.json(); + // Now only filter out tags with the name openssl-maj.min.patch + const tag = data + .filter((tag) => /^openssl-\d+\.\d+\.\d+$/.test(tag.name)) + .map((tag) => tag.name.replace("openssl-", "")) + .reduce((acc, tag) => { + const bestVersionParts = acc.split("."); + const comparingVersionParts = tag.split("."); + const length = Math.min( + bestVersionParts.length, + comparingVersionParts.length, + ); + for (let i = 0; i < length; i++) { + const bestPart = parseInt(bestVersionParts[i], 10); + const comparingPart = parseInt(comparingVersionParts[i], 10); + if (comparingPart !== bestPart) { + return comparingPart > bestPart ? tag : acc; + } + } + + return acc; + }); + + return tag; +} + +async function updateBuildScript(version) { + const buildScriptPath = path.join(__dirname, "../builds/openssl/build.sh"); + const buildScriptContent = fs.readFileSync(buildScriptPath, "utf8"); + + const updatedContent = buildScriptContent.replace( + /OPENSSL_VERSION="openssl-\d+\.\d+\.\d+"/, + `OPENSSL_VERSION="openssl-${version}"`, + ); + + fs.writeFileSync(buildScriptPath, updatedContent, "utf8"); +} + +async function updateBuildScriptToLatestOpenSSL() { + const latestTag = await fetchLatestOpenSSLTag(); + await updateBuildScript(latestTag); +} + +updateBuildScriptToLatestOpenSSL(); diff --git a/package.json b/package.json index 350554d..d7a79dd 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "serve": "webpack serve --mode development", "build": "rm -rf dist && webpack --mode production && rm -f dist/*.LICENSE.txt", "build:openssl": "cd emscr/builds/openssl && ./build.sh ${ARG}", - "build:openssl:docker": "docker run --rm -v $(pwd):$(pwd) -w $(pwd)/emscr/builds/openssl -u $(id -u):$(id -g) --platform linux/amd64 emscripten/emsdk /bin/bash ./build.sh ${ARG}" + "build:openssl:docker": "docker run --rm -v $(pwd):$(pwd) -w $(pwd)/emscr/builds/openssl -u $(id -u):$(id -g) --platform linux/amd64 emscripten/emsdk /bin/bash ./build.sh ${ARG}", + "dependencies:openssl:upgrade": "node emscr/tools/upgrade-ssl.js" }, "keywords": [ "openssl",