Skip to content

Commit dbb4a1a

Browse files
committed
Merge branch 'master' into tests/coverage
2 parents f56276c + 8c6da98 commit dbb4a1a

16 files changed

+569
-113
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: 97 additions & 52 deletions
Large diffs are not rendered by default.

src/Parameters/HooksCreateParameters.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@
2222

2323
class HooksCreateParameters extends BaseParameters
2424
{
25-
private ?string $callbackUrl = null;
25+
private string $callbackUrl;
2626

2727
private ?string $meetingId = null;
2828

29+
private ?string $eventId = null;
30+
2931
private ?bool $getRaw = null;
3032

3133
public function __construct(string $callbackUrl)
3234
{
3335
$this->callbackUrl = $callbackUrl;
3436
}
3537

36-
public function getCallbackUrl(): ?string
38+
public function getCallbackUrl(): string
3739
{
3840
return $this->callbackUrl;
3941
}
@@ -57,6 +59,18 @@ public function setMeetingId(string $meetingId): self
5759
return $this;
5860
}
5961

62+
public function getEventId(): ?string
63+
{
64+
return $this->eventId;
65+
}
66+
67+
public function setEventId(string $eventId): self
68+
{
69+
$this->eventId = $eventId;
70+
71+
return $this;
72+
}
73+
6074
public function getRaw(): ?bool
6175
{
6276
return $this->getRaw;

src/Parameters/HooksDestroyParameters.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222

2323
class HooksDestroyParameters extends BaseParameters
2424
{
25-
private ?string $hookId = null;
25+
private int $hookId;
2626

27-
public function __construct(string $hookId = null)
27+
public function __construct(int $hookId)
2828
{
2929
$this->hookId = $hookId;
3030
}
3131

32-
public function getHookId(): ?string
32+
public function getHookId(): int
3333
{
3434
return $this->hookId;
3535
}
3636

37-
public function setHookId(string $hookId): self
37+
public function setHookId(int $hookId): self
3838
{
3939
$this->hookId = $hookId;
4040

src/Responses/HooksCreateResponse.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,39 @@
2525
*/
2626
class HooksCreateResponse extends BaseResponse
2727
{
28-
public function getHookId(): int
28+
/**
29+
* According to documentation the hookId that needs to be used in the "destroy" command musst be of type number.
30+
* That is why the return here must be a number (= integer) too.
31+
*
32+
* But in the same time this property could be not part of the API-response in case the response failed. So it has
33+
* to return NULL as well.
34+
*
35+
* @see https://docs.bigbluebutton.org/development/webhooks/#hooksdestroy
36+
*/
37+
public function getHookId(): ?int
2938
{
39+
if (!$this->rawXml->hookID) {
40+
return null;
41+
}
42+
3043
return (int) $this->rawXml->hookID->__toString();
3144
}
3245

33-
public function isPermanentHook(): bool
46+
public function isPermanentHook(): ?bool
3447
{
48+
if (!$this->rawXml->permanentHook) {
49+
return null;
50+
}
51+
3552
return 'true' === $this->rawXml->permanentHook->__toString();
3653
}
3754

38-
public function hasRawData(): bool
55+
public function hasRawData(): ?bool
3956
{
57+
if (!$this->rawXml->rawData) {
58+
return null;
59+
}
60+
4061
return 'true' === $this->rawXml->rawData->__toString();
4162
}
4263
}

src/Responses/HooksDestroyResponse.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
*/
2626
class HooksDestroyResponse extends BaseResponse
2727
{
28-
public function removed(): bool
28+
public function removed(): ?bool
2929
{
30+
if (!$this->rawXml->removed) {
31+
return null;
32+
}
33+
3034
return 'true' === $this->rawXml->removed->__toString();
3135
}
3236
}

src/Util/UrlBuilder.php

Lines changed: 137 additions & 18 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;
@@ -36,46 +37,72 @@
3637
use BigBlueButton\Parameters\PutRecordingTextTrackParameters;
3738
use BigBlueButton\Parameters\UpdateRecordingsParameters;
3839

39-
/**
40-
* Class UrlBuilder.
41-
*/
4240
class UrlBuilder
4341
{
42+
/** @deprecated Property will be private soon. Use setter/getter instead. */
4443
protected string $hashingAlgorithm;
4544

46-
private string $securitySalt;
45+
private string $secret;
4746

48-
private string $bbbServerBaseUrl;
47+
private string $baseUrl;
4948

50-
public function __construct(string $secret, string $serverBaseUrl, string $hashingAlgorithm)
49+
public function __construct(string $secret, string $baseUrl, string $hashingAlgorithm)
5150
{
52-
$this->securitySalt = $secret;
53-
$this->bbbServerBaseUrl = $serverBaseUrl;
54-
$this->hashingAlgorithm = $hashingAlgorithm;
51+
$this->setSecret($secret);
52+
$this->setBaseUrl($baseUrl);
53+
$this->setHashingAlgorithm($hashingAlgorithm);
5554
}
5655

57-
/**
58-
* Sets the hashing algorithm.
59-
*/
60-
public function setHashingAlgorithm(string $hashingAlgorithm): void
56+
// Getters & Setters
57+
public function setSecret(string $secret): self
58+
{
59+
$this->secret = $secret;
60+
61+
return $this;
62+
}
63+
64+
public function setBaseUrl(string $baseUrl): self
65+
{
66+
// add tailing dir-separator if missing
67+
if ('/' != mb_substr($baseUrl, -1)) {
68+
$baseUrl .= '/';
69+
}
70+
71+
$this->baseUrl = $baseUrl;
72+
73+
return $this;
74+
}
75+
76+
public function setHashingAlgorithm(string $hashingAlgorithm): self
6177
{
6278
$this->hashingAlgorithm = $hashingAlgorithm;
79+
80+
return $this;
81+
}
82+
83+
public function getHashingAlgorithm(): string
84+
{
85+
return $this->hashingAlgorithm;
6386
}
6487

88+
// Basic functions
89+
6590
/**
6691
* Builds an API method URL that includes the url + params + its generated checksum.
6792
*/
6893
public function buildUrl(string $method = '', string $params = '', bool $append = true): string
6994
{
70-
return $this->bbbServerBaseUrl . 'api/' . $method . ($append ? '?' . $this->buildQs($method, $params) : '');
95+
return $this->baseUrl . 'api/' . $method . ($append ? '?' . $this->buildQs($method, $params) : '');
7196
}
7297

7398
/**
7499
* Builds a query string for an API method URL that includes the params + its generated checksum.
100+
*
101+
* @deprecated Function only used internal. Function will be private soon. No replacement.
75102
*/
76103
public function buildQs(string $method = '', string $params = ''): string
77104
{
78-
return $params . '&checksum=' . hash($this->hashingAlgorithm, $method . $params . $this->securitySalt);
105+
return $params . '&checksum=' . hash($this->hashingAlgorithm, $method . $params . $this->secret);
79106
}
80107

81108
// URL-Generators
@@ -144,18 +171,110 @@ public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $put
144171
return $this->buildUrl(ApiMethod::PUT_RECORDING_TEXT_TRACK, $putRecordingTextTrackParams->getHTTPQuery());
145172
}
146173

174+
/**
175+
* BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
176+
* Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
177+
*
178+
* @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
179+
*/
147180
public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string
148181
{
149-
return $this->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
182+
// store current hashing algorithm
183+
$hashingAlgorithm = $this->getHashingAlgorithm();
184+
185+
// change hashing algorithm for hooks
186+
$this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
187+
188+
// build URL
189+
$url = $this->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
190+
191+
// reset to 'normal' hashing algorithm
192+
$this->setHashingAlgorithm($hashingAlgorithm);
193+
194+
return $url;
150195
}
151196

197+
/**
198+
* BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
199+
* Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
200+
*
201+
* @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
202+
*/
152203
public function getHooksListUrl(): string
153204
{
154-
return $this->buildUrl(ApiMethod::HOOKS_LIST);
205+
// store current hashing algorithm
206+
$hashingAlgorithm = $this->getHashingAlgorithm();
207+
208+
// change hashing algorithm for hooks
209+
$this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
210+
211+
// build URL
212+
$url = $this->buildUrl(ApiMethod::HOOKS_LIST);
213+
214+
// reset to 'normal' hashing algorithm
215+
$this->setHashingAlgorithm($hashingAlgorithm);
216+
217+
return $url;
155218
}
156219

220+
/**
221+
* BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
222+
* Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
223+
*
224+
* @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
225+
*/
157226
public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string
158227
{
159-
return $this->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
228+
// store current hashing algorithm
229+
$hashingAlgorithm = $this->getHashingAlgorithm();
230+
231+
// change hashing algorithm for hooks
232+
$this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
233+
234+
// build URL
235+
$url = $this->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
236+
237+
// reset to 'normal' hashing algorithm
238+
$this->setHashingAlgorithm($hashingAlgorithm);
239+
240+
return $url;
241+
}
242+
243+
/**
244+
* This function defines the algorithm to be used for hooks.
245+
*
246+
* This function will evolve in phases:
247+
* - Phase 1: SHA1 as default (or superseded by environment-variable HASH_ALGO_FOR_HOOKS).
248+
* - 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).
249+
* - Phase 3: removal of this function, adaptation of the other hook-functions in this class and remove the use of env-variable HASH_ALGO_FOR_HOOKS.
250+
*
251+
* Background:
252+
* BB-Server below 3.0 are using SHA1-algorithm for hooks only, but allow higher algorithms for
253+
* other APIs. This is creating issues since the algorithm of choice is used in the urlBuilder-class
254+
* for the hashing of the checksum. This is resulting in denied requests for hooks if the algorithm
255+
* of choice is not SHA1.
256+
* The current planning for BBB-Server 3.0 (and on) is to align the hashing algorithm for hooks with
257+
* the rest of the system. Having this in mind two situations need to be covered:
258+
* - BBB-Server < 3.0 ==> SHA1 is default for hooks (even rest is using other algorithm)
259+
* - BBB-Server >= 3.0 ==> same algorithm everywhere (according to planning).
260+
*
261+
* @deprecated This function will evolve in phases and will later disappear
262+
*/
263+
private function getHashingAlgorithmForHooks(): string
264+
{
265+
// ---------------------------------- phase 1 ----------------------------------
266+
// in case this env-variable is not set, SHA1 shall be used as default (phase 1)
267+
return getenv('HASH_ALGO_FOR_HOOKS') ?: HashingAlgorithm::SHA_1;
268+
// ---------------------------------- phase 1 ----------------------------------
269+
270+
/* ---------------------------------- phase 2 ----------------------------------
271+
* if (getenv('HASH_ALGO_FOR_HOOKS')) {
272+
* 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);
273+
* }
274+
*
275+
* // in case this env-variable is not set, the 'normal' algorithm shall be used as default (phase 2)
276+
* return getenv('HASH_ALGO_FOR_HOOKS') ?: $this->getHashingAlgorithm();
277+
*
278+
* ---------------------------------- phase 2 ---------------------------------- */
160279
}
161280
}

0 commit comments

Comments
 (0)