1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor\TestSuite\Configuration; |
4
|
|
|
|
5
|
|
|
use SimpleSAML\Module\monitor\TestConfiguration; |
6
|
|
|
use SimpleSAML\Module\monitor\TestCase; |
7
|
|
|
use SimpleSAML\Module\monitor\TestData; |
8
|
|
|
use SimpleSAML\Module\monitor\TestResult; |
9
|
|
|
use SimpleSAML\Module\monitor\State; |
10
|
|
|
use SimpleSAML\Utils; |
11
|
|
|
|
12
|
|
|
final class Certificates extends \SimpleSAML\Module\monitor\TestSuiteFactory |
13
|
|
|
{ |
14
|
|
|
/** @var string|null */ |
15
|
|
|
private $metadataCert = null; |
16
|
|
|
|
17
|
|
|
/** @var string */ |
18
|
|
|
private $serverName; |
19
|
|
|
|
20
|
|
|
/** @var integer */ |
21
|
|
|
private $serverPort; |
22
|
|
|
|
23
|
|
|
/** @var integer */ |
24
|
|
|
private $certExpirationWarning; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \SimpleSAML\Module\monitor\TestConfiguration $configuration |
29
|
|
|
*/ |
30
|
|
|
public function __construct(TestConfiguration $configuration) |
31
|
|
|
{ |
32
|
|
|
$globalConfig = $configuration->getGlobalConfig(); |
33
|
|
|
$moduleConfig = $configuration->getModuleConfig(); |
34
|
|
|
$serverVars = $configuration->getServerVars(); |
35
|
|
|
|
36
|
|
|
$this->metadataCert = $globalConfig->getString('metadata.sign.certificate', null); |
37
|
|
|
$this->certExpirationWarning = $moduleConfig->getValue('certExpirationWarning', 28); |
38
|
|
|
$this->serverName = $serverVars->get('SERVER_NAME'); |
39
|
|
|
$this->serverPort = $serverVars->get('SERVER_PORT'); |
40
|
|
|
$this->setCategory('Configuration'); |
41
|
|
|
|
42
|
|
|
parent::__construct($configuration); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function invokeTest(): void |
50
|
|
|
{ |
51
|
|
|
// Check network connection to full public URL |
52
|
|
|
$input = [ |
53
|
|
|
'uri' => 'ssl://' . $this->serverName . ':' . $this->serverPort, |
54
|
|
|
'context' => stream_context_create([ |
55
|
|
|
"ssl" => [ |
56
|
|
|
"capture_peer_cert" => true, |
57
|
|
|
"verify_peer" => false, |
58
|
|
|
"verify_peer_name" => false |
59
|
|
|
] |
60
|
|
|
]), |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
$connTest = new TestCase\Network\ConnectUri(new TestData($input)); |
64
|
|
|
$connTestResult = $connTest->getTestResult(); |
65
|
|
|
|
66
|
|
|
$this->addTestResult($connTest->getTestResult()); |
67
|
|
|
|
68
|
|
|
if ($connTestResult->getState() === State::OK) { |
69
|
|
|
// We were able to connect |
70
|
|
|
if (Utils\HTTP::isHTTPS()) { |
71
|
|
|
// Check Service Communications Certificate |
72
|
|
|
$certData = $connTestResult->getOutput('certData'); |
73
|
|
|
|
74
|
|
|
$input = [ |
75
|
|
|
'category' => 'Service Communications Certificate', |
76
|
|
|
'certData' => $certData, |
77
|
|
|
'certExpirationWarning' => $this->certExpirationWarning, |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
$certTest = new TestCase\Cert(new TestData($input)); |
81
|
|
|
$this->addTestResult($certTest->getTestResult()); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// Check metadata signing certificate when available |
86
|
|
|
if (is_string($this->metadataCert)) { |
87
|
|
|
$input = [ |
88
|
|
|
'certFile' => Utils\Config::getCertPath($this->metadataCert), |
89
|
|
|
'category' => 'Metadata Signing Certificate', |
90
|
|
|
'certExpirationWarning' => $this->certExpirationWarning, |
91
|
|
|
]; |
92
|
|
|
$testData = new TestData($input); |
93
|
|
|
|
94
|
|
|
$test = new TestCase\Cert\File($testData); |
95
|
|
|
$this->addTestResult($test->getTestResult()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$testResult = new TestResult('Configuration', ''); |
99
|
|
|
$testResult->setState($this->calculateState()); |
100
|
|
|
$this->setTestResult($testResult); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|