Skip to content

Commit

Permalink
Merge pull request #96 from kaltura/from-v2.9-to-PSVAMB-43876-fix-ks-…
Browse files Browse the repository at this point in the history
…when-ac-is-on

PSVAMB-43876-fix-ks-when-ac-is-on
  • Loading branch information
adimachmali authored Oct 31, 2023
2 parents dfe59f6 + be62b2e commit 2cb15d9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
28 changes: 18 additions & 10 deletions lib/Kaltura/Client/ClientBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,16 +888,24 @@ public static function generateSessionV2($adminSecretForSigning, $userId, $type,
return str_replace(array('+', '/'), array('-', '_'), base64_encode($decodedKs));
}

protected static function aesEncrypt($key, $message)
{
return mcrypt_encrypt(
MCRYPT_RIJNDAEL_128,
substr(sha1($key, true), 0, 16),
$message,
MCRYPT_MODE_CBC,
str_repeat("\0", 16) // no need for an IV since we add a random string to the message anyway
);
}
protected static function aesEncrypt($key, $message)
{
$iv = str_repeat("\0", 16); // no need for an IV since we add a random string to the message anyway
$key = substr(sha1($key, true), 0, 16);
if (function_exists('openssl_encrypt')) {
// Pad with null byte to be compatible with mcrypt PKCS#5 padding
// See http://thefsb.tumblr.com/post/110749271235/using-opensslendecrypt-in-php-instead-of as reference
$blockSize = 16;
if (strlen($message) % $blockSize) {
$padLength = $blockSize - strlen($message) % $blockSize;
$message .= str_repeat("\0", $padLength);
}

return openssl_encrypt($message, 'AES-128-CBC', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
}

return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $message, MCRYPT_MODE_CBC, $iv);
}

private function hash ( $salt , $str )
{
Expand Down
11 changes: 11 additions & 0 deletions lib/KalturaHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ public static function getOption( $name, $default = null ) {
return $default;
}
}

public static function generateKSForPlayer($entryId) {
$adminSecret = sanitize_text_field(KalturaHelpers::getOption( 'kaltura_admin_secret' ));
$userId = ''; // anonymous user
$clientType = Kaltura_Client_Enum_SessionType::ADMIN;
$partnerId = intval( KalturaHelpers::getOption( 'kaltura_partner_id' ) );
$privileges = 'sview:'. $entryId . ',setrole:PLAYBACK_BASE_ROLE';
$ks = Kaltura_Client_ClientBase::generateSessionV2($adminSecret, $userId, $clientType, $partnerId, 86400, $privileges);

return $ks;
}

public static function getPlayerDimension() {
$name = 'kaltura_default_player_dimensions';
Expand Down
2 changes: 1 addition & 1 deletion lib/KalturaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class KalturaModel {
protected $_partnerId = null;


private function KalturaModel() {
private function __construct() {
$config = KalturaHelpers::getKalturaConfiguration();
$this->_client = new KalturaWordpressClientBase( $config );
$this->_userId = sanitize_user( KalturaHelpers::getLoggedUserId() );
Expand Down
17 changes: 11 additions & 6 deletions view/embed-code.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
$scriptSrc = KalturaHelpers::getServerUrl() . '/p/' . KalturaHelpers::getOption( 'kaltura_partner_id' ) . '/sp/' . KalturaHelpers::getOption( 'kaltura_partner_id' ) . '00/embedIframeJs/uiconf_id/' . (int)$embedOptions['uiconfid'] . '/partner_id/' . KalturaHelpers::getOption( 'kaltura_partner_id' );
$flashVars = $embedOptions['flashVars'];
$isPlaylist = $embedOptions['isPlaylist'];

$ks = KalturaHelpers::generateKSForPlayer($entryId);
?>

<script src="<?php echo esc_url($scriptSrc); ?>"></script>
Expand Down Expand Up @@ -83,12 +85,15 @@

<?php if(!$isPlaylist) : ?>
<script>
kWidget.embed({
"targetId": <?php echo wp_json_encode($playerId); ?>,
"wid": <?php echo wp_json_encode($wid); ?>,
"uiconf_id": <?php echo wp_json_encode($embedOptions['uiconfid']); ?>,
"entry_id": <?php echo wp_json_encode($entryId); ?>,
});
kWidget.embed({
"targetId": <?php echo wp_json_encode($playerId); ?>,
"wid": <?php echo wp_json_encode($wid); ?>,
"uiconf_id": <?php echo wp_json_encode($embedOptions['uiconfid']); ?>,
"entry_id": <?php echo wp_json_encode($entryId); ?>,
"flashvars": {
"ks": <?php echo wp_json_encode($ks); ?>,
}
});
</script>

<?php else: ?>
Expand Down

0 comments on commit 2cb15d9

Please sign in to comment.