Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit e47b9fa

Browse files
committed
Merge pull request repejota#54 from dfeyer/task-remove-openssl
BUGFIX: Don't use openssl_random_pseudo_bytes as it break the protocol
2 parents 3149cca + 87d762b commit e47b9fa

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"minimum-stability": "dev",
66
"license": "MIT",
77
"require": {
8+
"ircmaxell/random-lib": "^1.1"
89
},
910
"require-dev": {
1011
"phpunit/phpunit": "4.7.*",

src/Connection.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace Nats;
33

4+
use RandomLib\Factory;
5+
use RandomLib\Generator;
6+
47
/**
58
* Connection Class.
69
*/
@@ -112,6 +115,11 @@ public function getSubscriptions()
112115
*/
113116
private $streamWrapper;
114117

118+
/**
119+
* @var Generator
120+
*/
121+
private $randomGenerator;
122+
115123
/**
116124
* Constructor.
117125
*
@@ -124,6 +132,8 @@ public function __construct(ConnectionOptions $options = null)
124132
$this->subscriptions = [];
125133
$this->options = $options;
126134
$this->streamWrapper = new StreamWrapper();
135+
$randomFactory = new Factory();
136+
$this->randomGenerator = $randomFactory->getLowStrengthGenerator();
127137

128138
if (is_null($options)) {
129139
$this->options = new ConnectionOptions();
@@ -296,7 +306,7 @@ public function publish($subject, $payload = null)
296306
*/
297307
public function subscribe($subject, \Closure $callback)
298308
{
299-
$sid = uniqid();
309+
$sid = $this->randomGenerator->generateString(16);
300310
$msg = 'SUB '.$subject.' '.$sid;
301311
$this->send($msg);
302312
$this->subscriptions[$sid] = $callback;
@@ -315,7 +325,7 @@ public function subscribe($subject, \Closure $callback)
315325
*/
316326
public function queueSubscribe($subject, $queue, \Closure $callback)
317327
{
318-
$sid = openssl_random_pseudo_bytes(16);
328+
$sid = $this->randomGenerator->generateString(16);
319329
$msg = 'SUB '.$subject.' '.$queue.' '. $sid;
320330
$this->send($msg);
321331
$this->subscriptions[$sid] = $callback;

0 commit comments

Comments
 (0)