mcp-proxy-adapter 6.4.43__py3-none-any.whl → 6.4.44__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.
@@ -1,673 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Simple Certificate Creation Script
4
- This script creates basic certificates for testing using mcp_security_framework.
5
- Author: Vasiliy Zdanovskiy
6
- email: vasilyvz@gmail.com
7
- """
8
- import os
9
- import subprocess
10
- import sys
11
- import argparse
12
- from pathlib import Path
13
-
14
- # Import mcp_security_framework
15
- try:
16
- from mcp_security_framework.core.cert_manager import CertificateManager
17
- from mcp_security_framework.schemas.config import (
18
- CertificateConfig,
19
- CAConfig,
20
- ServerCertConfig,
21
- ClientCertConfig,
22
- )
23
- from mcp_security_framework.schemas.models import CertificateType
24
-
25
- SECURITY_FRAMEWORK_AVAILABLE = True
26
- except ImportError:
27
- SECURITY_FRAMEWORK_AVAILABLE = False
28
- print("Warning: mcp_security_framework not available, falling back to OpenSSL")
29
-
30
-
31
- class SimpleCertificateCreator:
32
- """Create certificates using OpenSSL directly."""
33
-
34
- def __init__(self, certs_dir: str = None, keys_dir: str = None):
35
- # Use current working directory as base
36
- cwd = Path.cwd()
37
-
38
- if certs_dir:
39
- self.certs_dir = Path(certs_dir).resolve()
40
- else:
41
- self.certs_dir = cwd / "certs"
42
-
43
- if keys_dir:
44
- self.keys_dir = Path(keys_dir).resolve()
45
- else:
46
- self.keys_dir = cwd / "keys"
47
- # Create directories
48
- self.certs_dir.mkdir(parents=True, exist_ok=True)
49
- self.keys_dir.mkdir(parents=True, exist_ok=True)
50
- print(f"🔧 Using certificates directory: {self.certs_dir}")
51
- print(f"🔧 Using keys directory: {self.keys_dir}")
52
-
53
- def run_command(self, cmd: list, description: str) -> bool:
54
- """Run a command and handle errors."""
55
- try:
56
- print(f"🔧 {description}...")
57
- # Use current working directory instead of project_root
58
- result = subprocess.run(cmd, capture_output=True, text=True, check=True)
59
- print(f"✅ {description} completed successfully")
60
- return True
61
- except subprocess.CalledProcessError as e:
62
- print(f"❌ {description} failed:")
63
- print(f" Command: {' '.join(cmd)}")
64
- print(f" Error: {e.stderr}")
65
- return False
66
- except Exception as e:
67
- print(f"❌ {description} failed: {e}")
68
- return False
69
-
70
- def create_ca_certificate(self) -> bool:
71
- """Create CA certificate using mcp_security_framework or OpenSSL fallback."""
72
- ca_cert_path = self.certs_dir / "ca_cert.pem"
73
- ca_key_path = self.keys_dir / "ca_key.pem"
74
- if ca_cert_path.exists() and ca_key_path.exists():
75
- print(f"ℹ️ CA certificate already exists: {ca_cert_path}")
76
- return True
77
- if SECURITY_FRAMEWORK_AVAILABLE:
78
- return self._create_ca_certificate_with_framework()
79
- else:
80
- return self._create_ca_certificate_with_openssl()
81
-
82
- def _create_ca_certificate_with_framework(self) -> bool:
83
- """Create CA certificate using mcp_security_framework."""
84
- try:
85
- print("🔧 Creating CA certificate using mcp_security_framework...")
86
- # Create CA certificate configuration
87
- ca_config = CAConfig(
88
- common_name="mcp_proxy_adapter_test_ca",
89
- organization="Test Organization",
90
- organizational_unit="Test Unit",
91
- country="US",
92
- state="Test State",
93
- locality="Test City",
94
- validity_years=10,
95
- )
96
- # Create certificate manager
97
- cert_config = CertificateConfig(
98
- cert_storage_path=str(self.certs_dir),
99
- key_storage_path=str(self.keys_dir),
100
- default_validity_days=365,
101
- key_size=2048,
102
- hash_algorithm="sha256",
103
- )
104
- cert_manager = CertificateManager(cert_config)
105
- # Create CA certificate
106
- cert_pair = cert_manager.create_root_ca(ca_config)
107
- if cert_pair and cert_pair.certificate_path and cert_pair.private_key_path:
108
- # Rename the generated files to the expected names
109
- generated_cert = Path(cert_pair.certificate_path)
110
- generated_key = Path(cert_pair.private_key_path)
111
- if generated_cert.exists() and generated_key.exists():
112
- # Move to expected names
113
- expected_cert = self.certs_dir / "ca_cert.pem"
114
- expected_key = self.keys_dir / "ca_key.pem"
115
- generated_cert.rename(expected_cert)
116
- generated_key.rename(expected_key)
117
- print(
118
- "✅ CA certificate created successfully using mcp_security_framework"
119
- )
120
- return True
121
- else:
122
- print("❌ Generated CA certificate files not found")
123
- return False
124
- else:
125
- print("❌ Failed to create CA certificate: Invalid certificate pair")
126
- return False
127
- except Exception as e:
128
- print(f"❌ Error creating CA certificate with framework: {e}")
129
- return False
130
-
131
- def _create_ca_certificate_with_openssl(self) -> bool:
132
- """Create CA certificate using OpenSSL fallback."""
133
- ca_cert_path = self.certs_dir / "ca_cert.pem"
134
- ca_key_path = self.keys_dir / "ca_key.pem"
135
- # Create CA private key
136
- key_cmd = ["openssl", "genrsa", "-out", str(ca_key_path), "2048"]
137
- if not self.run_command(key_cmd, "Creating CA private key"):
138
- return False
139
- # Create CA certificate
140
- cert_cmd = [
141
- "openssl",
142
- "req",
143
- "-new",
144
- "-x509",
145
- "-days",
146
- "3650",
147
- "-key",
148
- str(ca_key_path),
149
- "-out",
150
- str(ca_cert_path),
151
- "-subj",
152
- "/C=US/ST=Test State/L=Test City/O=Test Organization/CN=MCP Proxy Adapter Test CA",
153
- ]
154
- return self.run_command(cert_cmd, "Creating CA certificate")
155
-
156
- def create_server_certificate(self) -> bool:
157
- """Create server certificate using mcp_security_framework or OpenSSL fallback."""
158
- server_cert_path = self.certs_dir / "server_cert.pem"
159
- server_key_path = self.certs_dir / "server_key.pem"
160
- if server_cert_path.exists() and server_key_path.exists():
161
- print("ℹ️ Server certificate already exists")
162
- return True
163
- if SECURITY_FRAMEWORK_AVAILABLE:
164
- return self._create_server_certificate_with_framework()
165
- else:
166
- return self._create_server_certificate_with_openssl()
167
-
168
- def _create_server_certificate_with_framework(self) -> bool:
169
- """Create server certificate using mcp_security_framework."""
170
- try:
171
- print("🔧 Creating server certificate using mcp_security_framework...")
172
- # Find CA certificate and key files
173
- ca_cert_path = None
174
- ca_key_path = None
175
- # Look for CA certificate files with expected names
176
- expected_ca_cert = self.certs_dir / "ca_cert.pem"
177
- expected_ca_key = self.keys_dir / "ca_key.pem"
178
- if expected_ca_cert.exists():
179
- ca_cert_path = str(expected_ca_cert)
180
- else:
181
- # Fallback: look for CA certificate files with pattern
182
- for cert_file in self.certs_dir.glob("*_ca.crt"):
183
- ca_cert_path = str(cert_file)
184
- break
185
- if expected_ca_key.exists():
186
- ca_key_path = str(expected_ca_key)
187
- else:
188
- # Fallback: look for CA key files with pattern
189
- for key_file in self.keys_dir.glob("*_ca.key"):
190
- ca_key_path = str(key_file)
191
- break
192
- if not ca_cert_path or not ca_key_path:
193
- print("❌ CA certificate or key not found")
194
- return False
195
- # Create server certificate configuration
196
- server_config = ServerCertConfig(
197
- common_name="localhost",
198
- organization="Test Organization",
199
- organizational_unit="Test Unit",
200
- country="US",
201
- state="Test State",
202
- locality="Test City",
203
- subject_alt_names=["localhost", "127.0.0.1"],
204
- validity_years=1,
205
- ca_cert_path=ca_cert_path,
206
- ca_key_path=ca_key_path,
207
- )
208
- # Create certificate manager
209
- cert_config = CertificateConfig(
210
- cert_storage_path=str(self.certs_dir),
211
- key_storage_path=str(self.certs_dir), # Server keys in certs dir
212
- default_validity_days=365,
213
- key_size=2048,
214
- hash_algorithm="sha256",
215
- )
216
- cert_manager = CertificateManager(cert_config)
217
- # Create server certificate
218
- cert_pair = cert_manager.create_server_certificate(server_config)
219
- if cert_pair and cert_pair.certificate_path and cert_pair.private_key_path:
220
- # Rename the generated files to the expected names
221
- generated_cert = Path(cert_pair.certificate_path)
222
- generated_key = Path(cert_pair.private_key_path)
223
- if generated_cert.exists() and generated_key.exists():
224
- # Move to expected names
225
- generated_cert.rename(self.certs_dir / "server_cert.pem")
226
- generated_key.rename(self.certs_dir / "server_key.pem")
227
- print(
228
- "✅ Server certificate created successfully using mcp_security_framework"
229
- )
230
- return True
231
- else:
232
- print("❌ Generated certificate files not found")
233
- return False
234
- else:
235
- print(
236
- "❌ Failed to create server certificate: Invalid certificate pair"
237
- )
238
- return False
239
- except Exception as e:
240
- print(f"❌ Error creating server certificate with framework: {e}")
241
- return False
242
-
243
- def _create_server_certificate_with_openssl(self) -> bool:
244
- """Create server certificate using OpenSSL fallback."""
245
- server_cert_path = self.certs_dir / "server_cert.pem"
246
- server_key_path = self.certs_dir / "server_key.pem"
247
- # Create server private key
248
- key_cmd = ["openssl", "genrsa", "-out", str(server_key_path), "2048"]
249
- if not self.run_command(key_cmd, "Creating server private key"):
250
- return False
251
- # Create server certificate signing request
252
- csr_path = self.certs_dir / "server.csr"
253
- csr_cmd = [
254
- "openssl",
255
- "req",
256
- "-new",
257
- "-key",
258
- str(server_key_path),
259
- "-out",
260
- str(csr_path),
261
- "-subj",
262
- "/C=US/ST=Test State/L=Test City/O=Test Organization/CN=localhost",
263
- ]
264
- if not self.run_command(csr_cmd, "Creating server CSR"):
265
- return False
266
- # Create server certificate
267
- cert_cmd = [
268
- "openssl",
269
- "x509",
270
- "-req",
271
- "-days",
272
- "730",
273
- "-in",
274
- str(csr_path),
275
- "-CA",
276
- str(self.certs_dir / "ca_cert.pem"),
277
- "-CAkey",
278
- str(self.keys_dir / "ca_key.pem"),
279
- "-CAcreateserial",
280
- "-out",
281
- str(server_cert_path),
282
- ]
283
- success = self.run_command(cert_cmd, "Creating server certificate")
284
- # Clean up CSR
285
- if csr_path.exists():
286
- csr_path.unlink()
287
- return success
288
-
289
- def create_client_certificate(
290
- self, name: str, common_name: str, roles: list = None, permissions: list = None
291
- ) -> bool:
292
- """Create client certificate using mcp_security_framework or OpenSSL fallback."""
293
- cert_path = self.certs_dir / f"{name}_cert.pem"
294
- key_path = self.certs_dir / f"{name}_key.pem"
295
- if cert_path.exists() and key_path.exists():
296
- print(f"ℹ️ Client certificate {name} already exists: {cert_path}")
297
- return True
298
- if SECURITY_FRAMEWORK_AVAILABLE:
299
- return self._create_client_certificate_with_framework(
300
- name, common_name, roles, permissions
301
- )
302
- else:
303
- return self._create_client_certificate_with_openssl(name, common_name)
304
-
305
- def _create_client_certificate_with_framework(
306
- self, name: str, common_name: str, roles: list = None, permissions: list = None
307
- ) -> bool:
308
- """Create client certificate using mcp_security_framework."""
309
- try:
310
- print(
311
- f"🔧 Creating client certificate {name} using mcp_security_framework..."
312
- )
313
- # Find CA certificate and key files
314
- ca_cert_path = None
315
- ca_key_path = None
316
- # Look for CA certificate files with expected names
317
- expected_ca_cert = self.certs_dir / "ca_cert.pem"
318
- expected_ca_key = self.keys_dir / "ca_key.pem"
319
- if expected_ca_cert.exists():
320
- ca_cert_path = str(expected_ca_cert)
321
- else:
322
- # Fallback: look for CA certificate files with pattern
323
- for cert_file in self.certs_dir.glob("*_ca.crt"):
324
- ca_cert_path = str(cert_file)
325
- break
326
- if expected_ca_key.exists():
327
- ca_key_path = str(expected_ca_key)
328
- else:
329
- # Fallback: look for CA key files with pattern
330
- for key_file in self.keys_dir.glob("*_ca.key"):
331
- ca_key_path = str(key_file)
332
- break
333
- if not ca_cert_path or not ca_key_path:
334
- print("❌ CA certificate or key not found")
335
- return False
336
- # Create client certificate configuration
337
- client_config = ClientCertConfig(
338
- common_name=common_name,
339
- organization="Test Organization",
340
- organizational_unit="Test Unit",
341
- country="US",
342
- state="Test State",
343
- locality="Test City",
344
- validity_years=1,
345
- ca_cert_path=ca_cert_path,
346
- ca_key_path=ca_key_path,
347
- )
348
- # Create certificate manager
349
- cert_config = CertificateConfig(
350
- cert_storage_path=str(self.certs_dir),
351
- key_storage_path=str(self.certs_dir), # Client keys in certs dir
352
- default_validity_days=365,
353
- key_size=2048,
354
- hash_algorithm="sha256",
355
- )
356
- cert_manager = CertificateManager(cert_config)
357
- # Create client certificate
358
- cert_pair = cert_manager.create_client_certificate(client_config)
359
- if cert_pair and cert_pair.certificate_path and cert_pair.private_key_path:
360
- # Rename the generated files to the expected names
361
- generated_cert = Path(cert_pair.certificate_path)
362
- generated_key = Path(cert_pair.private_key_path)
363
- if generated_cert.exists() and generated_key.exists():
364
- # Move to expected names
365
- expected_cert = self.certs_dir / f"{name}_cert.pem"
366
- expected_key = self.certs_dir / f"{name}_key.pem"
367
- generated_cert.rename(expected_cert)
368
- generated_key.rename(expected_key)
369
- print(
370
- f"✅ Client certificate {name} created successfully using mcp_security_framework"
371
- )
372
- return True
373
- else:
374
- print(f"❌ Generated certificate files not found for {name}")
375
- return False
376
- else:
377
- print(
378
- f"❌ Failed to create client certificate {name}: Invalid certificate pair"
379
- )
380
- return False
381
- except Exception as e:
382
- print(f"❌ Error creating client certificate {name} with framework: {e}")
383
- return False
384
-
385
- def _create_client_certificate_with_openssl(
386
- self, name: str, common_name: str
387
- ) -> bool:
388
- """Create client certificate using OpenSSL fallback."""
389
- cert_path = self.certs_dir / f"{name}_cert.pem"
390
- key_path = self.certs_dir / f"{name}_key.pem"
391
- # Create client private key
392
- key_cmd = ["openssl", "genrsa", "-out", str(key_path), "2048"]
393
- if not self.run_command(key_cmd, f"Creating {name} private key"):
394
- return False
395
- # Create client certificate signing request
396
- csr_path = self.certs_dir / f"{name}.csr"
397
- csr_cmd = [
398
- "openssl",
399
- "req",
400
- "-new",
401
- "-key",
402
- str(key_path),
403
- "-out",
404
- str(csr_path),
405
- "-subj",
406
- f"/C=US/ST=Test State/L=Test City/O=Test Organization/CN={common_name}",
407
- ]
408
- if not self.run_command(csr_cmd, f"Creating {name} CSR"):
409
- return False
410
- # Create client certificate
411
- cert_cmd = [
412
- "openssl",
413
- "x509",
414
- "-req",
415
- "-days",
416
- "730",
417
- "-in",
418
- str(csr_path),
419
- "-CA",
420
- str(self.certs_dir / "ca_cert.pem"),
421
- "-CAkey",
422
- str(self.keys_dir / "ca_key.pem"),
423
- "-CAcreateserial",
424
- "-out",
425
- str(cert_path),
426
- ]
427
- success = self.run_command(cert_cmd, f"Creating {name} certificate")
428
- # Clean up CSR
429
- if csr_path.exists():
430
- csr_path.unlink()
431
- return success
432
-
433
- def create_legacy_certificates(self) -> bool:
434
- """Create legacy certificate files for compatibility."""
435
- legacy_files = [
436
- ("client_admin.crt", "client_admin.key", "admin"),
437
- ("admin.crt", "admin.key", "admin"),
438
- ("user.crt", "user.key", "user"),
439
- ("readonly.crt", "readonly.key", "readonly"),
440
- ]
441
- success = True
442
- for cert_file, key_file, source_name in legacy_files:
443
- cert_path = self.certs_dir / cert_file
444
- key_path = self.certs_dir / key_file
445
- if not cert_path.exists() or not key_path.exists():
446
- source_cert = self.certs_dir / f"{source_name}_cert.pem"
447
- source_key = self.certs_dir / f"{source_name}_key.pem"
448
- if source_cert.exists() and source_key.exists():
449
- self.run_command(
450
- ["cp", str(source_cert), str(cert_path)],
451
- f"Creating {cert_file}",
452
- )
453
- self.run_command(
454
- ["cp", str(source_key), str(key_path)], f"Creating {key_file}"
455
- )
456
- else:
457
- print(
458
- f"⚠️ Source certificate {source_name} not found for {cert_file}"
459
- )
460
- # Don't fail the entire process for missing legacy certificates
461
- continue
462
- return True # Always return True for legacy certificates
463
-
464
- def validate_certificates(self) -> bool:
465
- """Validate all created certificates."""
466
- print("\n🔍 Validating certificates...")
467
- cert_files = [
468
- "ca_cert.pem",
469
- "server_cert.pem",
470
- "admin_cert.pem",
471
- "user_cert.pem",
472
- "readonly_cert.pem",
473
- "guest_cert.pem",
474
- "proxy_cert.pem",
475
- ]
476
- success = True
477
- for cert_file in cert_files:
478
- cert_path = self.certs_dir / cert_file
479
- if cert_path.exists():
480
- try:
481
- result = subprocess.run(
482
- ["openssl", "x509", "-in", str(cert_path), "-text", "-noout"],
483
- capture_output=True,
484
- text=True,
485
- check=True,
486
- )
487
- print(f"✅ {cert_file}: Valid")
488
- except subprocess.CalledProcessError:
489
- print(f"❌ {cert_file}: Invalid")
490
- success = False
491
- else:
492
- print(f"⚠️ {cert_file}: Not found")
493
- return success
494
-
495
- def create_all(self) -> bool:
496
- """Create all certificates."""
497
- print("🔐 Creating All Certificates for Security Testing")
498
- print("=" * 60)
499
- success = True
500
- # 1. Create CA certificate
501
- if not self.create_ca_certificate():
502
- success = False
503
- print("❌ Cannot continue without CA certificate")
504
- return False
505
- # 2. Create server certificate
506
- if not self.create_server_certificate():
507
- success = False
508
- # 3. Create client certificates
509
- print("\n👥 Creating client certificates...")
510
- client_certs = [
511
- (
512
- "admin",
513
- "admin-client",
514
- ["admin"],
515
- [
516
- "read",
517
- "write",
518
- "execute",
519
- "delete",
520
- "admin",
521
- "register",
522
- "unregister",
523
- "heartbeat",
524
- "discover",
525
- ],
526
- ),
527
- (
528
- "user",
529
- "user-client",
530
- ["user"],
531
- ["read", "execute", "register", "unregister", "heartbeat", "discover"],
532
- ),
533
- ("readonly", "readonly-client", ["readonly"], ["read", "discover"]),
534
- ("guest", "guest-client", ["guest"], ["read", "discover"]),
535
- (
536
- "proxy",
537
- "proxy-client",
538
- ["proxy"],
539
- ["register", "unregister", "heartbeat", "discover"],
540
- ),
541
- ]
542
- for name, common_name, roles, permissions in client_certs:
543
- if not self.create_client_certificate(
544
- name, common_name, roles, permissions
545
- ):
546
- success = False
547
- # 4. Create legacy certificates
548
- print("\n🔄 Creating legacy certificates...")
549
- if not self.create_legacy_certificates():
550
- success = False
551
- # 5. Validate certificates
552
- if not self.validate_certificates():
553
- success = False
554
- # Create compatibility symlinks
555
- if success:
556
- # CA certificate symlink
557
- ca_cert = self.certs_dir / "ca_cert.pem"
558
- expected_ca_cert = self.certs_dir / "mcp_proxy_adapter_ca_ca.crt"
559
- if ca_cert.exists() and not expected_ca_cert.exists():
560
- try:
561
- expected_ca_cert.symlink_to(ca_cert)
562
- print(f"✅ Created CA certificate symlink: {expected_ca_cert}")
563
- except OSError:
564
- # On Windows, symlink might require admin privileges, copy instead
565
- import shutil
566
-
567
- shutil.copy2(ca_cert, expected_ca_cert)
568
- print(f"✅ Created CA certificate copy: {expected_ca_cert}")
569
-
570
- # Server certificate symlink
571
- server_cert = self.certs_dir / "server_cert.pem"
572
- expected_server_cert = self.certs_dir / "localhost_server.crt"
573
- if server_cert.exists() and not expected_server_cert.exists():
574
- try:
575
- expected_server_cert.symlink_to(server_cert)
576
- print(
577
- f"✅ Created server certificate symlink: {expected_server_cert}"
578
- )
579
- except OSError:
580
- # On Windows, symlink might require admin privileges, copy instead
581
- import shutil
582
-
583
- shutil.copy2(server_cert, expected_server_cert)
584
- print(f"✅ Created server certificate copy: {expected_server_cert}")
585
-
586
- # Server key symlink - check if it's in certs or keys directory
587
- server_key_certs = self.certs_dir / "server_key.pem"
588
- server_key_keys = self.keys_dir / "server_key.pem"
589
-
590
- if server_key_certs.exists():
591
- # Server key is in certs directory, move it to keys directory
592
- import shutil
593
-
594
- shutil.move(str(server_key_certs), str(server_key_keys))
595
- print(f"✅ Moved server key to keys directory: {server_key_keys}")
596
-
597
- if server_key_keys.exists():
598
- expected_server_key = self.keys_dir / "localhost_server.key"
599
- if not expected_server_key.exists():
600
- try:
601
- expected_server_key.symlink_to(server_key_keys)
602
- print(f"✅ Created server key symlink: {expected_server_key}")
603
- except OSError:
604
- # On Windows, symlink might require admin privileges, copy instead
605
- import shutil
606
-
607
- shutil.copy2(server_key_keys, expected_server_key)
608
- print(f"✅ Created server key copy: {expected_server_key}")
609
-
610
- # Print summary
611
- print("\n" + "=" * 60)
612
- print("📊 CERTIFICATE CREATION SUMMARY")
613
- print("=" * 60)
614
- if success:
615
- print("✅ All certificates created successfully!")
616
- print(f"📁 Certificates directory: {self.certs_dir}")
617
- print(f"🔑 Keys directory: {self.keys_dir}")
618
- print("\n📋 Created certificates:")
619
- cert_files = list(self.certs_dir.glob("*.pem")) + list(
620
- self.certs_dir.glob("*.crt")
621
- )
622
- for cert_file in sorted(cert_files):
623
- print(f" - {cert_file.name}")
624
- key_files = list(self.keys_dir.glob("*.pem")) + list(
625
- self.keys_dir.glob("*.key")
626
- )
627
- for key_file in sorted(key_files):
628
- print(f" - {key_file.name}")
629
- else:
630
- print("❌ Some certificates failed to create")
631
- print("Check the error messages above")
632
- return success
633
-
634
-
635
- def main():
636
- """Main function."""
637
- parser = argparse.ArgumentParser(description="Create certificates for testing")
638
- parser.add_argument(
639
- "--certs-dir", help="Directory for certificates (default: ./certs)"
640
- )
641
- parser.add_argument("--keys-dir", help="Directory for keys (default: ./keys)")
642
- args = parser.parse_args()
643
-
644
- # If no directories specified, check if we're in a test environment
645
- if not args.certs_dir and not args.keys_dir:
646
- cwd = Path.cwd()
647
- # Check if we're in a test environment by looking for typical directories
648
- if (cwd / "configs").exists() and (cwd / "examples").exists():
649
- # We're in a test environment, use current directory
650
- certs_dir = cwd / "certs"
651
- keys_dir = cwd / "keys"
652
- else:
653
- # Use default project structure
654
- certs_dir = None
655
- keys_dir = None
656
- else:
657
- certs_dir = args.certs_dir
658
- keys_dir = args.keys_dir
659
-
660
- creator = SimpleCertificateCreator(certs_dir=certs_dir, keys_dir=keys_dir)
661
- try:
662
- success = creator.create_all()
663
- sys.exit(0 if success else 1)
664
- except KeyboardInterrupt:
665
- print("\n⚠️ Certificate creation interrupted by user")
666
- sys.exit(1)
667
- except Exception as e:
668
- print(f"\n❌ Certificate creation failed: {e}")
669
- sys.exit(1)
670
-
671
-
672
- if __name__ == "__main__":
673
- main()