Skip to content

Commit 75219d6

Browse files
committed
Support all BigBlueButton hashing algorithms.
1 parent 5dbfd9d commit 75219d6

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

src/BigBlueButton.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace BigBlueButton;
2222

2323
use BigBlueButton\Core\ApiMethod;
24+
use BigBlueButton\Enum\HashingAlgorithm;
2425
use BigBlueButton\Exceptions\BadResponseException;
2526
use BigBlueButton\Parameters\CreateMeetingParameters;
2627
use BigBlueButton\Parameters\DeleteRecordingsParameters;
@@ -64,6 +65,9 @@ class BigBlueButton
6465
protected $bbbServerBaseUrl;
6566
protected $urlBuilder;
6667
protected $jSessionId;
68+
69+
protected $hashingAlgorithm;
70+
6771
protected $curlopts = [];
6872
protected $timeOut = 10;
6973

@@ -80,10 +84,17 @@ public function __construct($baseUrl = null, $secret = null, $opts = null)
8084
// BBB_SECRET is the new variable name and have higher priority against the old named BBB_SECURITY_SALT
8185
$this->securitySecret = $secret ?: getenv('BBB_SECRET') ?: getenv('BBB_SECURITY_SALT');
8286
$this->bbbServerBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL');
83-
$this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl);
87+
$this->hashingAlgorithm = HashingAlgorithm::SHA_256;
88+
$this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl, $this->hashingAlgorithm);
8489
$this->curlopts = $opts['curl'] ?? [];
8590
}
8691

92+
public function setHashingAlgorithm(string $hashingAlgorithm): void
93+
{
94+
$this->hashingAlgorithm = $hashingAlgorithm;
95+
$this->urlBuilder->setHashingAlgorithm($hashingAlgorithm);
96+
}
97+
8798
/**
8899
* @return ApiVersionResponse
89100
*

src/Enum/HashingAlgorithm.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5+
*
6+
* Copyright (c) 2016-2023 BigBlueButton Inc. and by respective authors (see below).
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the
9+
* terms of the GNU Lesser General Public License as published by the Free Software
10+
* Foundation; either version 3.0 of the License, or (at your option) any later
11+
* version.
12+
*
13+
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License along
18+
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
namespace BigBlueButton\Enum;
22+
23+
use MabeEnum\Enum;
24+
25+
class HashingAlgorithm extends Enum
26+
{
27+
public const SHA_1 = 'sha1';
28+
public const SHA_256 = 'sha256';
29+
public const SHA_512 = 'sha512';
30+
public const SHA_384 = 'sha384';
31+
}

src/Util/UrlBuilder.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class UrlBuilder
2727
{
28+
protected $hashingAlgorithm;
29+
2830
/**
2931
* @var string
3032
*/
@@ -40,11 +42,21 @@ class UrlBuilder
4042
*
4143
* @param mixed $secret
4244
* @param mixed $serverBaseUrl
45+
* @param mixed $hashingAlgorithm
4346
*/
44-
public function __construct($secret, $serverBaseUrl)
47+
public function __construct($secret, $serverBaseUrl, $hashingAlgorithm)
4548
{
4649
$this->securitySalt = $secret;
4750
$this->bbbServerBaseUrl = $serverBaseUrl;
51+
$this->hashingAlgorithm = $hashingAlgorithm;
52+
}
53+
54+
/**
55+
* Sets the hashing algorithm.
56+
*/
57+
public function setHashingAlgorithm(string $hashingAlgorithm): void
58+
{
59+
$this->hashingAlgorithm = $hashingAlgorithm;
4860
}
4961

5062
/**
@@ -71,6 +83,6 @@ public function buildUrl($method = '', $params = '', $append = true)
7183
*/
7284
public function buildQs($method = '', $params = '')
7385
{
74-
return $params . '&checksum=' . sha1($method . $params . $this->securitySalt);
86+
return $params . '&checksum=' . hash($this->hashingAlgorithm, $method . $params . $this->securitySalt);
7587
}
7688
}

0 commit comments

Comments
 (0)