Skip to content

Commit 29908b5

Browse files
committed
Use "localhost" as peer name for certificate validation
Fixes issue caused by #2
1 parent 97c2c2a commit 29908b5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/php/peer/CryptoSocket.class.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,30 @@
55
/**
66
* Intermediate common class for all cryptographic socket classes such
77
* as SSLSocket and TLSSocket.
8+
*
9+
* @see http://php.net/manual/en/context.ssl.php
810
*/
911
class CryptoSocket extends Socket {
1012
const CTX_WRP = 'ssl'; // stream context option key
13+
1114
protected $crpytoImpl= null;
1215

16+
/**
17+
* Constructor
18+
*
19+
* @param string $host hostname or IP address
20+
* @param int $port
21+
* @param resource $socket default NULL
22+
*/
23+
public function __construct($host, $port, $socket= null) {
24+
parent::__construct($host, $port, $socket);
25+
26+
// Use "localhost" as peer name in these well-known cases.
27+
if ('localhost' === $host || '127.0.0.1' === $host || '[::1]' === $host) {
28+
$this->setSocketOption('ssl', 'peer_name', 'localhost');
29+
}
30+
}
31+
1332
/**
1433
* Connect, then enable crypto
1534
*

0 commit comments

Comments
 (0)