Completed
Push — master ( 84aa2d...183b20 )
by Nils
20:22
created

HttpsRule::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: nils.langner
5
 * Date: 01.08.16
6
 * Time: 14:49
7
 */
8
9
namespace whm\Smoke\Rules\Http;
10
11
12
use whm\Smoke\Http\Response;
13
use whm\Smoke\Rules\Rule;
14
15
abstract class HttpsRule implements Rule
16
{
17
    public function validate(Response $response)
18
    {
19
        if ('https' === $response->getUri()->getScheme()) {
20
            $certInfo = $this->getCertifacateInformation($response->getUri()->getHost());
21
            $this->doValidate($certInfo);
22
        }
23
    }
24
25
    abstract protected function doValidate($certInfo);
26
27
    private function getCertifacateInformation($host)
28
    {
29
        $sslOptions = stream_context_create(array('ssl' => array('capture_peer_cert' => true)));
30
31
        $request = stream_socket_client(
32
            'ssl://' . $host . ':443',
33
            $errno,
34
            $errstr,
35
            30,
36
            STREAM_CLIENT_CONNECT,
37
            $sslOptions
38
        );
39
40
        $content = stream_context_get_params($request);
41
        $certinfo = openssl_x509_parse($content['options']['ssl']['peer_certificate']);
42
43
        return $certinfo;
44
    }
45
}