1
1
import fs from 'node:fs/promises'
2
2
import path from 'node:path'
3
3
import { fileURLToPath } from 'node:url'
4
- import { sceauSchema , SCEAU_FILE_NAME , verify } from 'sceau'
5
4
import { z } from 'zod'
6
5
import { zodToJsonSchema } from 'zod-to-json-schema'
7
6
import { env } from '../env.js'
@@ -11,8 +10,10 @@ export const prefixOverride = ''
11
10
12
11
const infoResponseBody = z . object ( {
13
12
version : z . string ( ) ,
14
- release : z . string ( ) ,
13
+ builtAt : z . string ( ) ,
15
14
buildURL : z . string ( ) ,
15
+ sourceURL : z . string ( ) ,
16
+ deploymentTag : z . string ( ) ,
16
17
deploymentURL : z . string ( ) ,
17
18
signaturePublicKey : z . string ( ) ,
18
19
} )
@@ -33,52 +34,14 @@ async function readVersion() {
33
34
34
35
// --
35
36
36
- async function verifyCodeSignature ( app : App ) {
37
- const rootDir = path . resolve (
38
- path . dirname ( fileURLToPath ( import . meta. url ) ) ,
39
- '../..'
40
- )
41
- const sceauFilePath = path . resolve ( rootDir , SCEAU_FILE_NAME )
42
- const sceauFileContents = await fs
43
- . readFile ( sceauFilePath , { encoding : 'utf8' } )
44
- . catch ( error => {
45
- app . log . fatal ( { msg : 'Failed to read code signature file' , error } )
46
- process . exit ( 1 )
47
- } )
48
- const sceau = sceauSchema . parse ( JSON . parse ( sceauFileContents ) )
49
- const result = await verify (
50
- app . sodium ,
51
- sceau ,
52
- rootDir ,
53
- app . sodium . from_hex ( sceau . publicKey )
54
- )
55
- if ( result . outcome === 'failure' ) {
56
- app . log . fatal ( {
57
- msg : 'Invalid code signature' ,
58
- manifestErrors : result . manifestErrors ,
59
- signatureVerified : result . signatureVerified ,
60
- } )
61
- process . exit ( 0 )
62
- }
63
- app . log . info ( {
64
- msg : 'Code signature verified' ,
65
- signedOn : result . timestamp ,
66
- sources : result . sourceURL ,
67
- build : result . buildURL ,
68
- } )
69
- }
70
-
71
- // --
72
-
73
37
export default async function infoRoutes ( app : App ) {
74
- if ( env . NODE_ENV === 'production' ) {
75
- await verifyCodeSignature ( app )
76
- }
77
38
const version = await readVersion ( )
78
39
const serverInfo : InfoResponseBody = {
79
40
version,
80
- release : env . RELEASE_TAG ,
81
- buildURL : env . BUILD_URL ,
41
+ builtAt : app . codeSignature . timestamp ,
42
+ buildURL : app . codeSignature . buildURL ,
43
+ sourceURL : app . codeSignature . sourceURL ,
44
+ deploymentTag : env . DEPLOYMENT_TAG ,
82
45
deploymentURL : env . DEPLOYMENT_URL ,
83
46
signaturePublicKey : env . SIGNATURE_PUBLIC_KEY ,
84
47
}
0 commit comments