-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathwindowsSignHook.ts
More file actions
72 lines (62 loc) · 1.94 KB
/
windowsSignHook.ts
File metadata and controls
72 lines (62 loc) · 1.94 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { spawn } from 'node:child_process'
export function spawnSignFile(filePath: string): Promise<void> {
return new Promise((resolve, reject) => {
console.log(`Path to file to sign: ${filePath}`)
const signToolPath = process.env.SIGNTOOL_PATH
if (!signToolPath) {
return reject(new Error('SIGNTOOL_PATH environment variable is not set'))
}
const trustedSigningAccount = process.env.TRUSTED_SIGNING_ACCOUNT
if (!trustedSigningAccount) {
return reject(
new Error('TRUSTED_SIGNING_ACCOUNT environment variable is not set')
)
}
const trustedSigningProfile = process.env.TRUSTED_SIGNING_PROFILE
if (!trustedSigningProfile) {
return reject(
new Error('TRUSTED_SIGNING_PROFILE environment variable is not set')
)
}
const trustedSigningEndpoint = process.env.TRUSTED_SIGNING_ENDPOINT
if (!trustedSigningEndpoint) {
return reject(
new Error('TRUSTED_SIGNING_ENDPOINT environment variable is not set')
)
}
const args = [
'code',
'trusted-signing',
filePath,
'-td',
'sha256',
'-fd',
'sha256',
'--trusted-signing-account',
trustedSigningAccount,
'--trusted-signing-certificate-profile',
trustedSigningProfile,
'--trusted-signing-endpoint',
trustedSigningEndpoint,
]
const signingProc = spawn(signToolPath, args, {
env: process.env,
cwd: process.cwd(),
stdio: 'inherit',
})
signingProc.on('close', (code) => {
if (code === 0) {
console.log('Signing process completed successfully')
resolve()
} else {
reject(new Error(`Signing process exited with code ${code}`))
}
})
signingProc.on('error', (error) => {
reject(new Error(`Failed to spawn signing process: ${error.message}`))
})
})
}
export default async function (filePath: string): Promise<void> {
return spawnSignFile(filePath)
}