Skip to content

Commit

Permalink
Added additional checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Jul 23, 2018
1 parent 991a772 commit b486f5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ protected function write($client, $data): Generator
{
yield Dispatcher::listenWrite($client);
Logger::log('worker', $this->pid, 'fwrite to', (int)$client . ' - ' . (string)$data);
@fwrite($client, $data);

if (is_resource($client)) {
$meta = stream_get_meta_data($client);

if (isset($meta['mode']) && strpos((string)$meta['mode'], '+') !== false) {
fwrite($client, $data);
}
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ public function __destruct()
/**
* Make server sockets
*
* @throws SocketException
* @throws SocketException|\Exception
* @return void
*/
protected function makeSocket(): void
{
if ($this->useSSL) {
if (!file_exists($this->cert)) {
throw new \Exception('Cert file not found');
}

$context = stream_context_create([
'ssl' => [
'local_cert' => $this->cert,
Expand Down
13 changes: 9 additions & 4 deletions src/Ssl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Ollyxar\WebSockets;

class Ssl {
class Ssl
{
public static function generateCert(string $certPath, string $pemPassPhrase): void
{
$certificateData = [
Expand All @@ -13,9 +14,13 @@ public static function generateCert(string $certPath, string $pemPassPhrase): vo
"emailAddress" => "[email protected]"
];

$privateKey = openssl_pkey_new();
$certificate = openssl_csr_new($certificateData, $privateKey);
$certificate = openssl_csr_sign($certificate, null, $privateKey, 365);
$privateKey = openssl_pkey_new([
'curve_name' => 'prime256v1',
'private_key_type' => OPENSSL_KEYTYPE_EC
]);

$certificate = openssl_csr_new($certificateData, $privateKey, ['digest_alg' => 'sha384']);
$certificate = openssl_csr_sign($certificate, null, $privateKey, 365, ['digest_alg' => 'sha384']);

$pem = [];
openssl_x509_export($certificate, $pem[0]);
Expand Down

0 comments on commit b486f5c

Please sign in to comment.