mcp-proxy-adapter 6.6.1__py3-none-any.whl → 6.6.3__py3-none-any.whl
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.
- mcp_proxy_adapter/api/app.py +28 -26
- mcp_proxy_adapter/config.py +2 -9
- mcp_proxy_adapter/core/server_adapter.py +1 -1
- mcp_proxy_adapter/examples/check_config.py +1 -1
- mcp_proxy_adapter/examples/config_builder.py +11 -17
- mcp_proxy_adapter/examples/{generate_certificates_bugfix.py → generate_certificates.py} +11 -0
- mcp_proxy_adapter/examples/generate_config.py +3 -3
- mcp_proxy_adapter/examples/run_full_test_suite.py +3 -3
- mcp_proxy_adapter/examples/security_test_client.py +6 -5
- mcp_proxy_adapter/examples/test_chk_hostname_automated.py +7 -10
- mcp_proxy_adapter/examples/test_framework_complete.py +269 -0
- mcp_proxy_adapter/examples/test_mcp_server.py +188 -0
- mcp_proxy_adapter/main.py +11 -18
- mcp_proxy_adapter/version.py +1 -1
- {mcp_proxy_adapter-6.6.1.dist-info → mcp_proxy_adapter-6.6.3.dist-info}/METADATA +1 -1
- {mcp_proxy_adapter-6.6.1.dist-info → mcp_proxy_adapter-6.6.3.dist-info}/RECORD +19 -23
- mcp_proxy_adapter/examples/config_builder_simple.py +0 -271
- mcp_proxy_adapter/examples/generate_all_certificates.py +0 -487
- mcp_proxy_adapter/examples/generate_certificates_cli.py +0 -406
- mcp_proxy_adapter/examples/generate_certificates_fixed.py +0 -313
- mcp_proxy_adapter/examples/generate_certificates_framework.py +0 -366
- mcp_proxy_adapter/examples/generate_certificates_openssl.py +0 -391
- {mcp_proxy_adapter-6.6.1.dist-info → mcp_proxy_adapter-6.6.3.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-6.6.1.dist-info → mcp_proxy_adapter-6.6.3.dist-info}/entry_points.txt +0 -0
- {mcp_proxy_adapter-6.6.1.dist-info → mcp_proxy_adapter-6.6.3.dist-info}/top_level.txt +0 -0
@@ -1,406 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
"""
|
3
|
-
Generate Certificates Using mcp_security_framework CLI
|
4
|
-
This script generates all necessary SSL certificates using the mcp_security_framework CLI.
|
5
|
-
|
6
|
-
Author: Vasiliy Zdanovskiy
|
7
|
-
email: vasilyvz@gmail.com
|
8
|
-
"""
|
9
|
-
import json
|
10
|
-
import os
|
11
|
-
import subprocess
|
12
|
-
import sys
|
13
|
-
from pathlib import Path
|
14
|
-
from typing import Dict, List, Optional
|
15
|
-
|
16
|
-
# Import required certificates configuration
|
17
|
-
from required_certificates import REQUIRED_CERTIFICATES, get_all_required_certificates
|
18
|
-
|
19
|
-
|
20
|
-
class CLICertificateGenerator:
|
21
|
-
"""Certificate generator using mcp_security_framework CLI."""
|
22
|
-
|
23
|
-
def __init__(self):
|
24
|
-
"""Initialize the certificate generator."""
|
25
|
-
self.working_dir = Path.cwd()
|
26
|
-
self.certs_dir = self.working_dir / "certs"
|
27
|
-
self.keys_dir = self.working_dir / "keys"
|
28
|
-
|
29
|
-
# Ensure directories exist
|
30
|
-
self.certs_dir.mkdir(exist_ok=True)
|
31
|
-
self.keys_dir.mkdir(exist_ok=True)
|
32
|
-
|
33
|
-
def print_step(self, step: str, description: str):
|
34
|
-
"""Print a formatted step header."""
|
35
|
-
print(f"\n{'=' * 60}")
|
36
|
-
print(f"🔧 STEP {step}: {description}")
|
37
|
-
print(f"{'=' * 60}")
|
38
|
-
|
39
|
-
def print_success(self, message: str):
|
40
|
-
"""Print a success message."""
|
41
|
-
print(f"✅ {message}")
|
42
|
-
|
43
|
-
def print_error(self, message: str):
|
44
|
-
"""Print an error message."""
|
45
|
-
print(f"❌ {message}")
|
46
|
-
|
47
|
-
def print_info(self, message: str):
|
48
|
-
"""Print an info message."""
|
49
|
-
print(f"ℹ️ {message}")
|
50
|
-
|
51
|
-
def check_framework(self) -> bool:
|
52
|
-
"""Check if mcp_security_framework CLI is available."""
|
53
|
-
try:
|
54
|
-
result = subprocess.run([
|
55
|
-
sys.executable, "-m", "mcp_security_framework.cli.cert_cli", "--help"
|
56
|
-
], capture_output=True, text=True)
|
57
|
-
|
58
|
-
if result.returncode == 0:
|
59
|
-
self.print_success("mcp_security_framework CLI is available")
|
60
|
-
return True
|
61
|
-
else:
|
62
|
-
self.print_error("mcp_security_framework CLI is not available")
|
63
|
-
return False
|
64
|
-
except Exception as e:
|
65
|
-
self.print_error(f"Failed to check framework: {e}")
|
66
|
-
return False
|
67
|
-
|
68
|
-
def create_ca_certificate_manually(self) -> bool:
|
69
|
-
"""Create CA certificate manually using OpenSSL."""
|
70
|
-
self.print_step("1", "Creating CA Certificate Manually")
|
71
|
-
|
72
|
-
ca_info = REQUIRED_CERTIFICATES["ca_cert"]
|
73
|
-
|
74
|
-
try:
|
75
|
-
# Check if CA certificate already exists
|
76
|
-
if ca_info["output_cert"].exists() and ca_info["output_key"].exists():
|
77
|
-
self.print_info(f"CA certificate already exists: {ca_info['output_cert']}")
|
78
|
-
return True
|
79
|
-
|
80
|
-
# Generate CA private key
|
81
|
-
key_cmd = [
|
82
|
-
"openssl", "genrsa", "-out", str(ca_info["output_key"]), "2048"
|
83
|
-
]
|
84
|
-
|
85
|
-
self.print_info("Generating CA private key...")
|
86
|
-
result = subprocess.run(key_cmd, capture_output=True, text=True, cwd=self.working_dir)
|
87
|
-
|
88
|
-
if result.returncode != 0:
|
89
|
-
self.print_error(f"Failed to generate CA key: {result.stderr}")
|
90
|
-
return False
|
91
|
-
|
92
|
-
# Generate CA certificate
|
93
|
-
cert_cmd = [
|
94
|
-
"openssl", "req", "-new", "-x509", "-days", str(ca_info["validity_days"]),
|
95
|
-
"-key", str(ca_info["output_key"]), "-out", str(ca_info["output_cert"]),
|
96
|
-
"-subj", f"/C={ca_info['country']}/ST={ca_info['state']}/L={ca_info['city']}/O={ca_info['organization']}/CN={ca_info['common_name']}"
|
97
|
-
]
|
98
|
-
|
99
|
-
self.print_info(f"Creating CA certificate: {ca_info['common_name']}")
|
100
|
-
result = subprocess.run(cert_cmd, capture_output=True, text=True, cwd=self.working_dir)
|
101
|
-
|
102
|
-
if result.returncode == 0:
|
103
|
-
self.print_success(f"CA certificate created: {ca_info['output_cert']}")
|
104
|
-
return True
|
105
|
-
else:
|
106
|
-
self.print_error(f"Failed to create CA certificate: {result.stderr}")
|
107
|
-
return False
|
108
|
-
|
109
|
-
except Exception as e:
|
110
|
-
self.print_error(f"Exception during CA certificate creation: {e}")
|
111
|
-
return False
|
112
|
-
|
113
|
-
def generate_server_certificate_with_framework(self) -> bool:
|
114
|
-
"""Generate server certificate using mcp_security_framework CLI."""
|
115
|
-
self.print_step("2", "Generating Server Certificate with Framework")
|
116
|
-
|
117
|
-
server_info = REQUIRED_CERTIFICATES["server_cert"]
|
118
|
-
|
119
|
-
try:
|
120
|
-
# Check if server certificate already exists
|
121
|
-
if server_info["output_cert"].exists() and server_info["output_key"].exists():
|
122
|
-
self.print_info(f"Server certificate already exists: {server_info['output_cert']}")
|
123
|
-
return True
|
124
|
-
|
125
|
-
# Create configuration file for framework
|
126
|
-
config_file = self.working_dir / "cert_config.json"
|
127
|
-
config = {
|
128
|
-
"ca": {
|
129
|
-
"cert_path": str(server_info["ca_cert_path"]),
|
130
|
-
"key_path": str(server_info["ca_key_path"])
|
131
|
-
},
|
132
|
-
"certificates": {
|
133
|
-
"storage_path": str(self.certs_dir),
|
134
|
-
"key_storage_path": str(self.keys_dir),
|
135
|
-
"default_validity_days": server_info["validity_days"],
|
136
|
-
"key_size": 2048,
|
137
|
-
"hash_algorithm": "sha256"
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
with open(config_file, 'w') as f:
|
142
|
-
json.dump(config, f, indent=2)
|
143
|
-
|
144
|
-
# Generate server certificate using framework CLI
|
145
|
-
cmd = [
|
146
|
-
sys.executable, "-m", "mcp_security_framework.cli.cert_cli",
|
147
|
-
"-c", str(config_file),
|
148
|
-
"create-server",
|
149
|
-
"-cn", server_info["common_name"],
|
150
|
-
"-o", server_info["organization"],
|
151
|
-
"-c", server_info["country"],
|
152
|
-
"-s", server_info["state"],
|
153
|
-
"-l", server_info["city"],
|
154
|
-
"-d", str(server_info["validity_days"])
|
155
|
-
]
|
156
|
-
|
157
|
-
# Add SAN if specified
|
158
|
-
if "san" in server_info:
|
159
|
-
for san in server_info["san"]:
|
160
|
-
cmd.extend(["--san", san])
|
161
|
-
|
162
|
-
self.print_info(f"Generating server certificate: {server_info['common_name']}")
|
163
|
-
result = subprocess.run(cmd, capture_output=True, text=True, cwd=self.working_dir)
|
164
|
-
|
165
|
-
if result.returncode == 0:
|
166
|
-
# Move generated files to expected locations
|
167
|
-
generated_cert = self.certs_dir / f"{server_info['common_name']}.crt"
|
168
|
-
generated_key = self.keys_dir / f"{server_info['common_name']}.key"
|
169
|
-
|
170
|
-
if generated_cert.exists():
|
171
|
-
generated_cert.rename(server_info["output_cert"])
|
172
|
-
if generated_key.exists():
|
173
|
-
generated_key.rename(server_info["output_key"])
|
174
|
-
|
175
|
-
self.print_success(f"Server certificate generated: {server_info['output_cert']}")
|
176
|
-
return True
|
177
|
-
else:
|
178
|
-
self.print_error(f"Failed to generate server certificate: {result.stderr}")
|
179
|
-
return False
|
180
|
-
|
181
|
-
except Exception as e:
|
182
|
-
self.print_error(f"Exception during server certificate generation: {e}")
|
183
|
-
return False
|
184
|
-
finally:
|
185
|
-
# Clean up config file
|
186
|
-
if config_file.exists():
|
187
|
-
config_file.unlink()
|
188
|
-
|
189
|
-
def generate_client_certificate_with_framework(self, cert_name: str) -> bool:
|
190
|
-
"""Generate client certificate using mcp_security_framework CLI."""
|
191
|
-
self.print_step(f"3.{cert_name}", f"Generating {cert_name.title()} Client Certificate with Framework")
|
192
|
-
|
193
|
-
client_info = REQUIRED_CERTIFICATES[cert_name]
|
194
|
-
|
195
|
-
try:
|
196
|
-
# Check if client certificate already exists
|
197
|
-
if client_info["output_cert"].exists() and client_info["output_key"].exists():
|
198
|
-
self.print_info(f"{cert_name} certificate already exists: {client_info['output_cert']}")
|
199
|
-
return True
|
200
|
-
|
201
|
-
# Create configuration file for framework
|
202
|
-
config_file = self.working_dir / "cert_config.json"
|
203
|
-
config = {
|
204
|
-
"ca": {
|
205
|
-
"cert_path": str(client_info["ca_cert_path"]),
|
206
|
-
"key_path": str(client_info["ca_key_path"])
|
207
|
-
},
|
208
|
-
"certificates": {
|
209
|
-
"storage_path": str(self.certs_dir),
|
210
|
-
"key_storage_path": str(self.keys_dir),
|
211
|
-
"default_validity_days": client_info["validity_days"],
|
212
|
-
"key_size": 2048,
|
213
|
-
"hash_algorithm": "sha256"
|
214
|
-
}
|
215
|
-
}
|
216
|
-
|
217
|
-
with open(config_file, 'w') as f:
|
218
|
-
json.dump(config, f, indent=2)
|
219
|
-
|
220
|
-
# Generate client certificate using framework CLI
|
221
|
-
cmd = [
|
222
|
-
sys.executable, "-m", "mcp_security_framework.cli.cert_cli",
|
223
|
-
"-c", str(config_file),
|
224
|
-
"create-client",
|
225
|
-
"-cn", client_info["common_name"],
|
226
|
-
"-o", client_info["organization"],
|
227
|
-
"-c", client_info["country"],
|
228
|
-
"-s", client_info["state"],
|
229
|
-
"-l", client_info["city"],
|
230
|
-
"-d", str(client_info["validity_days"])
|
231
|
-
]
|
232
|
-
|
233
|
-
# Add roles if specified
|
234
|
-
if "roles" in client_info:
|
235
|
-
for role in client_info["roles"]:
|
236
|
-
cmd.extend(["--roles", role])
|
237
|
-
|
238
|
-
# Add permissions if specified
|
239
|
-
if "permissions" in client_info:
|
240
|
-
for permission in client_info["permissions"]:
|
241
|
-
cmd.extend(["--permissions", permission])
|
242
|
-
|
243
|
-
self.print_info(f"Generating {cert_name} certificate: {client_info['common_name']}")
|
244
|
-
result = subprocess.run(cmd, capture_output=True, text=True, cwd=self.working_dir)
|
245
|
-
|
246
|
-
if result.returncode == 0:
|
247
|
-
# Move generated files to expected locations
|
248
|
-
generated_cert = self.certs_dir / f"{client_info['common_name']}.crt"
|
249
|
-
generated_key = self.keys_dir / f"{client_info['common_name']}.key"
|
250
|
-
|
251
|
-
if generated_cert.exists():
|
252
|
-
generated_cert.rename(client_info["output_cert"])
|
253
|
-
if generated_key.exists():
|
254
|
-
generated_key.rename(client_info["output_key"])
|
255
|
-
|
256
|
-
self.print_success(f"{cert_name} certificate generated: {client_info['output_cert']}")
|
257
|
-
return True
|
258
|
-
else:
|
259
|
-
self.print_error(f"Failed to generate {cert_name} certificate: {result.stderr}")
|
260
|
-
return False
|
261
|
-
|
262
|
-
except Exception as e:
|
263
|
-
self.print_error(f"Exception during {cert_name} certificate generation: {e}")
|
264
|
-
return False
|
265
|
-
finally:
|
266
|
-
# Clean up config file
|
267
|
-
if config_file.exists():
|
268
|
-
config_file.unlink()
|
269
|
-
|
270
|
-
def create_certificate_aliases(self) -> bool:
|
271
|
-
"""Create certificate aliases for different configurations."""
|
272
|
-
self.print_step("4", "Creating Certificate Aliases")
|
273
|
-
|
274
|
-
try:
|
275
|
-
# Create aliases for HTTPS configurations
|
276
|
-
if (self.certs_dir / "server_cert.pem").exists():
|
277
|
-
# HTTPS aliases
|
278
|
-
(self.certs_dir / "mcp_proxy_adapter_server.crt").unlink(missing_ok=True)
|
279
|
-
(self.certs_dir / "mcp_proxy_adapter_server.crt").symlink_to("server_cert.pem")
|
280
|
-
|
281
|
-
(self.certs_dir / "mcp_proxy_adapter_server.key").unlink(missing_ok=True)
|
282
|
-
(self.certs_dir / "mcp_proxy_adapter_server.key").symlink_to(self.keys_dir / "server_key.pem")
|
283
|
-
|
284
|
-
# mTLS aliases
|
285
|
-
(self.certs_dir / "localhost_server.crt").unlink(missing_ok=True)
|
286
|
-
(self.certs_dir / "localhost_server.crt").symlink_to("server_cert.pem")
|
287
|
-
|
288
|
-
self.print_success("Certificate aliases created")
|
289
|
-
|
290
|
-
# Create CA alias
|
291
|
-
if (self.certs_dir / "ca_cert.pem").exists():
|
292
|
-
(self.certs_dir / "mcp_proxy_adapter_ca_ca.crt").unlink(missing_ok=True)
|
293
|
-
(self.certs_dir / "mcp_proxy_adapter_ca_ca.crt").symlink_to("ca_cert.pem")
|
294
|
-
|
295
|
-
self.print_success("CA certificate alias created")
|
296
|
-
|
297
|
-
return True
|
298
|
-
|
299
|
-
except Exception as e:
|
300
|
-
self.print_error(f"Failed to create certificate aliases: {e}")
|
301
|
-
return False
|
302
|
-
|
303
|
-
def validate_certificates_with_framework(self) -> bool:
|
304
|
-
"""Validate generated certificates using framework."""
|
305
|
-
self.print_step("5", "Validating Certificates with Framework")
|
306
|
-
|
307
|
-
all_required = get_all_required_certificates()
|
308
|
-
validation_results = []
|
309
|
-
|
310
|
-
for cert_name in all_required:
|
311
|
-
cert_info = REQUIRED_CERTIFICATES[cert_name]
|
312
|
-
cert_file = cert_info["output_cert"]
|
313
|
-
|
314
|
-
if cert_file.exists():
|
315
|
-
try:
|
316
|
-
# Validate certificate using framework CLI
|
317
|
-
cmd = [
|
318
|
-
sys.executable, "-m", "mcp_security_framework.cli.cert_cli",
|
319
|
-
"validate", str(cert_file)
|
320
|
-
]
|
321
|
-
|
322
|
-
result = subprocess.run(cmd, capture_output=True, text=True, cwd=self.working_dir)
|
323
|
-
|
324
|
-
if result.returncode == 0:
|
325
|
-
self.print_success(f"{cert_name}: Valid")
|
326
|
-
validation_results.append(True)
|
327
|
-
else:
|
328
|
-
self.print_error(f"{cert_name}: Invalid - {result.stderr}")
|
329
|
-
validation_results.append(False)
|
330
|
-
|
331
|
-
except Exception as e:
|
332
|
-
self.print_error(f"{cert_name}: Validation failed - {e}")
|
333
|
-
validation_results.append(False)
|
334
|
-
else:
|
335
|
-
self.print_error(f"{cert_name}: Missing certificate file")
|
336
|
-
validation_results.append(False)
|
337
|
-
|
338
|
-
success_count = sum(validation_results)
|
339
|
-
total_count = len(validation_results)
|
340
|
-
|
341
|
-
self.print_info(f"Validation results: {success_count}/{total_count} certificates valid")
|
342
|
-
|
343
|
-
return success_count == total_count
|
344
|
-
|
345
|
-
def generate_all_certificates(self) -> bool:
|
346
|
-
"""Generate all required certificates."""
|
347
|
-
print("🔐 Generating All Certificates Using mcp_security_framework CLI")
|
348
|
-
print("=" * 60)
|
349
|
-
|
350
|
-
try:
|
351
|
-
# Check framework availability
|
352
|
-
if not self.check_framework():
|
353
|
-
return False
|
354
|
-
|
355
|
-
# Create CA certificate manually first
|
356
|
-
if not self.create_ca_certificate_manually():
|
357
|
-
return False
|
358
|
-
|
359
|
-
# Generate server certificate with framework
|
360
|
-
if not self.generate_server_certificate_with_framework():
|
361
|
-
return False
|
362
|
-
|
363
|
-
# Generate client certificates with framework
|
364
|
-
client_certs = ["admin_cert", "user_cert", "proxy_cert"]
|
365
|
-
for cert_name in client_certs:
|
366
|
-
if cert_name in REQUIRED_CERTIFICATES:
|
367
|
-
if not self.generate_client_certificate_with_framework(cert_name):
|
368
|
-
return False
|
369
|
-
|
370
|
-
# Create aliases
|
371
|
-
if not self.create_certificate_aliases():
|
372
|
-
return False
|
373
|
-
|
374
|
-
# Validate certificates with framework
|
375
|
-
if not self.validate_certificates_with_framework():
|
376
|
-
return False
|
377
|
-
|
378
|
-
# Print summary
|
379
|
-
print(f"\n{'=' * 60}")
|
380
|
-
print("📊 CERTIFICATE GENERATION SUMMARY")
|
381
|
-
print(f"{'=' * 60}")
|
382
|
-
print("✅ All certificates generated successfully!")
|
383
|
-
print(f"📁 Certificates directory: {self.certs_dir}")
|
384
|
-
print(f"📁 Keys directory: {self.keys_dir}")
|
385
|
-
|
386
|
-
return True
|
387
|
-
|
388
|
-
except Exception as e:
|
389
|
-
self.print_error(f"Certificate generation failed: {e}")
|
390
|
-
return False
|
391
|
-
|
392
|
-
|
393
|
-
def main():
|
394
|
-
"""Main entry point."""
|
395
|
-
generator = CLICertificateGenerator()
|
396
|
-
|
397
|
-
try:
|
398
|
-
success = generator.generate_all_certificates()
|
399
|
-
sys.exit(0 if success else 1)
|
400
|
-
except Exception as e:
|
401
|
-
print(f"❌ Fatal error: {e}")
|
402
|
-
sys.exit(1)
|
403
|
-
|
404
|
-
|
405
|
-
if __name__ == "__main__":
|
406
|
-
main()
|