Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement openssl version upgrade script #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions emscr/builds/openssl/build.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

OPENSSL_VERSION="openssl-3.1.0"
OPENSSL_VERSION="openssl-3.4.0"
OPENSSL_DIR="src"

if [ -d ${OPENSSL_DIR} ]; then
rm -rf ${OPENSSL_DIR}
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}
Expand Down
51 changes: 51 additions & 0 deletions emscr/tools/upgrade-ssl.js
Original file line number Diff line number Diff line change
@@ -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();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down