11'use strict' ;
2+ const fs = require ( 'fs' ) ;
3+ const crypto = require ( 'crypto' ) ;
24const path = require ( 'path' ) ;
35const debug = require ( 'debug' ) ( 'hadron-build:target' ) ;
46const { sign : _garasign } = require ( '@mongodb-js/signing-utils' ) ;
@@ -51,6 +53,20 @@ function getSigningMethod(src) {
5153 }
5254}
5355
56+ function hashFile ( filename ) {
57+ return new Promise ( ( resolve , reject ) => {
58+ const hash = crypto . createHash ( 'sha256' ) ;
59+ const fh = fs . createReadStream ( filename ) ;
60+
61+ fh . on ( 'data' , d => hash . update ( d ) ) ;
62+ fh . on ( 'end' , ( ) => {
63+ const digest = hash . digest ( 'hex' ) ;
64+ resolve ( digest ) ;
65+ } ) ;
66+ fh . on ( 'error' , reject ) ;
67+ } ) ;
68+ }
69+
5470/**
5571 * We are signing the file using `gpg` or `jsign` depending on the
5672 * file extension. If the extension is `.exe` or `.msi`, we use `jsign`
@@ -76,7 +92,9 @@ async function sign(src, garasign = _garasign) {
7692 signingMethod : getSigningMethod ( src ) ,
7793 } ;
7894
79- return await garasign ( src , clientOptions ) ;
95+ debug ( `checksum of ${ src } before signing: ${ await hashFile ( src ) } ` ) ;
96+ await garasign ( src , clientOptions ) ;
97+ debug ( `checksum of ${ src } after signing: ${ await hashFile ( src ) } ` ) ;
8098}
8199
82100module . exports = { sign, signArchive, getSignedFilename } ;
0 commit comments