Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9413 from kaltura/Propus-16.2.0-PLAT-10806
PLAT-10806 authenticate uri
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* @package server-infra | ||
* @subpackage request | ||
*/ | ||
class kNetworkUtils | ||
{ | ||
const KALTURA_AUTH_HEADER = 'HTTP_X_KALTURA_AUTH'; | ||
/** | ||
* @return bool | ||
* @throws Exception | ||
*/ | ||
public static function isAuthenticatedURI() | ||
{ | ||
if (!isset($_SERVER[self::KALTURA_AUTH_HEADER])) | ||
{ | ||
KalturaLog::warning("Missing Header Parameter - ". self::KALTURA_AUTH_HEADER); | ||
return false; | ||
} | ||
$xKalturaAuth = $_SERVER[self::KALTURA_AUTH_HEADER]; | ||
$parts = explode(',', $xKalturaAuth); | ||
if (count($parts) != 3) | ||
{ | ||
KalturaLog::warning('Invalid Fromat for ' . self::KALTURA_AUTH_HEADER); | ||
return false; | ||
} | ||
|
||
$version = $parts[0]; | ||
$timestamp = $parts[1]; | ||
$expectedSignature = $parts[2]; | ||
$url = $_SERVER['REQUEST_URI']; | ||
$secret = kConf::get('authentication_secret','local', null); | ||
if (!$secret) | ||
{ | ||
KalturaLog::warning("Missing authentication_secret in configuration"); | ||
return false; | ||
} | ||
|
||
$actualSignature = base64_encode(hash_hmac('sha256', "$version,$timestamp,$url", $secret, true)); | ||
KalturaLog::debug("Actual Signature [$actualSignature] - Expected Signature [$expectedSignature]" ); | ||
if ( $actualSignature !== $expectedSignature) | ||
{ | ||
KalturaLog::warning("Could not authenticate X-Kaltura-Auth"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters