-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcsrtool.php
More file actions
35 lines (26 loc) · 1.05 KB
/
csrtool.php
File metadata and controls
35 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require_once 'src/CSRTool.php';
require_once 'src/InputSanitizer.php';
use ZeroSSL\CliClient\CSRTool;
use ZeroSSL\CliClient\InputSanitizer;
// Parse command line arguments
$options = getopt("", ["domains:", "csrData:", "useEcc::", "output:"]);
// Validate and sanitize input
try {
$domains = InputSanitizer::processDomainsInput($options['domains'] ?? '');
$csrData = InputSanitizer::sanitizeCSRData($options['csrData'] ?? '');
$useEcc = isset($options['useEcc']);
$output = $options['output'] ?? 'csr_output';
// Generate private key
$privateKey = CSRTool::generatePrivateKey($useEcc);
// Generate CSR
$csr = CSRTool::getCSR($privateKey, $csrData, $domains, $useEcc);
// Export private key to file
openssl_pkey_export_to_file($privateKey, $output . '.key');
// Export CSR to file
openssl_csr_export_to_file($csr, $output . '.csr');
echo "Private key and CSR have been generated and saved to {$output}.key and {$output}.csr\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}