Lukas Kubanek Lukas Kubanek - 1 year ago 169
iOS Question

Private HTTP Live Streaming via CloudFront

I am working on an iOS app which allows downloading and HTTP live streaming of private videos. The videos are stored in an Amazon S3 bucket (as

and segmented as
files). Also CloudFront is turned on and connected to the bucket.

Since the content is private, I need to sign the URLs when connecting via CloudFront. In order to sign the URLs it's necessary to use the private key and therefore it's not possible to generate signed URLs in the iOS app without storing the private key in the bundle. And that would be a bad idea!

So I decided to write a simple Ruby server, which performs the URL signing and redirects to the generated signed CloudFront URL as follows:



For video downloads it works well, since there is only one request. But when I want the content streamed and give the
the URL of the signing server, only the first request is signed by the server and redirected to CloudFront. For the next requests the
takes the first signed CloudFront URL as the base and tries to connect directly without going throw the signing server.

The paths in the
files are relative.

Any suggestions how to implement this feature without the need to send all the content through the signing server?

Answer Source

The correct way to do private HLS with S3/CloudFront or any other storage/CDN is to use HLS encryption. See the Apple documentation about this topic.

In addition to the storage where your playlists and segmented video files are stored you have to integrate a secure HTTPS server for storing the top level playlists and keys. These keys are generated during the segmenting using the Apple HLS tools.

Here is how it works:

  1. The MPMoviePlayerController gets an URL pointing to the top level playlist (.m3u8) on the secure HTTPS sever.
  2. In this file there are links to the variant playlists (prog_index.m3u8) which are stored in S3/CloudFront and which point to the video files (.ts).
  3. Additionally the variant playlists contain a link to the keys which are necessary in order to read the video files. These keys are stored on the secure HTTPS server as well.

See the following image:

Protecting HLS Keys

Taken from the presentation Mobile Movies with HTTP LIve Streaming (CocoaConf DC, Jun '12)

Of course there are possibilities to make the infrastructure more secure, see the linked Apple documentation.

I also created a Ruby script for segmenting to produce the output with given base URLs, which makes things a lot simpler.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download