@certchip/signer 0.1.15 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/bin/signer.js CHANGED
@@ -1,19 +1,72 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * signer.js - Windows-only wrapper for signer.exe (KSP integration)
4
+ *
5
+ * @certchip/signer
6
+ * Copyright (c) 2025 Certchip. All rights reserved.
7
+ */
8
+
2
9
  const { spawn } = require('child_process');
3
10
  const path = require('path');
4
11
  const os = require('os');
12
+ const fs = require('fs');
13
+
14
+ // Check if running on Windows
15
+ if (os.platform() !== 'win32') {
16
+ console.error('Error: signer command is only available on Windows');
17
+ console.error('');
18
+ console.error('The signer command provides Windows KSP (Key Storage Provider)');
19
+ console.error('integration for use with signtool.exe and Windows certificate store.');
20
+ console.error('');
21
+ console.error('For cross-platform code signing, use signercli instead:');
22
+ console.error(' npx signercli -help');
23
+ process.exit(1);
24
+ }
25
+
26
+ /**
27
+ * Get the path to the signer.exe binary
28
+ * @returns {string} Full path to signer.exe
29
+ */
30
+ function getBinaryPath() {
31
+ return path.join(__dirname, 'win32-x64', 'signer.exe');
32
+ }
5
33
 
6
- function getBinaryPath(name) {
7
- const platform = os.platform();
8
- if (platform !== 'win32') {
9
- console.error('signer command is only available on Windows (Windows KSP integration)');
10
- console.error('Use signercli for cross-platform code signing');
11
- process.exit(1);
34
+ /**
35
+ * Check if the binary exists
36
+ * @param {string} binaryPath - Path to check
37
+ * @returns {boolean} True if binary exists
38
+ */
39
+ function checkBinary(binaryPath) {
40
+ try {
41
+ fs.accessSync(binaryPath, fs.constants.F_OK);
42
+ return true;
43
+ } catch (e) {
44
+ return false;
12
45
  }
13
- return path.join(__dirname, 'win32-x64', name + '.exe');
14
46
  }
15
47
 
16
- const binary = getBinaryPath('signer');
17
- const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit', windowsHide: true });
18
- child.on('close', code => process.exit(code || 0));
19
- child.on('error', err => { console.error(err.message); process.exit(1); });
48
+ // Main execution
49
+ const binary = getBinaryPath();
50
+
51
+ if (!checkBinary(binary)) {
52
+ console.error('Error: signer.exe not found');
53
+ console.error(`Expected path: ${binary}`);
54
+ console.error('');
55
+ console.error('Please reinstall the @certchip/signer package.');
56
+ process.exit(1);
57
+ }
58
+
59
+ // Spawn the binary with all command line arguments
60
+ const child = spawn(binary, process.argv.slice(2), {
61
+ stdio: 'inherit',
62
+ windowsHide: true
63
+ });
64
+
65
+ child.on('close', (code) => {
66
+ process.exit(code || 0);
67
+ });
68
+
69
+ child.on('error', (err) => {
70
+ console.error(`Error executing signer: ${err.message}`);
71
+ process.exit(1);
72
+ });
package/bin/signercli.js CHANGED
@@ -1,18 +1,139 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * signercli.js - Cross-platform wrapper for signercli binary
4
+ *
5
+ * @certchip/signer
6
+ * Copyright (c) 2025 Certchip. All rights reserved.
7
+ */
8
+
2
9
  const { spawn } = require('child_process');
3
10
  const path = require('path');
4
11
  const os = require('os');
12
+ const fs = require('fs');
5
13
 
14
+ /**
15
+ * Get the path to the native binary for the current platform
16
+ * @param {string} name - Binary name (without extension)
17
+ * @returns {string} Full path to the binary
18
+ */
6
19
  function getBinaryPath(name) {
7
20
  const platform = os.platform();
8
21
  const arch = os.arch();
9
- let platformId = platform === 'win32' ? 'win32' : platform === 'darwin' ? 'darwin' : 'linux';
10
- let archId = arch === 'x64' || arch === 'x86_64' ? 'x64' : 'arm64';
22
+
23
+ // Map platform names
24
+ let platformId;
25
+ switch (platform) {
26
+ case 'win32':
27
+ platformId = 'win32';
28
+ break;
29
+ case 'darwin':
30
+ platformId = 'darwin';
31
+ break;
32
+ default:
33
+ platformId = 'linux';
34
+ }
35
+
36
+ // Map architecture names
37
+ let archId;
38
+ switch (arch) {
39
+ case 'x64':
40
+ case 'x86_64':
41
+ archId = 'x64';
42
+ break;
43
+ case 'arm64':
44
+ case 'aarch64':
45
+ archId = 'arm64';
46
+ break;
47
+ default:
48
+ archId = arch;
49
+ }
50
+
11
51
  const ext = platform === 'win32' ? '.exe' : '';
12
- return path.join(__dirname, platformId + '-' + archId, name + ext);
52
+ const binaryPath = path.join(__dirname, `${platformId}-${archId}`, `${name}${ext}`);
53
+
54
+ return binaryPath;
55
+ }
56
+
57
+ /**
58
+ * Check if the binary exists
59
+ * @param {string} binaryPath - Path to check
60
+ * @returns {boolean} True if binary exists
61
+ */
62
+ function binaryExists(binaryPath) {
63
+ try {
64
+ fs.accessSync(binaryPath, fs.constants.F_OK);
65
+ return true;
66
+ } catch (e) {
67
+ return false;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Check if the binary is executable
73
+ * @param {string} binaryPath - Path to check
74
+ * @returns {boolean} True if binary is executable
75
+ */
76
+ function isExecutable(binaryPath) {
77
+ try {
78
+ fs.accessSync(binaryPath, fs.constants.X_OK);
79
+ return true;
80
+ } catch (e) {
81
+ return false;
82
+ }
13
83
  }
14
84
 
85
+ /**
86
+ * Grant execute permission to the binary (Unix only)
87
+ * @param {string} binaryPath - Path to the binary
88
+ * @returns {boolean} True if permission was granted
89
+ */
90
+ function grantExecutePermission(binaryPath) {
91
+ try {
92
+ // Get current mode and add execute permission
93
+ const stats = fs.statSync(binaryPath);
94
+ const newMode = stats.mode | 0o111; // Add execute for user, group, others
95
+ fs.chmodSync(binaryPath, newMode);
96
+ return true;
97
+ } catch (e) {
98
+ return false;
99
+ }
100
+ }
101
+
102
+ // Main execution
15
103
  const binary = getBinaryPath('signercli');
16
- const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit', windowsHide: true });
17
- child.on('close', code => process.exit(code || 0));
18
- child.on('error', err => { console.error(err.message); process.exit(1); });
104
+ const platform = os.platform();
105
+ const arch = os.arch();
106
+
107
+ // Check if binary exists
108
+ if (!binaryExists(binary)) {
109
+ console.error(`Error: signercli binary not found for ${platform}-${arch}`);
110
+ console.error(`Expected path: ${binary}`);
111
+ console.error('');
112
+ console.error('This platform may not be supported yet.');
113
+ console.error('Supported platforms: win32-x64, linux-x64');
114
+ process.exit(1);
115
+ }
116
+
117
+ // On Unix systems, ensure the binary has execute permission
118
+ if (platform !== 'win32' && !isExecutable(binary)) {
119
+ if (!grantExecutePermission(binary)) {
120
+ console.error(`Error: Cannot grant execute permission to ${binary}`);
121
+ console.error('Try running: chmod +x ' + binary);
122
+ process.exit(1);
123
+ }
124
+ }
125
+
126
+ // Spawn the binary with all command line arguments
127
+ const child = spawn(binary, process.argv.slice(2), {
128
+ stdio: 'inherit',
129
+ windowsHide: true
130
+ });
131
+
132
+ child.on('close', (code) => {
133
+ process.exit(code || 0);
134
+ });
135
+
136
+ child.on('error', (err) => {
137
+ console.error(`Error executing signercli: ${err.message}`);
138
+ process.exit(1);
139
+ });
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certchip/signer",
3
- "version": "0.1.15",
3
+ "version": "0.1.27",
4
4
  "description": "Cross-platform code and document signing CLI tool",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -11,12 +11,15 @@
11
11
  "scripts": {
12
12
  "test": "echo \"Error: no test specified\" && exit 1",
13
13
  "version:generate": "node scripts/generate-version.js",
14
+ "build:linux-static": "bash build_fullstatic_linux_x64.sh",
14
15
  "prebuild": "npm run version:generate",
15
- "prepack": "npm run version:generate"
16
+ "prepack": "npm run version:generate",
17
+ "postinstall": "node scripts/postinstall.js"
16
18
  },
17
19
  "files": [
18
20
  "bin/",
19
21
  "lib/",
22
+ "scripts/",
20
23
  "README.md"
21
24
  ],
22
25
  "keywords": [
@@ -0,0 +1,273 @@
1
+ #!/usr/bin/env node
2
+ //
3
+ // generate-version.js
4
+ // Generates C header files and resource files with version from package.json
5
+ //
6
+ // Copyright (c) 2025 Certchip. All rights reserved.
7
+ //
8
+ // Generates:
9
+ // - signercli version.h (include/version.h)
10
+ // - signercli.rc (src/signercli.rc)
11
+ // - signer.exe version.h (KSP/Inc/version.h)
12
+ // - otpkey.dll version.h (buildscript/version.h)
13
+ // - Certchip.dll version.h (KSP/Provider/version.h)
14
+ //
15
+
16
+ const fs = require('fs');
17
+ const path = require('path');
18
+
19
+ // Read package.json
20
+ const packagePath = path.join(__dirname, '..', 'package.json');
21
+ const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
22
+ const version = pkg.version;
23
+
24
+ // DLL versions (optional, defaults to main version with .0 suffix)
25
+ const dllVersions = pkg.dllVersions || {};
26
+ const otpkeyVersion = dllVersions.otpkey || `${version}.0`;
27
+ const certchipVersion = dllVersions.certchip || `${version}.0`;
28
+
29
+ // Helper: Convert version string "0.1.16" or "1.1.7.0" to comma-separated "0,1,16,0"
30
+ function versionToComma(ver) {
31
+ const parts = ver.split('.').map(n => parseInt(n, 10) || 0);
32
+ while (parts.length < 4) parts.push(0);
33
+ return parts.slice(0, 4).join(',');
34
+ }
35
+
36
+ // Helper: Convert version string to Windows resource format "0.1.16.0"
37
+ function versionToRC(ver) {
38
+ const parts = ver.split('.').map(n => parseInt(n, 10) || 0);
39
+ while (parts.length < 4) parts.push(0);
40
+ return parts.slice(0, 4).join('.');
41
+ }
42
+
43
+ console.log(`Generating version headers for v${version}...`);
44
+ console.log(` DLL versions: otpkey=${otpkeyVersion}, certchip=${certchipVersion}`);
45
+
46
+ // Generate signercli version.h
47
+ const signerCliHeader = `//
48
+ // version.h
49
+ // Auto-generated from package.json - DO NOT EDIT MANUALLY
50
+ //
51
+ // Copyright (c) 2025 Certchip. All rights reserved.
52
+ //
53
+
54
+ #ifndef SIGNER_VERSION_H
55
+ #define SIGNER_VERSION_H
56
+
57
+ #define SIGNER_CLI_VERSION "${version}"
58
+
59
+ #endif // SIGNER_VERSION_H
60
+ `;
61
+
62
+ const signerCliPath = path.join(__dirname, '..', 'include', 'version.h');
63
+ fs.writeFileSync(signerCliPath, signerCliHeader);
64
+ console.log(` Created: ${signerCliPath}`);
65
+
66
+ // Generate signer.exe version.h (Windows KSP project)
67
+ const signerVersionComma = versionToComma(version);
68
+ const signerVersionStr = versionToRC(version);
69
+ const signerHeader = `//
70
+ // version.h
71
+ // Auto-generated from package.json - DO NOT EDIT MANUALLY
72
+ //
73
+ // Copyright (c) 2025 Certchip. All rights reserved.
74
+ //
75
+
76
+ #ifndef SIGNER_VERSION_H
77
+ #define SIGNER_VERSION_H
78
+
79
+ #define SIGNER_VERSION L"${version}"
80
+
81
+ // Resource version info
82
+ #define SIGNER_VER_FILEVERSION ${signerVersionComma}
83
+ #define SIGNER_VER_FILEVERSION_STR "${signerVersionStr}"
84
+ #define SIGNER_VER_PRODUCTVERSION ${signerVersionComma}
85
+ #define SIGNER_VER_PRODUCTVERSION_STR "${signerVersionStr}"
86
+
87
+ #endif // SIGNER_VERSION_H
88
+ `;
89
+
90
+ // Try KSP path from environment or default
91
+ const kspPath = process.env.KSP_INC_PATH || 'D:\\CPDK\\Certchip\\KSP\\Inc';
92
+ if (fs.existsSync(kspPath)) {
93
+ const kspVersionPath = path.join(kspPath, 'version.h');
94
+ fs.writeFileSync(kspVersionPath, signerHeader);
95
+ console.log(` Created: ${kspVersionPath}`);
96
+ } else {
97
+ console.log(` Skipped: ${kspPath} (directory not found)`);
98
+ }
99
+
100
+ // Generate signer.exe Resource.rc (Windows KSP Config project)
101
+ const signerRC = `// Resource.rc
102
+ // Windows resource file for signer.exe version information
103
+ // Auto-generated from package.json - DO NOT EDIT MANUALLY
104
+
105
+ #include "winres.h"
106
+ #include "../Inc/version.h"
107
+
108
+ VS_VERSION_INFO VERSIONINFO
109
+ FILEVERSION SIGNER_VER_FILEVERSION
110
+ PRODUCTVERSION SIGNER_VER_PRODUCTVERSION
111
+ FILEFLAGSMASK 0x3fL
112
+ #ifdef _DEBUG
113
+ FILEFLAGS 0x1L
114
+ #else
115
+ FILEFLAGS 0x0L
116
+ #endif
117
+ FILEOS 0x40004L
118
+ FILETYPE 0x1L
119
+ FILESUBTYPE 0x0L
120
+ BEGIN
121
+ BLOCK "StringFileInfo"
122
+ BEGIN
123
+ BLOCK "000904b0"
124
+ BEGIN
125
+ VALUE "CompanyName", "Certchip"
126
+ VALUE "FileDescription", "Certchip Signer Configuration Command-Line Tool."
127
+ VALUE "FileVersion", SIGNER_VER_FILEVERSION_STR
128
+ VALUE "InternalName", "signer.exe"
129
+ VALUE "LegalCopyright", "Copyright (C) 2025 Certchip. All rights reserved."
130
+ VALUE "OriginalFilename", "signer.exe"
131
+ VALUE "ProductName", "Certchip Signer"
132
+ VALUE "ProductVersion", SIGNER_VER_PRODUCTVERSION_STR
133
+ END
134
+ END
135
+ BLOCK "VarFileInfo"
136
+ BEGIN
137
+ VALUE "Translation", 0x9, 1200
138
+ END
139
+ END
140
+ `;
141
+
142
+ const kspConfigPath = process.env.KSP_CONFIG_PATH || 'D:\\CPDK\\Certchip\\KSP\\Config';
143
+ if (fs.existsSync(kspConfigPath)) {
144
+ const signerRCPath = path.join(kspConfigPath, 'Resource.rc');
145
+ fs.writeFileSync(signerRCPath, signerRC);
146
+ console.log(` Created: ${signerRCPath}`);
147
+ } else {
148
+ console.log(` Skipped: ${kspConfigPath} (directory not found)`);
149
+ }
150
+
151
+ // Generate signercli.rc (Windows resource file)
152
+ const rcVersion = versionToRC(version);
153
+ const rcVersionComma = versionToComma(version);
154
+ const signerCliRC = `// signercli.rc
155
+ // Windows resource file for version information
156
+ // Auto-generated from package.json - DO NOT EDIT MANUALLY
157
+
158
+ // Version info constants (from winver.h)
159
+ #define VS_VERSION_INFO 1
160
+ #define VS_FFI_FILEFLAGSMASK 0x0000003FL
161
+ #define VOS_NT_WINDOWS32 0x00040004L
162
+ #define VFT_APP 0x00000001L
163
+ #define VFT2_UNKNOWN 0x00000000L
164
+
165
+ VS_VERSION_INFO VERSIONINFO
166
+ FILEVERSION ${rcVersionComma}
167
+ PRODUCTVERSION ${rcVersionComma}
168
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
169
+ FILEFLAGS 0
170
+ FILEOS VOS_NT_WINDOWS32
171
+ FILETYPE VFT_APP
172
+ FILESUBTYPE VFT2_UNKNOWN
173
+ BEGIN
174
+ BLOCK "StringFileInfo"
175
+ BEGIN
176
+ BLOCK "040904B0"
177
+ BEGIN
178
+ VALUE "CompanyName", "Certchip"
179
+ VALUE "FileDescription", "Certchip Signer CLI - Digital Signing Tool"
180
+ VALUE "FileVersion", "${rcVersion}"
181
+ VALUE "InternalName", "signercli"
182
+ VALUE "LegalCopyright", "Copyright (c) 2025 Certchip. All rights reserved."
183
+ VALUE "OriginalFilename", "signercli.exe"
184
+ VALUE "ProductName", "Certchip Signer CLI"
185
+ VALUE "ProductVersion", "${rcVersion}"
186
+ END
187
+ END
188
+ BLOCK "VarFileInfo"
189
+ BEGIN
190
+ VALUE "Translation", 0x0409, 0x04B0
191
+ END
192
+ END
193
+ `;
194
+
195
+ const signerCliRCPath = path.join(__dirname, '..', 'src', 'signercli.rc');
196
+ fs.writeFileSync(signerCliRCPath, signerCliRC);
197
+ console.log(` Created: ${signerCliRCPath}`);
198
+
199
+ // Generate otpkey.dll version.h
200
+ const otpkeyVersionComma = versionToComma(otpkeyVersion);
201
+ const otpkeyVersionStr = versionToRC(otpkeyVersion);
202
+ const otpkeyHeader = `#ifndef VERSION_H
203
+ #define VERSION_H
204
+
205
+ // Auto-generated from package.json - DO NOT EDIT MANUALLY
206
+
207
+ #define VER_FILEVERSION ${otpkeyVersionComma}
208
+ #define VER_FILEVERSION_STR "${otpkeyVersionStr}\\0"
209
+ #define VER_COMPANYNAME_STR "Certchip"
210
+ #define VER_FILEDESCRIPTION_STR "Otpkey Core Library"
211
+ #define VER_INTERNALNAME_STR "OTPKEY CORE LIB"
212
+ #define VER_LEGALCOPYRIGHT_STR "Copyright (C) 2025 Certchip. All rights reserved."
213
+ #define VER_LEGALTRADEMARKS1_STR "OTPKEY"
214
+ #define VER_LEGALTRADEMARKS2_STR "OTPKEY"
215
+ #define VER_ORIGINALFILENAME_STR "otpkey.dll"
216
+ #define VER_PRODUCTNAME_STR "OTPKEY"
217
+ #define VER_COMPANYDOMAIN_STR "otpkey.com"
218
+ #endif // VERSION_H
219
+ `;
220
+
221
+ const otpkeyPath = path.join(__dirname, '..', '..', 'buildscript', 'version.h');
222
+ if (fs.existsSync(path.dirname(otpkeyPath))) {
223
+ fs.writeFileSync(otpkeyPath, otpkeyHeader);
224
+ console.log(` Created: ${otpkeyPath}`);
225
+ } else {
226
+ console.log(` Skipped: ${otpkeyPath} (directory not found)`);
227
+ }
228
+
229
+ // Generate Certchip.dll (provider) version.h
230
+ const certchipVersionComma = versionToComma(certchipVersion);
231
+ const certchipVersionStr = versionToRC(certchipVersion);
232
+ const certchipHeader = `#ifndef PROVIDER_VERSION_H
233
+ #define PROVIDER_VERSION_H
234
+
235
+ // Auto-generated from package.json - DO NOT EDIT MANUALLY
236
+
237
+ #define PROVIDER_VER_FILEVERSION ${certchipVersionComma}
238
+ #define PROVIDER_VER_FILEVERSION_STR "${certchipVersionStr}"
239
+ #define PROVIDER_VER_COMPANYNAME_STR "Certchip"
240
+ #define PROVIDER_VER_FILEDESCRIPTION_STR "Certchip Key Storage Provider"
241
+ #define PROVIDER_VER_INTERNALNAME_STR "Certchip.dll"
242
+ #define PROVIDER_VER_LEGALCOPYRIGHT_STR "Copyright (C) 2025 Certchip. All rights reserved."
243
+ #define PROVIDER_VER_ORIGINALFILENAME_STR "Certchip.dll"
244
+ #define PROVIDER_VER_PRODUCTNAME_STR "Certchip Signer Provider"
245
+ #endif // PROVIDER_VERSION_H
246
+ `;
247
+
248
+ const certchipPath = process.env.KSP_PROVIDER_PATH || 'D:\\CPDK\\Certchip\\KSP\\Provider';
249
+ if (fs.existsSync(certchipPath)) {
250
+ const certchipVersionPath = path.join(certchipPath, 'version.h');
251
+ fs.writeFileSync(certchipVersionPath, certchipHeader);
252
+ console.log(` Created: ${certchipVersionPath}`);
253
+ } else {
254
+ console.log(` Skipped: ${certchipPath} (directory not found)`);
255
+ }
256
+
257
+ // Update otp.h VERSION macro (for Linux builds and otpkeyGetLibVersion())
258
+ const otpHPath = path.join(__dirname, '..', '..', 'otp', 'otp.h');
259
+ if (fs.existsSync(otpHPath)) {
260
+ let otpHContent = fs.readFileSync(otpHPath, 'utf8');
261
+ const versionRegex = /#define VERSION "[\d.]+"/;
262
+ if (versionRegex.test(otpHContent)) {
263
+ otpHContent = otpHContent.replace(versionRegex, `#define VERSION "${version}"`);
264
+ fs.writeFileSync(otpHPath, otpHContent);
265
+ console.log(` Updated: ${otpHPath}`);
266
+ } else {
267
+ console.log(` Skipped: ${otpHPath} (VERSION macro not found)`);
268
+ }
269
+ } else {
270
+ console.log(` Skipped: ${otpHPath} (file not found)`);
271
+ }
272
+
273
+ console.log('Version generation complete.');
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * postinstall.js - Set execute permissions on binary files (Unix only)
4
+ *
5
+ * @certchip/signer
6
+ * Copyright (c) 2025 Certchip. All rights reserved.
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const os = require('os');
12
+
13
+ // Skip on Windows
14
+ if (os.platform() === 'win32') {
15
+ process.exit(0);
16
+ }
17
+
18
+ const binDir = path.join(__dirname, '..', 'bin');
19
+
20
+ // List of platform directories and binaries to make executable
21
+ const platforms = ['linux-x64', 'linux-arm64', 'darwin-x64', 'darwin-arm64'];
22
+ const binaries = ['signercli'];
23
+
24
+ let errors = 0;
25
+
26
+ for (const platform of platforms) {
27
+ for (const binary of binaries) {
28
+ const binaryPath = path.join(binDir, platform, binary);
29
+
30
+ try {
31
+ if (fs.existsSync(binaryPath)) {
32
+ const stats = fs.statSync(binaryPath);
33
+ const newMode = stats.mode | 0o111; // Add execute permission
34
+ fs.chmodSync(binaryPath, newMode);
35
+ console.log(`Set execute permission: ${platform}/${binary}`);
36
+ }
37
+ } catch (e) {
38
+ // Silently ignore errors (e.g., platform not included)
39
+ }
40
+ }
41
+ }
42
+
43
+ process.exit(0);