|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor\TestCase\AuthSourc\Ldap; |
|
4
|
|
|
|
|
5
|
|
|
use \SimpleSAML\Module\monitor\State as State; |
|
6
|
|
|
use \SimpleSAML\Module\monitor\TestCase as TestCase; |
|
7
|
|
|
|
|
8
|
|
|
final class Connect extends \SimpleSAML\Module\monitor\TestCase |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
private $connection = null; |
|
11
|
|
|
|
|
12
|
|
|
private $hostname = null; |
|
13
|
|
|
private $port = null; |
|
14
|
|
|
private $enableTls = null; |
|
15
|
|
|
private $timeout = null; |
|
16
|
|
|
private $referrals = null; |
|
17
|
|
|
private $debug = null; |
|
18
|
|
|
|
|
19
|
|
|
/* |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function initialize() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->hostname = $this->getInput('hostname'); |
|
25
|
|
|
|
|
26
|
|
|
$authsourceData = $this->getInput('authsource_data'); |
|
27
|
|
|
$this->port = $authsourceData['port']; |
|
28
|
|
|
$this->enableTls = $authsourceData['enable_tls']; |
|
29
|
|
|
$this->timeout = isSet($authsourceData['timeout']) ? $authsourceData['timeout'] : 30; |
|
30
|
|
|
$this->referrals = isSet($authsourceData['referrals']) ? $authsourceData['referrals'] : true; |
|
31
|
|
|
$this->debug = isSet($authsourceData['debug']) ? $authsourceData['debug'] : false; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/* |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function invokeTest() |
|
38
|
|
|
{ |
|
39
|
|
|
try { |
|
40
|
|
|
$this->connection = new SimpleSAML_Auth_LDAP( |
|
41
|
|
|
$this->hostname, |
|
42
|
|
|
$this->enableTls, |
|
43
|
|
|
$this->debug, |
|
44
|
|
|
$this->timeout, |
|
45
|
|
|
$this->port, |
|
46
|
|
|
$this->referrals |
|
47
|
|
|
); |
|
48
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
49
|
|
|
$this->setState(State::FATAL); |
|
50
|
|
|
$msg = str_replace('Library - LDAP __construct(): ', '', $e->getMessage()); |
|
51
|
|
|
$connectString = $this->hostname; |
|
52
|
|
|
if (!preg_match('/^(ldap[s]?:\/\/(.*))$/', $this->hostname, $matches)) { |
|
53
|
|
|
$connectString = $this->hostname . ':' . $this->port; |
|
54
|
|
|
} |
|
55
|
|
|
$this->addMessage(State::FATAL, 'Network connection', $connectString, $msg); |
|
56
|
|
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
$testsuite = $this->getTestSuite(); |
|
59
|
|
|
|
|
60
|
|
|
// Actually connect and pull certificates whenever possible |
|
61
|
|
|
if (preg_match('/^(ldaps:\/\/(.*))$/', $this->hostname, $matches)) { |
|
62
|
|
|
$uri = str_replace('ldaps://', 'ssl://', $this->hostname) . ':636'; |
|
63
|
|
|
$context = stream_context_create(array("ssl" => array("capture_peer_cert" => true, "verify_peer" => true))); |
|
64
|
|
|
} else { |
|
65
|
|
|
$uri = 'tcp://' . $this->hostname . ':' . $this->port; |
|
66
|
|
|
$context = stream_context_create(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$test = new TestCase\Network\ConnectUri($testsuite, array('uri' => $uri, 'context' => $context)); |
|
70
|
|
|
$state = $test->getState(); |
|
71
|
|
|
|
|
72
|
|
|
if ($state === State::OK) { |
|
73
|
|
|
$connection = $test->getOutput('connection'); |
|
74
|
|
|
$cert = stream_context_get_params($connection); |
|
75
|
|
|
if (isSet($cert['options']['ssl']['peer_certificate'])) { |
|
76
|
|
|
$this->addOutput(openssl_x509_parse($cert['options']['ssl']['peer_certificate']), 'certData'); |
|
77
|
|
|
} |
|
78
|
|
|
$this->setState(State::OK); |
|
79
|
|
|
$this->addMessage(State::OK, 'Network connection', $this->hostname, 'Connection established'); |
|
80
|
|
|
} else { |
|
81
|
|
|
$this->setState(State::ERROR); |
|
82
|
|
|
$this->addMessage(State::ERROR, 'Network connection', $this->hostname, 'Connection failed'); |
|
83
|
|
|
} |
|
84
|
|
|
$this->addOutput($this->connection, 'connection'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.