Skip to content

Commit 721420c

Browse files
committed
Inroduce dynamic hash algo for hooks
1 parent 6d1f97d commit 721420c

File tree

5 files changed

+137
-22
lines changed

5 files changed

+137
-22
lines changed

.env

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Specify the value of your BigBlueButton secret
1+
# Specify the URL and SECRET of your BigBlueButton-Server (check on your BBB-Server with command 'bbb-conf --secret')
22
BBB_SERVER_BASE_URL="https://test-install.blindsidenetworks.com/bigbluebutton/"
3+
BBB_SECRET="8cd8ef52e8e101574e400365b55e11a6"
34

4-
# Specify the Server Base URL of your BigBlueButton
5-
BBB_SECRET="8cd8ef52e8e101574e400365b55e11a6"
5+
# SET THE HASHING ALGORITHM FOR HOOKS (BBB-SERVER < 3.0 MUST USE 'sha_1')
6+
HASH_ALGO_FOR_HOOKS="sha1"

src/BigBlueButton.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ class BigBlueButton
6464
protected string $jSessionId;
6565
protected string $hashingAlgorithm;
6666

67-
protected UrlBuilder $urlBuilder;
68-
6967
/**
7068
* @var array<int, mixed>
7169
*/
7270
protected array $curlOpts = [];
7371
protected int $timeOut = 10;
7472

73+
private UrlBuilder $urlBuilder;
74+
7575
/**
7676
* @param null|array<string, mixed> $opts
7777
*/
@@ -469,13 +469,18 @@ public function setTimeOut(int $TimeOutInSeconds): self
469469
}
470470

471471
/**
472-
* @deprecated Replaced by same function-name provided by UrlBuilder-BigBlueButton
472+
* @deprecated replaced by same function-name provided by UrlBuilder-BigBlueButton
473473
*
474-
* Public accessor for buildUrl.
474+
* Public accessor for buildUrl
475475
*/
476476
public function buildUrl(string $method = '', string $params = '', bool $append = true): string
477477
{
478-
return $this->urlBuilder->buildUrl($method, $params, $append);
478+
return $this->getUrlBuilder()->buildUrl($method, $params, $append);
479+
}
480+
481+
public function getUrlBuilder(): UrlBuilder
482+
{
483+
return $this->urlBuilder;
479484
}
480485

481486
// ____________________ INTERNAL CLASS METHODS ___________________

src/Util/UrlBuilder.php

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace BigBlueButton\Util;
2222

2323
use BigBlueButton\Core\ApiMethod;
24+
use BigBlueButton\Enum\HashingAlgorithm;
2425
use BigBlueButton\Parameters\CreateMeetingParameters;
2526
use BigBlueButton\Parameters\DeleteRecordingsParameters;
2627
use BigBlueButton\Parameters\EndMeetingParameters;
@@ -47,11 +48,16 @@ class UrlBuilder
4748

4849
private string $bbbServerBaseUrl;
4950

51+
/** @deprecated This property will disappear after a while */
52+
private string $hashAlgoForHooks;
53+
5054
public function __construct(string $secret, string $serverBaseUrl, string $hashingAlgorithm)
5155
{
5256
$this->securitySalt = $secret;
5357
$this->bbbServerBaseUrl = $serverBaseUrl;
5458
$this->hashingAlgorithm = $hashingAlgorithm;
59+
60+
$this->initiateAlgorithmForHooks();
5561
}
5662

5763
/**
@@ -62,6 +68,11 @@ public function setHashingAlgorithm(string $hashingAlgorithm): void
6268
$this->hashingAlgorithm = $hashingAlgorithm;
6369
}
6470

71+
public function getHashingAlgorithm(): string
72+
{
73+
return $this->hashingAlgorithm;
74+
}
75+
6576
/**
6677
* Builds an API method URL that includes the url + params + its generated checksum.
6778
*/
@@ -144,18 +155,94 @@ public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $put
144155
return $this->buildUrl(ApiMethod::PUT_RECORDING_TEXT_TRACK, $putRecordingTextTrackParams->getHTTPQuery());
145156
}
146157

158+
/**
159+
* BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
160+
* Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
161+
*
162+
* @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
163+
*/
147164
public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string
148165
{
149-
return $this->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
166+
// change hashing algorithm for hooks
167+
$this->setHashingAlgorithm($this->hashAlgoForHooks);
168+
169+
// build URL
170+
$url = $this->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
171+
172+
// reset to 'normal' hashing algorithm
173+
$this->setHashingAlgorithm($this->getHashingAlgorithm());
174+
175+
return $url;
150176
}
151177

178+
/**
179+
* BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
180+
* Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
181+
*
182+
* @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
183+
*/
152184
public function getHooksListUrl(): string
153185
{
154-
return $this->buildUrl(ApiMethod::HOOKS_LIST);
186+
// change hashing algorithm for hooks
187+
$this->setHashingAlgorithm($this->hashAlgoForHooks);
188+
189+
// build URL
190+
$url = $this->buildUrl(ApiMethod::HOOKS_LIST);
191+
192+
// reset to 'normal' hashing algorithm
193+
$this->setHashingAlgorithm($this->getHashingAlgorithm());
194+
195+
return $url;
155196
}
156197

198+
/**
199+
* BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
200+
* Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
201+
*
202+
* @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
203+
*/
157204
public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string
158205
{
159-
return $this->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
206+
// change hashing algorithm for hooks
207+
$this->setHashingAlgorithm($this->hashAlgoForHooks);
208+
209+
// build URL
210+
$url = $this->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
211+
212+
// reset to 'normal' hashing algorithm
213+
$this->setHashingAlgorithm($this->getHashingAlgorithm());
214+
215+
return $url;
216+
}
217+
218+
/**
219+
* Defines the algorithm to be used for hooks.
220+
*
221+
* Background: BBB-Server below 3.0 are using SHA1-algorithm for hooks. The current planning for
222+
* BBB-Server 3.0 (and on) is to align the hashing algorithm for hooks with the rest
223+
* of the system. Having this in mind the two situations need to be covered:
224+
* - BBB-Server < 3.0 ==> SHA1 is default for hooks (even rest is using other algorithm)
225+
* - BBB-Server >= 3.0 ==> same algorithm everywhere (according to planning).
226+
*
227+
* This function will evolve in phases:
228+
* - Phase 1: SHA1 as default (or superseded by environment-variable HASH_ALGO_FOR_HOOKS).
229+
* - Phase 2: same algo everywhere as default (or superseded by environment-variable HASH_ALGO_FOR_HOOKS and which will trigger in this case a deprecation-warning).
230+
* - Phase 3: removal of this function, the class-property '$hashAlgoForHooks' and the use of env-variable HASH_ALGO_FOR_HOOKS.
231+
*
232+
* @deprecated This function will evolve in phases and will later disappear
233+
*/
234+
private function initiateAlgorithmForHooks(): void
235+
{
236+
// in case this env-variable is not set, SHA1 shall be used as default (phase 1)
237+
$this->hashAlgoForHooks = getenv('HASH_ALGO_FOR_HOOKS') ?: HashingAlgorithm::SHA_1;
238+
239+
/* ---------------------------------- phase 2 ----------------------------------
240+
* // in case this env-variable is not set, the 'normal' algorithm shall be used as default (phase 2)
241+
* $this->hashAlgoForHooks = getenv('HASH_ALGO_FOR_HOOKS') ?: $this->getHashingAlgorithm();
242+
*
243+
* if (getenv('HASH_ALGO_FOR_HOOKS')) {
244+
* trigger_error('The environment variable HASH_ALGO_FOR_HOOKS will be removed soon. This will require you to run a BBB-Server 3.0 or higher!', E_USER_DEPRECATED);
245+
* }
246+
* ---------------------------------- phase 2 ---------------------------------- */
160247
}
161248
}

tests/BigBlueButtonTest.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
use BigBlueButton\Parameters\GetMeetingInfoParameters;
2828
use BigBlueButton\Parameters\GetRecordingsParameters;
2929
use BigBlueButton\Parameters\HooksCreateParameters;
30+
use BigBlueButton\Parameters\HooksDestroyParameters;
3031
use BigBlueButton\Parameters\IsMeetingRunningParameters;
3132
use BigBlueButton\Parameters\PublishRecordingsParameters;
3233
use BigBlueButton\Util\ParamsIterator;
3334
use Dotenv\Dotenv;
34-
use Tracy\Debugger;
3535

3636
/**
3737
* Class BigBlueButtonTest.
@@ -89,9 +89,9 @@ public function testApiVersion(): void
8989
// Create Meeting
9090

9191
/**
92-
* @deprecated Test will be removed together with the deprecated function from BigBlueButton::class
92+
* @deprecated test will be removed together with the deprecated function from BigBlueButton::class
9393
*
94-
* Test create meeting URL.
94+
* Test create meeting URL
9595
*/
9696
public function testCreateMeetingUrl(): void
9797
{
@@ -179,9 +179,9 @@ public function testCreateMeetingWithMultiDocument(): void
179179
// Join Meeting
180180

181181
/**
182-
* @deprecated Test will be removed together with the deprecated function from BigBlueButton::class
182+
* @deprecated test will be removed together with the deprecated function from BigBlueButton::class
183183
*
184-
* Test create join meeting URL.
184+
* Test create join meeting URL
185185
*/
186186
public function testCreateJoinMeetingUrl(): void
187187
{
@@ -233,9 +233,9 @@ public function testJoinMeeting(): void
233233
// End Meeting
234234

235235
/**
236-
* @deprecated Test will be removed together with the deprecated function from BigBlueButton::class
236+
* @deprecated test will be removed together with the deprecated function from BigBlueButton::class
237237
*
238-
* Test generate end meeting URL.
238+
* Test generate end meeting URL
239239
*/
240240
public function testCreateEndMeetingUrl(): void
241241
{
@@ -392,7 +392,32 @@ public function testHooksCreate(): void
392392
// create a hook
393393
$hooksCreateParameters = new HooksCreateParameters($this->faker->url);
394394
$hooksCreateResponse = $this->bbb->hooksCreate($hooksCreateParameters);
395-
$this->assertEquals('SUCCESS', $hooksCreateResponse->getReturnCode(), $hooksCreateResponse->getMessage());
395+
$this->assertTrue($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
396+
}
397+
398+
public function testHooksList(): void
399+
{
400+
// create a hook
401+
$hooksListResponse = $this->bbb->hooksList();
402+
$this->assertTrue($hooksListResponse->success(), $hooksListResponse->getMessage());
403+
}
404+
405+
public function testHooksDestroy(): void
406+
{
407+
// create a hook
408+
$hooksCreateParameters = new HooksCreateParameters($this->faker->url);
409+
$hooksCreateResponse = $this->bbb->hooksCreate($hooksCreateParameters);
410+
$this->assertTrue($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
411+
412+
// destroy existing hook
413+
$hooksDestroyParameters = new HooksDestroyParameters($hooksCreateResponse->getHookId());
414+
$hooksCreateResponse = $this->bbb->hooksDestroy($hooksDestroyParameters);
415+
$this->assertTrue($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
416+
417+
// destroy non-existing hook
418+
$hooksDestroyParameters = new HooksDestroyParameters($this->faker->uuid);
419+
$hooksCreateResponse = $this->bbb->hooksDestroy($hooksDestroyParameters);
420+
$this->assertFalse($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
396421
}
397422

398423
/**

tests/Parameters/HooksCreateParametersTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
namespace BigBlueButton\Parameters;
2222

2323
use BigBlueButton\TestCase;
24-
use Tracy\Debugger;
2524

2625
/**
2726
* @internal
@@ -39,12 +38,10 @@ public function testHooksCreateParameters(): void
3938
}
4039
$eventIds = implode(',', $eventIds);
4140

42-
4341
$hooksCreateParameters = new HooksCreateParameters($callBackUrl = $this->faker->url);
4442

4543
$this->assertEquals($callBackUrl, $hooksCreateParameters->getCallbackUrl());
4644

47-
4845
// Test setters that are ignored by the constructor
4946
$hooksCreateParameters->setMeetingId($meetingId = $this->faker->uuid);
5047
$hooksCreateParameters->setGetRaw($getRaw = $this->faker->boolean);

0 commit comments

Comments
 (0)