Skip to content

Commit 0169e97

Browse files
committed
Improve verify peer name API
Let's make the old methods switch both flags and do so consistently in ServerTlsContext and ClientTlsContext.
1 parent 8833f66 commit 0169e97

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/ClientTlsContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function withPeerVerification(): self
113113
{
114114
$clone = clone $this;
115115
$clone->verifyPeer = true;
116+
$clone->verifyPeerName = true;
116117

117118
return $clone;
118119
}
@@ -129,7 +130,6 @@ public function withoutPeerVerification(): self
129130
{
130131
$clone = clone $this;
131132
$clone->verifyPeer = false;
132-
// This is for compatibility with the former behaviour:
133133
$clone->verifyPeerName = false;
134134

135135
return $clone;

src/ServerTlsContext.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function fromServerResource($socket): ?self
5858

5959
private bool $verifyPeer = false;
6060

61-
private bool $verifyPeerName = true;
61+
private bool $verifyPeerName = false;
6262

6363
private int $verifyDepth = 10;
6464

@@ -143,6 +143,7 @@ public function withPeerVerification(): self
143143
{
144144
$clone = clone $this;
145145
$clone->verifyPeer = true;
146+
$clone->verifyPeerName = true;
146147

147148
return $clone;
148149
}
@@ -156,6 +157,7 @@ public function withoutPeerVerification(): self
156157
{
157158
$clone = clone $this;
158159
$clone->verifyPeer = false;
160+
$clone->verifyPeerName = false;
159161

160162
return $clone;
161163
}
@@ -199,7 +201,7 @@ public function withoutPeerNameVerification(): self
199201
*/
200202
public function hasPeerNameVerification(): bool
201203
{
202-
return $this->verifyPeer && $this->verifyPeerName;
204+
return $this->verifyPeerName;
203205
}
204206

205207
/**
@@ -473,7 +475,7 @@ public function toStreamContextArray(): array
473475
'crypto_method' => $this->toStreamCryptoMethod(),
474476
'peer_name' => $this->peerName,
475477
'verify_peer' => $this->verifyPeer,
476-
'verify_peer_name' => $this->verifyPeer && $this->verifyPeerName,
478+
'verify_peer_name' => $this->verifyPeerName,
477479
'verify_depth' => $this->verifyDepth,
478480
'ciphers' => $this->ciphers ?? \OPENSSL_DEFAULT_STREAM_CIPHERS,
479481
'honor_cipher_order' => true,

0 commit comments

Comments
 (0)