|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the LdapToolsBundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Chad Sikorra <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LdapTools\Bundle\LdapToolsBundle\Command; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Command\Command; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
use LdapTools\Utilities\LdapUtilities; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Retrieves the LDAP SSL certificate from a given server and generates the certificate bundle for it. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Chad Sikorra <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class SslCertificateCommand extends Command |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritDoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function configure() |
|
30
|
|
|
{ |
|
31
|
|
|
$this |
|
32
|
|
|
->setName('ldaptools:generate:sslcert') |
|
33
|
|
|
->addOption('server', null, InputOption::VALUE_REQUIRED, 'The LDAP server name.') |
|
34
|
|
|
->addOption('port', null, InputOption::VALUE_OPTIONAL, 'The LDAP port number.', 389) |
|
35
|
|
|
->setDescription('Retrieves the LDAP SSL/TLS certificate from a server and generates the certificate bundle.'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
|
42
|
|
|
{ |
|
43
|
|
|
$server = trim($input->getOption('server')); |
|
44
|
|
|
$port = (int) $input->getOption('port'); |
|
45
|
|
|
if (!$server) { |
|
46
|
|
|
throw new \Exception('You must enter a server name.'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$certs = LdapUtilities::getLdapSslCertificates($server, $port); |
|
50
|
|
|
$bundle = $certs['peer_certificate'].implode('', $certs['peer_certificate_chain']); |
|
51
|
|
|
if (empty($bundle)) { |
|
52
|
|
|
$output->writeln(sprintf('<error>Unable to retrieve SSL certificate from %s on port %s.</error>', $server, $port)); |
|
53
|
|
|
|
|
54
|
|
|
return 1; |
|
55
|
|
|
} |
|
56
|
|
|
$output->writeln($bundle); |
|
57
|
|
|
|
|
58
|
|
|
return 0; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|