New SecureToken implementation

I am implementing Streamlock to enable HTML5 video playback, but where with RTMP you can limit the domains allowed to stream, this doesn’t seem to be available for https connections using streamlock (

http://community.wowza.com/community/questions/5041/protecting-a-stream-with-allowdomains.html).

Because of that, I am looking at the SecureToken implementation but am having some pretty big problems figuring out what I am doing wrong. After going through the documentation a bit, I came across the PHP code here: https://github.com/remiheens/WowzaSecureToken

which I implemented.

For simplicity’s sake, I will just publish my secret token and change it as soon as the solution is found. In the application.xml it is set to auto accept all connections. We are using adaptive bitrate switching, so I had to leave off the playlist.m3u8 from the end of the value to hash.

Using the Github code from above, I passed it this info:

<?PHP
$wowzaToken = new \remiheens\WowzaSecureToken\WowzaSecureToken('wowzatoken','d1e37335a7154ac1');
$wowzaToken->setClientIP($_SERVER['REMOTE_ADDR']);
$wowzaToken->setURL('https://572a6f4f09a96.streamlock.net/s3/_definst_/smil:coursesaver/774/resolutions/resolutions.smil');
$wowzaToken->setHashMethod(\remiheens\WowzaSecureToken\WowzaSecureToken::SHA256);

$starttime = time();
$endtime = strtotime('+3 HOUR');
$params = array(
    'endtime' => $endtime,
    'starttime' => $starttime
);

$wowzaToken->setExtraParams($params);

$hash = $wowzaToken->getHash();

$url = $wowzaToken->getFullURL();

print_r($url);
?>

This returned back the string:

https://572a6f4f09a96.streamlock.net/s3/_definst_/smil:coursesaver/774/resolutions/resolutions.smil?wowzatokenendtime=1490057800&wowzatokenstarttime=1490047000&wowzatokenhash=OJKGG3NpAspvHDPblrp38iORlrw5CyMzhBghdz-4KHM=

which I tried to put in, but get the message: “Error loading stream: Manifest not found or invalid”. Now the docs only talked about removing the playlist.m3u8, but I modified the string to put it back in and now get this message:

“Cannot load M3U8: 403 Forbidden”

It isn’t writing anything to the log files, so I am not sure why I am getting that error, everything works just fine prior to enabling the SecureToken.

I tried simplifying the jwplayer code to bare bones for testing, this is where it is at:

    <script>

        $(function(){
            //Setup video player
            videoPlayer = jwplayer("video-object").setup({
                sources:[
                            {file: "https://572a6f4f09a96.streamlock.net/s3/_definst_/smil:coursesaver/774/resolutions/resolutions.smil/playlist.m3u8?wowzatokenendtime=1490057800&wowzatokenstarttime=1490047000&wowzatokenhash=J72sdH3Ei_w-Lu2FzhU9qZuVD4i9CQ6Ta8-RmyzyP4M="}
                        ],
                modes: [
                { type: "html5" },
                { type: "flash", src: "player.swf" }
                ]
            });

        });

    </script>

It started working, and I have no idea why. This was my final PHP code that I ended up with, then you just echo back the $playbackURL into the “file” object.

<?php
$clientIP = null; // provide client IP optionally
$host = "572a6f4f09a96.streamlock.net"; // your ip/host
$url= "https://".$host."/";
$stream = "s3/_definst_/smil:coursesaver/774/resolutions/resolutions.smil"; // your stream
$start = time();
$end = strtotime("+30 minutes");

$secret = "d1e37335a7154ac1";
$tokenName = "wowzatoken";

$hash = "";
if(is_null($clientIP)){
    $hash = hash('sha256', $stream."?".$secret."&{$tokenName}endtime=".$end."&{$tokenName}starttime=".$start, true); // generate the hash string
}

else{
    $hash = hash('sha256', $stream."?".$clientIP."&".$secret."&{$tokenName}endtime=".$end."&{$tokenName}starttime=".$start, true); // generate the hash string
}

$base64Hash = strtr(base64_encode($hash), '+/', '-_');
$params = array("{$tokenName}starttime=".$start, "{$tokenName}endtime=".$end, "{$tokenName}hash=".$base64Hash);

if(!is_null($clientIP)){
    $params[] = $clientIP;
}

sort($params);

$playbackURL = $url.$stream."/playlist.m3u8?";

if(preg_match("/(rtmp)/",$url)){
    $playbackURL = $url.$stream."?";
}

foreach($params as $entry){
    $playbackURL.= $entry."&";
}

$playbackURL = preg_replace("/(\&)$/","", $playbackURL);

?>

I really wish I knew what made it work, because I have 5 more servers to configure, but hopefully I will figure it out along the way.

Hello ! Can you help me with a complete SecureToken v2 script and configuration details for JWplayer? For a long time I have this problem and I can not configure a token generation script or how to configure the JWplayer player.