@enactprotocol/shared 1.0.13 → 1.2.0
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.
- package/dist/api/enact-api.js +2 -2
- package/dist/api/types.d.ts +10 -3
- package/dist/core/DaggerExecutionProvider.d.ts +1 -1
- package/dist/core/DaggerExecutionProvider.js +23 -19
- package/dist/core/EnactCore.d.ts +36 -19
- package/dist/core/EnactCore.js +157 -219
- package/dist/core/NativeExecutionProvider.d.ts +9 -0
- package/dist/core/NativeExecutionProvider.js +16 -0
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -4
- package/dist/lib/enact-direct.d.ts +0 -15
- package/dist/lib/enact-direct.js +0 -11
- package/dist/security/sign.d.ts +5 -5
- package/dist/security/sign.js +247 -113
- package/dist/security/verification-enforcer.d.ts +12 -0
- package/dist/security/verification-enforcer.js +26 -3
- package/dist/services/McpCoreService.d.ts +0 -12
- package/dist/services/McpCoreService.js +0 -9
- package/dist/types.d.ts +5 -4
- package/dist/utils/config.js +1 -1
- package/dist/utils/version.js +23 -2
- package/package.json +3 -6
- package/src/api/enact-api.ts +2 -2
- package/src/api/types.ts +11 -4
- package/src/core/DaggerExecutionProvider.ts +26 -13
- package/src/core/EnactCore.ts +226 -270
- package/src/index.ts +0 -5
- package/src/lib/enact-direct.ts +0 -21
- package/src/services/McpCoreService.ts +0 -20
- package/src/types.ts +10 -12
- package/src/utils/config.ts +1 -1
- package/src/utils/version.ts +23 -2
- package/src/security/index.ts +0 -3
- package/src/security/security.ts +0 -188
- package/src/security/sign.ts +0 -797
- package/src/security/verification-enforcer.ts +0 -268
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
// src/security/verification-enforcer.ts - Mandatory signature verification enforcement
|
|
2
|
-
import {
|
|
3
|
-
verifyTool,
|
|
4
|
-
VERIFICATION_POLICIES,
|
|
5
|
-
type VerificationPolicy,
|
|
6
|
-
} from "./sign";
|
|
7
|
-
import type { EnactTool, ExecutionResult } from "../types";
|
|
8
|
-
import logger from "../exec/logger";
|
|
9
|
-
|
|
10
|
-
export interface VerificationEnforcementOptions {
|
|
11
|
-
skipVerification?: boolean;
|
|
12
|
-
verifyPolicy?: "permissive" | "enterprise" | "paranoid";
|
|
13
|
-
force?: boolean;
|
|
14
|
-
allowUnsigned?: boolean; // Explicit flag for allowing unsigned tools (only for dev/testing)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface VerificationEnforcementResult {
|
|
18
|
-
allowed: boolean;
|
|
19
|
-
reason: string;
|
|
20
|
-
verificationResult?: {
|
|
21
|
-
isValid: boolean;
|
|
22
|
-
message: string;
|
|
23
|
-
validSignatures: number;
|
|
24
|
-
totalSignatures: number;
|
|
25
|
-
verifiedSigners: Array<{ signer: string; role?: string; keyId: string }>;
|
|
26
|
-
errors: string[];
|
|
27
|
-
};
|
|
28
|
-
error?: {
|
|
29
|
-
message: string;
|
|
30
|
-
code: string;
|
|
31
|
-
details?: any;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Enforce mandatory signature verification for tool execution
|
|
37
|
-
* This is the central function that should be called before ANY tool execution
|
|
38
|
-
*/
|
|
39
|
-
export async function enforceSignatureVerification(
|
|
40
|
-
tool: EnactTool,
|
|
41
|
-
options: VerificationEnforcementOptions = {},
|
|
42
|
-
): Promise<VerificationEnforcementResult> {
|
|
43
|
-
const toolName = tool.name || "unknown";
|
|
44
|
-
|
|
45
|
-
// Check if verification is explicitly skipped
|
|
46
|
-
if (options.skipVerification) {
|
|
47
|
-
logger.warn(
|
|
48
|
-
`🚨 SECURITY WARNING: Signature verification skipped for tool: ${toolName}`,
|
|
49
|
-
);
|
|
50
|
-
logger.warn(
|
|
51
|
-
` This bypasses security measures and is NOT recommended for production use!`,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
allowed: true,
|
|
56
|
-
reason: `Verification skipped by request for tool: ${toolName}`,
|
|
57
|
-
verificationResult: {
|
|
58
|
-
isValid: false,
|
|
59
|
-
message: "Verification skipped",
|
|
60
|
-
validSignatures: 0,
|
|
61
|
-
totalSignatures: 0,
|
|
62
|
-
verifiedSigners: [],
|
|
63
|
-
errors: ["Signature verification was explicitly skipped"],
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Check if tool has any signatures
|
|
69
|
-
const hasSignatures =
|
|
70
|
-
!!(tool.signatures && Object.keys(tool.signatures).length > 0) ||
|
|
71
|
-
!!tool.signature;
|
|
72
|
-
|
|
73
|
-
if (!hasSignatures) {
|
|
74
|
-
logger.warn(`⚠️ Tool has no signatures: ${toolName}`);
|
|
75
|
-
|
|
76
|
-
// Only allow unsigned tools if explicitly permitted (for development/testing)
|
|
77
|
-
if (options.allowUnsigned) {
|
|
78
|
-
logger.warn(
|
|
79
|
-
` Allowing unsigned tool execution due to allowUnsigned flag (DEV/TEST ONLY)`,
|
|
80
|
-
);
|
|
81
|
-
return {
|
|
82
|
-
allowed: true,
|
|
83
|
-
reason: `Unsigned tool allowed by explicit permission: ${toolName}`,
|
|
84
|
-
verificationResult: {
|
|
85
|
-
isValid: false,
|
|
86
|
-
message: "No signatures found, but execution allowed",
|
|
87
|
-
validSignatures: 0,
|
|
88
|
-
totalSignatures: 0,
|
|
89
|
-
verifiedSigners: [],
|
|
90
|
-
errors: [
|
|
91
|
-
"Tool has no signatures but execution was explicitly allowed",
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Reject unsigned tools by default
|
|
98
|
-
return {
|
|
99
|
-
allowed: false,
|
|
100
|
-
reason: `Tool has no signatures and unsigned execution is not permitted: ${toolName}`,
|
|
101
|
-
error: {
|
|
102
|
-
message: `Tool "${toolName}" has no cryptographic signatures. For security, only signed tools can be executed.`,
|
|
103
|
-
code: "NO_SIGNATURES_FOUND",
|
|
104
|
-
details: {
|
|
105
|
-
toolName,
|
|
106
|
-
hasSignature: !!tool.signature,
|
|
107
|
-
hasSignatures: !!tool.signatures,
|
|
108
|
-
signatureCount: tool.signatures
|
|
109
|
-
? Object.keys(tool.signatures).length
|
|
110
|
-
: 0,
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Perform signature verification
|
|
117
|
-
try {
|
|
118
|
-
logger.info(`🔐 Verifying signatures for tool: ${toolName}`);
|
|
119
|
-
|
|
120
|
-
// Determine verification policy
|
|
121
|
-
const policyKey = (options.verifyPolicy || "permissive").toUpperCase() as
|
|
122
|
-
| "PERMISSIVE"
|
|
123
|
-
| "ENTERPRISE"
|
|
124
|
-
| "PARANOID";
|
|
125
|
-
const policy: VerificationPolicy =
|
|
126
|
-
VERIFICATION_POLICIES[policyKey] || VERIFICATION_POLICIES.PERMISSIVE;
|
|
127
|
-
|
|
128
|
-
logger.info(` Using verification policy: ${policyKey.toLowerCase()}`);
|
|
129
|
-
if (policy.minimumSignatures) {
|
|
130
|
-
logger.info(
|
|
131
|
-
` Minimum signatures required: ${policy.minimumSignatures}`,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
if (policy.requireRoles) {
|
|
135
|
-
logger.info(` Required roles: ${policy.requireRoles.join(", ")}`);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Verify the tool
|
|
139
|
-
const verificationResult = await verifyTool(tool, policy);
|
|
140
|
-
|
|
141
|
-
if (verificationResult.isValid) {
|
|
142
|
-
logger.info(`✅ Signature verification passed for tool: ${toolName}`);
|
|
143
|
-
logger.info(
|
|
144
|
-
` Valid signatures: ${verificationResult.validSignatures}/${verificationResult.totalSignatures}`,
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
if (verificationResult.verifiedSigners.length > 0) {
|
|
148
|
-
logger.info(
|
|
149
|
-
` Verified signers: ${verificationResult.verifiedSigners
|
|
150
|
-
.map((s) => `${s.signer}${s.role ? ` (${s.role})` : ""}`)
|
|
151
|
-
.join(", ")}`,
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
allowed: true,
|
|
157
|
-
reason: `Tool signature verification passed: ${verificationResult.message}`,
|
|
158
|
-
verificationResult,
|
|
159
|
-
};
|
|
160
|
-
} else {
|
|
161
|
-
logger.error(`❌ Signature verification failed for tool: ${toolName}`);
|
|
162
|
-
logger.error(` Policy: ${policyKey.toLowerCase()}`);
|
|
163
|
-
logger.error(
|
|
164
|
-
` Valid signatures: ${verificationResult.validSignatures}/${verificationResult.totalSignatures}`,
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
if (verificationResult.errors.length > 0) {
|
|
168
|
-
logger.error(` Errors:`);
|
|
169
|
-
verificationResult.errors.forEach((error) =>
|
|
170
|
-
logger.error(` - ${error}`),
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
allowed: false,
|
|
176
|
-
reason: `Tool signature verification failed: ${verificationResult.message}`,
|
|
177
|
-
verificationResult,
|
|
178
|
-
error: {
|
|
179
|
-
message: `Tool "${toolName}" failed signature verification. ${verificationResult.message}`,
|
|
180
|
-
code: "SIGNATURE_VERIFICATION_FAILED",
|
|
181
|
-
details: {
|
|
182
|
-
toolName,
|
|
183
|
-
policy: policyKey.toLowerCase(),
|
|
184
|
-
validSignatures: verificationResult.validSignatures,
|
|
185
|
-
totalSignatures: verificationResult.totalSignatures,
|
|
186
|
-
errors: verificationResult.errors,
|
|
187
|
-
verifiedSigners: verificationResult.verifiedSigners,
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
} catch (error) {
|
|
193
|
-
const errorMessage =
|
|
194
|
-
error instanceof Error ? error.message : "Unknown verification error";
|
|
195
|
-
logger.error(
|
|
196
|
-
`💥 Signature verification error for tool: ${toolName} - ${errorMessage}`,
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
allowed: false,
|
|
201
|
-
reason: `Signature verification error: ${errorMessage}`,
|
|
202
|
-
error: {
|
|
203
|
-
message: `Signature verification failed due to error: ${errorMessage}`,
|
|
204
|
-
code: "VERIFICATION_ERROR",
|
|
205
|
-
details: { toolName, originalError: error },
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Create an execution result for verification failure
|
|
213
|
-
*/
|
|
214
|
-
export function createVerificationFailureResult(
|
|
215
|
-
tool: EnactTool,
|
|
216
|
-
verificationResult: VerificationEnforcementResult,
|
|
217
|
-
executionId: string,
|
|
218
|
-
): ExecutionResult {
|
|
219
|
-
return {
|
|
220
|
-
success: false,
|
|
221
|
-
error: verificationResult.error || {
|
|
222
|
-
message: verificationResult.reason,
|
|
223
|
-
code: "VERIFICATION_FAILED",
|
|
224
|
-
},
|
|
225
|
-
metadata: {
|
|
226
|
-
executionId,
|
|
227
|
-
toolName: tool.name || "unknown",
|
|
228
|
-
version: tool.version,
|
|
229
|
-
executedAt: new Date().toISOString(),
|
|
230
|
-
environment: "direct",
|
|
231
|
-
command: tool.command,
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Log security audit information for tool execution
|
|
238
|
-
*/
|
|
239
|
-
export function logSecurityAudit(
|
|
240
|
-
tool: EnactTool,
|
|
241
|
-
verificationResult: VerificationEnforcementResult,
|
|
242
|
-
executionAllowed: boolean,
|
|
243
|
-
options: VerificationEnforcementOptions,
|
|
244
|
-
) {
|
|
245
|
-
const auditLog = {
|
|
246
|
-
timestamp: new Date().toISOString(),
|
|
247
|
-
tool: tool.name || "unknown",
|
|
248
|
-
version: tool.version,
|
|
249
|
-
command: tool.command,
|
|
250
|
-
executionAllowed,
|
|
251
|
-
verificationSkipped: options.skipVerification || false,
|
|
252
|
-
verificationPolicy: options.verifyPolicy || "permissive",
|
|
253
|
-
verificationResult: verificationResult.verificationResult
|
|
254
|
-
? {
|
|
255
|
-
isValid: verificationResult.verificationResult.isValid,
|
|
256
|
-
validSignatures:
|
|
257
|
-
verificationResult.verificationResult.validSignatures,
|
|
258
|
-
totalSignatures:
|
|
259
|
-
verificationResult.verificationResult.totalSignatures,
|
|
260
|
-
verifiedSigners:
|
|
261
|
-
verificationResult.verificationResult.verifiedSigners,
|
|
262
|
-
}
|
|
263
|
-
: null,
|
|
264
|
-
errors: verificationResult.error ? [verificationResult.error.message] : [],
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
logger.info(`🔍 Security Audit Log:`, auditLog);
|
|
268
|
-
}
|