mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-20 17:15:39 -05:00
Signed per-component updater, release 1.1.55
This commit is contained in:
@@ -73,6 +73,8 @@ function cleanBuildDir() {
|
||||
fs.mkdirSync(BUILD_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
let credentialsId = null;
|
||||
|
||||
function encryptCredentialsFile() {
|
||||
const CryptoUtils = require('./crypto-utils');
|
||||
|
||||
@@ -109,6 +111,7 @@ function encryptCredentialsFile() {
|
||||
}
|
||||
}
|
||||
|
||||
credentialsId = crypto.createHash('sha256').update(JSON.stringify(credentials)).digest('hex');
|
||||
const buildKey = CryptoUtils.deriveKey('vyla-home-build-key', 'vyla-home-payload-salt-v1');
|
||||
const encryptedData = CryptoUtils.encryptObject(credentials, buildKey);
|
||||
|
||||
@@ -229,6 +232,32 @@ function validatePayload(zipPath) {
|
||||
return validationResults.checksum;
|
||||
}
|
||||
|
||||
function directoryId(dir) {
|
||||
const hash = crypto.createHash('sha256');
|
||||
const walk = (current, rel) => {
|
||||
for (const name of fs.readdirSync(current).sort()) {
|
||||
const full = path.join(current, name);
|
||||
const relPath = rel ? `${rel}/${name}` : name;
|
||||
if (fs.statSync(full).isDirectory()) {
|
||||
walk(full, relPath);
|
||||
} else {
|
||||
hash.update(`${relPath}\0${getFileChecksum(full)}\n`);
|
||||
}
|
||||
}
|
||||
};
|
||||
walk(dir, '');
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
function signManifest(manifest) {
|
||||
const key = process.env.VYLA_UPDATE_SIGNING_KEY;
|
||||
if (!key) {
|
||||
throw new Error('VYLA_UPDATE_SIGNING_KEY is required to sign the update manifest.');
|
||||
}
|
||||
const UpdateClient = require('./update-client');
|
||||
return crypto.sign(null, Buffer.from(UpdateClient.canonicalManifest(manifest)), key.replace(/\\n/g, '\n')).toString('base64');
|
||||
}
|
||||
|
||||
async function build() {
|
||||
try {
|
||||
cloneAllRepos();
|
||||
@@ -319,13 +348,41 @@ async function build() {
|
||||
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
|
||||
wrapperVersion = pkg.version || '2.0.0';
|
||||
} catch (e) { }
|
||||
const releaseVersion = (process.env.RELEASE_VERSION || wrapperVersion).replace(/^v/, '');
|
||||
|
||||
const assetsDir = path.join(__dirname, 'release-assets');
|
||||
fs.rmSync(assetsDir, { recursive: true, force: true });
|
||||
fs.mkdirSync(assetsDir, { recursive: true });
|
||||
|
||||
const components = {};
|
||||
const addComponent = (name, fill, id) => {
|
||||
const file = `${name}.zip`;
|
||||
const target = path.join(assetsDir, file);
|
||||
const componentZip = new AdmZip();
|
||||
fill(componentZip);
|
||||
componentZip.writeZip(target);
|
||||
components[name] = { file, sha256: getFileChecksum(target), id, size: fs.statSync(target).size };
|
||||
};
|
||||
|
||||
for (const repo of REPOS) {
|
||||
const destRepo = path.join(BUILD_DIR, repo);
|
||||
addComponent(repo, (z) => z.addLocalFolder(destRepo, repo), directoryId(destRepo));
|
||||
}
|
||||
addComponent('config', (z) => z.addLocalFolder(configDir, 'config'), directoryId(configDir));
|
||||
|
||||
const bundledCredentials = path.join(BUILD_DIR, 'encrypted-credentials.json');
|
||||
if (fs.existsSync(bundledCredentials) && credentialsId) {
|
||||
addComponent('secrets', (z) => z.addFile('encrypted-credentials.json', fs.readFileSync(bundledCredentials)), credentialsId);
|
||||
}
|
||||
|
||||
const manifest = {
|
||||
version: wrapperVersion,
|
||||
version: releaseVersion,
|
||||
sha256: checksum,
|
||||
timestamp: new Date().toISOString(),
|
||||
hasEncryptedCredentials: !!encryptedCredentialsPath
|
||||
hasEncryptedCredentials: !!encryptedCredentialsPath,
|
||||
components
|
||||
};
|
||||
manifest.signature = signManifest(manifest);
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, 'manifest.json'), JSON.stringify(manifest, null, 2), 'utf8');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user