-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsign.js
41 lines (37 loc) · 1.84 KB
/
sign.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const path = require('path');
const fs = require('fs');
const childProcess = require('child_process');
const TEMP_DIR = path.join(__dirname, 'release_signing', 'tmp');
if (!fs.statSync(TEMP_DIR).isDirectory()) {
fs.mkdirSync(TEMP_DIR);
}
function sign(configuration) {
// credentials from ssl.com
const USER_NAME = process.env.WINDOWS_SIGN_USER_NAME;
const USER_PASSWORD = process.env.WINDOWS_SIGN_USER_PASSWORD;
const CREDENTIAL_ID = process.env.WINDOWS_SIGN_CREDENTIAL_ID;
const USER_TOTP = process.env.WINDOWS_SIGN_USER_TOTP;
if (USER_NAME && USER_PASSWORD && USER_TOTP && CREDENTIAL_ID) {
console.log(`Signing ${configuration.path}`);
// const { name, dir } = path.parse(configuration.path);
// CodeSignTool can't sign in place without verifying the overwrite with a
// y/m interaction so we are creating a new file in a temp directory and
// then replacing the original file with the signed file.
const { base, dir } = path.parse(configuration.path);
const tempFile = path.join(TEMP_DIR, base);
//childProcess.execSync(`mkdir -p "${TEMP_DIR}"`, { stdio: 'inherit' });
const setDir = `cd ../CodeSignTool`;
const signFile = `CodeSignTool sign -input_file_path="${configuration.path}" -output_dir_path="${TEMP_DIR}" -credential_id="${CREDENTIAL_ID}" -username="${USER_NAME}" -password="${USER_PASSWORD}" -totp_secret="${USER_TOTP}"`;
const moveFile = `mv "${tempFile}" "${dir}"`;
childProcess.execSync(`${setDir} && ${signFile} && ${moveFile}`, { stdio: 'inherit' });
} else {
console.warn(`sign.js - Can't sign file ${configuration.path}, missing value for:
${USER_NAME ? '' : 'WINDOWS_SIGN_USER_NAME'}
${USER_PASSWORD ? '' : 'WINDOWS_SIGN_USER_PASSWORD'}
${CREDENTIAL_ID ? '' : 'WINDOWS_SIGN_CREDENTIAL_ID'}
${USER_TOTP ? '' : 'WINDOWS_SIGN_USER_TOTP'}
`);
process.exit(1);
}
}
exports.default = sign;