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

dev: Add ddsignfiles wrapper #1774

Closed
wants to merge 2 commits into from
Closed
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
93 changes: 93 additions & 0 deletions dev/build/SignFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// File copied from https://dev.azure.com/devdiv/Engineering/_git/MicroBuild?path=/src/NodeJS/Signing/SignFiles.js&_a=contents&version=GBmain

const fs = require('fs')
const path = require('path')
const execSync = require('child_process').execSync
const tempSigningDir = path.join(process.env.AGENT_TEMPDIRECTORY, 'signing')

/**
* Accepts a simple JS array, converts the array to JSON, then signs the files with DDSignFiles.
* @param {Array} FilesArray - JS array of files to sign and the certs to sign them with.
* @returns {number} exit code of DDSignFiles. 0 for success, non-zero for failure.
*/
function signFiles(FilesArray) {
var filesToSign = prepareDDSignJson(FilesArray)
console.debug(JSON.stringify(filesToSign, null, " "))
writeFilesToSignToDisk(filesToSign)
return runDDSignFiles()
}

/**
* Converts a JS array to JSON for DDSignFiles
* @param {Array} array - JS array of files to sign and the certs to sign them with.
* @returns The contents of the JS array transformed into a JSON object format for DDSignFiles.
*/
function prepareDDSignJson(array) {
var filesToSign = {
"SignFileRecordList": []
}

for (var cert in array) {
var innerJson = {
"SignFileList": [],
"Certs": cert
}

array[cert].forEach(function (file) {
var paths = {
"SrcPath": file,
"DstPath": null // DDSignFiles converts null to SrcPath.
}
innerJson.SignFileList.push(paths)
})
filesToSign.SignFileRecordList.push(innerJson)
}
return filesToSign
}


/**
* Writes the JSON to a file on disk. DDSignFiles needs to read a file.
* @param {object} filesToSign - json content to write to disk.
*/
function writeFilesToSignToDisk(filesToSign) {
try {
var jsonFile = path.join(tempSigningDir, 'FilesToSign.json')

if (!fs.existsSync(tempSigningDir)) {
fs.mkdirSync(tempSigningDir)
}

fs.writeFileSync(jsonFile, JSON.stringify(filesToSign, null))
} catch (e) {
if (e.code === 'ENOENT') {
console.error("Error code suggests a file or directory could not be found. Are you writing to a directory that does not exist?")
}
console.error('See https://nodejs.org/api/errors.html#common-system-errors for more information and contact [email protected] for assistance.')
console.error(e)
}
}

/**
* Runs the DDSignFiles tool for the files to sign and returns the exit code.
* @returns {number} exit code of DDSignFiles.
*/
function runDDSignFiles() {
var binPath = path.join(process.env.MBSIGN_APPFOLDER, 'ddsignfiles.dll')
var jsonFile = path.join(tempSigningDir, 'FilesToSign.json')
console.info(`Running command: dotnet ${binPath}' /filelist:${jsonFile}`)

try {
execSync(`dotnet ${binPath} /filelist:${jsonFile}`, { stdio: "inherit" })
}

catch (error) {
console.error(`DDSignFiles exited with error.status: ${error.status}`)
console.error(error)
return error.status
}

return 0
}

module.exports = signFiles
4 changes: 2 additions & 2 deletions dev/package-lock.json

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

2 changes: 1 addition & 1 deletion dev/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/vscode-azext-dev",
"author": "Microsoft Corporation",
"version": "2.0.4",
"version": "2.1.0",
"description": "Common dev dependency tools for developing Azure extensions for VS Code",
"tags": [
"azure",
Expand Down
Loading