2018-12-13 17:59:47 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Utility to codesign the finished Installers.
|
|
|
|
|
|
* This enables the App to verify the authenticity of the Updates, and
|
|
|
|
|
|
* enables the User to verify the authenticity of their manually downloaded
|
|
|
|
|
|
* Installer with the openssl utility.
|
|
|
|
|
|
*
|
2019-08-13 10:25:58 +02:00
|
|
|
|
* ATTENTION MAC USERS: Safari started to automatically unpack zip files and then delete them,
|
|
|
|
|
|
* so you'll have to look in your trash to get the original file.
|
|
|
|
|
|
* once we switch to dmg this won't be necessary anymore, but:
|
|
|
|
|
|
* https://github.com/electron-userland/electron-builder/issues/2199
|
|
|
|
|
|
*
|
2019-09-05 12:16:25 +02:00
|
|
|
|
* The installer signatures are created in the following files:
|
2019-09-20 09:00:15 +02:00
|
|
|
|
* https://mail.tutanota.com/desktop/win-sig.bin (for Windows)
|
2020-01-17 10:52:49 +01:00
|
|
|
|
* https://mail.tutanota.com/desktop/mac-sig-dmg.bin (for Mac .dmg installer)
|
2020-01-23 11:09:29 +01:00
|
|
|
|
* https://mail.tutanota.com/desktop/mac-sig-zip.bin (for Mac .zip update file)
|
2019-09-20 09:00:15 +02:00
|
|
|
|
* https://mail.tutanota.com/desktop/linux-sig.bin (for Linux)
|
2018-12-13 17:59:47 +01:00
|
|
|
|
*
|
2018-12-20 14:40:58 +01:00
|
|
|
|
* They allow verifying the initial download via
|
2018-12-13 17:59:47 +01:00
|
|
|
|
*
|
|
|
|
|
|
* # get public key from github
|
2019-09-05 12:16:25 +02:00
|
|
|
|
* wget https://raw.githubusercontent.com/tutao/tutanota/master/tutao-pub.pem
|
2018-12-13 17:59:47 +01:00
|
|
|
|
* or
|
2019-09-05 12:16:25 +02:00
|
|
|
|
* curl https://raw.githubusercontent.com/tutao/tutanota/master/tutao-pub.pem > tutao-pub.pem
|
2018-12-13 17:59:47 +01:00
|
|
|
|
* # validate the signature against public key
|
|
|
|
|
|
* openssl dgst -sha512 -verify tutao-pub.pem -signature signature.bin tutanota.installer.ext
|
|
|
|
|
|
*
|
|
|
|
|
|
* openssl should Print 'Verified OK' after the second command if the signature matches the certificate
|
|
|
|
|
|
*
|
|
|
|
|
|
* This prevents an attacker from getting forged Installers/updates installed/applied
|
|
|
|
|
|
*
|
|
|
|
|
|
* get pem cert from pfx:
|
|
|
|
|
|
* openssl pkcs12 -in comodo-codesign.pfx -clcerts -nokeys -out tutao-cert.pem
|
|
|
|
|
|
*
|
|
|
|
|
|
* get private key from pfx:
|
|
|
|
|
|
* openssl pkcs12 -in comodo-codesign.pfx -nocerts -out tutao.pem
|
|
|
|
|
|
*
|
|
|
|
|
|
* get public key from pem cert:
|
|
|
|
|
|
* openssl x509 -pubkey -noout -in tutao-cert.pem > tutao-pub.pem
|
|
|
|
|
|
* */
|
|
|
|
|
|
|
|
|
|
|
|
const Promise = require('bluebird')
|
|
|
|
|
|
const fs = Promise.promisifyAll(require('fs-extra'))
|
|
|
|
|
|
const path = require('path')
|
2019-09-05 12:16:25 +02:00
|
|
|
|
const spawnSync = require('child_process').spawnSync
|
|
|
|
|
|
const jsyaml = require('js-yaml')
|
2018-12-13 17:59:47 +01:00
|
|
|
|
|
|
|
|
|
|
/**
|
2019-09-05 12:16:25 +02:00
|
|
|
|
* Creates a signature on the given application file, writes it to signatureFileName and adds the signature to the yaml file.
|
|
|
|
|
|
* Requires environment variable HSM_USER_PIN to be set to the HSM user pin.
|
|
|
|
|
|
* @param filePath The application file to sign. Needs to be the full path to the file.
|
|
|
|
|
|
* @param signatureFileName The signature will be written to that file. Must not contain any path.
|
|
|
|
|
|
* @param ymlFileName This yaml file will be adapted to include the signature. Must not contain any path.
|
2018-12-13 17:59:47 +01:00
|
|
|
|
*/
|
2019-09-05 12:16:25 +02:00
|
|
|
|
function signer(filePath, signatureFileName, ymlFileName) {
|
2018-12-13 17:59:47 +01:00
|
|
|
|
console.log("Signing", path.basename(filePath), '...')
|
|
|
|
|
|
const dir = path.dirname(filePath)
|
2019-09-05 12:16:25 +02:00
|
|
|
|
const sigOutPath = path.join(dir, signatureFileName)
|
|
|
|
|
|
const result = spawnSync("/usr/bin/pkcs11-tool", [
|
|
|
|
|
|
"-s",
|
|
|
|
|
|
"-m", "SHA512-RSA-PKCS",
|
|
|
|
|
|
"--id", "10",
|
|
|
|
|
|
"--pin", "env:HSM_USER_PIN",
|
|
|
|
|
|
"-i", path.basename(filePath),
|
|
|
|
|
|
"-o", signatureFileName
|
|
|
|
|
|
], {
|
|
|
|
|
|
cwd: dir,
|
|
|
|
|
|
stdio: [process.stdin, process.stdout, process.stderr]
|
|
|
|
|
|
})
|
|
|
|
|
|
if (result.status !== 0) {
|
|
|
|
|
|
throw new Error("error invoking process" + JSON.stringify(result))
|
2018-12-13 17:59:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-17 10:52:49 +01:00
|
|
|
|
if (ymlFileName) {
|
|
|
|
|
|
console.log(`attaching signature to yml...`, ymlFileName)
|
|
|
|
|
|
const ymlPath = path.join(dir, ymlFileName)
|
|
|
|
|
|
let yml = jsyaml.safeLoad(fs.readFileSync(ymlPath, 'utf8'))
|
|
|
|
|
|
const signatureContent = fs.readFileSync(sigOutPath)
|
|
|
|
|
|
yml.signature = signatureContent.toString('base64')
|
|
|
|
|
|
fs.writeFileSync(ymlPath, jsyaml.safeDump(yml), 'utf8')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("Not attaching signature to yml")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-13 17:59:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-20 14:40:58 +01:00
|
|
|
|
module.exports = signer
|