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

HttpsRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 2
doValidate() 0 1 ?
A getCertifacateInformation() 0 18 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
}