1 | <?php |
||
9 | class Downloader |
||
10 | { |
||
11 | 12 | public static function downloadCertificateFromUrl(string $url, int $timeout = 30): array |
|
12 | { |
||
13 | // Trusted variable to keep track of SSL trust |
||
14 | 12 | $trusted = true; |
|
15 | 12 | $sslConfig = StreamConfig::configSecure(); |
|
16 | 12 | $parsedUrl = new Url($url); |
|
17 | 11 | $client = null; |
|
18 | |||
19 | try { |
||
20 | 11 | $client = stream_socket_client( |
|
21 | 11 | "ssl://{$parsedUrl->getTestURL()}", |
|
22 | 11 | $errorNumber, |
|
23 | 11 | $errorDescription, |
|
24 | 11 | $timeout, |
|
25 | 11 | STREAM_CLIENT_CONNECT, |
|
26 | 11 | $sslConfig->getContext() |
|
27 | ); |
||
28 | 4 | unset($sslConfig); |
|
29 | 7 | } catch (Throwable $thrown) { |
|
30 | // Try agian in insecure mode |
||
31 | 7 | $sslConfig = StreamConfig::configInsecure(); |
|
32 | 7 | $trusted = false; |
|
33 | |||
34 | try { |
||
35 | // As the URL failed verification we set to false |
||
36 | 7 | $client = stream_socket_client( |
|
37 | 7 | "ssl://{$parsedUrl->getTestURL()}", |
|
38 | 7 | $errorNumber, |
|
39 | 7 | $errorDescription, |
|
40 | 7 | $timeout, |
|
41 | 7 | STREAM_CLIENT_CONNECT, |
|
42 | 7 | $sslConfig->getContext() |
|
43 | ); |
||
44 | 2 | unset($sslConfig); |
|
45 | 5 | } catch (Throwable $thrown) { |
|
46 | 5 | (new Handler($thrown))->downloadHandler($parsedUrl); |
|
47 | } |
||
48 | } |
||
49 | |||
50 | 6 | return self::prepareCertificateResponse($client, $trusted, $parsedUrl); |
|
51 | } |
||
52 | |||
53 | 6 | private static function prepareCertificateResponse($resultClient, bool $trusted, Url $parsedUrl): array |
|
81 | |||
82 | 2 | public static function downloadRevocationListFromUrl(string $url): array |
|
94 | } |
||
95 |