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