-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SecureConnector: add optional TlsPeer, this...
...allows to capture your peer certificate and/or it's chain
- Loading branch information
1 parent
28fac70
commit 313ca21
Showing
4 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace React\Socket; | ||
|
||
class TlsPeer | ||
{ | ||
private $peerCertificate; | ||
private $peerCertificateChain; | ||
|
||
public function __construct($context) | ||
{ | ||
if (isset($context['options']['ssl']['peer_certificate'])) { | ||
$this->peerCertificate = $context['options']['ssl']['peer_certificate']; | ||
} | ||
if (isset($context['options']['ssl']['peer_certificate_chain'])) { | ||
$this->peerCertificateChain = $context['options']['ssl']['peer_certificate_chain']; | ||
} | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasPeerCertificate() | ||
{ | ||
return $this->peerCertificate !== null; | ||
} | ||
|
||
/** | ||
* @return null|resource (OpenSSL x509) | ||
*/ | ||
public function getPeerCertificate() | ||
{ | ||
return $this->peerCertificate; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasPeerCertificateChain() | ||
{ | ||
return $this->peerCertificateChain !== null; | ||
} | ||
|
||
/** | ||
* @return null|array of OpenSSL x509 resources | ||
*/ | ||
public function getPeerCertificateChain() | ||
{ | ||
return $this->peerCertificateChain; | ||
} | ||
|
||
protected function free() | ||
{ | ||
if ($this->peerCertificate) { | ||
\openssl_x509_free($this->peerCertificate); | ||
$this->peerCertificate = null; | ||
} | ||
if (\is_array($this->peerCertificateChain)) { | ||
foreach ($this->peerCertificateChain as $cert) { | ||
\openssl_x509_free($cert); | ||
} | ||
$this->peerCertificateChain = null; | ||
} | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
$this->free(); | ||
} | ||
} |