@@ -22,6 +22,8 @@ final class ClientTlsContext
2222
2323 private bool $ verifyPeer = true ;
2424
25+ private bool $ verifyPeerName = true ;
26+
2527 private int $ verifyDepth = 10 ;
2628
2729 private ?array $ peerFingerprint = null ;
@@ -127,6 +129,8 @@ public function withoutPeerVerification(): self
127129 {
128130 $ clone = clone $ this ;
129131 $ clone ->verifyPeer = false ;
132+ // This is for compatibility with the former behaviour:
133+ $ clone ->verifyPeerName = false ;
130134
131135 return $ clone ;
132136 }
@@ -139,6 +143,40 @@ public function hasPeerVerification(): bool
139143 return $ this ->verifyPeer ;
140144 }
141145
146+ /**
147+ * Enable peer name verification, this is the default with verifyPeer enabled.
148+ *
149+ * @return self Cloned, modified instance.
150+ */
151+ public function withPeerNameVerification (): self
152+ {
153+ $ clone = clone $ this ;
154+ $ clone ->verifyPeerName = true ;
155+
156+ return $ clone ;
157+ }
158+
159+ /**
160+ * Disable peer name verification.
161+ *
162+ * @return self Cloned, modified instance.
163+ */
164+ public function withoutPeerNameVerification (): self
165+ {
166+ $ clone = clone $ this ;
167+ $ clone ->verifyPeerName = false ;
168+
169+ return $ clone ;
170+ }
171+
172+ /**
173+ * @return bool Whether peer verification is enabled.
174+ */
175+ public function hasPeerNameVerification (): bool
176+ {
177+ return $ this ->verifyPeerName ;
178+ }
179+
142180 /**
143181 * Maximum chain length the peer might present including the certificates in the local trust store.
144182 *
@@ -452,7 +490,7 @@ public function toStreamContextArray(): array
452490 'crypto_method ' => $ this ->toStreamCryptoMethod (),
453491 'peer_name ' => $ this ->peerName ,
454492 'verify_peer ' => $ this ->verifyPeer ,
455- 'verify_peer_name ' => $ this ->verifyPeer ,
493+ 'verify_peer_name ' => $ this ->verifyPeerName ,
456494 'verify_depth ' => $ this ->verifyDepth ,
457495 'ciphers ' => $ this ->ciphers ?? \OPENSSL_DEFAULT_STREAM_CIPHERS ,
458496 'capture_peer_cert ' => $ this ->capturePeer ,
0 commit comments