1 | <?php |
||
5 | class Reader |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @param $url |
||
10 | * @return Certificate |
||
11 | */ |
||
12 | 1 | public function readFromUrl($url) |
|
13 | { |
||
14 | 1 | $urlHost = parse_url($url, PHP_URL_HOST); |
|
15 | |||
16 | 1 | $streamContext = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE))); |
|
17 | 1 | $stream = stream_socket_client("ssl://".$urlHost.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $streamContext); |
|
18 | 1 | $streamParams = stream_context_get_params($stream); |
|
19 | |||
20 | 1 | $certResource = $streamParams['options']['ssl']['peer_certificate']; |
|
21 | |||
22 | 1 | return new Certificate($this->certResourceToString($certResource)); |
|
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param $file |
||
27 | * @return Certificate |
||
28 | */ |
||
29 | 6 | public function readFromFile($file) |
|
33 | |||
34 | /** |
||
35 | * @param $certResource |
||
36 | * @return string |
||
37 | */ |
||
38 | 1 | protected function certResourceToString($certResource) |
|
46 | } |
||
47 |