|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jalle19\CertificateParser\Provider; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class StreamContext |
|
7
|
|
|
* @package Jalle19\CertificateParser\Provider |
|
8
|
|
|
*/ |
|
9
|
|
|
class StreamContext |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var bool |
|
14
|
|
|
*/ |
|
15
|
|
|
private $verifyPeerName; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $sniServerName; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* StreamContext constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param bool $verifyPeerName (optional) |
|
27
|
|
|
* @param string|null $sniServerName (optional) |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct($verifyPeerName = true, $sniServerName = null) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->verifyPeerName = $verifyPeerName; |
|
32
|
|
|
$this->sniServerName = $sniServerName; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return boolean |
|
38
|
|
|
*/ |
|
39
|
|
|
public function verifyPeerName() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->verifyPeerName; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param boolean $verifyPeerName |
|
47
|
|
|
*/ |
|
48
|
|
|
public function setVerifyPeerName($verifyPeerName) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->verifyPeerName = $verifyPeerName; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getSniServerName() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->sniServerName; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $sniServerName |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setSniServerName($sniServerName) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->sniServerName = $sniServerName; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getArray() |
|
76
|
|
|
{ |
|
77
|
|
|
$context = [ |
|
78
|
|
|
'ssl' => [ |
|
79
|
|
|
'capture_peer_cert' => true, |
|
80
|
|
|
'verify_peer' => false, |
|
81
|
|
|
'verify_peer_name' => $this->verifyPeerName(), |
|
82
|
|
|
], |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
if ($this->sniServerName !== null) { |
|
86
|
|
|
$context['ssl']['SNI_enabled'] = true; |
|
87
|
|
|
$context['ssl']['SNI_server_name'] = $this->getSniServerName(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $context; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return resource |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getResource() |
|
98
|
|
|
{ |
|
99
|
|
|
return stream_context_create($this->getArray()); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|