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

Changed time server to http://timestamp.digicert.com #3

Open
wants to merge 6 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
lib
lib
/.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This action signs files that are supported by `signtool.exe` with a code signing

### `timestampUrl`

**Optional** Url of the timestamp server. Default is 'http://timestamp.verisign.com/scripts/timstamp.dll'
**Optional** Url of the timestamp server. Default is 'http://timestamp.digicert.com'

## Example usage

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

65 changes: 32 additions & 33 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,67 +37,67 @@ async function createCertificatePfx() {

async function addCertificateToStore(){
try {
const password : string= core.getInput('password');
if (password == ''){
const password: string = core.getInput('password');
if (password == '') {
console.log("Password is required to add pfx certificate to store");
return false;
return false;
}
var command = `certutil -f -p ${password} -importpfx ${certificateFileName}`
console.log("Adding cert to store command: " + command);
const command = `certutil -f -p ${password} -importpfx ${certificateFileName}`
console.log(`Adding cert to store command: ${command}`);
const { stdout } = await asyncExec(command);
console.log(stdout);
return true;
} catch(err) {
console.log(err.stdout);
console.log(err.stderr);
} catch (err) {
console.log(err);
return false;
}
}

async function signWithSigntool(fileName: string) {
try {
// var command = `"${signtool}" sign /sm /t ${timestampUrl} /sha1 "1d7ec06212fdeae92f8d3010ea422ecff2619f5d" /n "DanaWoo" ${fileName}`
var vitalParameterIncluded = false;
var timestampUrl : string = core.getInput('timestampUrl');
// var command = `"${signtool}" sign /sm /tr ${timestampUrl} /sha1 "1d7ec06212fdeae92f8d3010ea422ecff2619f5d" /n "DanaWoo" ${fileName}`
let vitalParameterIncluded = false;
let timestampUrl: string = core.getInput('timestampUrl');
if (timestampUrl === '') {
timestampUrl = 'http://timestamp.verisign.com/scripts/timstamp.dll'; // 'http://timestamp.digicert.com';//
timestampUrl = 'http://timestamp.digicert.com'; // 'http://timestamp.digicert.com';//
}
var command = `"${signtool}" sign /sm /t ${timestampUrl}`
const sha1 : string= core.getInput('certificatesha1');
if (sha1 != ''){
let command = `"${signtool}" sign /sm /tr ${timestampUrl}`
const sha1: string = core.getInput('certificatesha1');
if (sha1 != '') {
command = command + ` /sha1 "${sha1}"`
vitalParameterIncluded = true;
vitalParameterIncluded = true;
}
const name : string= core.getInput('certificatename');
if (name != ''){
vitalParameterIncluded = true;
const name : string = core.getInput('certificatename');
if (name != '') {
vitalParameterIncluded = true;
command = command + ` /n "${name}"`
}
if (!vitalParameterIncluded){
console.log("You need to include a NAME or a SHA1 Hash for the certificate to sign with.")
if (!vitalParameterIncluded) {
console.log('You need to include a NAME or a SHA1 Hash for the certificate to sign with.')
}
command = command + ` ${fileName}`;
console.log("Signing command: " + command);
command = `${command} ${fileName}`;
console.log(`Signing command: ${command}`);
const { stdout } = await asyncExec(command);
console.log(stdout);
return true;
} catch(err) {
console.log(err.stdout);
console.log(err.stderr);
console.log(err);
return false;
}
}

async function trySignFile(fileName: string) {
console.log(`Signing ${fileName}.`);
const extension = path.extname(fileName);
for (let i=0; i< 10; i++) {
for (let i = 0; i < 3; i++) {
await sleep(i);
if (signtoolFileExtensions.includes(extension)) {
if (await signWithSigntool(fileName))
if (await signWithSigntool(fileName)) {
return;
}
}
}

throw `Failed to sign '${fileName}'.`;
}

Expand All @@ -108,10 +108,10 @@ async function* getFiles(folder: string, recursive: boolean): any {
const stat = await fs.stat(fullPath);
if (stat.isFile()) {
const extension = path.extname(file);
if (signtoolFileExtensions.includes(extension) || extension == '.nupkg')
if (signtoolFileExtensions.includes(extension) || extension == '.nupkg') {
yield fullPath;
}
else if (stat.isDirectory() && recursive) {
}
} else if (stat.isDirectory() && recursive) {
yield* getFiles(fullPath, recursive);
}
}
Expand All @@ -129,11 +129,10 @@ async function run() {
try {
if (await createCertificatePfx())
{
if (await addCertificateToStore())
if (await addCertificateToStore())
await signFiles();
}
}
catch (err) {
} catch (err) {
core.setFailed(`Action failed with error: ${err}`);
}
}
Expand Down
42 changes: 29 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "code-sign-action",
"version": "1.0.0",
"version": "2.0.0",
"description": "Sign files with a code signing certificate.",
"main": "index.js",
"scripts": {
Expand All @@ -18,11 +18,11 @@
},
"homepage": "https://github.com/DanaBear/code-sign-action#readme",
"dependencies": {
"@actions/core": "^1.2.0"
"@actions/core": "^1.8.2"
},
"devDependencies": {
"@types/node": "^12.11.1",
"@zeit/ncc": "^0.20.5",
"typescript": "^3.6.4"
"@types/node": "^17.0.35",
"@zeit/ncc": "^0.22.3",
"typescript": "^4.7.2"
}
}